ICS modules

This commit is contained in:
Thanakorn S
2026-03-21 14:58:15 +07:00
parent 2e558a55bb
commit a4f474b5df
45 changed files with 3110 additions and 597 deletions
+25
View File
@@ -0,0 +1,25 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
$sql = "SELECT *
FROM md_contact
WHERE
company_id = :company_id and
contact_name like :keyword
LIMIT 50
";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":keyword" => '%'.$data["keyword"].'%'
]);
db_check($sth, $answer);
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
$answer["result"] = $result;
$answer["success"] = 1;
exit(json_encode($answer));
?>
+87
View File
@@ -0,0 +1,87 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
try {
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging, $uuid, &$answer) {
$id = (int)$data['id'];
$warehouse_id = (int)$data["warehouse"];
$whMgmt = new WarehouseManager($pdo, $company_id);
$warehouse = $whMgmt->getStockContext($warehouse_id, $id);
$row = $warehouse['row'] ?? [];
$table = $warehouse['table'];
$table_log = json_decode($row['log'] ?? '[]', true);
$table_log[] = $logging;
if ($id > 0) {
$sql = "UPDATE `$table` SET
`product_sku` = :product_sku,
`in` = :quantity,
`zone` = :zone,
`aisle` = :aisle,
`rack` = :rack,
`contact_id` = :contact_id,
`description` = :description,
`log` = :log
WHERE id = :id AND company_id = :company_id";
$sth = $pdo->prepare($sql);
$sth->execute([
":id" => $id,
":company_id" => $company_id,
":product_sku" => $data["product_sku"],
":quantity" => $data["quantity"],
":zone" => $data["zone"],
":aisle" => $data["aisle"],
":rack" => $data["rack"],
":contact_id" => (int)$data["contact_id"],
":description" => $data["description"],
":log" => json_encode($table_log),
]);
} else {
$sql = "INSERT INTO `$table`
(uuid, company_id, `date`, product_sku, `in`, zone, aisle, rack, contact_id, `description`, `log`, `type`)
VALUES
(:uuid, :company_id, :date, :product_sku, :quantity, :zone, :aisle, :rack, :contact_id, :description, :log, 'in')";
$sth = $pdo->prepare($sql);
$sth->execute([
":uuid" => $uuid,
":company_id" => $company_id,
":date" => date('Y-m-d H:i:s'),
":product_sku" => $data["product_sku"],
":quantity" => $data["quantity"],
":zone" => $data["zone"],
":aisle" => $data["aisle"],
":rack" => $data["rack"],
":contact_id" => (int)$data["contact_id"],
":description" => $data["description"],
":log" => json_encode($table_log),
]);
}
$whMgmt->adjustBalance('in', $warehouse_id, $data["product_sku"], $row['in'] ?? 0, $data["quantity"]);
});
$answer["success"] = 1;
} catch (PDOException $e) {
$answer["success"] = 0;
$answer["message"] = "Database error, please try again";
} catch (Exception $e) {
$answer["success"] = 0;
$answer["message"] = "Something went wrong";
}
exit(json_encode($answer));
?>
+87
View File
@@ -0,0 +1,87 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
try {
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging, $uuid) {
$id = (int)$data['id'];
$warehouse_id = (int)$data["warehouse"];
$whMgmt = new WarehouseManager($pdo, $company_id);
$warehouse = $whMgmt->getStockContext($warehouse_id, $id);
$row = $warehouse['row'] ?? [];
$table = $warehouse['table'];
$table_log = json_decode($row['log'] ?? '[]', true);
$table_log[] = $logging;
if ($id > 0) {
$sql = "UPDATE `$table` SET
`product_sku` = :product_sku,
`out` = :quantity,
`zone` = :zone,
`aisle` = :aisle,
`rack` = :rack,
`contact_id` = :contact_id,
`description` = :description,
`log` = :log
WHERE id = :id AND company_id = :company_id";
$sth = $pdo->prepare($sql);
$sth->execute([
":id" => $id,
":company_id" => $company_id,
":product_sku" => $data["product_sku"],
":quantity" => $data["quantity"],
":zone" => $data["zone"],
":aisle" => $data["aisle"],
":rack" => $data["rack"],
":contact_id" => (int)$data["contact_id"],
":description" => $data["description"],
":log" => json_encode($table_log),
]);
} else {
$sql = "INSERT INTO `$table`
(uuid, company_id, `date`, product_sku, `out`, zone, aisle, rack, contact_id, `description`, `log`, `type`)
VALUES
(:uuid, :company_id, :date, :product_sku, :quantity, :zone, :aisle, :rack, :contact_id, :description, :log, 'out')";
$sth = $pdo->prepare($sql);
$sth->execute([
":uuid" => $uuid,
":company_id" => $company_id,
":date" => date('Y-m-d H:i:s'),
":product_sku" => $data["product_sku"],
":quantity" => $data["quantity"],
":zone" => $data["zone"],
":aisle" => $data["aisle"],
":rack" => $data["rack"],
":contact_id" => (int)$data["contact_id"],
":description" => $data["description"],
":log" => json_encode($table_log),
]);
}
$whMgmt->adjustBalance('out', $warehouse_id, $data["product_sku"], $row['out'] ?? 0, $data["quantity"]);
});
$answer["success"] = 1;
} catch (PDOException $e) {
$answer["success"] = 0;
$answer["message"] = "Database error, please try again";
} catch (Exception $e) {
$answer["success"] = 0;
$answer["message"] = "Something went wrong";
}
exit(json_encode($answer));
?>
@@ -0,0 +1,113 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
try {
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging, $uuid) {
$id = (int)$data['id'];
$whMgmt = new WarehouseManager($pdo, $company_id);
for ($i = 0; $i < 2; $i++) {
$data['type'] = ($i == 0) ? "from" : "to";
$data['ref_type'] = ($i == 0) ? "to" : "from";
$data['col'] = ($i == 0) ? "out" : "in";
$warehouse_id = (int)$data['warehouse_' . $data["type"]];
$ref_warehouse_id = (int)$data['warehouse_' . $data["ref_type"]];
$data["warehouse"] = $data['warehouse_' . $data["type"]];
$data["zone"] = $data['zone_' . $data["type"]];
$data["aisle"] = $data['aisle_' . $data["type"]];
$data["rack"] = $data['rack_' . $data["type"]];
$warehouse = $whMgmt->getStockContext($warehouse_id, $id);
$row = $warehouse['row'] ?? [];
$table = $warehouse['table'];
// get uuid for update
if ($id > 0 && $data['type'] == "from") {
$sql = "SELECT uuid FROM `$table`
WHERE company_id = :company_id AND id = :id";
$sth = $pdo->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":id" => $id
]);
$uuid = $sth->fetchColumn();
}
$table_log = json_decode($row['log'] ?? '[]', true);
$table_log[] = $logging;
if ($id > 0) {
$sql = "UPDATE `$table` SET
`product_sku` = :product_sku,
`{$data['col']}` = :quantity,
`zone` = :zone,
`aisle` = :aisle,
`rack` = :rack,
`contact_id` = :contact_id,
`description` = :description,
`log` = :log
WHERE uuid = :uuid AND company_id = :company_id";
$sth = $pdo->prepare($sql);
$sth->execute([
":uuid" => $uuid,
":company_id" => $company_id,
":product_sku" => $data["product_sku"],
":quantity" => $data["quantity"],
":zone" => $data["zone"],
":aisle" => $data["aisle"],
":rack" => $data["rack"],
":contact_id" => (int)$data["contact_id"],
":description" => $data["description"],
":log" => json_encode($table_log),
]);
} else {
$sql = "INSERT INTO `$table`
(uuid, company_id, `date`, product_sku, `{$data['col']}`, ref_warehouse, zone, aisle, rack, contact_id, `description`, `log`, `type`)
VALUES
(:uuid, :company_id, :date, :product_sku, :quantity, :ref_warehouse, :zone, :aisle, :rack, :contact_id, :description, :log, 'transfer')";
$sth = $pdo->prepare($sql);
$sth->execute([
":uuid" => $uuid,
":company_id" => $company_id,
":date" => date('Y-m-d H:i:s'),
":product_sku" => $data["product_sku"],
":quantity" => $data["quantity"],
":ref_warehouse" => $ref_warehouse_id,
":zone" => $data["zone"],
":aisle" => $data["aisle"],
":rack" => $data["rack"],
":contact_id" => (int)$data["contact_id"],
":description" => $data["description"],
":log" => json_encode($table_log),
]);
}
$whMgmt->adjustBalance($data['col'], $warehouse_id, $data["product_sku"], $row[$data['col']] ?? 0, $data["quantity"]);
}
});
$answer["success"] = 1;
} catch (PDOException $e) {
$answer["success"] = 0;
$answer["message"] = "Database error, please try again";
} catch (Exception $e) {
$answer["success"] = 0;
$answer["message"] = "Something went wrong";
}
exit(json_encode($answer));
?>
+10 -3
View File
@@ -4,7 +4,14 @@
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$warehouse = (int)$data['warehouse'];
// identity source of zone and aisle
if(empty($data["type"])){
$warehouse = (int)$data['warehouse'];
$zone = $data['zone'];
}else{
$warehouse = (int)$data['warehouse_'.$data["type"]];
$zone = $data['zone_'.$data["type"]];
}
$sql = "SELECT *
FROM md_storage
@@ -18,7 +25,7 @@
$sth->execute([
":company_id" => $company_id,
":warehouse" => $warehouse,
":zone" => $data["zone"]
":zone" => $zone
]);
db_check($sth, $answer);
@@ -26,7 +33,7 @@
$output = [];
foreach ($pre as $key => $value) {
$output = array_merge($output, range($value["aisle_form"], $value["aisle_to"]));
$output = array_merge($output, range($value["aisle_from"], $value["aisle_to"]));
}
$answer["output"] = $output;
+24 -5
View File
@@ -3,8 +3,26 @@
require '../../../assets/utils/db_auth.php';
// identity source of zone and aisle
if(empty($data["type"])){
$warehouse = (int)$data['warehouse'];
$zone = $data['zone'];
$aisle = $data["aisle"];
}else{
$warehouse = (int)$data['warehouse_'.$data["type"]];
$zone = $data['zone_'.$data["type"]];
$aisle = $data["aisle_".$data["type"]];
}
// Detect if numeric and zero-pad both input and query columns
if (is_numeric($aisle)) {
$aisle = str_pad($aisle, 5, '0', STR_PAD_LEFT);
$condition = "LPAD(aisle_from, 5, '0') <= :aisle_from AND LPAD(aisle_to, 5, '0') >= :aisle_to";
} else {
$condition = ":aisle_from >= aisle_from AND :aisle_to <= aisle_to";
}
$id = (int)$data['id'];
$warehouse = (int)$data['warehouse'];
$sql = "SELECT *
FROM md_storage
@@ -12,15 +30,16 @@
company_id = :company_id and
warehouse = :warehouse and
`zone` = :zone and
:aisle between aisle_from and aisle_to
$condition
";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":warehouse" => $warehouse,
":zone" => $data["zone"],
":aisle" => $data["aisle"]
":zone" => $zone,
":aisle_from" => $aisle,
":aisle_to" => $aisle
]);
db_check($sth, $answer);
@@ -28,7 +47,7 @@
$output = [];
foreach ($pre as $key => $value) {
$output = array_merge($output, range($value["rack_form"], $value["rack_to"]));
$output = array_merge($output, range($value["rack_from"], $value["rack_to"]));
}
$answer["output"] = $output;
+51
View File
@@ -0,0 +1,51 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$warehouse = (int)$data["wh"];
// get warehouse name
$sql = "SELECT warehouse_name
FROM md_warehouse
WHERE
company_id = :company_id and
id = :warehouse
";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":warehouse" => $warehouse
]);
db_check($sth, $answer);
$warehouse = $sth->fetchColumn();
$table = "td_stock_" . $warehouse;
$sql = "SELECT a.* , a.in as quantity, b.contact_name, c.product_name
FROM `{$table}` a
LEFT JOIN md_contact b ON
a.company_id = b.company_id and
a.contact_id = b.id
LEFT JOIN md_product c ON
a.company_id = b.company_id and
a.product_sku = c.sku
WHERE
a.company_id = :company_id and
a.id = :id ";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":id" => $id
]);
db_check($sth, $answer);
$answer["output"] = $sth->fetch(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
+51
View File
@@ -0,0 +1,51 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$warehouse = (int)$data["wh"];
// get warehouse name
$sql = "SELECT warehouse_name
FROM md_warehouse
WHERE
company_id = :company_id and
id = :warehouse
";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":warehouse" => $warehouse
]);
db_check($sth, $answer);
$warehouse = $sth->fetchColumn();
$table = "td_stock_" . $warehouse;
$sql = "SELECT a.* , a.out as quantity, b.contact_name, c.product_name
FROM `{$table}` a
LEFT JOIN md_contact b ON
a.company_id = b.company_id and
a.contact_id = b.id
LEFT JOIN md_product c ON
a.company_id = b.company_id and
a.product_sku = c.sku
WHERE
a.company_id = :company_id and
a.id = :id ";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":id" => $id
]);
db_check($sth, $answer);
$answer["output"] = $sth->fetch(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
@@ -0,0 +1,101 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$warehouse = (int)$data["wh"];
/**
* FROM warehouse, zone, aisle, rack, product name, quantity, contact name
*/
// get warehouse name
$sql = "SELECT warehouse_name
FROM md_warehouse
WHERE
company_id = :company_id and
id = :warehouse
";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":warehouse" => $warehouse
]);
db_check($sth, $answer);
$warehouse = $sth->fetchColumn();
$table = "td_stock_" . $warehouse;
$sql = "SELECT a.* , a.out as quantity, b.contact_name, c.product_name
FROM `{$table}` a
LEFT JOIN md_contact b ON
a.company_id = b.company_id and
a.contact_id = b.id
LEFT JOIN md_product c ON
a.company_id = b.company_id and
a.product_sku = c.sku
WHERE
a.company_id = :company_id and
a.id = :id ";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":id" => $id
]);
db_check($sth, $answer);
$output = $sth->fetch(PDO::FETCH_ASSOC);
/**
* TO warehouse, zone, aisle, rack, product name, quantity, contact name
*/
// get warehouse name
$sql = "SELECT warehouse_name
FROM md_warehouse
WHERE
company_id = :company_id and
id = :warehouse
";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":warehouse" => $output["ref_warehouse"]
]);
db_check($sth, $answer);
$warehouse = $sth->fetchColumn();
$table = "td_stock_" . $warehouse;
$sql = "SELECT a.* , a.in as quantity, b.contact_name, c.product_name
FROM `{$table}` a
LEFT JOIN md_contact b ON
a.company_id = b.company_id and
a.contact_id = b.id
LEFT JOIN md_product c ON
a.company_id = b.company_id and
a.product_sku = c.sku
WHERE
a.company_id = :company_id and
a.uuid = :id ";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":id" => $output["uuid"]
]);
db_check($sth, $answer);
$output["ref"] = $sth->fetch(PDO::FETCH_ASSOC);
$answer["output"] = $output;
$answer["success"] = 1;
exit(json_encode($answer));
?>
+7 -1
View File
@@ -4,7 +4,13 @@
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$warehouse = (int)$data['warehouse'];
// identity source of zone and aisle
if(empty($data["type"])){
$warehouse = (int)$data['warehouse'];
}else{
$warehouse = (int)$data['warehouse_'.$data["type"]];
}
$sql = "SELECT *
FROM md_storage
+53
View File
@@ -0,0 +1,53 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$warehouse = (int)$data["warehouse"];
// get warehouse name
$sql = "SELECT warehouse_name
FROM md_warehouse
WHERE
company_id = :company_id and
id = :warehouse
";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":warehouse" => $warehouse
]);
db_check($sth, $answer);
$warehouse = $sth->fetchColumn();
if(!$warehouse) {
$answer["message"] = "Warehouse not found";
exit(json_encode($answer));
}
$table = "td_stock_" . $warehouse;
$sql = "SELECT a.* , ROUND(a.in,2) as quantity ,
b.product_name
FROM `{$table}` a
LEFT JOIN md_product b ON
a.company_id = b.company_id and
a.product_sku = b.sku
WHERE
a.company_id = {$company_id} and
a.type = 'in'
ORDER BY a.date DESC";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id
]);
db_check($sth, $answer);
$answer["output"] = $sth->fetchAll(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
+53
View File
@@ -0,0 +1,53 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$warehouse = (int)$data["warehouse"];
// get warehouse name
$sql = "SELECT warehouse_name
FROM md_warehouse
WHERE
company_id = :company_id and
id = :warehouse
";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":warehouse" => $warehouse
]);
db_check($sth, $answer);
$warehouse = $sth->fetchColumn();
if(!$warehouse) {
$answer["message"] = "Warehouse not found";
exit(json_encode($answer));
}
$table = "td_stock_" . $warehouse;
$sql = "SELECT a.* , ROUND(a.out,2) as quantity ,
b.product_name
FROM `{$table}` a
LEFT JOIN md_product b ON
a.company_id = b.company_id and
a.product_sku = b.sku
WHERE
a.company_id = {$company_id} and
a.type = 'out'
ORDER BY a.date DESC";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id
]);
db_check($sth, $answer);
$answer["output"] = $sth->fetchAll(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
+54
View File
@@ -0,0 +1,54 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
$id = (int)$data['id'];
$warehouse = (int)$data["warehouse"];
// get warehouse name
$sql = "SELECT warehouse_name
FROM md_warehouse
WHERE
company_id = :company_id and
id = :warehouse
";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id,
":warehouse" => $warehouse
]);
db_check($sth, $answer);
$warehouse = $sth->fetchColumn();
if(!$warehouse) {
$answer["message"] = "Warehouse not found";
exit(json_encode($answer));
}
$table = "td_stock_" . $warehouse;
$sql = "SELECT a.* , ROUND(a.in,2) as quantity,
b.product_name
FROM `{$table}` a
LEFT JOIN md_product b ON
a.company_id = b.company_id and
a.product_sku = b.sku
WHERE
a.company_id = {$company_id} and
a.type = 'transfer' and
a.out > 0
ORDER BY a.date DESC";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id
]);
db_check($sth, $answer);
$answer["output"] = $sth->fetchAll(PDO::FETCH_ASSOC);
$answer["success"] = 1;
exit(json_encode($answer));
?>
+24
View File
@@ -0,0 +1,24 @@
<?php
session_start();
require '../../../assets/utils/db_auth.php';
$sql = "SELECT SUM(capacity) as total_capacity, count(*) as total_warehouse
FROM md_warehouse a
WHERE
a.company_id = :company_id
";
$sth = $pdo2->prepare($sql);
$sth->execute([
":company_id" => $company_id
]);
db_check($sth, $answer);
$output = $sth->fetch(PDO::FETCH_ASSOC);
$answer["output"] = $output;
$answer["success"] = 1;
exit(json_encode($answer));
?>
@@ -76,14 +76,14 @@
<!-- Contact -->
<div class="mb-3 col-lg-6">
<label for="contact" class="form-label">Contact</label>
<input type="text" class="form-control" id="contact" placeholder="Enter contact name">
<input type="text" class="form-control contact_search" id="contact" placeholder="Enter contact name">
</div>
<!-- Notes / Description -->
<div class="mb-3 col-lg-12">
<label for="notes" class="form-label">Notes / Description</label>
<textarea class="form-control" id="notes" rows="3" placeholder="Enter any notes"></textarea>
<label for="description" class="form-label">Notes / Description</label>
<textarea class="form-control" id="description" rows="3" placeholder="Enter any notes"></textarea>
</div>
<!-- Submit Button -->
@@ -108,8 +108,11 @@
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/manage_stock_in.php",
autoPrepare: true,
checkRequired: 0,
checkRequired: 1,
debugMode: 0,
data: {
"contact_id": $("#contact").attr('data-id')
},
action: 'manage',
onSuccess: function(res) {
@@ -142,13 +145,14 @@
function retrieve_zone() {
function retrieve_zone(callback) {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_zone.php",
autoPrepare: true,
checkRequired: 0,
noLoading: true,
debugMode: 0,
action: 'read',
onSuccess: function(res) {
var option = `<option value="">Please select zone</option>`;
@@ -156,6 +160,8 @@
option += `<option value='${item.zone}'>${item.zone}</option>`;
})
$(`select#zone`).html(option);
if (callback) callback(); // ← add this
}
});
@@ -163,7 +169,7 @@
function retrieve_aisle() {
function retrieve_aisle(callback) {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_aisle.php",
@@ -177,6 +183,8 @@
option += `<option value='${item}'>${item}</option>`;
})
$(`select#aisle`).html(option);
if (callback) callback(); // ← add this
}
});
@@ -184,7 +192,7 @@
function retrieve_rack() {
function retrieve_rack(callback) {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_rack.php",
@@ -198,6 +206,71 @@
option += `<option value='${item}'>${item}</option>`;
})
$(`select#rack`).html(option);
if (callback) callback(); // ← add this
}
});
}
function retrieve_for_edit() {
<?php if(empty($_GET["id"])){ ?>
return false;
<?php } ?>
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_stock_in.php",
autoPrepare: true,
checkRequired: 0,
debugMode: 0,
action: 'read',
onSuccess: function(res) {
var data = res.output;
// 1. Set warehouse (already populated from page load)
$(`#warehouse`).val('<?php echo $_GET["wh"];?>').attr('disabled', true); // set warehouse BEFORE retrieve_zone
// 2. Retrieve zone (autoPrepare reads warehouse value)
retrieve_zone(function() {
$(`select#zone`).val(data.zone).attr('disabled', true); // set zone BEFORE retrieve_aisle
// 3. Retrieve aisle (autoPrepare reads zone value)
retrieve_aisle(function() {
$(`#aisle`).val(data.aisle).attr('disabled', true); // set aisle BEFORE retrieve_rack
// 4. Retrieve rack (autoPrepare reads aisle value)
retrieve_rack(function() {
$(`#rack`).val(data.rack).attr('disabled', true);
// retrieve for edit
$.each(data, function(key, item) {
if (!['warehouse', 'zone', 'aisle', 'rack'].includes(key)) {
$(`#${key}`).val(item);
}
});
$('#contact').val(data.contact_name)
.attr('secondary', data.contact_name)
.attr('data-id', data.contact_id);
$('#product_name').val(data.product_name);
$('#product_sku').attr('secondary', data.product_sku);
$(`button[type=submit]`).text('Update');
$(`button[type=reset]`).hide();
});
});
});
// Set re
}
});
@@ -208,12 +281,13 @@
$(async function() {
try {
await retrieve_warehouse();
await retrieve_for_edit();
} catch (e) {
console.log(e);
}
});
<?php if(empty($_GET["id"])){ ?>
$("select#warehouse").change(function() {
retrieve_zone();
});
@@ -225,8 +299,8 @@
$("select#aisle").change(function() {
retrieve_rack();
});
<?php } ?>
</script>
</body>
+307
View File
@@ -0,0 +1,307 @@
<?php
session_start();
require '../config.php';
require '../include_header.php';
?>
<body>
<?php require '../include_topbar.php';?>
<?php require '../include_sidebar.php';?>
<!-- MAIN CONTENT -->
<main id="content" class="content py-15">
<div class="container-fluid">
<div class="row ">
<div class="col-12">
<div class="mb-6">
<h1 class="fs-3 mb-0">Stock Out</h1>
</div>
</div>
</div>
<div class="row g">
<div class="col-lg-8 col-12">
<div class="card">
<div class="card-body p-5">
<h2 class="fs-5 mb-4">Add Stock</h2>
<form class="row gx-5">
<!-- Product Name -->
<div class="mb-3 col-lg-3">
<label for="product_sku" class="form-label">SKU</label>
<input type="text" id="product_sku" class="form-control product_search"
placeholder="Type product sku..." autocomplete="off" required>
</div>
<div class="mb-3 col-lg-3">
<label for="product_name" class="form-label">Name</label>
<input type="text" id="product_name" class="form-control" autocomplete="off" disabled>
</div>
<!-- SKU or Product Code -->
<div class="mb-3 col-lg-6">
<label for="quantity" class="form-label">Quantity</label>
<input type="number" class="form-control" id="quantity" placeholder="Enter quantity" required>
</div>
<!-- Warehouse -->
<div class="mb-3 col-lg-6">
<label for="warehouse" class="form-label">Warehouse</label>
<select name="warehouse" id="warehouse" class="form-select" required></select>
</div>
<div class="mb-3 col-lg-6">
<label for="zone" class="form-label">Zone</label>
<select name="zone" id="zone" class="form-select" required>
<option value="">Please select zone</option>
</select>
</div>
<div class="mb-3 col-lg-6">
<label for="aisle" class="form-label">Aisle</label>
<select name="aisle" id="aisle" class="form-select" required>
<option value="">Please select aisle</option>
</select>
</div>
<div class="mb-3 col-lg-6">
<label for="rack" class="form-label">Rack</label>
<select name="rack" id="rack" class="form-select" required>
<option value="">Please select rack</option>
</select>
</div>
<!-- Contact -->
<div class="mb-3 col-lg-6">
<label for="contact" class="form-label">Contact</label>
<input type="text" class="form-control contact_search" id="contact" placeholder="Enter contact name">
</div>
<!-- Notes / Description -->
<div class="mb-3 col-lg-12">
<label for="description" class="form-label">Notes / Description</label>
<textarea class="form-control" id="description" rows="3" placeholder="Enter any notes"></textarea>
</div>
<!-- Submit Button -->
<div class="mb-3 col-lg-12">
<button type="submit" class="btn btn-primary" onclick="manage_stock_out();">Add Stock</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</main>
<?php require "../include_ending.php";?>
<script>
function manage_stock_out() {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/manage_stock_out.php",
autoPrepare: true,
checkRequired: 1,
debugMode: 0,
data: {
"contact_id": $("#contact").attr('data-id')
},
action: 'manage',
onSuccess: function(res) {
window.location.href = "<?php echo $server_url?>ics/stock_out.php";
}
});
}
function retrieve_warehouse() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/warehouse.php",
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
var option = `<option value="">Please select warehouse</option>`;
$.each(res.output, function(key, item) {
option += `<option value='${item.id}'>${item.warehouse_name}</option>`;
})
$(`select#warehouse`).html(option);
}
});
}
function retrieve_zone(callback) {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_zone.php",
autoPrepare: true,
checkRequired: 0,
noLoading: true,
debugMode: 0,
action: 'read',
onSuccess: function(res) {
var option = `<option value="">Please select zone</option>`;
$.each(res.output, function(key, item) {
option += `<option value='${item.zone}'>${item.zone}</option>`;
})
$(`select#zone`).html(option);
if (callback) callback(); // ← add this
}
});
}
function retrieve_aisle(callback) {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_aisle.php",
autoPrepare: true,
checkRequired: 0,
noLoading: true,
action: 'read',
onSuccess: function(res) {
var option = `<option value="">Please select aisle</option>`;
$.each(res.output, function(key, item) {
option += `<option value='${item}'>${item}</option>`;
})
$(`select#aisle`).html(option);
if (callback) callback(); // ← add this
}
});
}
function retrieve_rack(callback) {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_rack.php",
autoPrepare: true,
checkRequired: 0,
noLoading: true,
action: 'read',
onSuccess: function(res) {
var option = `<option value="">Please select rack</option>`;
$.each(res.output, function(key, item) {
option += `<option value='${item}'>${item}</option>`;
})
$(`select#rack`).html(option);
if (callback) callback(); // ← add this
}
});
}
function retrieve_for_edit() {
<?php if(empty($_GET["id"])){ ?>
return false;
<?php } ?>
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_stock_out.php",
autoPrepare: true,
checkRequired: 0,
debugMode: 0,
action: 'read',
onSuccess: function(res) {
var data = res.output;
// 1. Set warehouse (already populated from page load)
$(`#warehouse`).val(<?php echo $_GET["wh"];?>).attr('disabled', true); // set warehouse BEFORE retrieve_zone
// 2. Retrieve zone (autoPrepare reads warehouse value)
retrieve_zone(function() {
$(`select#zone`).val(data.zone).attr('disabled', true); // set zone BEFORE retrieve_aisle
// 3. Retrieve aisle (autoPrepare reads zone value)
retrieve_aisle(function() {
$(`#aisle`).val(data.aisle).attr('disabled', true); // set aisle BEFORE retrieve_rack
// 4. Retrieve rack (autoPrepare reads aisle value)
retrieve_rack(function() {
$(`#rack`).val(data.rack).attr('disabled', true);
// retrieve for edit
$.each(data, function(key, item) {
if (!['warehouse', 'zone', 'aisle', 'rack'].includes(key)) {
$(`#${key}`).val(item);
}
});
$('#contact').val(data.contact_name)
.attr('secondary', data.contact_name)
.attr('data-id', data.contact_id);
$('#product_name').val(data.product_name);
$('#product_sku').attr('secondary', data.product_sku);
$(`button[type=submit]`).text('Update');
$(`button[type=reset]`).hide();
});
});
});
// Set re
}
});
}
$(async function() {
try {
await retrieve_warehouse();
await retrieve_for_edit();
} catch (e) {
console.log(e);
}
});
<?php if(empty($_GET["id"])){ ?>
$("select#warehouse").change(function() {
retrieve_zone();
});
$("select#zone").change(function() {
retrieve_aisle();
});
$("select#aisle").change(function() {
retrieve_rack();
});
<?php } ?>
</script>
</body>
</html>
+369
View File
@@ -0,0 +1,369 @@
<?php
session_start();
require '../config.php';
require '../include_header.php';
?>
<body>
<?php require '../include_topbar.php';?>
<?php require '../include_sidebar.php';?>
<!-- MAIN CONTENT -->
<main id="content" class="content py-15">
<div class="container-fluid">
<div class="row ">
<div class="col-12">
<div class="mb-6">
<h1 class="fs-3 mb-0">Stock Transfer</h1>
</div>
</div>
</div>
<div class="row g">
<div class="col-lg-8 col-12">
<div class="card">
<div class="card-body p-5">
<h2 class="fs-5 mb-4">Add Stock</h2>
<form class="row gx-5">
<!-- Product Name -->
<div class="mb-3 col-lg-3">
<label for="product_sku" class="form-label">SKU</label>
<input type="text" id="product_sku" class="form-control product_search"
placeholder="Type product sku..." autocomplete="off" required>
</div>
<div class="mb-3 col-lg-3">
<label for="product_name" class="form-label">Name</label>
<input type="text" id="product_name" class="form-control" autocomplete="off" disabled>
</div>
<!-- SKU or Product Code -->
<div class="mb-3 col-lg-6">
<label for="quantity" class="form-label">Quantity</label>
<input type="number" class="form-control" id="quantity" placeholder="Enter quantity" required>
</div>
<!-- Warehouse -->
<div class="mb-3 col-lg-3">
<label for="warehouse" class="form-label">From Warehouse</label>
<select name="warehouse" id="warehouse_from" role="from" class="form-select" required></select>
</div>
<div class="mb-3 col-lg-3">
<label for="zone" class="form-label">From Zone</label>
<select name="zone" id="zone_from" role="from" class="form-select" required>
<option value="">Please select zone</option>
</select>
</div>
<div class="mb-3 col-lg-3">
<label for="aisle" class="form-label">From Aisle</label>
<select name="aisle" id="aisle_from" role="from" class="form-select" required>
<option value="">Please select aisle</option>
</select>
</div>
<div class="mb-3 col-lg-3">
<label for="rack" class="form-label">From Rack</label>
<select name="rack" id="rack_from" role="from" class="form-select" required>
<option value="">Please select rack</option>
</select>
</div>
<!-- Warehouse -->
<div class="mb-3 col-lg-3">
<label for="warehouse" class="form-label">To Warehouse</label>
<select name="warehouse" id="warehouse_to" role="to" class="form-select" required></select>
</div>
<div class="mb-3 col-lg-3">
<label for="zone" class="form-label">To Zone</label>
<select name="zone" id="zone_to" role="to" class="form-select" required>
<option value="">Please select zone</option>
</select>
</div>
<div class="mb-3 col-lg-3">
<label for="aisle" class="form-label">To Aisle</label>
<select name="aisle" id="aisle_to" role="to" class="form-select" required>
<option value="">Please select aisle</option>
</select>
</div>
<div class="mb-3 col-lg-3">
<label for="rack" class="form-label">To Rack</label>
<select name="rack" id="rack_to" role="to" class="form-select" required>
<option value="">Please select rack</option>
</select>
</div>
<!-- Contact -->
<div class="mb-3 col-lg-6">
<label for="contact" class="form-label">Contact</label>
<input type="text" class="form-control contact_search" id="contact" placeholder="Enter contact name">
</div>
<!-- Notes / Description -->
<div class="mb-3 col-lg-12">
<label for="description" class="form-label">Notes / Description</label>
<textarea class="form-control" id="description" rows="3" placeholder="Enter any notes"></textarea>
</div>
<!-- Submit Button -->
<div class="mb-3 col-lg-12">
<button type="submit" class="btn btn-primary" onclick="manage_stock_transfer();">Add Stock</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</main>
<?php require "../include_ending.php";?>
<script>
function manage_stock_transfer() {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/manage_stock_transfer.php",
autoPrepare: true,
checkRequired: 1,
debugMode: 0,
data: {
"contact_id": $("#contact").attr('data-id')
},
action: 'manage',
onSuccess: function(res) {
window.location.href = "<?php echo $server_url?>ics/stock_transfer.php";
}
});
}
function retrieve_warehouse(type) {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/warehouse.php",
autoPrepare: true,
checkRequired: 0,
data: {
"type": type
},
action: 'read',
onSuccess: function(res) {
var option = `<option value="">Please select warehouse</option>`;
$.each(res.output, function(key, item) {
option += `<option value='${item.id}'>${item.warehouse_name}</option>`;
})
$(`select[name='warehouse'][role='${type}']`).html(option);
}
});
}
function retrieve_zone(type, callback) {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_zone.php",
autoPrepare: true,
checkRequired: 0,
data: {
"type": type
},
noLoading: true,
debugMode: 0,
action: 'read',
onSuccess: function(res) {
var option = `<option value="">Please select zone</option>`;
$.each(res.output, function(key, item) {
option += `<option value='${item.zone}'>${item.zone}</option>`;
})
$(`select[name='zone'][role='${type}']`).html(option);
if (callback) callback(); // ← add this
}
});
}
function retrieve_aisle(type, callback) {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_aisle.php",
autoPrepare: true,
checkRequired: 0,
data: {
"type": type
},
noLoading: true,
action: 'read',
onSuccess: function(res) {
var option = `<option value="">Please select aisle</option>`;
$.each(res.output, function(key, item) {
option += `<option value='${item}'>${item}</option>`;
})
$(`select[name='aisle'][role='${type}']`).html(option);
if (callback) callback(); // ← add this
}
});
}
function retrieve_rack(type, callback) {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_rack.php",
autoPrepare: true,
checkRequired: 0,
data: {
"type": type
},
noLoading: true,
action: 'read',
onSuccess: function(res) {
var option = `<option value="">Please select rack</option>`;
$.each(res.output, function(key, item) {
option += `<option value='${item}'>${item}</option>`;
})
$(`select[name='rack'][role='${type}']`).html(option);
if (callback) callback(); // ← add this
}
});
}
function retrieve_for_edit() {
<?php if(empty($_GET["id"])){ ?>
return false;
<?php } ?>
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/retrieve_stock_transfer.php",
autoPrepare: true,
checkRequired: 0,
debugMode: 0,
action: 'read',
onSuccess: function(res) {
var type = 'from';
var warehouse = res.output.ref.ref_warehouse;
var data = res.output;
/**
* From warehouse
*/
$(`select[name='warehouse'][role=${type}]`).val(warehouse).attr('disabled', true);
retrieve_zone(type, function() {
$(`select[name='zone'][role=${type}]`).val(data.zone).attr('disabled', true);
retrieve_aisle(type, function() {
$(`select[name='aisle'][role=${type}]`).val(data.aisle).attr('disabled', true);
retrieve_rack(type, function() {
$(`select[name='rack'][role=${type}]`).val(data.rack).attr('disabled', true);
type = 'to';
warehouse = res.output.ref_warehouse;
data = res.output.ref;
/**
* To warehouse
*/
$(`select[name='warehouse'][role=${type}]`).val(warehouse).attr('disabled', true);
retrieve_zone(type, function() {
$(`select[name='zone'][role=${type}]`).val(data.zone).attr('disabled', true);
retrieve_aisle(type, function() {
$(`select[name='aisle'][role=${type}]`).val(data.aisle).attr('disabled',true);
retrieve_rack(type, function() {
$(`select[name='rack'][role=${type}]`).val(data.rack).attr('disabled',true);
});
});
});
});
});
});
var data = res.output;
// retrieve for edit
$.each(data, function(key, item) {
if (!['warehouse', 'zone', 'aisle', 'rack'].includes(key)) {
$(`#${key}`).val(item);
}
});
$('#contact').val(data.contact_name)
.attr('secondary', data.contact_name)
.attr('data-id', data.contact_id);
$('#product_name').val(data.product_name);
$('#product_sku').attr('secondary', data.product_sku);
$(`button[type=submit]`).text('Update');
$(`button[type=reset]`).hide();
}
});
}
$(async function() {
try {
await retrieve_warehouse("from");
await retrieve_warehouse("to");
await retrieve_for_edit();
} catch (e) {
console.log(e);
}
});
<?php if(empty($_GET["id"])){ ?>
$("select[name='warehouse']").change(function() {
retrieve_zone($(this).attr('role'));
});
$("select[name='zone']").change(function() {
retrieve_aisle($(this).attr('role'));
});
$("select[name='aisle']").change(function() {
retrieve_rack($(this).attr('role'));
});
<?php } ?>
</script>
</body>
</html>
+110 -4
View File
@@ -18,7 +18,7 @@
<div class="mb-6 d-flex justify-content-between align-items-center">
<h1 class="fs-3 mb-0">Stock in
</h1>
<a href="<?php echo $server_url?>ics/add_stock_in.php" class="btn btn-primary">
<a href="<?php echo $server_url?>ics/manage_stock_in.php" class="btn btn-primary">
<span><i class="ti ti-plus"></i></span>
<span>ADD Stock In</span></a>
@@ -27,18 +27,31 @@
</div>
<div class="row g-5">
<div class="mb-3 col-lg-2">
<input class="form-control" value='Warehouse' disabled>
</div>
<div class="mb-3 col-lg-4">
<select name="warehouse" id="warehouse" class="form-select" required></select>
</div>
<div class="mb-3 col-lg-6">
<button class='btn btn-secondary' onclick='retrieve_stock_in()'>Search</button>
</div>
<div class="col-12">
<div class="card">
<div class="card-body p-5">
<h2 class="mb-4 fs-5">Item List</h2>
<div class="table-responsive">
<table class="table table-hover mb-0 table-centered" id="product">
<table class="table table-hover mb-0 table-centered" id="stock_in">
<thead class="table-primary border-light">
<tr>
<th>Date</th>
<th>Product</th>
<th>Quantity</th>
<th>Warehouse</th>
<th>Storage Location</th>
<th>Zone</th>
<th>Aisle</th>
<th>Rack</th>
<th>Status</th>
<th>Action</th>
</tr>
@@ -63,7 +76,100 @@
<?php require "../include_ending.php";?>
<script>
function retrieve_stock_in() {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/stock_in.php",
autoPrepare: true,
checkRequired: 0,
debugMode: 0,
action: 'read',
onSuccess: function(res) {
// Register the array as a table name
alasql('CREATE TABLE IF NOT EXISTS stock_in');
alasql.tables.stock_in.data = res.output || [];
var total_records = alasql.tables.stock_in.data.length;
var table_id = 'stock_in';
var page = generate_pagination(table_id, total_records);
$(`table#${table_id} tfoot`).html(page);
// dynamic function name
if (typeof window[`change_page_${table_id}`] === "function") {
window[`change_page_${table_id}`](1);
} else {
console.error(`Function change_page_${table_id} does not exist.`);
}
}
});
}
function change_page_stock_in(page_num) {
var offset = (page_num - 1) * prop_limit;
var page_data = alasql(`SELECT * FROM stock_in LIMIT ${prop_limit} OFFSET ${offset}`);
var body = ``;
var warehouse = $(`select#warehouse`).val();
$.each(page_data, function(key, item) {
body += `<tr>
<td class="py-3">${format_date(item["date"])}</td>
<td class="py-3">${item["product_sku"]}: ${item['product_name']}</td>
<td class="py-3">${item['quantity']}</td>
<td class="py-3">${item['zone']}</td>
<td class="py-3">${item['aisle']}</td>
<td class="py-3">${item['rack']}</td>
<td class="py-3">
${(item['status'])?'<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?>ics/manage_stock_in.php?id=${item['id']}&wh=${warehouse}" class=""><i class="ti ti-eye fs-5"></i></a>
<a href="#" class="link-danger"><i class="ti ti-trash ms-2 fs-5"></i></a>
</td>
</tr>`;
})
$("table#stock_in > tbody").html(body);
}
function retrieve_warehouse() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/warehouse.php",
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
var option = ``;
$.each(res.output, function(key, item) {
option += `<option value='${item.id}'>${item.warehouse_name}</option>`;
})
$(`select#warehouse`).html(option);
}
});
}
$(async function() {
try {
await retrieve_warehouse();
await retrieve_stock_in();
} catch (e) {
console.log(e);
}
});
</script>
</body>
+177
View File
@@ -0,0 +1,177 @@
<?php
session_start();
require '../config.php';
require '../include_header.php';
?>
<body>
<?php require '../include_topbar.php';?>
<?php require '../include_sidebar.php';?>
<!-- MAIN CONTENT -->
<main id="content" class="content py-15">
<div class="container-fluid">
<div class="row ">
<div class="col-12">
<div class="mb-6 d-flex justify-content-between align-items-center">
<h1 class="fs-3 mb-0">Stock Out
</h1>
<a href="<?php echo $server_url?>ics/manage_stock_out.php" class="btn btn-primary">
<span><i class="ti ti-plus"></i></span>
<span>ADD Stock Out</span></a>
</div>
</div>
</div>
<div class="row g-5">
<div class="mb-3 col-lg-2">
<input class="form-control" value='Warehouse' disabled>
</div>
<div class="mb-3 col-lg-4">
<select name="warehouse" id="warehouse" class="form-select" required></select>
</div>
<div class="mb-3 col-lg-6">
<button class='btn btn-secondary' onclick='retrieve_stock_out()'>Search</button>
</div>
<div class="col-12">
<div class="card">
<div class="card-body p-5">
<h2 class="mb-4 fs-5">Item List</h2>
<div class="table-responsive">
<table class="table table-hover mb-0 table-centered" id="stock_out">
<thead class="table-primary border-light">
<tr>
<th>Date</th>
<th>Product</th>
<th>Quantity</th>
<th>Zone</th>
<th>Aisle</th>
<th>Rack</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody></tbody>
<tfoot class="">
</tfoot>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<?php require "../include_ending.php";?>
<script>
function retrieve_stock_out() {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/stock_out.php",
autoPrepare: true,
checkRequired: 0,
debugMode: 0,
action: 'read',
onSuccess: function(res) {
// Register the array as a table name
alasql('CREATE TABLE IF NOT EXISTS stock_out');
alasql.tables.stock_out.data = res.output || [];
var total_records = alasql.tables.stock_out.data.length;
var table_id = 'stock_out';
var page = generate_pagination(table_id, total_records);
$(`table#${table_id} tfoot`).html(page);
// dynamic function name
if (typeof window[`change_page_${table_id}`] === "function") {
window[`change_page_${table_id}`](1);
} else {
console.error(`Function change_page_${table_id} does not exist.`);
}
}
});
}
function change_page_stock_out(page_num) {
var offset = (page_num - 1) * prop_limit;
var page_data = alasql(`SELECT * FROM stock_out LIMIT ${prop_limit} OFFSET ${offset}`);
var body = ``;
var warehouse = $(`select#warehouse`).val();
$.each(page_data, function(key, item) {
body += `<tr>
<td class="py-3">${format_date(item["date"])}</td>
<td class="py-3">${item["product_sku"]}: ${item['product_name']}</td>
<td class="py-3">${item['quantity']}</td>
<td class="py-3">${item['zone']}</td>
<td class="py-3">${item['aisle']}</td>
<td class="py-3">${item['rack']}</td>
<td class="py-3">
${(item['status'])?'<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?>ics/manage_stock_out.php?id=${item['id']}&wh=${warehouse}" class=""><i class="ti ti-eye fs-5"></i></a>
<a href="#" class="link-danger"><i class="ti ti-trash ms-2 fs-5"></i></a>
</td>
</tr>`;
})
$("table#stock_out > tbody").html(body);
}
function retrieve_warehouse() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/warehouse.php",
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
var option = ``;
$.each(res.output, function(key, item) {
option += `<option value='${item.id}'>${item.warehouse_name}</option>`;
})
$(`select#warehouse`).html(option);
}
});
}
$(async function() {
try {
await retrieve_warehouse();
await retrieve_stock_out();
} catch (e) {
console.log(e);
}
});
</script>
</body>
</html>
+54 -20
View File
@@ -23,23 +23,26 @@
</div>
<div class="row g-5 mb-5">
<div class="col-xl-3 col-md-6 col-12">
<div class="card ">
<div class="card" id="capacity">
<div class="card-body p-5">
<div class="d-flex justify-content-between">
<div>
<span class="mb-4 d-block">Total Sales</span>
<h3 class="fw-bold mb-0">1,234</h3>
<span class="mb-4 d-block">Total Capacity</span>
<h3 class="fw-bold mb-0 text-info">0</h3>
<p class="mb-0 small text-secondary">Across all warehouses</p>
</div>
<div class="">
<i class="ti ti-box-seam fs-3 text-muted"></i>
</div>
</div>
<!-- overlay -->
<div class="card-loader-overlay">
<div class="spinner-border spinner-border-sm text-primary"></div>
</div>
</div>
</div>
</div>
<div class="col-xl-3 col-md-6 col-12">
<div class="card ">
<div class="card-body p-5">
@@ -53,6 +56,10 @@
<i class="ti ti-trending-up fs-3 text-success"></i>
</div>
</div>
<!-- overlay -->
<div class="card-loader-overlay">
<div class="spinner-border spinner-border-sm text-primary"></div>
</div>
</div>
</div>
@@ -71,6 +78,10 @@
<i class="ti ti-trending-down fs-3 text-danger"></i>
</div>
</div>
<!-- overlay -->
<div class="card-loader-overlay">
<div class="spinner-border spinner-border-sm text-primary"></div>
</div>
</div>
</div>
@@ -89,6 +100,10 @@
<i class="ti ti-alert-triangle fs-3 text-warning"></i>
</div>
</div>
<!-- overlay -->
<div class="card-loader-overlay">
<div class="spinner-border spinner-border-sm text-primary"></div>
</div>
</div>
</div>
@@ -116,6 +131,10 @@
<div>
<div id="stockMovementChart"></div>
</div>
<!-- overlay -->
<div class="card-loader-overlay">
<div class="spinner-border spinner-border-sm text-primary"></div>
</div>
</div>
</div>
@@ -134,6 +153,10 @@
<div>
<div id="stockLevelTrendChart"></div>
</div>
<!-- overlay -->
<div class="card-loader-overlay">
<div class="spinner-border spinner-border-sm text-primary"></div>
</div>
</div>
</div>
@@ -231,28 +254,39 @@
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<footer class="text-center py-2 mt-6 text-secondary ">
<p class="mb-0">Copyright © 2026 InApp Inventory Dashboard. Developed by <a href="https://codescandy.com/"
target="_blank" class="text-primary">CodesCandy</a> </p>
</footer>
</div>
</div>
<div class="position-fixed end-0 bottom-0 m-4">
<a href="https://codescandy.com/template/inventory-admin-dashboard-template/" class="btn btn-dark"
target="_blank"> Download Now</a>
</div>
</div>
</div>
</main>
<?php require "../include_ending.php";?>
<script>
function retrieve_warehouse_stats() {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/warehouse_stats.php",
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
console.log(res);
$("#capacity h3").text(format_number(res.output.total_capacity,2));
$("#capacity p").text("Accross "+ format_number(res.output.total_warehouse) + " warehouses");
$("#capacity .card-loader-overlay").hide();
}
});
}
$(function() {
retrieve_warehouse_stats();
});
</script>
+177
View File
@@ -0,0 +1,177 @@
<?php
session_start();
require '../config.php';
require '../include_header.php';
?>
<body>
<?php require '../include_topbar.php';?>
<?php require '../include_sidebar.php';?>
<!-- MAIN CONTENT -->
<main id="content" class="content py-15">
<div class="container-fluid">
<div class="row ">
<div class="col-12">
<div class="mb-6 d-flex justify-content-between align-items-center">
<h1 class="fs-3 mb-0">Stock Transfer
</h1>
<a href="<?php echo $server_url?>ics/manage_stock_transfer.php" class="btn btn-primary">
<span><i class="ti ti-plus"></i></span>
<span>ADD Stock Transfer</span></a>
</div>
</div>
</div>
<div class="row g-5">
<div class="mb-3 col-lg-2">
<input class="form-control" value='Warehouse From' disabled>
</div>
<div class="mb-3 col-lg-4">
<select name="warehouse" id="warehouse" class="form-select" required></select>
</div>
<div class="mb-3 col-lg-4">
<button class='btn btn-secondary' onclick='retrieve_stock_transfer()'>Search</button>
</div>
<div class="col-12">
<div class="card">
<div class="card-body p-5">
<h2 class="mb-4 fs-5">Item List</h2>
<div class="table-responsive">
<table class="table table-hover mb-0 table-centered" id="stock_transfer">
<thead class="table-primary border-light">
<tr>
<th>Date</th>
<th>Product</th>
<th>Quantity</th>
<th>Zone</th>
<th>Aisle</th>
<th>Rack</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody></tbody>
<tfoot class="">
</tfoot>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<?php require "../include_ending.php";?>
<script>
function retrieve_stock_transfer() {
return ajax_request({
url: "<?php echo $server_url?>ics/api/engine/stock_transfer.php",
autoPrepare: true,
checkRequired: 0,
debugMode: 0,
action: 'read',
onSuccess: function(res) {
// Register the array as a table name
alasql('CREATE TABLE IF NOT EXISTS stock_transfer');
alasql.tables.stock_transfer.data = res.output || [];
var total_records = alasql.tables.stock_transfer.data.length;
var table_id = 'stock_transfer';
var page = generate_pagination(table_id, total_records);
$(`table#${table_id} tfoot`).html(page);
// dynamic function name
if (typeof window[`change_page_${table_id}`] === "function") {
window[`change_page_${table_id}`](1);
} else {
console.error(`Function change_page_${table_id} does not exist.`);
}
}
});
}
function change_page_stock_transfer(page_num) {
var offset = (page_num - 1) * prop_limit;
var page_data = alasql(`SELECT * FROM stock_transfer LIMIT ${prop_limit} OFFSET ${offset}`);
var body = ``;
var warehouse = $(`select#warehouse`).val();
$.each(page_data, function(key, item) {
body += `<tr>
<td class="py-3">${format_date(item["date"])}</td>
<td class="py-3">${item["product_sku"]}: ${item['product_name']}</td>
<td class="py-3">${item['quantity']}</td>
<td class="py-3">${item['zone']}</td>
<td class="py-3">${item['aisle']}</td>
<td class="py-3">${item['rack']}</td>
<td class="py-3">
${(item['status'])?'<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?>ics/manage_stock_transfer.php?id=${item['id']}&wh=${warehouse}" class=""><i class="ti ti-eye fs-5"></i></a>
<a href="#" class="link-danger"><i class="ti ti-trash ms-2 fs-5"></i></a>
</td>
</tr>`;
})
$("table#stock_transfer > tbody").html(body);
}
function retrieve_warehouse() {
return ajax_request({
url: "<?php echo $server_url?>inventory/api/engine/warehouse.php",
autoPrepare: true,
checkRequired: 0,
action: 'read',
onSuccess: function(res) {
var option = ``;
$.each(res.output, function(key, item) {
option += `<option value='${item.id}'>${item.warehouse_name}</option>`;
})
$(`select#warehouse`).html(option);
}
});
}
$(async function() {
try {
await retrieve_warehouse();
await retrieve_stock_transfer();
} catch (e) {
console.log(e);
}
});
</script>
</body>
</html>