Back to ER Diagrams
Document Flow Logic

Document Flow System

End-to-end procurement document lifecycle management, relationships, and status tracking from requisition to payment.

8 Document Types
Chained Documents
Full Audit Trail

1. Overview

The Document Flow system manages the complete lifecycle of procurement documents from creation to archival. It tracks document relationships, maintains audit trails, enforces sequential dependencies, and ensures proper document numbering and versioning.

Key Capabilities

  • Automatic document number generation with configurable formats
  • Document chaining (PR → RFQ → Quotation → PO → GRN → Invoice)
  • Version control and revision history
  • Document status lifecycle management
  • Cross-reference tracking between related documents
  • Attachment management with virus scanning

2. Document Types in ProKure

Purchase Requisition

PR-YYYY-NNNNN

Internal request to procure items/services

  • • Initiates procurement cycle
  • • Requires approval workflow
  • • Can generate multiple RFQs

Request for Quotation

RFQ-YYYY-NNNNN

Solicitation sent to vendors

  • • Links to one PR
  • • Sent to multiple vendors
  • • Receives vendor quotations

Vendor Quotation

QT-YYYY-NNNNN

Price/terms response from vendor

  • • Response to RFQ
  • • Compared for selection
  • • Selected one becomes PO basis

Purchase Order

PO-YYYY-NNNNN

Official order to vendor

  • • Legal commitment to purchase
  • • Based on approved quotation
  • • Triggers GRN & Invoice

Goods Receipt Note

GRN-YYYYMM-NNNN

Receiving acknowledgment

  • • Records quantity received
  • • Quality inspection link
  • • Updates inventory

Vendor Invoice

INV-VENDOR-NNNNN

Payment request from vendor

  • • Links to PO and GRN
  • • Three-way match required
  • • Triggers payment process

Credit/Debit Note

CN/DN-YYYY-NNNNN

Adjustment documents

  • • Returns and adjustments
  • • Price corrections
  • • Quantity discrepancies

Contract

CON-YYYY-NNN

Long-term agreement

  • • Framework agreements
  • • Rate contracts
  • • Multiple POs reference

3. Database Tables Involved

Core Document Tables

procurement.purchase_requisitions

Purchase requisition header information

id (PK)
pr_number
requester_id (FK)
department_id (FK)
priority
required_date
status
total_amount
created_at

procurement.rfqs

Request for quotation headers

id (PK)
rfq_number
pr_id (FK)
submission_deadline
validity_period
status
created_at

procurement.quotations

Vendor quotation responses

id (PK)
quotation_number
rfq_id (FK)
vendor_id (FK)
total_amount
validity_date
is_selected
status

procurement.purchase_orders

Purchase order headers

id (PK)
po_number
quotation_id (FK)
vendor_id (FK)
contract_id (FK)
order_date
delivery_date
total_amount
status
revision

inventory.grns

Goods receipt note headers

id (PK)
grn_number
po_id (FK)
warehouse_id (FK)
receipt_date
received_by (FK)
status
inspection_status

finance.vendor_invoices

Vendor invoice headers

id (PK)
invoice_number
vendor_id (FK)
po_id (FK)
invoice_date
due_date
total_amount
match_status
payment_status

Document Management Tables

system.document_sequences

Auto-increment sequences for document numbers

id (PK)
document_type
prefix
current_value
format_pattern
fiscal_year
reset_annually

system.document_attachments

File attachments for any document

id (PK)
document_type
document_id
file_name
file_path
file_size
uploaded_by (FK)
is_virus_scanned

audit.document_history

Complete audit trail for document changes

id (PK)
document_type
document_id
action
old_values
new_values
changed_by (FK)
changed_at
ip_address

4. Document Chain (Procurement Lifecycle)

┌─────────────────────────────────────────────────────────────────────────────────┐
│                          PROCUREMENT DOCUMENT FLOW                               │
└─────────────────────────────────────────────────────────────────────────────────┘

┌──────────────────┐
│   REQUISITION    │  Internal need identified
│   (PR-2024-001)  │
└────────┬─────────┘
         │ Approved
         ▼
┌──────────────────┐      ┌──────────────────┐
│      RFQ         │─────►│   RFQ VENDORS    │  Sent to 3-5 vendors
│  (RFQ-2024-001)  │      │ (Multiple Rows)  │
└────────┬─────────┘      └──────────────────┘
         │ Vendors respond
         ▼
┌──────────────────┐      ┌──────────────────┐      ┌──────────────────┐
│   QUOTATION 1    │      │   QUOTATION 2    │      │   QUOTATION 3    │
│  (QT-2024-001)   │      │  (QT-2024-002)   │      │  (QT-2024-003)   │
└────────┬─────────┘      └──────────────────┘      └──────────────────┘
         │ Selected
         ▼
┌──────────────────┐
│  PURCHASE ORDER  │  Legal commitment
│   (PO-2024-001)  │
└────────┬─────────┘
         │ Goods shipped
         ├─────────────────────────────────┐
         ▼                                 ▼
┌──────────────────┐              ┌──────────────────┐
│      GRN 1       │              │      GRN 2       │  (Partial deliveries)
│  (GRN-2024-001)  │              │  (GRN-2024-002)  │
└────────┬─────────┘              └────────┬─────────┘
         │                                 │
         └─────────────┬───────────────────┘
                       ▼
              ┌──────────────────┐
              │  VENDOR INVOICE  │  Payment request
              │  (INV-2024-001)  │
              └────────┬─────────┘
                       │ Three-way match
                       ▼
              ┌──────────────────┐
              │     PAYMENT      │  Funds released
              │  (PAY-2024-001)  │
              └──────────────────┘

