40 lines
1.4 KiB
PHP
40 lines
1.4 KiB
PHP
<?php
|
|
session_start();
|
|
require '../../../assets/utils/db_auth.php';
|
|
require '../../../assets/utils/classes/InvoiceManager.php';
|
|
|
|
$inv = new InvoiceManager($pdo2, $company_id);
|
|
$id = (int)($data['invoice_id'] ?? 0);
|
|
|
|
if ($id > 0) {
|
|
$result = $inv->getInvoiceById($id);
|
|
if (!$result) {
|
|
http_response_code(404);
|
|
$answer['message'] = 'Invoice not found.';
|
|
exit(json_encode($answer));
|
|
}
|
|
$answer['output'] = $result;
|
|
|
|
// Fetch linked credit notes for invoice detail page
|
|
if ($result['doc_type'] === 'invoice') {
|
|
$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 / 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));
|
|
?>
|