CRM: Contract management
Technical specification for contract management in the PestControlOS CRM (PWA).
Data model
- Firestore: Technician-specific contract collections (e.g.
[User] Contractsor per contractKey). Document fields: customer, address, visit frequency, last visit date, next visit (computed or stored), status (Overdue, Due Soon, On Schedule, No Date). Add contract; assign technician; add directly to calendar (creates or links calendar event). - Scoping: Contracts are scoped by technician access level. Admin can add/assign to any technician; technician sees only their own contracts. Firestore rules: read/write where
request.auth.token.contractKeymatches collection or role is admin/super_admin.
Operations
- Add new contract: Create document in target technician’s contract collection. Assign technician via dropdown; assigned technician receives in-app notification (write to
notifications/{user}/itemsin Firestore). - Track visits: Update last visit date; next visit calculated from frequency or stored. Status logic: Overdue (next visit past), Due Soon (within threshold), On Schedule, No Date.
- Search and filter: Client-side or Firestore query by status, technician, customer name. Counters for Behind/Due/Up-to-date for UI.
- Add to calendar: Create event in technician’s workview linked to contract; or link existing event. Ensures contract appears on schedule.
Rules
- Contract collections are namespaced per technician. Rules must allow read/write only for that technician or admin/super_admin. No cross-technician read of contract documents unless admin.