Files
wms-app/app/order/api/engine/void_invoice.php
T
Thanakorn SandClaude Sonnet 4.6 b8798bc02d Wire targeted toast notifications to document status transitions
Adds emit_notification_user() to 7 endpoints so the acting user and
all admins/owners receive a real-time toast on key document actions:
confirm/cancel order, issue/void invoice, confirm return, confirm PO,
receive PO goods. Other staff and viewers are not notified.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 13:44:55 +07:00

37 lines
1.1 KiB
PHP

<?php
session_start();
require_once '../../../assets/utils/db_auth.php';
require_role($user_role, ['owner', 'admin']);
require_once '../../../assets/utils/classes/InvoiceManager.php';
require_once '../../../assets/utils/notify_node.php';
$id = (int)($data['id'] ?? 0);
if (!$id) {
$answer['message'] = 'Invalid ID.';
http_response_code(400);
exit(json_encode($answer));
}
try {
dbTransaction($pdo2, function($pdo) use ($id, $company_id, $logging) {
$inv = new InvoiceManager($pdo, $company_id);
$inv->voidInvoice($id, $logging);
});
$answer['success'] = 1;
$answer['message'] = 'Invoice voided.';
notify_node('invoice_updated', [], $company_id);
emit_notification_user($company_id, $user_id, 'Invoice Voided', 'The invoice has been voided.', 'warning');
} 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));
?>