Doc Upload Technical Documentation

DocUpload Feature Technical Documentation

Overview

The DocUpload feature enables users to scan a QR code from a document details page (e.g., Purchase Bill) using a mobile device to upload a PDF copy of the document. The system uses AI (AWS Bedrock) to extract key details from the uploaded PDF and verifies them against the existing system record before storing the file in AWS S3.


1. User Workflow

  1. Initiate: User opens a document details page (e.g., BillDetails.razor).
  2. Generate QR: User clicks “Upload Document”. The system generates a temporary token and displays a QR code.
  3. Scan: User scans the QR code with a mobile device, which opens the mobile-optimized DocUploadOption.razor page.
  4. Select File: User selects a PDF file from their device.
  5. AI Extraction: The system sends the PDF to AWS Bedrock to extract the Party Name, GSTIN, and Total Amount.
  6. Verification: The system compares AI-extracted data with database records. If there’s a mismatch (e.g., GSTIN doesn’t match), the user is prompted for confirmation.
  7. Store: Upon confirmation, the PDF is uploaded directly to AWS S3 using a pre-signed URL.
  8. Finalize: The system marks the token as used, and the upload is complete.

2. Technical Architecture

Frontend (Blazor Web - Mobile Optimized)

  • BillDetails.razor: Entry point for Purchase Bills.
  • DocUploadShowQr.razor: Dialog component that displays the generated QR code.
  • DocUploadOption.razor: The primary mobile interface for file selection and upload status. Uses MudFileUpload and displays real-time AI verification results.

Service Layer (Web Project)

  • IDocUploadService / DocUploadService:
    • Proxies requests to the API.
    • AWS Bedrock Integration: Uses IAmazonBedrockRuntime to perform OCR and data extraction using the amazon.nova-lite-v1:0 model (or similar).
    • Fetches system prompts for AI from the AIInsights service.

Backend API (ErpCrystal_MFG.Api)

  • DocUploadController:
    • Handles token generation/validation.
    • Implements verification logic (VerifyDocUploadBill) to compare AI results with DB data.
  • DocUploadRepository:
    • Persists temporary tokens in the Users table (System DB).
    • Fetches live document data (Bill/Invoice details) from client databases using Dapper.

Storage & Infrastructure

  • AWS S3: Primary storage for uploaded PDFs. Files are organized by dbname, DocType, and YearDocNo.
  • Pre-signed URLs: Generated locally on the client for secure, direct-to-S3 uploads without proxying heavy binary data through the app server.

3. Data Models (ErpCrystal_MFG.Models)

DocUpload

Tracks the context of an upload session.

  • TokenId: Unique Guid used for the mobile link.
  • DocId: The internal database ID of the document (Bill/Invoice).
  • DocType: “B” (Bill), “I” (Invoice), “V” (Voucher).
  • DbName: Target database name.
  • CreatedOn: Timestamp for token expiration (standard 10-minute window).

DocUploadVerifyAiResponse

The structure returned by the AI extraction logic.

  • PartyName: Extracted vendor/party name.
  • Gstin: Extracted GST registration number.
  • TotalAmount: Extracted grand total.

DocUploadVerifyBill

The comparison result sent from API to UI.

  • BillVerifyInd: Indicates match status (GstinAmountMatch, PartyAmountMatch, or Mismatch).
  • SystemValue vs AiValue: Pairs of data for side-by-side comparison.

4. Security & Validation

  • Token Expiration: Upload tokens expire after 10 minutes to prevent unauthorized access.
  • Single Use: Once a file is successfully uploaded, the token is cleared from the database.
  • AI Thresholds: Verification allows a small tolerance (e.g., ₹5.00) for amount matching to account for minor rounding differences in OCR.
  • GSTIN Normalization: Spaces and special characters are stripped before comparison.

5. Key File Locations

Layer File Path
UI ErpCrystal_MFG.Web/Pages/DocUploadOption.razor
QR UI ErpCrystal_MFG.Web/Pages/DocUploadShowQr.razor
Service ErpCrystal_MFG.Web/Services/DocUploadService.cs
API ErpCrystal_MFG.Api/Controllers/DocUploadController.cs
Repository ErpCrystal_MFG.Api/Repositories/DocUploadRepository.cs
Model ErpCrystal_MFG.Models/DocUpload.cs