Schedule: gate Completed status on required reports (inspections vs charge-backed events)
Objective
- Stop treating Completed on the mobile schedule as only “end time is in the past.”
- For inspection rows and for events tied to a charge (
event._chargeId), Completed should also require required reports for the relevant service(s) to be satisfied, using the same primary-only / primary-charge applicability rules as web inspection reports. - Leave Up Next (current window
[start, end]) and time-only completion for item types that are out of scope (vacation, block, standalone events without_chargeId,eventGroupshells, etc.) unless product decides otherwise.
Background
ScheduleCardtoday setsisCompletedwithend.isBefore(now)andisUpNextwithstart.isBefore(now) && end.isAfter(now)only—no reads of charges, events-on-charge, or report completion (components/schedule/ScheduleCard.tsx).- The schedule list is built by
combineScheduleItemsinlib/scheduleUtils.ts, which attaches nestedsubItems(events under an inspection). Sub-rows render time and equipment but do not currently surface their own Completed / Up Next badges separate from the parent card. useSchedulealready loads inspections withpopulate: ["charges", "services", "people", "reports"]and events withinspectionPopulated: ["charges", "reports", "people"](hooks/useSchedule.ts), so much of the data needed for gating may already be on the client—or a computed flag from the API may be preferable to avoid drift with web.- Domain relationships (for defining “charge has an event” and linking reports to services) live in backend models such as
src/models/inspectionSchema.ts(charges, events,_reportIds),src/models/eventSchema.ts(_chargeId→ charge),src/models/chargeSchema.ts(isPrimary,_serviceId), andsrc/models/reportSchema.ts(_serviceId,_requiredReportTypeId,status,requiredReportIndex). - When
nowis pastendtimebut reports are still missing, showing plain Completed is misleading—product sign-off is needed on an alternate label or treatment (e.g. Pending reports).
Scope
Attik Mobile
- Inspection rows (
ScheduleItem.type === "inspection"): derive completion only after required slots for charges that do not have any linkedEventon that inspection (same inspection,event._chargeId === charge._id) are satisfied, plus the existing applicability rules forprimaryOnlyvscharge.isPrimary(parity with web / toolsv2 as the source of truth for those rules). - Event rows with
_chargeId: gate Completed on required reports for that charge’s service until satisfied; events without_chargeIdkeep time-only completion. - Other types: vacations, blocks, standalone events without inspection charge linkage, and
eventGroupitems—keep current time-based Completed unless product extends scope. - Sub-items: grouped events under an inspection (
item.subItemsinScheduleCard) may need per-sub-item completion signaling if the parent row alone is insufficient—decision needed with design/product. - Map tab (
app/(app)/map.tsx) usescombineScheduleItems; confirm whether the same completion semantics should apply anywhere schedule-derived UI shows “completed” (e.g.StopMarkerprops today are not wired from report state).
Attik Backend (optional but valuable)
- A single shared computation (endpoint field or shared package) that, given populated inspection + charges + services + required report types + reports + events, returns booleans such as schedule-completion for an inspection and per charge-backed event would reduce divergence between mobile and web—whether to implement server-side vs client-only is a decision for the implementer.
Attik Frontend / web parity
- Align
primaryOnlyand primary-charge filtering with whatever web implementation is canonical (see related work on inspection reports if still landing).
References
- Mobile:
attik-mobile/components/schedule/ScheduleCard.tsx,attik-mobile/lib/scheduleUtils.ts,attik-mobile/hooks/useSchedule.ts,attik-mobile/app/(app)/index.tsx - Backend:
attik-backend/src/models/inspectionSchema.ts,attik-backend/src/models/eventSchema.ts,attik-backend/src/models/chargeSchema.ts,attik-backend/src/models/reportSchema.ts
Status: Completed
Log in to comment and vote
No comments yet
Be the first to share your thoughts.