50 Commits

Author SHA1 Message Date
redz1029 20e95ffe37 feat(edge): day sheet digest push
Co-Authored-By: claude-flow <ruv@ruv.net>
2026-09-28 13:50:31 +08:00
redz1029 e0dd3f6368 feat(db): day sheet RPCs, auto-submit cron, digest queue
Add submit_day_sheet, disapprove_day_sheet, justify_day_sheet,
approve_day_sheets (all SECURITY DEFINER, grant to authenticated)
and auto_submit_day_sheets (revoked from all client roles).

auto_submit_day_sheets:
  1. Reopens approved yesterday sheets for programmers whose timer
     was still running at end of day (amended event).
  2. Auto-promotes stale draft sheets to pending (auto_submitted event).
  3. Inserts day_sheet_digest notifications + scheduled_notifications
     (epoch=YYYYMMDD, ON CONFLICT DO NOTHING) for every admin.

Extends chk_at_least_one_ref on scheduled_notifications to allow
notify_type = 'day_sheet_digest' rows with no FK reference.

Registers pg_cron job 'programmer_day_sheet_autosubmit' at 16:05 UTC
(00:05 Asia/Manila) in a DO $$ EXCEPTION block.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-09-28 13:31:26 +08:00
redz1029 e2ff0140ef feat(db): programmer day sheets schema, triggers, RLS
Adds migration 20260927150000_add_programmer_day_sheets.sql:
- manila_today() stable helper (Asia/Manila timezone)
- programmer_day_sheets table with draft/pending/disapproved/approved status,
  unique(programmer_id, work_date), updated_at trigger, RLS
- programmer_day_sheet_events table with kind/body checks, cascade FK, RLS
- work_date column on programmer_task_work_logs (add, backfill, default, not null)
- ensure_day_sheet() SECURITY DEFINER; revoked from public/anon/authenticated
- BEFORE INSERT trigger validate_work_log_date (work_date_locked error code)
- AFTER INSERT trigger on work_logs → ensure_day_sheet
- AFTER INSERT trigger on activity_logs → ensure_day_sheet for assignee
- RLS SELECT policies (own sheet or admin; events through parent sheet)
- notifications.day_sheet_id FK column + partial index
- Add day sheets tables to supabase_realtime publication

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-09-27 22:51:41 +08:00
redz1029 b307f66f2c Add PM extension (Projects, Work Logs, Comments) + Quill rich-text UI
Projects: Brick-backed model with list/detail screens and nav entry.
Work Logs: per-contributor time ledger, assignee running-clock +
helper logged minutes with Hours/Minutes input; pause-after-save and
helper-deduct prompts.
Comments: threaded comments with file attachments and Quill composer.
Detail screen: tabbed layout (Work Log / Comments / Activity),
editable title + description via edit dialog, Quill-rendered
descriptions with legacy plain-text fallback.
Create dialog: fixed-width (480px max), Quill description editor.
Shared QuillFieldEditor + QuillReadOnly widgets extracted for reuse.
RLS: hardened activity-log actor binding, immutable creator_id/
created_at triggers, SECURITY INVOKER visibility helper,
append-only work-log and scoped comment policies.
Brick migration for project_id FK on programmer_tasks.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-09-27 16:06:26 +08:00
redz1029 627645056b Add Programmer Tasks module (work-log + time tracking)
Separate feature for the `programmer` role to record dev work by category,
distinct from the IT help-desk `tasks` feature. Modeled on the IT Service
Requests pattern (Brick offline-first model -> Riverpod stream/controller ->
list/detail screens); seed of a future Project Management workflow.

- programmer_tasks + programmer_task_activity_logs (category enum, RLS,
  realtime) via supabase migration
- single assignee, self-logged or lead-assigned; assign/reassign logged
- pause-on-switch: starting a task while another runs prompts to pause the
  running one, keeping one active task per user for accurate time attribution
- worked-duration math shared with help-desk tasks via a generic core in
  task_duration.dart (existing callers unchanged)
