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
@@ -1,4 +1,5 @@
<?php
require_once __DIR__ . '/DocumentNumberManager.php';
require_once __DIR__ . '/../classes_ac/PostingWindowGuard.php';
class PaymentBillingManager {
@@ -11,23 +12,10 @@ class PaymentBillingManager {
$this->company_id = $company_id;
}
private function generateBillingNumber(): string
private function generateBillingNumber(array $data = []): string
{
$prefix = 'PB-' . date('Ymd') . '-';
$sth = $this->pdo->prepare(
"SELECT billing_number FROM td_payment_billing
WHERE company_id = :company_id
AND billing_number LIKE :prefix
ORDER BY billing_number DESC
LIMIT 1"
);
$sth->execute([
':company_id' => $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, 'payment_billing', 'td_payment_billing', 'billing_number');
}
private function unavailableDocumentAmount(int $invoice_id): float
@@ -340,7 +328,7 @@ class PaymentBillingManager {
)->execute([
':company_id' => $this->company_id,
':uuid' => bin2hex(random_bytes(16)),
':billing_number' => $this->generateBillingNumber(),
':billing_number' => $this->generateBillingNumber($data),
':contact_id' => $contact_id,
':billing_date' => $billing_date,
':amount' => $net_amount,