Table of Contents

#155 — Contact Ledger Supplier Purchase Not Synced With Inventory (Resolved)

← Back to Manara Bugs · View issue #155 in MantisBT


Reported by: Khaled Tarabay on 2026-08-01T08:44:10+01:00
Assigned to: Claude
Resolved by: Claude on 2026-08-01T10:13:44+01:00
Severity: major
Priority: normal
Reproducibility: always
Category: General

Description: right now when your contact is a supplier and buy something from them say ONU/ONT it auto creates and invoice and expense but the purchase doesn't show in the inventory what must happen is that you, it should check if there is an existing inventory item with this name so in our ONU/ONT example incase there is ONU/ONT in the inventory it adds up upon the existing entry, say I bought 15 ONUs and had 20 in the inventory, instead of creating a new ONU/ONT entry in the entry it should pile upon the existing one so my entry shows 35 ONUs in inventory, also in case I have an ONU/ONT entry but zero in stock the purchase should add the number so in our example I had 0 ONU/ONT in the entry pre-purchase after the purchase it becomes 15 ONU/ONT, and incase I don't have ONU/ONT it creates an entry with the number I purchased. now also the option of labor/installation cannot be stored so purchase with this label doesn't need to be in the an inventory entry, also remove the others option from the dropdown of the contact ledger contents in the case of supplier and internet provider

Resolution: FIXED (verified live).

WHAT: A supplier/internet-provider purchase created an invoice + expense but never showed up in inventory. Now each purchased physical good adds its quantity to inventory — piling onto an existing same-named item, or creating it. Labor/Installation lines aren't stocked, and “Other” was removed from the purchase Contents dropdown.

WHERE: app/controllers/ContactController.php (addTransaction, purchase branch); app/classes/Crm/ContactLedgerEffects.php (new); app/classes/Inventory/InventoryItem.php; app/classes/Billing/InvoiceContentType.php.

WHY: nothing linked a contact purchase to the inventory stock pool.

FIX: New ContactLedgerEffects::applyInventoryForPurchase() (called inside the same transaction as the invoice): for each Contents line, resolve its catalog code by name and SKIP a 'labor' line (not stockable); otherwise InventoryItem::findIdByName() (new, case-insensitive) finds the existing same-named item and adds the quantity via adjustStock(+qty,'restock',…) — which logs a StockMovement and records the supplier + unit cost — or creates a new item at 0 and adjusts up (so even a new item's opening stock is an audited movement). Covers all three cases from the ticket: item exists (e.g. 20 → 35), item exists at 0 (0 → 15), item absent (created with 15). Migration 079 deletes the 'other' system row from the Contents catalog.

VERIFIED (throwaway MySQL): a purchase of ONU/ONT x15 + Labor + Router x5 stocked ONU=15 (with a logged movement) and Router=5 and skipped Labor; a second ONU x15 piled to 30 with no duplicate item; a pre-existing 0-stock item went 0 → 7. PHPUnit 29/29.

DEPLOY: prod must run /run-migrations.php to apply migration 079.

Activity / Notes

WHAT: A supplier/internet-provider purchase created an invoice + expense but never showed up in inventory. Now each purchased physical good adds its quantity to inventory — piling onto an existing same-named item, or creating it. Labor/Installation lines aren't stocked, and “Other” was removed from the purchase Contents dropdown.

WHERE: app/controllers/ContactController.php (addTransaction, purchase branch); app/classes/Crm/ContactLedgerEffects.php (new); app/classes/Inventory/InventoryItem.php; app/classes/Billing/InvoiceContentType.php.

WHY: nothing linked a contact purchase to the inventory stock pool.

FIX: New ContactLedgerEffects::applyInventoryForPurchase() (called inside the same transaction as the invoice): for each Contents line, resolve its catalog code by name and SKIP a 'labor' line (not stockable); otherwise InventoryItem::findIdByName() (new, case-insensitive) finds the existing same-named item and adds the quantity via adjustStock(+qty,'restock',…) — which logs a StockMovement and records the supplier + unit cost — or creates a new item at 0 and adjusts up (so even a new item's opening stock is an audited movement). Covers all three cases from the ticket: item exists (e.g. 20 → 35), item exists at 0 (0 → 15), item absent (created with 15). Migration 079 deletes the 'other' system row from the Contents catalog.

VERIFIED (throwaway MySQL): a purchase of ONU/ONT x15 + Labor + Router x5 stocked ONU=15 (with a logged movement) and Router=5 and skipped Labor; a second ONU x15 piled to 30 with no duplicate item; a pre-existing 0-stock item went 0 → 7. PHPUnit 29/29.

DEPLOY: prod must run /run-migrations.php to apply migration 079.

Full History

Date User Field Change
2026-08-01T08:44:10+01:00 Khaled Tarabay issue-new New Issue
2026-08-01T10:13:38+01:00 Claude Assigned To ⇒ Claudine
2026-08-01T10:13:40+01:00 Claude tag-added Tag Attached: done-by-claude
2026-08-01T10:13:42+01:00 Claude note-added Note Added: 0000113
2026-08-01T10:13:44+01:00 Claude Status new ⇒ resolved

Synced automatically from MantisBT issue #155.