Files
wms-app/app/assets/utils/classes_ac/posting/InvoicePosting.php
T
2026-05-20 10:17:02 +07:00

43 lines
1.3 KiB
PHP

<?php
require_once __DIR__ . '/BasePosting.php';
class InvoicePosting extends BasePosting
{
protected function getDocType(): string { return 'invoice'; }
protected function getSkuTotalAccountColumn(): string { return 'sales_account_code'; }
protected function fetchDocument(int $id): array
{
$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;
}
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');
}
}