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
+5 -12
View File
@@ -1,4 +1,5 @@
<?php
require_once __DIR__ . '/DocumentNumberManager.php';
require_once __DIR__ . '/../classes_ac/PostingWindowGuard.php';
/**
@@ -31,18 +32,10 @@ class QuotationManager
// Private helpers
// ─────────────────────────────────────────────────────────────
private function generateNumber(): string
private function generateNumber(array $data = []): string
{
$prefix = 'QT-' . date('Ym') . '-';
$sth = $this->pdo->prepare(
"SELECT quotation_number FROM td_quotation
WHERE company_id = :cid AND quotation_number LIKE :prefix
ORDER BY id DESC LIMIT 1"
);
$sth->execute([':cid' => $this->company_id, ':prefix' => $prefix . '%']);
$last = $sth->fetchColumn();
$seq = $last ? ((int)substr($last, -4) + 1) : 1;
return $prefix . str_pad($seq, 4, '0', STR_PAD_LEFT);
return (new DocumentNumberManager($this->pdo, $this->company_id))
->resolveNumber($data, 'quotation', 'td_quotation', 'quotation_number');
}
/**
@@ -183,7 +176,7 @@ class QuotationManager
[$subtotal, $tax, $grand] = $this->computeTotals($items, $discount);
if ($id === 0) {
$number = $this->generateNumber();
$number = $this->generateNumber($data);
$log = [array_merge($logging, ['action' => 'create_quotation'])];
$this->pdo->prepare(