ERP Order Verification System
Overview
Section titled “Overview”The ERP Order Verification system provides immediate feedback on whether an order submitted to the ERP system was correctly processed with all items intact. This addresses a critical issue where the Prophet 21 ERP sometimes silently drops certain line items during order creation without returning an explicit error.
Problem Solved
Section titled “Problem Solved”- Silent Item Dropping: The Prophet 21 ERP may silently drop or modify items during order creation without returning an explicit error
- Verification Challenges: Previous attempts to verify order contents using the transaction-based API failed with “400 Bad Request” errors
- User Uncertainty: Without verification, users had no clear way to know if their orders were correctly processed by the ERP
Solution Architecture
Section titled “Solution Architecture”The Order Verification system uses a multi-step approach:
- Order Creation/Update: The standard order creation/update flow creates or updates an order in the ERP
- Post-Creation Verification: After successful order creation/update, a separate verification process uses the P21 Data Services API (not the transaction API) to fetch the actual items in the ERP order
- Comparison & Analysis: The system compares what was sent to what actually exists in the ERP system
- Status Persistence: The verification status and any discrepancies are stored in the database and returned to the frontend
- User Interface Updates: The UI clearly displays verification status and highlights problematic items that need attention
Verification Flow
Section titled “Verification Flow”sequenceDiagram participant Frontend participant Backend participant TransactionAPI as P21 Transaction API participant DataServicesAPI as P21 Data Services API participant Database
Frontend->>Backend: Send order creation/update request Backend->>TransactionAPI: Create/update order TransactionAPI-->>Backend: Return order number Backend->>DataServicesAPI: Fetch actual items in order DataServicesAPI-->>Backend: Return actual items Backend->>Backend: Compare sent vs. actual items Backend->>Database: Store verification status Backend-->>Frontend: Return status, verification details Frontend->>Frontend: Update UI with verification informationVerification States
Section titled “Verification States”The verification system defines several states:
verified: All items submitted to the ERP exist in the order with correct quantitiesmismatch: One or more items are missing or have quantity discrepancies compared to what was sentverification_failed: The verification process itself encountered an errorpending: Initial state, verification not yet attempted
Database Schema
Section titled “Database Schema”The verification status and details are stored in the orders table:
erpVerificationStatus: Text enum (‘verified’, ‘mismatch’, ‘verification_failed’, ‘pending’, null)erpUnverifiedItemIds: JSONB array of objects containing details of problematic items
Components
Section titled “Components”1. Verification Service
Section titled “1. Verification Service”In prophet21-service.ts, two key methods handle verification:
fetchVerifiedOrderItems: Makes a call to the P21 Data Services API to get the actual order itemsexecuteOrderVerification: Compares sent items with items returned from the API
2. API Integration
Section titled “2. API Integration”- The
createOrderandupdateOrdermethods inProphet21Servicecall the verification process - The API endpoints (
generate-quote.tsandupdate-quote.ts) handle the verification results and update the database
3. Frontend Components
Section titled “3. Frontend Components”pdfOrderStore.tsmanages verification state and handles API responsesOrderEditor.tsxdisplays verification status, highlighting problematic items
How It Works in Practice
Section titled “How It Works in Practice”- User submits an order creation/update request
- After the ERP processes the order, our system calls the Data Services API to verify what’s actually in the order
- Any discrepancies are identified and tracked
- The UI displays clear feedback about verification status
- For mismatches, problematic items are highlighted and users are guided on what to do next
Benefits
Section titled “Benefits”- Immediate Feedback: Users know immediately if their orders were processed correctly
- Problem Identification: Specific items that weren’t processed correctly are clearly identified
- Actionable Guidance: Clear instructions on how to resolve issues
- Error Traceability: Verification status persists across page refreshes and system restarts