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)); ?>