Orders with pay at closing show agreement unsigned
Objective
- Fix Pay at Close (PAC) orders where staff and worklists show agreement unsigned and reports stay locked, even though clients and CSRs see agreements as signed (or complete) in the portal.
- Restore a trustworthy single source of truth for “agreements done” vs “payment done” on PAC jobs so reports release when the business expects them to.
- Reduce failed PAC journeys where the only workaround is cancel PAC and pay by card.
Background
- Product feedback reports multiple markets affected: PAC selected, order/worklist shows unsigned agreement, but opening agreements on the inspection shows signed documents.
- In the client portal, agreements can appear complete while PAC remains pending on the order and reports do not release.
- Reported examples:
- WPI inspection
1008593904— Example inspection - GTC —
130 Thrushwood Dr, Fayetteville, Georgia 30215 RIA1639- Reported workaround: client cancels PAC and pays by card, then flow can proceed.
- Code review points to three separate systems that can disagree:
- Attik agreements (
Agreementcollection, client route/client/job/[slug]/agreement/[id]) - FlexFund / ISN PAC agreement (separate signing link on the payment; status via webhooks)
- Denormalized job fields
inspection.agreement.signed/inspection.paidused for badges and report lock
- Stale agreement rule (intentional today):
agreementLockSync.tstreats only stale signed active agreements as not signed at the job level (only stale signed → not signedin unit tests). Individual rows can still show Signed / Outdated in the Agreements UI while the order chip stays unsigned. - Report lock rule:
checkReportAccess.tsunlocks when paid (unlesstoBeInvoiced) and non-stale agreements are satisfied (DB query preferred over staleinspection.agreementsync). - PAC pending rule: Pending PAC does not contribute to
inspection.paid(payAtClosePaymentContributesToTotalPaid); payment should move tocompletedon FlexFund statuses such asSIGNATURE_RECEIVEDviaPOST /webhooks/flexfundand totals sync. - Screenshots from the field:



Scope
Backend
- Job-level agreement sync:
attik-backend/src/events/streamHandlers/agreementStream.tsupdatesinspection.agreement.present/inspection.agreement.signedviaattik-backend/src/util/functions/agreements/agreementLockSync.ts(non-stale rows must be signed; stale-only signed → jobsigned: false). - Report access:
attik-backend/src/util/functions/inspection/checkReportAccess.ts(paid + agreement rules; uses Agreement DB when query succeeds). - Stale worker:
attik-backend/src/events/bullmq/agreementStaleWorker.tsand signing hash logic underattik-backend/src/util/functions/agreements/. - PAC payment lifecycle:
attik-backend/src/routes/webhooks/flexfund/flexfundWebhook.ts, status mapping inattik-backend/src/util/functions/payments/pacIsnFlexFundStatuses.tsandpaymentStatusMapping.ts, transitions inpaymentStatusValidator.ts. - PAC totals / paid flag:
attik-backend/src/util/functions/isn/isnPayAtCloseOrderTotal.ts(payAtClosePaymentContributesToTotalPaid),attik-backend/src/util/functions/forecast/syncTotalsOnInspections.ts. - Decision needed: For affected inspection IDs, determine which failure mode applies — stale-only lock, unsigned non-stale agreement,
inspection.agreementdesync, or PAC webhook/status stuck in pending. - Decision needed: Whether stale-only signed agreements should continue to show as unsigned on staff badges or should surface as outdated with different lock/report behavior.
Frontend
- Staff unsigned/signed chip:
attik-frontend/src/components/ui/StatusBadges.tsxusesjob.agreement.signed(not per-document status). - Worklist filter:
attik-frontend/src/components/task-check/AgreementsNeeded.tsx(agreementSigned: 'false',!job.agreement.signed). - Inspection agreements tab:
attik-frontend/src/app/tools/inspections/[id]/components/Agreements.tsx(per-rowstatus, stale/outdated UI). - Client portal agreements list:
attik-frontend/src/app/client/job/[slug]/components/AttikAgreementList.tsx(row-level Signed / Outdated). - Client report lock:
attik-frontend/src/app/client/job/[slug]/components/ReportList.tsxwithattik-frontend/src/util/functions/report/computeAgreementSignedForReportLock.ts(can prefer agreements array over synced fields). - PAC UX:
attik-frontend/src/app/client/job/[slug]/pay-beta/PaymentBetaClient.tsx,PendingPACAlert.tsx, helpers inattik-frontend/src/util/functions/payments/pacStatusHelpers.ts(isPACPaymentPending,Pending Signaturelabels). - Decision needed: Clearer distinction in UI between Attik agreement unsigned/outdated vs FlexFund PAC signature still required.
Out of scope unless expanded
- Mobile app agreement badges (similar
inspection.agreement.signedpattern exists inattik-mobilebut not reported in examples).
References
- Example inspection: https://www.attik.ai/inspections/1008593904?tab=activity-feed
- Agreement lock rules:
attik-backend/src/util/functions/agreements/agreementLockSync.ts,attik-backend/tests/unit/agreementLockSync.test.ts - Report lock:
attik-backend/src/util/functions/inspection/checkReportAccess.ts,attik-backend/tests/integration/lockReport.test.ts - FlexFund webhook:
attik-backend/src/routes/webhooks/flexfund/flexfundWebhook.ts
Status: Completed
Log in to comment and vote
No comments yet
Be the first to share your thoughts.