document number sequence

This commit is contained in:
Thanakorn S
2026-05-26 08:19:40 +07:00
parent 4f884177a5
commit 1904fea84c
25 changed files with 846 additions and 216 deletions
+14 -5
View File
@@ -47,6 +47,11 @@ class StockManager {
return 'td_stock_' . $warehouse_id;
}
private function stockReferenceSql(): string
{
return "CONCAT(DATE_FORMAT(COALESCE(a.`date`, a.updated_at), '%Y%m%d%H%i%s'), '-', LPAD(a.id, 11, '0'))";
}
// ─────────────────────────────────────────────────────────────
// TRANSACTION BASIS — Read
// ─────────────────────────────────────────────────────────────
@@ -66,12 +71,13 @@ class StockManager {
{
$table = $this->stockTableNameFromWarehouseId($warehouse_id);
$column = $type === 'out' ? 'ROUND(a.out, 2)' : 'ROUND(a.in, 2)';
$stock_ref = $this->stockReferenceSql();
// Transfer list: show only the outbound side (out > 0) to avoid duplicate display
$extra_cond = ($type === 'transfer') ? 'AND a.out > 0' : '';
$sth = $this->pdo->prepare(
"SELECT a.*, {$column} AS quantity, b.product_name, b.uom
"SELECT a.*, {$stock_ref} AS stock_reference, {$column} AS quantity, b.product_name, b.uom
FROM `{$table}` a
LEFT JOIN md_product b
ON a.company_id = b.company_id
@@ -102,9 +108,10 @@ class StockManager {
public function getStockInById(int $warehouse_id, int $id): array|false
{
$table = $this->stockTableNameFromWarehouseId($warehouse_id);
$stock_ref = $this->stockReferenceSql();
$sth = $this->pdo->prepare(
"SELECT a.*, a.in AS quantity,
"SELECT a.*, {$stock_ref} AS stock_reference, a.in AS quantity,
b.contact_name,
c.product_name, c.uom,
d.expiry_date
@@ -137,9 +144,10 @@ class StockManager {
public function getStockOutById(int $warehouse_id, int $id): array|false
{
$table = $this->stockTableNameFromWarehouseId($warehouse_id);
$stock_ref = $this->stockReferenceSql();
$sth = $this->pdo->prepare(
"SELECT a.*, a.out AS quantity,
"SELECT a.*, {$stock_ref} AS stock_reference, a.out AS quantity,
b.contact_name,
c.product_name, c.uom
FROM `{$table}` a
@@ -170,10 +178,11 @@ class StockManager {
public function getTransferById(int $warehouse_id, int $id): array|false
{
$table = $this->stockTableNameFromWarehouseId($warehouse_id);
$stock_ref = $this->stockReferenceSql();
// Fetch the outbound (from) row
$sth = $this->pdo->prepare(
"SELECT a.*, a.out AS quantity,
"SELECT a.*, {$stock_ref} AS stock_reference, a.out AS quantity,
b.contact_name,
c.product_name, c.uom
FROM `{$table}` a
@@ -193,7 +202,7 @@ class StockManager {
$to_table = $this->stockTableNameFromWarehouseId($to_warehouse_id);
$sth = $this->pdo->prepare(
"SELECT a.*, a.in AS quantity,
"SELECT a.*, {$stock_ref} AS stock_reference, a.in AS quantity,
b.contact_name,
c.product_name, c.uom
FROM `{$to_table}` a