accounting workflows

This commit is contained in:
Thanakorn S
2026-05-20 10:17:02 +07:00
parent 04a683bd02
commit 7396db6ffc
199 changed files with 23539 additions and 5345 deletions
+54 -2
View File
@@ -303,6 +303,16 @@ class ProductManager {
return $sth->fetch(PDO::FETCH_ASSOC);
}
public function getProductImage(int $id): string
{
$sth = $this->pdo->prepare(
"SELECT product_image FROM md_product
WHERE company_id = :company_id AND id = :id"
);
$sth->execute([':company_id' => $this->company_id, ':id' => $id]);
return (string)($sth->fetchColumn() ?: '');
}
/**
* Search products by SKU keyword — for live autocomplete on stock forms.
*
@@ -368,6 +378,8 @@ class ProductManager {
':category' => $data['category'],
':product_image' => $product_image,
':description' => $data['description'],
':sales_account_code' => trim((string)($data['sales_account_code'] ?? '')) ?: null,
':purchase_account_code' => trim((string)($data['purchase_account_code'] ?? '')) ?: null,
':status' => (int)$data['status'],
':log' => json_encode($table_log),
];
@@ -386,6 +398,8 @@ class ProductManager {
reorder_point = :reorder_point,
category = :category,
product_image = :product_image,
sales_account_code = :sales_account_code,
purchase_account_code = :purchase_account_code,
`description` = :description,
`status` = :status,
`log` = :log
@@ -395,14 +409,52 @@ class ProductManager {
$this->pdo->prepare(
"INSERT INTO md_product
(company_id, product_name, sku, barcode, uom, price, cost_price, min_stock, reorder_point,
category, product_image, `description`, `status`, `log`)
category, product_image, sales_account_code, purchase_account_code, `description`, `status`, `log`)
VALUES
(:company_id, :product_name, :sku, :barcode, :uom, :price, :cost_price, :min_stock, :reorder_point,
:category, :product_image, :description, :status, :log)"
:category, :product_image, :sales_account_code, :purchase_account_code, :description, :status, :log)"
)->execute($params);
}
}
/**
* Update only the accounting account mapping fields for a product.
*
* This is used by Accounting so product master data can stay locked while
* finance users maintain GL routing for SKU-based posting.
*/
public function updateAccountMapping(int $id, ?string $sales_account_code, ?string $purchase_account_code, array $logging): void
{
$sth = $this->pdo->prepare(
"SELECT `log` FROM md_product
WHERE company_id = :company_id AND id = :id"
);
$sth->execute([':company_id' => $this->company_id, ':id' => $id]);
$existing_log = $sth->fetchColumn();
if ($existing_log === false) {
throw new Exception('Product not found.');
}
$table_log = json_decode($existing_log ?: '[]', true) ?: [];
$table_log[] = $logging;
$sth = $this->pdo->prepare(
"UPDATE md_product SET
sales_account_code = :sales_account_code,
purchase_account_code = :purchase_account_code,
`log` = :log
WHERE id = :id AND company_id = :company_id"
);
$sth->execute([
':company_id' => $this->company_id,
':id' => $id,
':sales_account_code' => $sales_account_code,
':purchase_account_code' => $purchase_account_code,
':log' => json_encode($table_log),
]);
}
/**
* Soft-delete a product by negating its company_id.
*