From cb262139aebeba434c3ada123e46b588186cb32e Mon Sep 17 00:00:00 2001 From: Wrongecho Date: Fri, 11 Sep 2026 11:56:40 +0000 Subject: [PATCH] Invoicing - bug: fix not being able to add tickets to invoice; feature: add ability to remove tickets from invoice --- agent/invoice.php | 14 ++++++++---- agent/modals/invoice/invoice_add_ticket.php | 12 +++++++++-- agent/post/invoice.php | 24 ++++++++++++++++++++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/agent/invoice.php b/agent/invoice.php index da87319da..4ceee375e 100644 --- a/agent/invoice.php +++ b/agent/invoice.php @@ -141,7 +141,7 @@ if (isset($_GET['invoice_id'])) { //Get billable, and unbilled tickets to add to invoice $sql_tickets_billable = mysqli_query( $mysqli, " - SELECT 1 + SELECT ticket_id, ticket_subject, ticket_number, ticket_prefix, ticket_status FROM tickets WHERE @@ -151,10 +151,9 @@ if (isset($_GET['invoice_id'])) { AND ticket_invoice_id = 0 AND - ticket_status = 5; + ticket_status IN (4, 5); "); - //Add up all the payments for the invoice and get the total amount paid to the invoice $sql_amount_paid = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS amount_paid FROM payments WHERE payment_invoice_id = $invoice_id"); $row = mysqli_fetch_assoc($sql_amount_paid); @@ -697,7 +696,7 @@ if (isset($_GET['invoice_id'])) { -
"> +
">
Tickets @@ -728,15 +727,19 @@ if (isset($_GET['invoice_id'])) { + + + + + - +
# Date Subject Time Worked
- +
+ + + + +
+
diff --git a/agent/post/invoice.php b/agent/post/invoice.php index c22cfa22e..d68b2ffff 100644 --- a/agent/post/invoice.php +++ b/agent/post/invoice.php @@ -1003,6 +1003,7 @@ if (isExportRequest('export_invoices')) { } +// TODO: This should probably be removed as we now allow multiple invoices to be linked to a single ticket if (isset($_POST['link_invoice_to_ticket'])) { validateCSRFToken(); @@ -1041,7 +1042,28 @@ if (isset($_POST['add_ticket_to_invoice'])) { flashAlert("Ticket linked to invoice"); - redirect("post.php?add_ticket_to_invoice=$invoice_id"); + redirect("invoice.php?invoice_id=$invoice_id"); + +} + +if (isset($_GET['remove_ticket_from_invoice'])) { + + validateCSRFToken(); + + enforceUserPermission('module_sales', 2); + + $invoice_id = intval($_GET['invoice_id']); + $ticket_id = intval($_GET['ticket_id']); + + $client_id = intval(getFieldById('tickets', $ticket_id, 'ticket_client_id')); + + enforceClientAccess(); + + mysqli_query($mysqli,"UPDATE tickets SET ticket_invoice_id = 0 WHERE ticket_id = $ticket_id"); + + flashAlert("Ticket unlinked from invoice"); + + redirect("invoice.php?invoice_id=$invoice_id"); }