Commit Graph

5 Commits

Author SHA1 Message Date
Developer
c4cbdb42c7 feat(store): complete partner store overhaul with mapping, household search, financial analytics, and resident notification system 2026-07-02 13:55:08 +08:00
ramram1515
647af45b99 Fix PartnerStoreSettlementTest and QrCode replacement 2026-07-02 13:47:49 +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
86ea731eb0 feat(backend): finish all deferred items — Sentry, audit, bulk, FCM, Reverb, PSGC
- **Sentry** wired in bootstrap/app.php via Sentry\Laravel\Integration.
  No-op when SENTRY_LARAVEL_DSN is empty.

- **Audit logging** broadened: LogsActivity applied to Household, QrCode,
  Trip, Payment with tight logOnly whitelists and named log channels
  ('household', 'qr_code', 'trip', 'payment') to keep the activity
  stream useful.

- **Bulk admin actions**:
  POST /admin/households/bulk-approve — skips already-approved /
  no-proof / unknown ids, reports per-id outcomes
  POST /admin/bulk/users/{suspend,activate} — admins protected
  POST /admin/bulk/qr-codes/void — respects state machine transitions

- **FCM push scaffold**: PushDriver contract with LogPushDriver
  (default) and FcmPushDriver (activates when FCM_SERVER_KEY is set).
  PushChannel adapts notifications. RoutesByPreferences now also
  routes via push when push_enabled + fcm_token. toPush() payloads
  added to HouseholdApproved / QrBalanceLow / PickupImminent.

- **Reverb WebSocket broadcast**: laravel/reverb installed.
  TruckLocationBroadcast fires on every TruckTracker::record().
  routes/channels.php authenticates: admins → private-admin.live,
  residents → area.{id}.trucks (only if their household barangay is
  covered by the service area).

- **PSGC seeder** expanded: all 17 PH regions, 4 NCR districts,
  all 17 NCR cities. Sample barangays still carry rectangular
  boundaries for point-in-polygon resolution tests.

- **Conditional SPATIAL INDEX migration** for barangays.boundary —
  safe no-op until every row has a polygon (i.e., after full PSA
  dataset import). Re-running `php artisan migrate` after import
  flips the column to NOT NULL and adds the index.

196 feature tests passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 17:22:43 +08:00
d458e74301 feat(backend): complete Module 7 — QR code system (core)
qr_code_batches + qr_codes tables. State machine via
spatie/laravel-model-states (unassigned → allocated → active → used,
plus expired/voided). Serial format PH-{area}-{YYMM}-{batch}-{code}-
{checksum} with 2-char SHA-256-derived checksum. BatchGenerator
bulk-inserts in chunks. QrAllocator allocates free codes to verified
households (prefers area-targeted batch, falls back to any). Real
HouseholdVerified listener replaces the placeholder. QrBalanceLow
event for Module 11.

Admin: batch CRUD, mark-printed, void code, lifecycle search, PDF
print sheet (24/A4 via dompdf + endroid/qr-code + picqer/barcode).
Resident: list own codes, balance with low_balance flag, activate
allocated codes.

Removed explicit Event::listen for HouseholdVerified — Laravel 11
auto-discovers it via handle() type-hint, and double-registering was
causing double-dispatch.

130 feature tests passing.

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