User Tools

Site Tools


wiki:manara:bugs:edit_item_line_in_invoice

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

wiki:manara:bugs:edit_item_line_in_invoice [2026/07/27 07:16] – Auto-synced from MantisBT mantisbotwiki:manara:bugs:edit_item_line_in_invoice [2026/08/03 07:14] (current) – Removed: not a current major-bug page mantisbot
Line 1: Line 1:
-====== edit item line in invoice (Resolved) ====== 
- 
-**Reported by:** Khaled Tarabay on 2026-07-25T13:31:59+01:00\\ 
-**Assigned to:** Claude\\ 
-**Resolved by:** Claude on 2026-07-27T07:15:22+01:00\\ 
-**Priority:** normal\\ 
-**Severity:** minor\\ 
-**Reproducibility:** always\\ 
-**Category:** General 
- 
-**Description:** 
-when adding an item line to an invoice should only be editable in the case issued and drafted, right now it is uneditable in all cases, make it editable in the cases of status issued and status draft, and completely uneditable in the cases of paid, partially paid, prepaid 
- 
-**Steps to Reproduce:** 
-invoice -> click to view full invoice details -> edit/add item line 
- 
- 
-**Resolution:** 
-FIXED. What: adding/removing an invoice's line items should only be allowed while the invoice is Draft or Issued, and blocked once it's Partially Paid, Paid, or Void. Before this fix there was no such rule at all -- items could be added to (and sometimes removed from) an already-paid invoice. 
- 
-Where: app/classes/Billing/Invoice.php (new itemsEditableForStatus() helper), app/controllers/BillingController.php (addItem()/deleteItem()), app/views/billing/show.php (Add a Charge form + per-row Delete button), app/controllers/Api/InvoiceApiController.php (addItem() -- the JSON API had no status check at all, not even for void). 
- 
-Why: total_amount/amount_paid/invoice_status_id are auto-derived by a database trigger (sp_recalc_invoice) off invoice_items + payments whenever the invoice is Issued/Partially Paid/Paid. So adding a line item to an already-Paid invoice doesn't just look wrong -- it silently flips the invoice's own status back to Partially Paid behind the biller's back on the very next recalc. Draft and Void are explicit human decisions the trigger never touches; Paid/Partially Paid are derived state that line-item edits would corrupt. 
- 
-Fix: a single new Invoice::itemsEditableForStatus() check (draft/issued only) is now enforced in three places -- the web page (buttons/forms only render when editable), the web controller (blocks the POST itself, not just the UI), and the JSON API (previously had zero status awareness). 
- 
-BONUS (found while verifying this): line-item deletion was actually completely broken for EVERY invoice, in every status, before this fix -- a MySQL error ("Can't update table 'invoices' in a trigger because it's already in use by the statement that invoked it") was firing on every delete attempt. It was silently swallowed and shown as a plausible-sounding "could not be removed" message, which is almost certainly why nobody had reported it as its own separate bug. Fixed alongside this ticket (InvoiceItem::delete()) since Draft/Issued invoices need deletion to actually work for this fix to mean anything. 
- 
-Verified live against the local database: created one real test invoice per status (Draft/Issued/Partially Paid/Paid/Void), confirmed the Add-a-Charge form and Delete button only render for Draft/Issued, and confirmed the controller itself blocks add AND delete for Partially Paid/Paid/Void even with a valid, correctly-formed request bypassing the UI entirely -- while Draft/Issued now genuinely allow both (previously delete didn't work for ANY status, per the bonus fix above). Full test suite: 29/29 passing. 
- 
-===== Activity / Notes ===== 
- 
-  * **2026-07-27T07:15:20+01:00 - Claude:** FIXED. What: adding/removing an invoice's line items should only be allowed while the invoice is Draft or Issued, and blocked once it's Partially Paid, Paid, or Void. Before this fix there was no such rule at all -- items could be added to (and sometimes removed from) an already-paid invoice. 
- 
-Where: app/classes/Billing/Invoice.php (new itemsEditableForStatus() helper), app/controllers/BillingController.php (addItem()/deleteItem()), app/views/billing/show.php (Add a Charge form + per-row Delete button), app/controllers/Api/InvoiceApiController.php (addItem() -- the JSON API had no status check at all, not even for void). 
- 
-Why: total_amount/amount_paid/invoice_status_id are auto-derived by a database trigger (sp_recalc_invoice) off invoice_items + payments whenever the invoice is Issued/Partially Paid/Paid. So adding a line item to an already-Paid invoice doesn't just look wrong -- it silently flips the invoice's own status back to Partially Paid behind the biller's back on the very next recalc. Draft and Void are explicit human decisions the trigger never touches; Paid/Partially Paid are derived state that line-item edits would corrupt. 
- 
-Fix: a single new Invoice::itemsEditableForStatus() check (draft/issued only) is now enforced in three places -- the web page (buttons/forms only render when editable), the web controller (blocks the POST itself, not just the UI), and the JSON API (previously had zero status awareness). 
- 
-BONUS (found while verifying this): line-item deletion was actually completely broken for EVERY invoice, in every status, before this fix -- a MySQL error ("Can't update table 'invoices' in a trigger because it's already in use by the statement that invoked it") was firing on every delete attempt. It was silently swallowed and shown as a plausible-sounding "could not be removed" message, which is almost certainly why nobody had reported it as its own separate bug. Fixed alongside this ticket (InvoiceItem::delete()) since Draft/Issued invoices need deletion to actually work for this fix to mean anything. 
- 
-Verified live against the local database: created one real test invoice per status (Draft/Issued/Partially Paid/Paid/Void), confirmed the Add-a-Charge form and Delete button only render for Draft/Issued, and confirmed the controller itself blocks add AND delete for Partially Paid/Paid/Void even with a valid, correctly-formed request bypassing the UI entirely -- while Draft/Issued now genuinely allow both (previously delete didn't work for ANY status, per the bonus fix above). Full test suite: 29/29 passing. 
- 
-===== Full History ===== 
- 
-^ Date Modified ^ Username ^ Field ^ Change ^ 
-| 2026-07-25T13:31:59+01:00 | Khaled Tarabay | issue-new | New Issue | 
-| 2026-07-27T07:15:15+01:00 | Claude | Assigned To |  => Claudine | 
-| 2026-07-27T07:15:18+01:00 | Claude | tag-added | Tag Attached: done-by-claude | 
-| 2026-07-27T07:15:20+01:00 | Claude | note-added | Note Added: 0000009 | 
-| 2026-07-27T07:15:22+01:00 | Claude | Status | new => resolved | 
- 
----- 
-Synced automatically from MantisBT issue #44. 
  
wiki/manara/bugs/edit_item_line_in_invoice.1785132997.txt.gz · Last modified: by mantisbot