accounting workflows
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/StockSourceManager.php';
|
||||
|
||||
try {
|
||||
$mgr = new StockSourceManager($pdo2, $company_id);
|
||||
$answer['output'] = $mgr->getBySource(
|
||||
trim((string)($data['source'] ?? '')),
|
||||
(int)($data['source_id'] ?? 0)
|
||||
);
|
||||
$answer['success'] = 1;
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
?>
|
||||
@@ -16,67 +16,17 @@
|
||||
$lot_number = trim($data['lot_number'] ?? '');
|
||||
$serial = trim($data['serial_number'] ?? '');
|
||||
|
||||
if (!$warehouse_id || $zone === '' || $aisle === '' || $rack === '') {
|
||||
$answer['message'] = 'Location label is incomplete.';
|
||||
http_response_code(400);
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
function rackRow(PDO $pdo, int $company_id, int $warehouse_id, string $zone, string $aisle, string $rack): array|false {
|
||||
$sth = $pdo->prepare(
|
||||
"SELECT id, product_sku, td_stock_id
|
||||
FROM md_rack
|
||||
WHERE company_id = :company_id
|
||||
AND warehouse = :warehouse
|
||||
AND zone = :zone
|
||||
AND aisle = :aisle
|
||||
AND rack = :rack
|
||||
LIMIT 1"
|
||||
);
|
||||
$sth->execute([
|
||||
':company_id' => $company_id,
|
||||
':warehouse' => $warehouse_id,
|
||||
':zone' => $zone,
|
||||
':aisle' => $aisle,
|
||||
':rack' => $rack,
|
||||
]);
|
||||
return $sth->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
try {
|
||||
$rack_row = rackRow($pdo2, $company_id, $warehouse_id, $zone, $aisle, $rack);
|
||||
if (!$rack_row) throw new Exception("Location {$zone}-{$aisle}-{$rack} does not exist.");
|
||||
|
||||
if ($mode === 'in' || $mode === 'to') {
|
||||
if ($rack_row['product_sku'] !== null) {
|
||||
throw new Exception("Location {$zone}-{$aisle}-{$rack} is already occupied by {$rack_row['product_sku']}.");
|
||||
}
|
||||
|
||||
if ($mode === 'in' && $product_sku !== '') {
|
||||
$whMgmt->validateStockUnique($product_sku, $lot_number ?: null, $serial ?: null);
|
||||
}
|
||||
} elseif ($mode === 'out' || $mode === 'from') {
|
||||
if ($product_sku === '') throw new Exception('Scan the SKU label first.');
|
||||
|
||||
$stock = $whMgmt->getRackStock($warehouse_id, $zone, $aisle, $rack);
|
||||
if (!$stock) {
|
||||
throw new Exception("Location {$zone}-{$aisle}-{$rack} has no approved stock to move out.");
|
||||
}
|
||||
|
||||
if ($stock['product_sku'] !== $product_sku) {
|
||||
throw new Exception("Location holds {$stock['product_sku']}, not {$product_sku}.");
|
||||
}
|
||||
|
||||
if ($lot_number !== '' && (string)$stock['lot_number'] !== $lot_number) {
|
||||
throw new Exception("Location holds lot '{$stock['lot_number']}', not '{$lot_number}'.");
|
||||
}
|
||||
|
||||
if ($serial !== '' && (string)$stock['serial_number'] !== $serial) {
|
||||
throw new Exception("Location holds serial '{$stock['serial_number']}', not '{$serial}'.");
|
||||
}
|
||||
} else {
|
||||
throw new Exception('Invalid scan validation mode.');
|
||||
}
|
||||
$whMgmt->validateScanLocation(
|
||||
$mode,
|
||||
$warehouse_id,
|
||||
$zone,
|
||||
$aisle,
|
||||
$rack,
|
||||
$product_sku,
|
||||
$lot_number,
|
||||
$serial
|
||||
);
|
||||
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
|
||||
+18
-24
@@ -134,6 +134,7 @@
|
||||
<?php require "../include_ending.php";?>
|
||||
|
||||
<script>
|
||||
// custom.js globals: set_select_value(), load_location_config(), init_lot_search_inputs()
|
||||
|
||||
var advanced = false;
|
||||
var label_rack = 'Location';
|
||||
@@ -142,22 +143,6 @@
|
||||
var scan_sku_ready = false;
|
||||
var scan_location_ready = false;
|
||||
|
||||
function load_location_config(callback) {
|
||||
return ajax_request({
|
||||
url: server_url + 'setting/api/engine/company_setting.php',
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
action: 'read',
|
||||
onSuccess: function(res) {
|
||||
var s = res.output;
|
||||
advanced = s.advanced_location == 1;
|
||||
label_rack = s.location_label_rack || (advanced ? 'Rack' : 'Location');
|
||||
label_zone = s.location_label_zone || 'Zone';
|
||||
label_aisle = s.location_label_aisle || 'Aisle';
|
||||
if (callback) callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function apply_location_labels() {
|
||||
if (advanced) {
|
||||
@@ -177,14 +162,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function set_select_value(selector, value, label) {
|
||||
if (!value) return;
|
||||
var $select = $(selector);
|
||||
if (!$select.find(`option[value="${value}"]`).length) {
|
||||
$select.append(`<option value="${value}">${label || value}</option>`);
|
||||
}
|
||||
$select.val(value);
|
||||
}
|
||||
|
||||
function apply_sku_label_scan(data) {
|
||||
$('#product_sku').val(data.sku).attr('secondary', data.sku);
|
||||
@@ -593,6 +570,23 @@
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('lot:selected', '#lot_number', function(e, lot) {
|
||||
if (expiryPicker) {
|
||||
expiryPicker.setDate(lot.expiry_date || '', true, 'Y-m-d');
|
||||
if (expiryPicker.altInput) expiryPicker.altInput.disabled = true;
|
||||
}
|
||||
$('#expiry_date').prop('disabled', true)
|
||||
.attr('title', 'Expiry date is locked for existing lots');
|
||||
});
|
||||
|
||||
$(document).on('lot:cleared', '#lot_number', function() {
|
||||
$('#expiry_date').prop('disabled', false).removeAttr('title');
|
||||
if (expiryPicker) {
|
||||
expiryPicker.clear();
|
||||
if (expiryPicker.altInput) expiryPicker.altInput.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
// ── Flatpickr: display dd/mm/yyyy, send yyyy-mm-dd to API ──────────
|
||||
var expiryPicker = flatpickr("#expiry_date", {
|
||||
dateFormat: "Y-m-d", // actual value stored in input (sent to API)
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
<?php require "../include_ending.php";?>
|
||||
|
||||
<script>
|
||||
// custom.js globals: set_select_value(), load_location_config()
|
||||
|
||||
var advanced = false;
|
||||
var label_rack = 'Location';
|
||||
@@ -131,14 +132,6 @@
|
||||
var pending_scan_lot = '';
|
||||
var pending_scan_serial = '';
|
||||
|
||||
function set_select_value(selector, value, label) {
|
||||
if (!value) return;
|
||||
var $select = $(selector);
|
||||
if (!$select.find(`option[value="${value}"]`).length) {
|
||||
$select.append(`<option value="${value}">${label || value}</option>`);
|
||||
}
|
||||
$select.val(value).prop('disabled', false);
|
||||
}
|
||||
|
||||
function apply_sku_label_scan(data) {
|
||||
$('#product_sku').val(data.sku).attr('secondary', data.sku);
|
||||
@@ -218,22 +211,6 @@
|
||||
manage_stock_out();
|
||||
}
|
||||
|
||||
function load_location_config(callback) {
|
||||
return ajax_request({
|
||||
url: server_url + 'setting/api/engine/company_setting.php',
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
action: 'read',
|
||||
onSuccess: function(res) {
|
||||
var s = res.output;
|
||||
advanced = s.advanced_location == 1;
|
||||
label_rack = s.location_label_rack || (advanced ? 'Rack' : 'Location');
|
||||
label_zone = s.location_label_zone || 'Zone';
|
||||
label_aisle = s.location_label_aisle || 'Aisle';
|
||||
if (callback) callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function apply_location_labels() {
|
||||
if (advanced) {
|
||||
|
||||
@@ -153,6 +153,7 @@
|
||||
<?php require "../include_ending.php";?>
|
||||
|
||||
<script>
|
||||
// custom.js globals: set_select_value(), load_location_config()
|
||||
|
||||
// ── Location config ───────────────────────────────────────────────────────
|
||||
var advanced = false;
|
||||
@@ -165,14 +166,6 @@
|
||||
var pending_scan_lot = '';
|
||||
var pending_scan_serial = '';
|
||||
|
||||
function set_select_value(selector, value, label) {
|
||||
if (!value) return;
|
||||
var $select = $(selector);
|
||||
if (!$select.find(`option[value="${value}"]`).length) {
|
||||
$select.append(`<option value="${value}">${label || value}</option>`);
|
||||
}
|
||||
$select.val(value).prop('disabled', false);
|
||||
}
|
||||
|
||||
function apply_sku_label_scan(data) {
|
||||
$('#product_sku').val(data.sku).attr('secondary', data.sku);
|
||||
@@ -287,22 +280,6 @@
|
||||
manage_stock_transfer();
|
||||
}
|
||||
|
||||
function load_location_config(callback) {
|
||||
return ajax_request({
|
||||
url: '<?php echo $server_url?>setting/api/engine/company_setting.php',
|
||||
autoPrepare: true,
|
||||
checkRequired: 0,
|
||||
action: 'read',
|
||||
onSuccess: function(res) {
|
||||
var s = res.output;
|
||||
advanced = s.advanced_location == 1;
|
||||
label_rack = s.location_label_rack || (advanced ? 'Rack' : 'Location');
|
||||
label_zone = s.location_label_zone || 'Zone';
|
||||
label_aisle = s.location_label_aisle || 'Aisle';
|
||||
if (callback) callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function apply_location_labels() {
|
||||
if (advanced) {
|
||||
|
||||
+30
-8
@@ -127,7 +127,35 @@
|
||||
function source_label(source) {
|
||||
source = source || '';
|
||||
if (!source) return 'Manual';
|
||||
return source.charAt(0).toUpperCase() + source.slice(1).replace(/_/g, ' ');
|
||||
return source.split('_').map(function(w) {
|
||||
return w.charAt(0).toUpperCase() + w.slice(1);
|
||||
}).join(' ');
|
||||
}
|
||||
|
||||
var source_view_urls = {
|
||||
'supplier_return': '<?php echo $server_url?>po/manage_supplier_return.php',
|
||||
'order': '<?php echo $server_url?>order/manage_order.php',
|
||||
'return': '<?php echo $server_url?>order/manage_return.php',
|
||||
};
|
||||
|
||||
function action_cell(item, warehouse) {
|
||||
var source = item.source || '';
|
||||
var source_id = parseInt(item.source_id) || 0;
|
||||
var view_url;
|
||||
|
||||
if (source && source_view_urls[source] && source_id > 0) {
|
||||
view_url = source_view_urls[source] + '?id=' + source_id;
|
||||
} else {
|
||||
view_url = '<?php echo $server_url?>ics/manage_stock_out.php?id=' + item['id'] + '&wh=' + warehouse;
|
||||
}
|
||||
|
||||
var delete_btn = (!source)
|
||||
? `<a href="javascript:void(0);" class="link-danger" onclick="delete_stock_out($(this),${item['id']})">
|
||||
<i class="ti ti-trash ms-2 fs-5"></i>
|
||||
</a>`
|
||||
: '';
|
||||
|
||||
return `<a href="${view_url}"><i class="ti ti-eye fs-5"></i></a>${delete_btn}`;
|
||||
}
|
||||
|
||||
function source_cell(source) {
|
||||
@@ -227,13 +255,7 @@
|
||||
<td class="py-3">
|
||||
${item['status'] == 1 ? '<span class="badge bg-success">Approved</span>' : '<span class="badge bg-warning text-dark">Draft</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="javascript:void(0);" class="link-danger"
|
||||
onclick="delete_stock_out($(this),${item['id']})">
|
||||
<i class="ti ti-trash ms-2 fs-5"></i>
|
||||
</a>
|
||||
</td>
|
||||
<td class="py-3">${action_cell(item, warehouse)}</td>
|
||||
</tr>`;
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user