User Tools

Site Tools


wiki:manara:bugs:154

#154 — Contact Ledger Services Not Creating Instances of Maintenance and Installation (Resolved)

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


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

Description: right now in the contact ledger when you add service and choose it's quality either maintenance or installation it creates an invoice but doesn't create an installation entry or a maintenance one , what we want is that when add a service as installation that it auto creates an installation entry and the same when maintenance visit is the service entered, it must also auto create a maintenance entry in the maintenance tab, and also reconnection fee and static ip options in the contact ledger add items when the contact is a client they should be removed

Resolution: FIXED (verified live).

WHAT: In the contact ledger, selling a client-contact an “Installation” or “Maintenance Visit” service created only the invoice — no matching installation/maintenance entry appeared in those tabs. Also removed Static IP + Reconnection Fee from the client Services dropdown as requested.

WHERE: app/controllers/ContactController.php (addTransaction) + app/controllers/BillingController.php (storeContactSale); app/classes/Crm/ContactLedgerEffects.php (new); app/classes/FieldOps/{Installation,Maintenance}.php; installations + maintenance_jobs schema; app/classes/Billing/InvoiceServiceType.php.

WHY: installations and maintenance_jobs required a customer_id (NOT NULL FK to customers), and a contact is not a customer — so a client-contact sale had nowhere to attach a field job.

FIX: Migration 079 makes both tables polymorphic — customer_id becomes nullable and a nullable contact_id (FK to contacts) is added, with a XOR CHECK 1), mirroring the invoices polymorphism. New ContactLedgerEffects::applyFieldJobsForSale() (called from both sale entry points, inside the same DB transaction as the invoice) creates a contact-backed installation/maintenance for each Installation/Maintenance service line, linked to the sale invoice (so it isn't billed twice), amount = that line's qty x price. Both models COALESCE the contact name into the existing customer_name alias, so list/show render it with no view changes; the edit forms + validate() handle a contact-backed row (customer picker replaced by the contact shown read-only, customer requirement skipped, linkage preserved). Migration 079 also deletes the Static IP + Reconnection Fee system rows from the Services catalog.

VERIFIED against an isolated throwaway MySQL 8.0 (a separate port, real .env.local never touched): fresh schema loads clean; migration 079 upgrades an old-shape DB and is idempotent; functional 23/23 (a client sale of Internet+Installation+Maintenance created exactly one contact-backed installation + one maintenance job, each invoice-linked with the correct amount, shown as the contact name; internet-only sale created no field job); edit-path 7/7; PHPUnit 29/29 (869 assertions).

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

Activity / Notes

  • 2026-08-01T10:13:32+01:00 - Claude: FIXED (verified live).

WHAT: In the contact ledger, selling a client-contact an “Installation” or “Maintenance Visit” service created only the invoice — no matching installation/maintenance entry appeared in those tabs. Also removed Static IP + Reconnection Fee from the client Services dropdown as requested.

WHERE: app/controllers/ContactController.php (addTransaction) + app/controllers/BillingController.php (storeContactSale); app/classes/Crm/ContactLedgerEffects.php (new); app/classes/FieldOps/{Installation,Maintenance}.php; installations + maintenance_jobs schema; app/classes/Billing/InvoiceServiceType.php.

WHY: installations and maintenance_jobs required a customer_id (NOT NULL FK to customers), and a contact is not a customer — so a client-contact sale had nowhere to attach a field job.

FIX: Migration 079 makes both tables polymorphic — customer_id becomes nullable and a nullable contact_id (FK to contacts) is added, with a XOR CHECK 2), mirroring the invoices polymorphism. New ContactLedgerEffects::applyFieldJobsForSale() (called from both sale entry points, inside the same DB transaction as the invoice) creates a contact-backed installation/maintenance for each Installation/Maintenance service line, linked to the sale invoice (so it isn't billed twice), amount = that line's qty x price. Both models COALESCE the contact name into the existing customer_name alias, so list/show render it with no view changes; the edit forms + validate() handle a contact-backed row (customer picker replaced by the contact shown read-only, customer requirement skipped, linkage preserved). Migration 079 also deletes the Static IP + Reconnection Fee system rows from the Services catalog.

VERIFIED against an isolated throwaway MySQL 8.0 (a separate port, real .env.local never touched): fresh schema loads clean; migration 079 upgrades an old-shape DB and is idempotent; functional 23/23 (a client sale of Internet+Installation+Maintenance created exactly one contact-backed installation + one maintenance job, each invoice-linked with the correct amount, shown as the contact name; internet-only sale created no field job); edit-path 7/7; PHPUnit 29/29 (869 assertions).

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

Full History

Date User Field Change
2026-08-01T08:21:13+01:00 Khaled Tarabay issue-new New Issue
2026-08-01T10:13:27+01:00 Claude Assigned To ⇒ Claudine
2026-08-01T10:13:31+01:00 Claude tag-added Tag Attached: done-by-claude
2026-08-01T10:13:32+01:00 Claude note-added Note Added: 0000112
2026-08-01T10:13:35+01:00 Claude Status new ⇒ resolved

Synced automatically from MantisBT issue #154.

1) , 2)
customer_id IS NULL) <> (contact_id IS NULL
wiki/manara/bugs/154.txt · Last modified: by mantisbot