إنتقل إلى المحتوى الرئيسي

Invoice-to-Cash Workflow

Metadata

FieldValue
PhasePhase 2: Forge
FWCR CategoryInvoice-to-Cash
OwnerProduct Team
StatusPlanned
Last UpdatedMay 2026

Overview

This workflow handles the complete sales order-to-ZATCA clearance cycle for Phase 2. It ensures every invoice is cryptographically stamped by ZATCA before delivery to the buyer, with AI-powered error resolution for failed submissions.

Goal: Achieve >65% FWCR for Invoice-to-Cash by end of Phase 2.


Actors

RoleDescription
Sales RepCreates quotations and converts to Sales Orders
AccountantReviews, adjusts pricing, submits invoices
SystemGenerates ZATCA XML, calls API, attaches stamps
AI AssistantTranslates ZATCA errors into actionable guidance
CustomerReceives stamped invoice via email/PDF

Preconditions

  • Customer master exists with ZATCA-compliant fields (CR number, VAT number, building number)
  • Products/Services configured with correct tax templates
  • ZATCA API credentials configured in system
  • OCI blob storage configured for PDF archiving
  • Liquid Glass UI workspace for invoicing role configured

Postconditions

  • Invoice cleared by ZATCA (cryptographic stamp)
  • PDF with ZATCA QR code attached to invoice
  • AR ledger entry created
  • Audit trail captured
  • Customer notified with stamped invoice

User Flow

Happy Path

┌─────────────────────────────────────────────────────────────────────────────┐
│ INVOICE-TO-CASH WORKFLOW │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ [Sales Rep] │
│ │ │
│ ▼ │
│ 1. Create/Edit Quotation │
│ │ │
│ ▼ │
│ [System] ─── Validate pricing & tax templates ──▶ [Quotation validated] │
│ │ │
│ ▼ │
│ 2. Convert to Sales Order │
│ │ │
│ ▼ │
│ [Accountant] │
│ │ │
│ ▼ │
│ 3. Review SO & Adjust if needed │
│ │ │
│ ▼ │
│ [System] ─── Generate ZATCA XML ──▶ [XML created] │
│ │ │
│ ▼ │
│ 4. Submit for ZATCA Clearance │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ ZATCA API CALL │ │
│ │ ┌─────────────────────────────────────────────┐ │ │
│ │ │ POST /v2/invoices/clearance │ │ │
│ │ │ Body: { XML payload } │ │ │
│ │ └─────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │ │
│ ├──────────────────────┬────────────────────────┤ │
│ ▼ ▼ │
│ ✓ CLEARED ✗ REJECTED │
│ │ │ │
│ ▼ ▼ │
│ 5. Attach stamp 6. AI Error Resolution │
│ │ │ │
│ ▼ ▼ │
│ 7. Generate PDF 7. Display: "Buyer's building │
│ │ number is missing" │
│ ▼ │ │
│ 8. Create AR Entry 8. Highlight field in UI │
│ │ │ │
│ ▼ ▼ │
│ 9. Notify Customer 9. User corrects & resubmits │
│ │ │ │
│ ▼ │ │
│ 10. COMPLETE ◄─────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

Step-by-Step

StepActorActionSystem Response
1Sales RepCreates or edits quotationValidates pricing, tax templates
2Sales RepReviews quotation with customer
3Sales RepConverts to Sales OrderCreates SO with unique ID
4AccountantReviews SO, adjusts if neededShows ZATCA field readiness
5SystemGenerates ZATCA XML payloadValidates required fields
6AccountantClicks "Submit for Clearance"
7SystemCalls ZATCA APIReturns stamp or error
8aSystem (success)Attaches cryptographic stampXML updated with hash
8bSystem (error)Calls AI Error ResolutionTranslates JSON to plain text
9aSystem (success)Generates PDF with QR codePDF stored in OCI blob
9bAccountant (error)Reviews AI guidanceFixes indicated field(s)
10SystemCreates AR invoice entryGL entries posted
11SystemSends email to customerStamped PDF attached

Error Scenarios

ScenarioZATCA Error CodeAI TranslationResolution
Missing buyer's building numberBR-01"Buyer's building number is missing. Add it in Customer master under Address."User edits customer address
Missing VAT registration numberBR-02"Buyer's VAT number is not provided. Add VAT# in Customer master."User adds VAT#
Invoice total mismatchBR-08"Invoice total doesn't match sum of line items + VAT. Check line 3."User corrects amount
Duplicate invoiceBR-15"This invoice was already submitted. Use amendment flow for corrections."User checks submission history
Invalid date formatBR-04"Invoice date should be in Gregorian calendar format."User corrects date
Missing seller detailsBR-06"Your company details are incomplete. Update in Company master."User updates settings

Acceptance Criteria

#CriteriaTest Scenario
1Invoice clears ZATCA in under 2 secondsGiven valid invoice, When submitted, Then clearance received in 2s
2AI error message is actionableGiven ZATCA rejection, When AI resolves, Then user knows exact field to fix
3PDF contains ZATCA QR codeGiven cleared invoice, When PDF generated, Then QR code scannable
4AR entry matches invoice amountGiven cleared invoice, When posted, Then GL shows correct amounts
5Customer receives stamped PDFGiven cleared invoice, When complete, Then email sent with PDF
6Audit trail is immutableGiven any invoice action, When logged, Then cannot be modified

Compliance Requirements

RequirementImplementation
ZATCA Phase 2All invoices must be cleared before delivery
ZATCA XML SchemaTLV-compliant fields per Fatoora specification
Cryptographic StampSHA-256 hash + ZATCA signature in XML
PDF RequirementsQR code with ZATCA portal URL
Data ResidencyAll documents stored in OCI Riyadh/Jeddah
Audit TrailTimestamped, immutable logs for all actions

Technical Notes

ComponentImplementation
Frontend (Liquid Glass)Next.js + shadcn/ui, RTL-ready, role-based workspace
API GatewayMiddleware for request orchestration, auth, logging
ERPNextSales Order, Delivery Note, Sales Invoice doctypes
Custom Appbayancore_erp for ZATCA XML generation, error handling
AIGPT-4o with ZATCA error corpus for plain-English translations
StorageOCI Object Storage for PDFs, OCI DB for audit logs

Metrics

MetricTargetMeasurement
FWCR: Invoice-to-Cash>65%(Cleared without rework) / (Total submitted)
Time-to-ZATCA Clearanceunder 2 secondsAverage API response time
ZATCA Rejection Rateunder 5%(Rejected) / (Total submitted)
AI Error Resolution Rate>90%(Resolved after AI help) / (Total errors)
Invoice Cycle Timeunder 10 minutesStart of SO to cleared invoice

Dependencies

DependencyStatusNotes
ZATCA API credentialsReadySandbox configured
OCI Object StorageReadyJeddah region
ERPNext 15+ReadyFrappe 15
Liquid Glass UI componentsPlannedPhase 1 deliverable
AI Error Resolution servicePlannedRequires ZATCA error corpus
Customer master ZATCA fieldsPlannedRequires data migration

DocumentLink
OS Blueprint../os-blueprint
ZATCA Compliance../../03-compliance/zatca
AI Architecture../../04-ai-features/rag-architecture
Technical Spec../../05-technical-spec/sad
Phase 2 Release../../08-release/phase-2-forge

Document Status

Status: ✅ PLANNED Last Updated: May 2026 Next Review: Pre-Phase 2 kickoff