fix login and configurations

This commit is contained in:
nok
2026-08-03 11:17:41 +07:00
parent 7b294f70da
commit 618045540a
11 changed files with 364 additions and 31 deletions
+54 -4
View File
@@ -269,7 +269,7 @@ run($pdo, "
CREATE TABLE IF NOT EXISTS `md_bin` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_id` int(11) NOT NULL,
`td_stock_id` int(11) NOT NULL DEFAULT 0,
`td_stock_id` int(11) DEFAULT NULL,
`warehouse` int(11) NOT NULL,
`storage_id` int(11) NOT NULL DEFAULT 0,
`zone` varchar(10) NOT NULL,
@@ -283,6 +283,15 @@ CREATE TABLE IF NOT EXISTS `md_bin` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
", 'md_bin');
// Column made nullable — WarehouseManager::releaseBin() does `SET td_stock_id =
// NULL` to mark a bin empty (mirroring product_sku on the same row), but the
// column was NOT NULL DEFAULT 0. Under strict SQL mode this made releaseBin()
// fail with "Column 'td_stock_id' cannot be null" on every supplier return,
// every fully-depleted stock-out, and every stock transfer. Every read site
// (getBinStock(), occupyBin()) already treats 0 and NULL as equivalent "empty"
// (`if (!$td_stock_id)`), so this is a safe, behavior-preserving widening.
run($pdo, "ALTER TABLE `md_bin` MODIFY `td_stock_id` int(11) DEFAULT NULL", 'md_bin.td_stock_id nullable');
run($pdo, "
CREATE TABLE IF NOT EXISTS `td_bin_log` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
@@ -513,7 +522,7 @@ CREATE TABLE IF NOT EXISTS `td_stock` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ref_id` int(11) unsigned NOT NULL DEFAULT 0,
`company_id` int(11) NOT NULL DEFAULT 0,
`uuid` varchar(20) NOT NULL,
`uuid` varchar(64) NOT NULL,
`type` varchar(20) NOT NULL,
`ref_warehouse` varchar(20) NOT NULL DEFAULT '',
`date` datetime DEFAULT NULL,
@@ -540,6 +549,22 @@ CREATE TABLE IF NOT EXISTS `td_stock` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
", 'td_stock (base template)');
// Column widened for db_auth.php's 32-char $uuid (bin2hex(random_bytes(16))) plus
// manager-appended suffixes (e.g. "_ret_0", "_srn_0", "_3") — varchar(20) was too
// narrow and caused "Data too long for column 'uuid'" on every real stock movement
// (PO receipt, order confirm, return confirm, stock transfer) under strict SQL mode.
run($pdo, "ALTER TABLE `td_stock` MODIFY `uuid` varchar(64) NOT NULL", 'td_stock.uuid width');
// Per-warehouse td_stock_<id> tables are cloned from td_stock at warehouse-creation
// time (WarehouseManager::createStockTableForWarehouse()) and are NOT otherwise
// tracked by this script — widen uuid on every one that already exists so
// previously-created warehouses get the same fix. New warehouses get it for free
// from the template above.
$stockTables = $pdo->query("SHOW TABLES LIKE 'td\\_stock\\_%'")->fetchAll(PDO::FETCH_COLUMN);
foreach ($stockTables as $t) {
run($pdo, "ALTER TABLE `{$t}` MODIFY `uuid` varchar(64) NOT NULL", "{$t}.uuid width");
}
run($pdo, "
CREATE TABLE IF NOT EXISTS `etl_stock_summary` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
@@ -558,6 +583,24 @@ CREATE TABLE IF NOT EXISTS `etl_stock_summary` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
", 'etl_stock_summary');
run($pdo, "
CREATE TABLE IF NOT EXISTS `etl_gl_summary` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`company_id` int(11) unsigned NOT NULL DEFAULT 0,
`acc_code` int(11) NOT NULL DEFAULT 0,
`period` varchar(7) NOT NULL,
`debit` decimal(18,4) NOT NULL DEFAULT 0.0000,
`credit` decimal(18,4) NOT NULL DEFAULT 0.0000,
`count` int(11) NOT NULL DEFAULT 0,
`source_updated_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `company_id_acc_code_period` (`company_id`,`acc_code`,`period`),
KEY `company_id` (`company_id`),
KEY `period` (`period`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
", 'etl_gl_summary');
// ── Transactions ──────────────────────────────────────────────────────────────
run($pdo, "
CREATE TABLE IF NOT EXISTS `td_gl` (
@@ -795,6 +838,7 @@ CREATE TABLE IF NOT EXISTS `td_return` (
`tax` decimal(18,4) NOT NULL DEFAULT 0.0000,
`tax_adjustment` decimal(8,2) NOT NULL DEFAULT 0.00,
`notes` text NOT NULL DEFAULT '',
`formula_id` int(11) DEFAULT NULL,
`log` mediumtext NOT NULL DEFAULT '{}',
PRIMARY KEY (`id`),
KEY `company_id` (`company_id`),
@@ -806,6 +850,12 @@ CREATE TABLE IF NOT EXISTS `td_return` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
", 'td_return');
// Column added for ReturnManager::saveFormula() / custom credit-note GL formula
// selection — was missing from the original table (unlike td_invoice/td_receipt/
// td_payment, which all have formula_id). Without it, ReturnManager::saveReturn()
// fails on every insert.
run($pdo, "ALTER TABLE `td_return` ADD COLUMN `formula_id` int(11) DEFAULT NULL AFTER `notes`", 'td_return.formula_id');
run($pdo, "
CREATE TABLE IF NOT EXISTS `td_return_item` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
@@ -1135,7 +1185,7 @@ CREATE TABLE IF NOT EXISTS `td_payment_item` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
", 'td_payment_item');
run_ddl("
run($pdo, "
CREATE TABLE IF NOT EXISTS `document_types` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`company_id` int(11) NOT NULL DEFAULT 0,
@@ -1152,7 +1202,7 @@ CREATE TABLE IF NOT EXISTS `document_types` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
", 'document_types');
run_ddl("
run($pdo, "
CREATE TABLE IF NOT EXISTS `document_number_sequences` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`company_id` int(11) NOT NULL DEFAULT 0,