Files
wms-app/app/order/api/engine/retrieve_invoice.php
T
Thanakorn SandClaude Sonnet 4.6 b07882e3f4 code audit fixes: require_once, issue flow, role guards
- Upgraded all plain `require` to `require_once` across 172 api/engine
  and api/engine_report files to prevent class-redeclaration errors
- Added issue button, issue_invoice() with GL toastr, and delete_invoice()
  to expense/manage_purchase_invoice.php, bringing it in line with
  po/manage_purchase_invoice.php
- Added can_delete role guard (admin/owner only) to trash icons on
  revenue/invoice.php and expense/purchase_invoice.php, matching the
  existing pattern in finance/receipt.php and finance/payment.php

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-23 17:06:08 +07:00

40 lines
1.4 KiB
PHP

<?php
session_start();
require_once '../../../assets/utils/db_auth.php';
require_once '../../../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));
?>