- list distinguishes running vs paused with a per-task Resume shortcut
- accessible dialog labels; route /programmer-tasks + nav gated to admin/programmer
- unit/widget tests: controller lifecycle, duration math, pause-switch dialog

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-09-27 01:13:33 +08:00
redz1029 3cb980b629 QA hardening: security RLS fixes, Flutter 3.47.5 upgrade, UI/validation fixes
Security — enforce write authorization server-side (was UI/RPC-only):
- it_service_requests RLS: block cross-office read/edit + self-approve (QA-015)
- pass_slips RLS: owner can complete but not self-approve (QA-046)
- swap_requests RLS: scope select/update to participants + admin (QA-047)
- storage: tighten it_service_attachments + task_attachments write/delete (QA-027)
- admin_user_management edge function: allow programmers to manage users (QA-016)

Fixes:
- workforce generator "uncovered shifts" false alarms (QA-043/044)
- network-map VLAN + New-location dialog validation, disabled-until-valid (QA-048)
- de-flake time-of-day-dependent dashboard metrics test (QA-045)

Toolchain:
- upgrade to Flutter 3.47.5 / Dart 3.13.4; font_awesome_flutter 11.0.0,
  flutter_quill 11.6.0, pdfrx 2.6.5; clear resulting deprecations (QA-002)

analyze clean; 139 tests pass; web build succeeds. Report + evidence in docs/qa/.

Note: also carries the in-progress Brick model cleanup already present in the
working tree. QA-001 (AI keys public in the build) is deferred by owner decision.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-09-26 11:52:16 +08:00
redz1029 d813ee45a2 Network map enhancements and fixes 2026-06-05 16:42:56 +08:00
redz1029 5e20d14f23 Fixed attendance 2026-06-05 10:34:26 +08:00
redz1029 ce0be25136 Fixed IT Service Request Saving 2026-06-04 11:28:55 +08:00
redz1029 7f38086237 Migration fixes 2026-05-21 06:29:37 +08:00
redz1029 5d0a66bb52 Initial Commit : Network Map 2026-05-21 06:29:14 +08:00
redz1029 48cd3bcd60 Offline Support 2026-04-27 06:20:39 +08:00
redz1029 872c2aab87 UI Enhancements in IT Service Request, Announcements, Workforce and notification fixes 2026-03-22 18:00:10 +08:00
redz1029 049ab2c794 Added My Schedule tab in attendance screen
Allow 1 Day, Whole Week and Date Range swapping
2026-03-22 11:52:25 +08:00
redz1029 3fb6fd5c93 Announcements and IT Job Checklist 2026-03-21 18:51:04 +08:00
redz1029 7d9096963a finalized reminder notification system migrations 2026-03-21 12:58:38 +08:00
redz1029 758869920c Fix push notifications never delivered — 3 root causes
1. CRITICAL: Double idempotency check silently discarded every notification.
   process_scheduled_notifications called try_mark_notification_pushed first,
   then send_fcm called it again and saw "already pushed" → skipped FCM send.
   Fix: Remove the check from process_scheduled_notifications; send_fcm's
   own check is sufficient (and needed for direct Flutter client calls).

2. SEND_FCM_URL env var crash: If not configured, edge function crashed on
   module load. Fix: Derive from SUPABASE_URL (always auto-set) as fallback.

3. Timing windows too narrow: ±30s windows with 60s cron intervals could
   miss events between runs. Fix: Widen to ±90s. ON CONFLICT DO NOTHING
   prevents duplicates, making wider windows safe.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-20 20:50:45 +08:00
redz1029 d81e2cde26 Fix RAISE NOTICE syntax in migration error handler
Use parameterized RAISE NOTICE with %L placeholders instead of trying to
concatenate strings inside quoted literals. This fixes the syntax error where
|| operators were being treated as string content instead of SQL operators.
2026-03-20 18:30:19 +08:00
redz1029 20720ba541 Fix SQL syntax error in pg_cron.schedule() calls
Replace dollar-quoted strings with simple single-quoted strings in cron.schedule()
function calls. The cron.schedule() function expects text literals, not dollar-quoted
blocks. Use quote_literal() for the interval value in the cleanup query to properly
escape the string.
2026-03-20 18:28:24 +08:00
redz1029 d484f62cbd Implement push notification reminder system with 9 notification types
Adds comprehensive push notification reminders using pg_cron + pg_net:
- Shift check-in reminder (15 min before, with countdown banner)
- Shift check-out reminder (hourly, persistent until checkout)
- Overtime idle reminder (15 min without task)
- Overtime checkout reminder (30 min after task completion)
- IT service request event reminder (1 hour before event)
- IT service request evidence reminder (daily)
- Paused task reminder (daily)
- Backlog reminder (15 min before shift end)
- Pass slip expiry reminder (15 min before 1-hour limit, with countdown banner)

