Commit Graph

6 Commits

Author SHA1 Message Date
Developer
aa8fdaa5aa fix(scanner): add team_id to collection_logs for robust stats tracking
- Created a database migration to add `team_id` to `collection_logs`.
- Created a database migration to backfill `team_id` for past scans using `trip_id` and scanner's active team.
- Updated `ScanService` to lookup the scanner's active team and store the `team_id` directly on the `CollectionLog`.
- Modified the `CollectionTeam` model's `collectionLogs()` relation to be a direct `HasMany` using the new `team_id` instead of routing through `Trip`.
- Updated `AdminTeamReportController` to query metrics directly from `collection_logs.team_id`, ensuring all past and future scans (including those done without an active trip) correctly increment team stats and daily charts.
2026-07-06 16:00:01 +08:00
Developer
f517b77377 style: fix linting issues with Laravel Pint 2026-07-02 13:55:34 +08:00
Developer
a1470eb85e feat: implement team standby status, helper persistence, and store portal foundations 2026-07-02 12:03:50 +08:00
Developer
b85fc255cf feat: implement barangay and household management with associated tests 2026-06-29 15:02:52 +08:00
bb2c574f5c feat: multi-LGU tenancy — Phase B (full data scoping)
Backend models + DB:
- Adds tenant_id to 13 more parent tables: service_areas, routes,
  collection_teams, trucks, trips, qr_code_batches, qr_codes,
  collection_logs, dumpsite_releases, payments, daily_collection_stats,
  weekly_route_performance, monthly_store_sales.
  Child tables (route_stops, trip_stops, team_members,
  truck_location_history, etc.) inherit scoping via their parent
  relation — they aren't queried directly in production code.
- HasTenant trait applied to all 13 models, plus tenant_id added
  to each fillable. Creating any one of these now auto-fills
  tenant_id from Tenancy::current().
- BatchGenerator's bulk QrCode insert was bypassing model events
  (and therefore the HasTenant creating hook). Now sets tenant_id
  inline from the just-created batch's tenant_id, which itself
  goes through the trait. Fixes "0 codes returned for resident in
  same tenant" regression.

Backfill:
- SanPascualTenantSeeder extended to backfill all 18 tenant-aware
  tables. Idempotent — only updates rows where tenant_id is null.
  Production live data: backfilled 1 route, 1 team, 1 truck, 3
  trips, 1 batch, 200 codes, 5 collection logs.

Tests:
- TestCase base now creates a default "TEST-LGU" tenant in setUp,
  sets it as Tenancy::current(), and attaches X-Tenant-Code on
  every JSON request. Tear-down clears the tenant.
- UserFactory defaults tenant_id to Tenancy::current()->id, so
  factory-created users land in the test tenant.
- Net result: 202 tests still passing, no per-test changes
  required.

Phase A scope (5 tables) + Phase B scope (13 tables) = 18 of the
~22 tenant-aware tables. The remaining child tables (route_stops,
trip_stops, team_members, truck_location_history, household_members,
trip_timeline_events, store_purchases, store_sales) are scoped
implicitly through their parent.

What's still un-tenant-aware:
- Admin web (Blade-based) — single-tenant context for now
- Driver/scanner endpoints — they currently rely on the bearer
  token's user.tenant_id, which works correctly via ResolveTenant's
  fallback. No action needed.
- Super-admin onboarding UI — Phase C.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 22:57:56 +08:00
15f9295d34 feat(backend): complete Module 9 (teams + trucks)
trucks (with optional last_known_coordinates POINT 4326),
collection_teams, team_members. Admin CRUD for both. TeamConflictDetector
flags double-assignment of driver/scanner/truck/helper across active
teams; override_conflicts: true bypasses for emergencies. Promotes
routes.default_team_id to a real FK now that collection_teams exists.

144 feature tests passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 02:48:40 +08:00