stock database design

This commit is contained in:
Thanakorn S
2026-03-09 17:03:18 +07:00
parent 7cb78d013b
commit 2e558a55bb
5 changed files with 66 additions and 17 deletions
+19 -1
View File
@@ -5,6 +5,8 @@ require '../../../assets/utils/db_auth.php';
$id = (int)($data['id'] ?? 0);
$pdo2->beginTransaction();
// get existing log
$sql = "SELECT `log`
FROM md_warehouse
@@ -51,6 +53,7 @@ if ($id > 0) {
":status" => (int)($data["status"] ?? 1),
":log" => json_encode($table_log, JSON_UNESCAPED_UNICODE),
]);
db_check($sth, $answer);
} else {
@@ -70,10 +73,25 @@ if ($id > 0) {
":status" => (int)($data["status"] ?? 1),
":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;
exit(json_encode($answer));