Document Relationships

PR → RFQ (One to Many)

One PR can generate multiple RFQs for different categories

rfqs.pr_id → purchase_requisitions.id
RFQ → Quotations (One to Many)

One RFQ receives multiple quotations from vendors

quotations.rfq_id → rfqs.id
Quotation → PO (One to One)

Selected quotation becomes PO basis

purchase_orders.quotation_id → quotations.id
PO → GRN (One to Many)

One PO can have multiple GRNs for partial deliveries

grns.po_id → purchase_orders.id
PO → Invoice (One to Many)

One PO can have multiple invoices

vendor_invoices.po_id → purchase_orders.id
Contract → PO (One to Many)

Framework contract can have multiple release POs

purchase_orders.contract_id → contracts.id

5. Document Status Lifecycle

Purchase Requisition Status Flow

DRAFT
SUBMITTED
PENDING_APPROVAL
APPROVED
RFQ_CREATED
COMPLETED

Purchase Order Status Flow

DRAFT
PENDING_APPROVAL
APPROVED
SENT_TO_VENDOR
ACKNOWLEDGED
PARTIALLY_RECEIVED
CLOSED

Invoice Status Flow

RECEIVED
MATCHING
MATCHED
PENDING_PAYMENT
SCHEDULED
PAID

6. Document Number Generation

Document Format Pattern Example Resets
Purchase Requisition PR-{YYYY}-{NNNNN} PR-2024-00142 Annually
RFQ RFQ-{YYYY}-{NNNNN} RFQ-2024-00089 Annually
Quotation QT-{YYYY}-{NNNNN} QT-2024-00312 Annually
Purchase Order PO-{YYYY}-{NNNNN} PO-2024-00067 Annually
GRN GRN-{YYYY}{MM}-{NNNN} GRN-202403-0024 Monthly
Invoice INV-{VENDOR}-{NNNNN} INV-ABC-00156 Never
Contract CON-{YYYY}-{NNN} CON-2024-012 Annually
public class DocumentNumberService
{
    public async Task<string> GenerateDocumentNumber(
        DocumentType docType, Dictionary<string, string> parameters = null)
    {
        // Use transaction to ensure unique numbers
        await using var transaction = await _sequenceRepo.BeginTransactionAsync();

        try
        {
            // Get or create sequence for this document type
            var sequence = await _sequenceRepo.GetSequenceAsync(
                docType, DateTime.UtcNow.Year);

            // Increment and save
            sequence.CurrentValue++;
            await _sequenceRepo.UpdateAsync(sequence);
            await transaction.CommitAsync();

            // Format the number
            return FormatDocumentNumber(sequence, parameters);
        }
        catch
        {
            await transaction.RollbackAsync();
            throw;
        }
    }
}

7. Cross-Document Validation Rules

public class DocumentValidationService
{
    public async Task<ValidationResult> ValidateDocumentCreation(
        DocumentType docType, Guid? parentDocId)
    {
        var errors = new List<string>();

        switch (docType)
        {
            case DocumentType.RFQ:
                // RFQ requires approved PR
                var pr = await _prRepo.GetByIdAsync(parentDocId.Value);
                if (pr.Status != PrStatus.Approved)
                    errors.Add("PR must be approved before creating RFQ");
                break;

            case DocumentType.PurchaseOrder:
                // PO requires selected quotation within validity
                var quote = await _quoteRepo.GetByIdAsync(parentDocId.Value);
                if (!quote.IsSelected)
                    errors.Add("Quotation must be selected");
                if (quote.ValidityDate < DateTime.UtcNow)
                    errors.Add("Quotation has expired");
                break;

            case DocumentType.GRN:
                // GRN requires PO sent to vendor
                var po = await _poRepo.GetByIdAsync(parentDocId.Value);
                if (po.Status < PoStatus.SentToVendor)
                    errors.Add("PO must be sent to vendor");
                break;
        }

        return new ValidationResult { IsValid = errors.Count == 0, Errors = errors };
    }
}

8. Audit Trail & History

Event Type Description Data Captured
CREATE Document created Full document snapshot
UPDATE Document modified Old values, new values, changed fields
STATUS_CHANGE Status transition From status, to status, trigger action
APPROVAL Approval action taken Approver, action, comments
REVISION New revision created Revision number, reason, changes
ATTACHMENT File attached/removed File details, action type

9. Integration Summary

Key Integrations

  • RBAC: Permission checks before document operations
  • Approvals: Status transitions trigger approval workflows
  • Notifications: Document events trigger notifications
  • Three-Way Match: Invoice processing uses PO/GRN data
  • Vendor Rating: Document completion feeds performance metrics
  • Audit: All document actions logged to history

Key Takeaways

  • Documents follow a strict chain: PR → RFQ → Quotation → PO → GRN → Invoice
  • Each document type has its own status lifecycle with validation rules
  • Cross-document references maintain data integrity
  • Automatic number generation ensures unique, traceable identifiers
  • Complete audit trail for compliance and traceability

ProKure Database Documentation - Document Flow Logic v1.0

Part of the ProKure Procurement Management System