Database: Extended scheduled_notifications table to support polymorphic references
(schedule_id, task_id, it_service_request_id, pass_slip_id) with unique constraint
and epoch column for deduplication. Implemented 8 enqueue functions + master dispatcher.
Uses pg_cron every minute to enqueue and pg_net to trigger process_scheduled_notifications
edge function, eliminating need for external cron job. Credentials stored in vault with
GUC fallback for flexibility.

Flutter: Added ShiftCountdownBanner and PassSlipCountdownBanner widgets that display
persistent countdown timers for active shifts and pass slips. Both auto-dismiss when
user completes the action. FCM handler triggers shift countdown on start_15 messages.
navigate_to field in data payload enables flexible routing to any screen.

Edge function: Updated process_scheduled_notifications to handle all 9 types with
appropriate titles, bodies, and routing. Includes pass_slip_id in idempotency tracking.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-20 18:26:48 +08:00
redz1029 4b63b55812 Initial commit for shift push notification reminders 2026-03-18 22:03:50 +08:00
redz1029 3af7a1e348 Added configurable shift types and holiday settings 2026-03-18 16:51:34 +08:00
redz1029 3e3e4d560e Ensures allowing assigned IT Staff to check in outside geofence when and IT Service Request venue is outside premise 2026-03-17 07:20:24 +08:00
redz1029 81853c4367 Added programmer role and fixed snackbar not showing 2026-03-16 07:23:20 +08:00
redz1029 9f7791e56f Migration to add leave_of_absence(id) and pass_slips(id) on notifications table 2026-03-15 22:37:42 +08:00
redz1029 6fd3b66251 OTA Updates for adnroid app and web apk uploader 2026-03-15 19:24:34 +08:00
redz1029 b8ec5dbf69 weekend on call shifts 2026-03-09 18:24:16 +08:00
redz1029 aee4604fed Team color read access 2026-03-09 17:52:55 +08:00
redz1029 ac38a21f9a Fixed attendance checkout postgrest unable to choose the best function candidate 2026-03-09 13:37:25 +08:00
redz1029 0f675d4274 Attendance log now record both check in and out photos and allow IT Staffs, Dispatchers and Admins to view for verification 2026-03-08 18:45:31 +08:00
redz1029 9178b438a2 rotation config migration 2026-03-08 17:32:13 +08:00
redz1029 ce82a88e04 Migrations 2026-03-08 16:58:05 +08:00
redz1029 94088a8796 Implemented Task Pause and Resume 2026-03-04 07:12:00 +08:00
redz1029 bfcca47353 Reports migrations 2026-03-03 18:15:45 +08:00
redz1029 b9153a070f Fixed migrations 2026-03-01 19:12:13 +08:00
redz1029 830c99a3ff Migrations 2026-03-01 18:51:53 +08:00
redz1029 0a8e388757 Move push notification to client instead of db trigger 2026-02-28 16:19:08 +08:00
redz1029 9cc99e612a Allow background sound notification 2026-02-26 21:43:05 +08:00
redz1029 6ccf820438 FCM push Notifications 2026-02-25 23:37:08 +08:00
redz1029 5979a04254 * Push Notification Setup and attempt
* Office Ordering
* Allow editing of Task and Ticket Details after creation
2026-02-24 21:06:46 +08:00
redz1029 9a0cf7a89d Added migration non admin read only service table 2026-02-23 18:26:25 +08:00
redz1029 46a84b4d95 Added Service 2026-02-21 21:57:31 +08:00
redz1029 6238c701c0 Added Task number 2026-02-21 21:37:36 +08:00
redz1029 1478667bbf Added Action Taken on Task 2026-02-21 15:44:12 +08:00
redz1029 8d31a629ac Added Type, Category and Signatories on task 2026-02-21 14:33:22 +08:00
redz1029 4811621dc5 Swap Accept, Reject and Escalate 2026-02-21 08:31:20 +08:00
redz1029 5ec57a1cec Auto Task Assignment 2026-02-18 23:14:50 +08:00
redz1029 8c1bb7646e Fixed user management 2026-02-18 20:43:11 +08:00
redz1029 04fd874a48 chore: remove unused profile lock migration and admin_profile_service 2026-02-18 18:13:10 +08:00
redz1029 1f16da8f88 Initial commit 2026-02-09 20:10:42 +08:00