document number sequence
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/DocumentNumberManager.php';
|
||||
require_once __DIR__ . '/../classes_ac/PostingWindowGuard.php';
|
||||
require_once __DIR__ . '/../classes_ac/GlManager.php';
|
||||
|
||||
@@ -70,37 +71,13 @@ class InvoiceManager {
|
||||
/**
|
||||
* Generate next sequential document number.
|
||||
*
|
||||
* @param string $doc_type 'invoice' | 'credit_note' | 'supplier_credit_note'
|
||||
* @return string e.g. "INV-20260502-0001" | "CN-20260502-0001" | "DN-20260502-0001"
|
||||
* @param string $doc_type 'invoice' | 'credit_note' | 'purchase_invoice' | 'supplier_credit_note'
|
||||
* @return string e.g. "INV-2605-00001" | "CN-2605-00001" | "PI-2605-00001" | "SCN-2605-00001"
|
||||
*/
|
||||
private function generateInvoiceNumber(string $doc_type): string
|
||||
private function generateInvoiceNumber(string $doc_type, array $data = []): string
|
||||
{
|
||||
$prefix_map = [
|
||||
'invoice' => 'INV',
|
||||
'credit_note' => 'CN',
|
||||
'supplier_credit_note' => 'DN',
|
||||
'purchase_invoice' => 'PINV',
|
||||
];
|
||||
$prefix = ($prefix_map[$doc_type] ?? 'INV') . '-' . date('Ymd') . '-';
|
||||
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT invoice_number FROM td_invoice
|
||||
WHERE company_id = :company_id
|
||||
AND doc_type = :doc_type
|
||||
AND invoice_number LIKE :prefix
|
||||
ORDER BY invoice_number DESC
|
||||
LIMIT 1"
|
||||
);
|
||||
$sth->execute([
|
||||
':company_id' => $this->company_id,
|
||||
':doc_type' => $doc_type,
|
||||
':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, $doc_type, 'td_invoice', 'invoice_number');
|
||||
}
|
||||
|
||||
private function addSettlementFields(array $row): array
|
||||
@@ -1013,7 +990,7 @@ class InvoiceManager {
|
||||
)->execute([
|
||||
':company_id' => $this->company_id,
|
||||
':uuid' => bin2hex(random_bytes(16)),
|
||||
':invoice_number' => $this->generateInvoiceNumber('credit_note'),
|
||||
':invoice_number' => $this->generateInvoiceNumber('credit_note', $data),
|
||||
':ref_invoice_id' => $ref_invoice_id,
|
||||
':order_id' => $order_id,
|
||||
':contact_id' => $contact_id,
|
||||
@@ -1132,7 +1109,7 @@ class InvoiceManager {
|
||||
)->execute([
|
||||
':company_id' => $this->company_id,
|
||||
':uuid' => bin2hex(random_bytes(16)),
|
||||
':invoice_number' => $this->generateInvoiceNumber('supplier_credit_note'),
|
||||
':invoice_number' => $this->generateInvoiceNumber('supplier_credit_note', $data),
|
||||
':ref_invoice_id' => $ref_invoice_id,
|
||||
':contact_id' => $contact_id,
|
||||
':subtotal' => $subtotal,
|
||||
|
||||
Reference in New Issue
Block a user