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
@@ -1,21 +1,42 @@
<?php
/**
* InvoicePosting
*
* Builds the journal entry for a posted sales invoice.
* DR: Accounts Receivable
* CR: Revenue + Output VAT
*/
class InvoicePosting
{
private PDO $pdo;
private int $companyId;
require_once __DIR__ . '/BasePosting.php';
public function __construct(PDO $pdo, int $company_id)
class InvoicePosting extends BasePosting
{
protected function getDocType(): string { return 'invoice'; }
protected function getSkuTotalAccountColumn(): string { return 'sales_account_code'; }
protected function fetchDocument(int $id): array
{
$this->pdo = $pdo;
$this->companyId = $company_id;
$sth = $this->pdo->prepare(
"SELECT i.*, COALESCE(c.contact_name, '') AS contact_name
FROM td_invoice i
LEFT JOIN md_contact c
ON c.company_id = i.company_id AND c.id = i.contact_id
WHERE i.company_id = :cid AND i.id = :id AND i.doc_type = 'invoice'
LIMIT 1"
);
$sth->execute([':cid' => $this->companyId, ':id' => $id]);
$doc = $sth->fetch(PDO::FETCH_ASSOC);
if (!$doc) throw new Exception("Invoice #{$id} not found.");
return $doc;
}
// TODO: build(int $invoice_id): array — returns [header, lines] ready for JournalManager
protected function getAmounts(array $doc): array
{
$grand_total = abs((float)$doc['grand_total']);
$tax = abs((float)$doc['tax']);
return [
'grand_total' => $grand_total,
'tax' => $tax,
'total' => $grand_total - $tax,
'amount' => $grand_total,
];
}
protected function getDocDate(array $doc): string
{
return $doc['issued_date'] ?? date('Y-m-d');
}
}