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
+9 -27
View File
@@ -17,41 +17,23 @@
// Fetch linked credit notes for invoice detail page
if ($result['doc_type'] === 'invoice') {
$sth = $pdo2->prepare(
"SELECT * FROM td_invoice
WHERE company_id = :company_id
AND ref_invoice_id = :ref_id
AND doc_type = 'credit_note'
ORDER BY id DESC"
);
$sth->execute([':company_id' => $company_id, ':ref_id' => $id]);
$answer['credit_notes'] = $sth->fetchAll(PDO::FETCH_ASSOC);
$answer['credit_notes'] = $inv->getLinkedCreditNotes($id, 'credit_note');
}
if ($result['doc_type'] === 'purchase_invoice') {
$answer['supplier_credit_notes'] = $inv->getLinkedCreditNotes($id, 'supplier_credit_note');
}
} else {
$order_id = (int)($data['order_id'] ?? 0);
$doc_type = $data['doc_type'] ?? '';
$answer['output'] = $inv->getInvoiceList($order_id, $doc_type);
// For credit note tab — join ref invoice number
if ($doc_type === 'credit_note') {
$rows = $answer['output'];
foreach ($rows as &$row) {
if ((int)$row['ref_invoice_id'] > 0) {
$sth = $pdo2->prepare(
"SELECT invoice_number FROM td_invoice
WHERE id = :id AND company_id = :company_id"
);
$sth->execute([':id' => $row['ref_invoice_id'], ':company_id' => $company_id]);
$row['ref_invoice_number'] = $sth->fetchColumn() ?: '—';
} else {
$row['ref_invoice_number'] = '—';
}
}
unset($row);
$answer['output'] = $rows;
// For credit note / debit note tabs — join ref invoice number
if ($doc_type === 'credit_note' || $doc_type === 'supplier_credit_note') {
$answer['output'] = $inv->addReferenceInvoiceNumbers($answer['output']);
}
}
$answer['success'] = 1;
exit(json_encode($answer));
?>
?>