stock database design
This commit is contained in:
+20
-1
@@ -33,6 +33,10 @@ $(function () {
|
|||||||
type: 'POST',
|
type: 'POST',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: { json: json },
|
data: { json: json },
|
||||||
|
// for CSRF validation
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
||||||
|
},
|
||||||
|
|
||||||
success: function (res) {
|
success: function (res) {
|
||||||
|
|
||||||
@@ -80,7 +84,10 @@ $(function () {
|
|||||||
// Replace input value with SKU
|
// Replace input value with SKU
|
||||||
$(this)
|
$(this)
|
||||||
.val(product.sku)
|
.val(product.sku)
|
||||||
.attr("secondary", product.id);
|
.attr("secondary", product.sku);
|
||||||
|
$('input#product_name')
|
||||||
|
.val(product.product_name)
|
||||||
|
.attr("secondary", product.product_name)
|
||||||
|
|
||||||
console.log("Input updated with SKU:", product.sku);
|
console.log("Input updated with SKU:", product.sku);
|
||||||
|
|
||||||
@@ -97,6 +104,15 @@ $(function () {
|
|||||||
.appendTo(ul);
|
.appendTo(ul);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add this ↓
|
||||||
|
$el.on('blur', function () {
|
||||||
|
var secondary = $(this).attr('secondary');
|
||||||
|
if (secondary) {
|
||||||
|
$(this).val(secondary);
|
||||||
|
$('input#product_name').val($('input#product_name').attr('secondary'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -147,6 +163,7 @@ function prepare_form_data(check_required, raw_data) {
|
|||||||
|
|
||||||
if (!is_valid) {
|
if (!is_valid) {
|
||||||
alert("Please fill in all mandatory fields.");
|
alert("Please fill in all mandatory fields.");
|
||||||
|
isAjaxProcessing = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,6 +195,7 @@ function ajax_request(options) {
|
|||||||
|
|
||||||
let payloadJson = prepare_form_data(options.checkRequired ?? 0, true);
|
let payloadJson = prepare_form_data(options.checkRequired ?? 0, true);
|
||||||
if (payloadJson === false) {
|
if (payloadJson === false) {
|
||||||
|
isAjaxProcessing = false;
|
||||||
return Promise.reject("validation_failed");
|
return Promise.reject("validation_failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,6 +213,7 @@ function ajax_request(options) {
|
|||||||
// add action to JSON
|
// add action to JSON
|
||||||
payloadJson['action'] = options.action;
|
payloadJson['action'] = options.action;
|
||||||
}else{
|
}else{
|
||||||
|
isAjaxProcessing = false;
|
||||||
return Promise.reject("please_define_action");
|
return Promise.reject("please_define_action");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,16 +28,20 @@
|
|||||||
<h2 class="fs-5 mb-4">Add Stock</h2>
|
<h2 class="fs-5 mb-4">Add Stock</h2>
|
||||||
<form class="row gx-5">
|
<form class="row gx-5">
|
||||||
<!-- Product Name -->
|
<!-- Product Name -->
|
||||||
<div class="mb-3 col-lg-6">
|
<div class="mb-3 col-lg-3">
|
||||||
<label for="product_sku" class="form-label">Product</label>
|
<label for="product_sku" class="form-label">SKU</label>
|
||||||
<input type="text" id="product_sku" class="form-control product_search"
|
<input type="text" id="product_sku" class="form-control product_search"
|
||||||
placeholder="Type product name..." autocomplete="off">
|
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>
|
</div>
|
||||||
|
|
||||||
<!-- SKU or Product Code -->
|
<!-- SKU or Product Code -->
|
||||||
<div class="mb-3 col-lg-6">
|
<div class="mb-3 col-lg-6">
|
||||||
<label for="quantity" class="form-label">Quantity</label>
|
<label for="quantity" class="form-label">Quantity</label>
|
||||||
<input type="number" class="form-control" id="quantity" placeholder="Enter quantity">
|
<input type="number" class="form-control" id="quantity" placeholder="Enter quantity" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@@ -45,26 +49,26 @@
|
|||||||
<!-- Warehouse -->
|
<!-- Warehouse -->
|
||||||
<div class="mb-3 col-lg-6">
|
<div class="mb-3 col-lg-6">
|
||||||
<label for="warehouse" class="form-label">Warehouse</label>
|
<label for="warehouse" class="form-label">Warehouse</label>
|
||||||
<select name="warehouse" id="warehouse" class="form-select"></select>
|
<select name="warehouse" id="warehouse" class="form-select" required></select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3 col-lg-6">
|
<div class="mb-3 col-lg-6">
|
||||||
<label for="zone" class="form-label">Zone</label>
|
<label for="zone" class="form-label">Zone</label>
|
||||||
<select name="zone" id="zone" class="form-select">
|
<select name="zone" id="zone" class="form-select" required>
|
||||||
<option value="">Please select zone</option>
|
<option value="">Please select zone</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3 col-lg-6">
|
<div class="mb-3 col-lg-6">
|
||||||
<label for="aisle" class="form-label">Aisle</label>
|
<label for="aisle" class="form-label">Aisle</label>
|
||||||
<select name="aisle" id="aisle" class="form-select">
|
<select name="aisle" id="aisle" class="form-select" required>
|
||||||
<option value="">Please select aisle</option>
|
<option value="">Please select aisle</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3 col-lg-6">
|
<div class="mb-3 col-lg-6">
|
||||||
<label for="rack" class="form-label">Rack</label>
|
<label for="rack" class="form-label">Rack</label>
|
||||||
<select name="rack" id="rack" class="form-select">
|
<select name="rack" id="rack" class="form-select" required>
|
||||||
<option value="">Please select rack</option>
|
<option value="">Please select rack</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -106,6 +110,7 @@
|
|||||||
autoPrepare: true,
|
autoPrepare: true,
|
||||||
checkRequired: 0,
|
checkRequired: 0,
|
||||||
debugMode: 0,
|
debugMode: 0,
|
||||||
|
action: 'manage',
|
||||||
onSuccess: function(res) {
|
onSuccess: function(res) {
|
||||||
|
|
||||||
window.location.href = "<?php echo $server_url?>ics/stock_in.php";
|
window.location.href = "<?php echo $server_url?>ics/stock_in.php";
|
||||||
@@ -123,6 +128,7 @@
|
|||||||
url: "<?php echo $server_url?>inventory/api/engine/warehouse.php",
|
url: "<?php echo $server_url?>inventory/api/engine/warehouse.php",
|
||||||
autoPrepare: true,
|
autoPrepare: true,
|
||||||
checkRequired: 0,
|
checkRequired: 0,
|
||||||
|
action: 'read',
|
||||||
onSuccess: function(res) {
|
onSuccess: function(res) {
|
||||||
var option = `<option value="">Please select warehouse</option>`;
|
var option = `<option value="">Please select warehouse</option>`;
|
||||||
$.each(res.output, function(key, item) {
|
$.each(res.output, function(key, item) {
|
||||||
@@ -143,6 +149,7 @@
|
|||||||
autoPrepare: true,
|
autoPrepare: true,
|
||||||
checkRequired: 0,
|
checkRequired: 0,
|
||||||
noLoading: true,
|
noLoading: true,
|
||||||
|
action: 'read',
|
||||||
onSuccess: function(res) {
|
onSuccess: function(res) {
|
||||||
var option = `<option value="">Please select zone</option>`;
|
var option = `<option value="">Please select zone</option>`;
|
||||||
$.each(res.output, function(key, item) {
|
$.each(res.output, function(key, item) {
|
||||||
@@ -163,6 +170,7 @@
|
|||||||
autoPrepare: true,
|
autoPrepare: true,
|
||||||
checkRequired: 0,
|
checkRequired: 0,
|
||||||
noLoading: true,
|
noLoading: true,
|
||||||
|
action: 'read',
|
||||||
onSuccess: function(res) {
|
onSuccess: function(res) {
|
||||||
var option = `<option value="">Please select aisle</option>`;
|
var option = `<option value="">Please select aisle</option>`;
|
||||||
$.each(res.output, function(key, item) {
|
$.each(res.output, function(key, item) {
|
||||||
@@ -183,6 +191,7 @@
|
|||||||
autoPrepare: true,
|
autoPrepare: true,
|
||||||
checkRequired: 0,
|
checkRequired: 0,
|
||||||
noLoading: true,
|
noLoading: true,
|
||||||
|
action: 'read',
|
||||||
onSuccess: function(res) {
|
onSuccess: function(res) {
|
||||||
var option = `<option value="">Please select rack</option>`;
|
var option = `<option value="">Please select rack</option>`;
|
||||||
$.each(res.output, function(key, item) {
|
$.each(res.output, function(key, item) {
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ require '../../../assets/utils/db_auth.php';
|
|||||||
|
|
||||||
$id = (int)($data['id'] ?? 0);
|
$id = (int)($data['id'] ?? 0);
|
||||||
|
|
||||||
|
$pdo2->beginTransaction();
|
||||||
|
|
||||||
// get existing log
|
// get existing log
|
||||||
$sql = "SELECT `log`
|
$sql = "SELECT `log`
|
||||||
FROM md_warehouse
|
FROM md_warehouse
|
||||||
@@ -51,6 +53,7 @@ if ($id > 0) {
|
|||||||
":status" => (int)($data["status"] ?? 1),
|
":status" => (int)($data["status"] ?? 1),
|
||||||
":log" => json_encode($table_log, JSON_UNESCAPED_UNICODE),
|
":log" => json_encode($table_log, JSON_UNESCAPED_UNICODE),
|
||||||
]);
|
]);
|
||||||
|
db_check($sth, $answer);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -70,10 +73,25 @@ if ($id > 0) {
|
|||||||
":status" => (int)($data["status"] ?? 1),
|
":status" => (int)($data["status"] ?? 1),
|
||||||
":log" => json_encode($table_log, JSON_UNESCAPED_UNICODE),
|
":log" => json_encode($table_log, JSON_UNESCAPED_UNICODE),
|
||||||
]);
|
]);
|
||||||
|
db_check($sth, $answer);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(!empty($data["warehouse_name"])){
|
||||||
|
/**
|
||||||
|
* Create warehouse table
|
||||||
|
*/
|
||||||
|
$safe_name = 'td_stock_' . preg_replace('/[^a-zA-Z0-9_]/', '', $data["warehouse_name"]);
|
||||||
|
|
||||||
|
$sql = "CREATE TABLE `$safe_name` LIKE `td_stock`";
|
||||||
|
$sth = $pdo2->prepare($sql);
|
||||||
|
$sth->execute();
|
||||||
|
db_check($sth, $answer);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
db_check($sth, $answer);
|
$pdo2->commit();
|
||||||
|
|
||||||
$answer["success"] = 1;
|
$answer["success"] = 1;
|
||||||
exit(json_encode($answer));
|
exit(json_encode($answer));
|
||||||
|
|||||||
@@ -90,6 +90,7 @@
|
|||||||
autoPrepare: true,
|
autoPrepare: true,
|
||||||
checkRequired: 0,
|
checkRequired: 0,
|
||||||
debugMode: 0,
|
debugMode: 0,
|
||||||
|
action: 'manage',
|
||||||
onSuccess: function(res) {
|
onSuccess: function(res) {
|
||||||
|
|
||||||
window.location.href = "<?php echo $server_url?>inventory/warehouse.php";
|
window.location.href = "<?php echo $server_url?>inventory/warehouse.php";
|
||||||
@@ -106,6 +107,7 @@
|
|||||||
url: "<?php echo $server_url?>inventory/api/engine/warehouse.php",
|
url: "<?php echo $server_url?>inventory/api/engine/warehouse.php",
|
||||||
autoPrepare: true,
|
autoPrepare: true,
|
||||||
checkRequired: 0,
|
checkRequired: 0,
|
||||||
|
action: 'read',
|
||||||
onSuccess: function(res) {
|
onSuccess: function(res) {
|
||||||
var option = ``;
|
var option = ``;
|
||||||
$.each(res.output, function(key, item) {
|
$.each(res.output, function(key, item) {
|
||||||
@@ -124,6 +126,7 @@
|
|||||||
url: "<?php echo $server_url?>inventory/api/engine/retrieve_storage.php",
|
url: "<?php echo $server_url?>inventory/api/engine/retrieve_storage.php",
|
||||||
autoPrepare: true,
|
autoPrepare: true,
|
||||||
checkRequired: 0,
|
checkRequired: 0,
|
||||||
|
action: 'read',
|
||||||
onSuccess: function(res) {
|
onSuccess: function(res) {
|
||||||
|
|
||||||
$.each(res.output, function(key, item) {
|
$.each(res.output, function(key, item) {
|
||||||
|
|||||||
@@ -81,7 +81,7 @@
|
|||||||
return ajax_request({
|
return ajax_request({
|
||||||
url: "<?php echo $server_url?>inventory/api/engine/manage_warehouse.php",
|
url: "<?php echo $server_url?>inventory/api/engine/manage_warehouse.php",
|
||||||
autoPrepare: true,
|
autoPrepare: true,
|
||||||
checkRequired: 0,
|
checkRequired: 1,
|
||||||
debugMode: 0,
|
debugMode: 0,
|
||||||
action: 'manage',
|
action: 'manage',
|
||||||
onSuccess: function(res) {
|
onSuccess: function(res) {
|
||||||
|
|||||||
Reference in New Issue
Block a user