accounting workflows
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/BasePosting.php';
|
||||
|
||||
class CreditNotePosting extends BasePosting
|
||||
{
|
||||
protected function getDocType(): string { return 'credit_note'; }
|
||||
|
||||
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 = 'credit_note'
|
||||
LIMIT 1"
|
||||
);
|
||||
$sth->execute([':cid' => $this->companyId, ':id' => $id]);
|
||||
$doc = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$doc) throw new Exception("Credit note #{$id} not found.");
|
||||
return $doc;
|
||||
}
|
||||
|
||||
protected function getAmounts(array $doc): array
|
||||
{
|
||||
// grand_total is negative in DB for credit notes — use abs()
|
||||
$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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user