more OOP and restructure utils
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
session_start();
|
||||
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/FileUploader.php';
|
||||
|
||||
$id = (int)$data['id'];
|
||||
|
||||
@@ -57,6 +58,7 @@
|
||||
sku = :sku,
|
||||
price = :price,
|
||||
min_stock = :min_stock,
|
||||
reorder_point = :reorder_point,
|
||||
category = :category,
|
||||
product_image = :product_image,
|
||||
`description` = :description,
|
||||
@@ -72,6 +74,7 @@
|
||||
":sku" => $data["sku"],
|
||||
":price" => $data["price"],
|
||||
":min_stock" => $data["min_stock"],
|
||||
":reorder_point" => $data["reorder_point"],
|
||||
":category" => $data["category"],
|
||||
":product_image"=> $db_image_string,
|
||||
":description" => $data["description"],
|
||||
@@ -82,9 +85,9 @@
|
||||
} else {
|
||||
|
||||
$sql = "INSERT INTO md_product
|
||||
(company_id, product_name, sku, price, min_stock, category, product_image, `description`, `status`, `log`)
|
||||
(company_id, product_name, sku, price, min_stock, reorder_point, category, product_image, `description`, `status`, `log`)
|
||||
VALUES
|
||||
(:company_id, :product_name, :sku, :price, :min_stock, :category, :product_image, :description, :status, :log)";
|
||||
(:company_id, :product_name, :sku, :price, :min_stock, :reorder_point, :category, :product_image, :description, :status, :log)";
|
||||
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([
|
||||
@@ -93,6 +96,7 @@
|
||||
":sku" => $data["sku"],
|
||||
":price" => $data["price"],
|
||||
":min_stock" => $data["min_stock"],
|
||||
":reorder_point" => $data["reorder_point"],
|
||||
":category" => $data["category"],
|
||||
":product_image"=> $db_image_string,
|
||||
":description" => $data["description"],
|
||||
|
||||
@@ -3,10 +3,14 @@
|
||||
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM md_product
|
||||
$sql = "SELECT a.* , IFNULL(SUM(b.total_in-b.total_out),0) AS product_balance
|
||||
FROM md_product a
|
||||
LEFT JOIN warehouse_balance b ON
|
||||
a.company_id = b.company_id AND
|
||||
a.sku = b.product_sku
|
||||
WHERE
|
||||
company_id = {$company_id}";
|
||||
a.company_id = {$company_id}
|
||||
GROUP BY a.id";
|
||||
$sth = $pdo2->prepare($sql);
|
||||
$sth->execute([
|
||||
":company_id" => $company_id
|
||||
|
||||
@@ -3,10 +3,14 @@
|
||||
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM md_product_category
|
||||
$sql = "SELECT a.* , COUNT(b.id) AS product_count
|
||||
FROM md_product_category a
|
||||
LEFT JOIN md_product b ON
|
||||
a.company_id = b.company_id AND
|
||||
a.id = b.category
|
||||
WHERE
|
||||
company_id = {$company_id}";
|
||||
a.company_id = {$company_id}
|
||||
GROUP BY a.id";
|
||||
$sth = $pdo2->prepare($sql);
|
||||
$sth->execute([
|
||||
":company_id" => $company_id
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/Reports.php';
|
||||
|
||||
$report = new Reports($pdo2, $company_id);
|
||||
|
||||
$answer["total_category"] = $report->getTotalCategory();
|
||||
$answer["active_category"] = $report->getActiveCategory();
|
||||
$answer["inactive_category"] = $report->getInactiveCategory();
|
||||
$answer["total_product"] = $report->getTotalProduct();
|
||||
$answer["success"] = 1;
|
||||
exit(json_encode($answer));
|
||||
|
||||
?>
|
||||
@@ -3,10 +3,17 @@
|
||||
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
|
||||
$sql = "SELECT a.*
|
||||
$sql = "SELECT a.*, IFNULL(COUNT(DISTINCT b.product_sku), 0) AS unique_product,
|
||||
c.name AS manager_name, c.surname AS manager_surname
|
||||
FROM md_warehouse a
|
||||
LEFT JOIN warehouse_balance b ON
|
||||
a.company_id = b.company_id AND
|
||||
a.id = b.warehouse_id
|
||||
LEFT JOIN wms.user c ON
|
||||
a.manager = c.user_id
|
||||
WHERE
|
||||
a.company_id = :company_id";
|
||||
a.company_id = :company_id
|
||||
GROUP BY a.id";
|
||||
$sth = $pdo2->prepare($sql);
|
||||
$sth->execute([
|
||||
":company_id" => $company_id
|
||||
@@ -14,20 +21,6 @@
|
||||
db_check($sth, $answer);
|
||||
|
||||
$answer["output"] = $sth->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// modify output
|
||||
foreach($answer["output"] as $key => $item){
|
||||
// status
|
||||
if($item["status"]==1){
|
||||
$answer["output"][$key]["status"] = 'Active';
|
||||
$answer["output"][$key]["bg_class"] = 'success';
|
||||
}else{
|
||||
$answer["output"][$key]["status"] = 'Inactive';
|
||||
$answer["output"][$key]["bg_class"] = 'secondary';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$answer["success"] = 1;
|
||||
exit(json_encode($answer));
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/Reports.php';
|
||||
|
||||
$report = new Reports($pdo2, $company_id);
|
||||
|
||||
$answer["total_warehouse"] = $report->getTotalWarehouse();
|
||||
$answer["total_location"] = $report->getTotalLocation();
|
||||
$answer["total_capacity"] = $report->getTotalCapacity();
|
||||
$answer["total_product"] = $report->getTotalProduct();
|
||||
$answer["success"] = 1;
|
||||
|
||||
exit(json_encode($answer));
|
||||
|
||||
?>
|
||||
@@ -43,17 +43,28 @@
|
||||
<label for="price" class="form-label">Price</label>
|
||||
<input type="number" class="form-control" id="price" placeholder="0.00" step="0.01" required>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="min_stock" class="form-label">min_stock</label>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label for="min_stock" class="form-label">Min Stock</label>
|
||||
<input type="number" class="form-control" id="min_stock" placeholder="0" required>
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label for="reorder_point" class="form-label">Reorder Point</label>
|
||||
<input type="number" class="form-control" id="reorder_point" placeholder="0" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<div class="col-md-3 mb-3">
|
||||
<label for="category" class="form-label">Category</label>
|
||||
<select class="form-select" id="category" required> </select>
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label for="status" class="form-label">status</label>
|
||||
<select class="form-select" id="status" required>
|
||||
<option value="1">Active</option>
|
||||
<option value="0">inactive</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<!-- Remove d-none from file input so it shows by default -->
|
||||
<div class="mb-3">
|
||||
@@ -109,7 +120,7 @@
|
||||
url: "<?php echo $server_url?>inventory/api/engine/manage_product.php",
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
debugMode: 1,
|
||||
debugMode: 0,
|
||||
formData: formData,
|
||||
action: 'manage',
|
||||
onSuccess: function(res) {
|
||||
|
||||
@@ -40,10 +40,17 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<div class="col-md-3 mb-3">
|
||||
<label for="manager" class="form-label">Manager</label>
|
||||
<select class="form-select" id="manager" required> </select>
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label for="status" class="form-label">status</label>
|
||||
<select class="form-select" id="status" required>
|
||||
<option value="1">Active</option>
|
||||
<option value="0">inactive</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="capacity" class="form-label">Capacity</label>
|
||||
<input type="number" class="form-control" id="capacity" placeholder="0.00" step="0.01" required>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
</div>
|
||||
<div class="">
|
||||
<span>Total Categories</span>
|
||||
<h2 class="fw-bold mb-0">6</h2>
|
||||
<h2 class="fw-bold mb-0" id="total_category">6</h2>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -52,7 +52,7 @@
|
||||
</div>
|
||||
<div class="">
|
||||
<span>Active</span>
|
||||
<h2 class="fw-bold mb-0">5</h2>
|
||||
<h2 class="fw-bold mb-0" id="active_category">5</h2>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -71,7 +71,7 @@
|
||||
</div>
|
||||
<div class="">
|
||||
<span>Inactive</span>
|
||||
<h2 class="fw-bold mb-0">1</h2>
|
||||
<h2 class="fw-bold mb-0" id="inactive_category">1</h2>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -90,7 +90,7 @@
|
||||
</div>
|
||||
<div class="">
|
||||
<span>Total Products</span>
|
||||
<h2 class="fw-bold mb-0">356</h2>
|
||||
<h2 class="fw-bold mb-0" id="total_product">356</h2>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -194,6 +194,7 @@
|
||||
<th>SKU</th>
|
||||
<th>Current Stock</th>
|
||||
<th>Min Stock</th>
|
||||
<th>Reorder Point</th>
|
||||
<th>Status</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
@@ -217,6 +218,29 @@
|
||||
<?php require "../include_ending.php";?>
|
||||
|
||||
<script>
|
||||
function retrieve_stats() {
|
||||
|
||||
return ajax_request({
|
||||
url: "<?php echo $server_url?>inventory/api/engine/product_stats.php",
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
action: 'read',
|
||||
debugMode: 0,
|
||||
onSuccess: function(res) {
|
||||
|
||||
$("#total_category").text(res.total_category);
|
||||
$("#active_category").text(res.active_category);
|
||||
$("#inactive_category").text(res.inactive_category);
|
||||
$("#total_product").text(res.total_product);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function retrieve_category() {
|
||||
|
||||
return ajax_request({
|
||||
@@ -224,6 +248,7 @@
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
action: 'read',
|
||||
debugMode: 0,
|
||||
onSuccess: function(res) {
|
||||
|
||||
// Register the array as a table name
|
||||
@@ -271,6 +296,7 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
function change_page_category(page_num) {
|
||||
|
||||
var offset = (page_num - 1) * prop_limit;
|
||||
@@ -283,9 +309,9 @@
|
||||
<td class="py-3">${item['category']}</td>
|
||||
<td class="py-3">${item['slug']}</td>
|
||||
<td class="py-3">${item['description']}</td>
|
||||
<td class="py-3">${item['status']}</td>
|
||||
<td class="py-3">${item['product_count']}</td>
|
||||
<td class="py-3">
|
||||
${(item['status'])?'<span class="badge bg-success">Active</span>':'<span class="badge bg-secondary">Inactive</span>'}
|
||||
${(item['status']==1)?'<span class="badge bg-success">Active</span>':'<span class="badge bg-secondary">Inactive</span>'}
|
||||
</td>
|
||||
<td class="py-3">
|
||||
<a href="<?php echo $server_url?>inventory/manage_category.php?id=${item['id']}" class=""><i class="ti ti-eye fs-5"></i></a>
|
||||
@@ -332,6 +358,7 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
function change_page_product(page_num) {
|
||||
|
||||
var offset = (page_num - 1) * prop_limit;
|
||||
@@ -343,10 +370,11 @@
|
||||
body += `<tr>
|
||||
<td class="py-3">${item['product_name']}</td>
|
||||
<td class="py-3">${item['sku']}</td>
|
||||
<td class="py-3">${item['description']}</td>
|
||||
<td class="py-3" style='text-align: right;'>${format_number(item['product_balance'],4)}</td>
|
||||
<td class="py-3" style='text-align: right;'>${format_number(item['min_stock'],2)}</td>
|
||||
<td class="py-3" style='text-align: right;'>${format_number(item['reorder_point'],2)}</td>
|
||||
<td class="py-3">
|
||||
${(item['status'])?'<span class="badge bg-success">Active</span>':'<span class="badge bg-secondary">Inactive</span>'}
|
||||
${(item['status']==1)?'<span class="badge bg-success">Active</span>':'<span class="badge bg-secondary">Inactive</span>'}
|
||||
</td>
|
||||
<td class="py-3">
|
||||
<a href="<?php echo $server_url?>inventory/manage_product.php?id=${item['id']}" class=""><i class="ti ti-eye fs-5"></i></a>
|
||||
@@ -361,6 +389,7 @@
|
||||
|
||||
$(async function() {
|
||||
try {
|
||||
await retrieve_stats();
|
||||
await retrieve_category();
|
||||
await retrieve_product();
|
||||
} catch (e) {
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<div class="card ">
|
||||
<div class="card-body p-0">
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap ">
|
||||
<div class=" p-6 flex-grow-1 d-flex justify-content-between">
|
||||
<div class=" p-6 flex-grow-1 d-flex justify-content-between" id="total_warehouse">
|
||||
<div class="d-flex flex-column">
|
||||
<span class="fs-2 fw-bold mb-3 d-block">5</span>
|
||||
<span class="fs-5">Total Warehouses</span>
|
||||
@@ -50,7 +50,7 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class=" p-6 flex-grow-1 d-flex justify-content-between">
|
||||
<div class=" p-6 flex-grow-1 d-flex justify-content-between" id="total_capacity">
|
||||
<div class="d-flex flex-column">
|
||||
<span class="fs-2 fw-bold mb-3 d-block">41,000</span>
|
||||
<span class="fs-5">Total Capacity</span>
|
||||
@@ -78,7 +78,7 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class=" p-6 flex-grow-1 d-flex justify-content-between">
|
||||
<div class=" p-6 flex-grow-1 d-flex justify-content-between" id="total_space_used">
|
||||
<div class="d-flex flex-column">
|
||||
<span class="fs-2 fw-bold mb-3 d-block">25,500</span>
|
||||
<span class="fs-5">Space Used</span>
|
||||
@@ -101,7 +101,7 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="-0 p-6 flex-grow-1 d-flex justify-content-between">
|
||||
<div class="-0 p-6 flex-grow-1 d-flex justify-content-between" id="total_product">
|
||||
<div class="d-flex flex-column">
|
||||
<span class="fs-2 fw-bold mb-3 d-block">730</span>
|
||||
<span class="fs-5">Total Products</span>
|
||||
@@ -251,6 +251,30 @@
|
||||
<?php require "../include_ending.php";?>
|
||||
|
||||
<script>
|
||||
function retrieve_stats() {
|
||||
|
||||
return ajax_request({
|
||||
url: "<?php echo $server_url?>inventory/api/engine/warehouse_stats.php",
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
action: 'read',
|
||||
onSuccess: function(res) {
|
||||
|
||||
$("#total_warehouse span.fs-2").text(res.total_warehouse);
|
||||
$("#total_warehouse small.text-info").text(`Across ${res.total_location} locations`);
|
||||
|
||||
$("#total_capacity span.fs-2").text(format_number(res.total_capacity,2));
|
||||
|
||||
$("#total_product span.fs-2").text(res.total_product);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function retrieve_warehouse() {
|
||||
|
||||
return ajax_request({
|
||||
@@ -294,11 +318,11 @@
|
||||
body += `<tr>
|
||||
<td class="py-3">${item['warehouse_name']}</td>
|
||||
<td class="py-3">${item['location']}</td>
|
||||
<td class="py-3">${item['manager']}</td>
|
||||
<td class="py-3">${item['manager_name']} ${item['manager_surname']}</td>
|
||||
<td class="py-3" style='text-align: right;'>${format_number(item['capacity'],2)}</td>
|
||||
<td class="py-3">${item['product']}</td>
|
||||
<td class="py-3">${item['unique_product']}</td>
|
||||
<td class="py-3">
|
||||
<span class="badge bg-${item['bg_class']}">${item.status}</span>
|
||||
${(item['status']==1)?'<span class="badge bg-success">Active</span>':'<span class="badge bg-secondary">Inactive</span>'}
|
||||
</td>
|
||||
<td class="py-3">
|
||||
<a href="<?php echo $server_url?>inventory/manage_warehouse.php?id=${item['id']}" class=""><i class="ti ti-eye fs-5"></i></a>
|
||||
@@ -371,6 +395,7 @@
|
||||
|
||||
$(async function() {
|
||||
try {
|
||||
await retrieve_stats();
|
||||
await retrieve_warehouse();
|
||||
await retrieve_storage();
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user