- 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>
69 lines
2.4 KiB
PHP
69 lines
2.4 KiB
PHP
<?php
|
|
session_start();
|
|
require_once '../../../assets/utils/db_auth.php';
|
|
require_role($user_role, ['owner', 'admin', 'staff']);
|
|
require_once '../../../assets/utils/classes/ReceiptBillingManager.php';
|
|
|
|
try {
|
|
$mgr = new ReceiptBillingManager($pdo2, $company_id);
|
|
$action = $data['action'] ?? ($_POST['action'] ?? '');
|
|
|
|
if ($action === 'billable_documents') {
|
|
$contact_id = (int)($data['contact_id'] ?? 0);
|
|
$answer['output'] = $mgr->getBillableDocuments($contact_id);
|
|
$answer['success'] = 1;
|
|
exit(json_encode($answer));
|
|
}
|
|
|
|
if ($action === 'open_billings') {
|
|
$contact_id = (int)($data['contact_id'] ?? 0);
|
|
$answer['output'] = $mgr->getOpenBillingList($contact_id);
|
|
$answer['success'] = 1;
|
|
exit(json_encode($answer));
|
|
}
|
|
|
|
if ($action === 'retrieve') {
|
|
$billing_id = (int)($data['id'] ?? $data['billing_id'] ?? 0);
|
|
$answer['output'] = $mgr->getBillingById($billing_id);
|
|
$answer['success'] = 1;
|
|
exit(json_encode($answer));
|
|
}
|
|
|
|
if ($action === 'void') {
|
|
$billing_id = (int)($data['id'] ?? $data['billing_id'] ?? 0);
|
|
dbTransaction($pdo2, function($pdo) use ($billing_id, $company_id, $logging) {
|
|
$mgr = new ReceiptBillingManager($pdo, $company_id);
|
|
$mgr->voidBilling($billing_id, $logging);
|
|
});
|
|
$answer['success'] = 1;
|
|
$answer['message'] = 'Receipt billing voided.';
|
|
exit(json_encode($answer));
|
|
}
|
|
|
|
if ($action === 'create') {
|
|
$new_id = null;
|
|
dbTransaction($pdo2, function($pdo) use ($data, $company_id, $logging, &$new_id) {
|
|
$mgr = new ReceiptBillingManager($pdo, $company_id);
|
|
$new_id = $mgr->createBilling($data, $logging);
|
|
});
|
|
$answer['success'] = 1;
|
|
$answer['new_id'] = $new_id;
|
|
$answer['message'] = 'Receipt billing created.';
|
|
exit(json_encode($answer));
|
|
}
|
|
|
|
$answer['output'] = $mgr->getBillingList();
|
|
$answer['success'] = 1;
|
|
|
|
} catch (PDOException $e) {
|
|
$answer['message'] = 'Database error, please try again.';
|
|
http_response_code(500);
|
|
|
|
} catch (Exception $e) {
|
|
$answer['message'] = $e->getMessage();
|
|
http_response_code(400);
|
|
}
|
|
|
|
exit(json_encode($answer));
|
|
?>
|