InfraForge Docs

InfraNotes Core · v2

Welcome

Select a document from the sidebar to read it.

Invoice Approval Workflow System

Overview

The approval workflow system allows organizations to implement customizable approval processes for invoices. This system enables businesses to enforce financial governance by requiring one or more approvers to review and authorize invoices before they can be processed further.

Key Features

  1. Configurable Approval Chains: Define multi-step approval workflows with sequential steps
  2. Multiple Approver Types: Support for individual users, roles, or team-based approvers
  3. Delegation Support: Allow approvers to delegate their responsibility to others
  4. Centralized Workflows: Create reusable workflow templates that can be applied to multiple invoices
  5. Approval Tracking: Complete history and audit trail of the approval process
  6. Notifications: Automated notifications for pending approvals and status changes
  7. Amount-based Thresholds: Optional amount thresholds to determine which workflow applies

Implementation Components

The approval workflow system consists of the following components:

Database Schema

  • approval_workflows: Defines reusable workflow templates
  • approval_workflow_steps: Configures the steps within a workflow
  • approval_instances: Tracks active approval processes
  • approval_actions: Records individual approval decisions
  • approval_delegates: Manages approver delegations

Models

  • ApprovalWorkflow: Defines a reusable approval workflow
  • ApprovalWorkflowStep: Defines a single step in an approval chain
  • ApprovalInstance: Represents an active approval process
  • ApprovalActionRecord: Records an approval action (approve/reject/delegate)
  • ApprovalDelegate: Represents a delegation of approval authority

Services

  • ApprovalWorkflowService: Manages workflows and processes approval actions
  • NotificationService: Sends notifications for approval events

API Endpoints

Workflow Management

  • POST /api/approval/workflows: Create a new workflow
  • GET /api/approval/workflows: List workflows
  • GET /api/approval/workflows/{id}: Get a specific workflow
  • PUT /api/approval/workflows/{id}: Update a workflow
  • DELETE /api/approval/workflows/{id}: Delete a workflow

Workflow Steps

  • POST /api/approval/workflows/{id}/steps: Add a step to a workflow
  • PUT /api/approval/workflows/{id}/steps/{stepId}: Update a workflow step
  • DELETE /api/approval/workflows/{id}/steps/{stepId}: Delete a workflow step

Approval Operations

  • POST /api/approval/request: Request approval for an invoice
  • POST /api/approval/instances/{id}/approve: Approve a request
  • POST /api/approval/instances/{id}/reject: Reject a request
  • POST /api/approval/instances/{id}/delegate: Delegate approval to another user
  • POST /api/approval/instances/{id}/cancel: Cancel an approval request

Approval Status

  • GET /api/approval/instances: List approval instances
  • GET /api/approval/instances/{id}: Get a specific approval instance
  • GET /api/approval/pending: Get pending approvals for the current user

Delegation Management

  • POST /api/approval/delegates: Add a delegate
  • GET /api/approval/delegates: List delegates
  • DELETE /api/approval/delegates/{id}: Remove a delegate

Usage Examples

Creating a Workflow

// POST /api/approval/workflows
{
  "name": "Invoice Approval - Finance",
  "description": "Standard invoice approval workflow for finance department",
  "entity_type": "invoice",
  "is_active": true,
  "min_amount_threshold": 1000.00,
  "max_amount_threshold": 10000.00,
  "is_default": false
}

Adding Steps to a Workflow

// POST /api/approval/workflows/123/steps
{
  "step_order": 1,
  "approver_type": "user",
  "approver_id": 456,
  "name": "Department Manager Approval",
  "description": "Initial approval by department manager",
  "is_required": true
}

Requesting Approval

// POST /api/approval/request
{
  "entity_type": "invoice",
  "entity_id": 789,
  "workflow_id": 123,
  "notes": "Please approve this invoice for project XYZ"
}

Approving a Request

// POST /api/approval/instances/456/approve
{
  "notes": "Approved - within budget and properly documented"
}

Rejecting a Request

// POST /api/approval/instances/456/reject
{
  "notes": "Rejected - missing supporting documentation"
}

Delegating Approval

// POST /api/approval/instances/456/delegate
{
  "delegate_id": 789,
  "notes": "Please review this invoice while I'm on vacation"
}

Integration with Invoice System

The approval workflow system integrates seamlessly with the existing invoice management system:

  1. The invoice model has been extended with approval-related fields:

    • approval_status: Current approval status
    • approval_workflow_id: Reference to the associated workflow
    • requires_approval: Flag indicating if approval is required
    • last_approval_action_at: Timestamp of the last approval action
  2. Invoice repository methods have been extended with:

    • SetApprovalStatus: Updates the approval status of an invoice
    • SetApprovalWorkflow: Associates a workflow with an invoice
    • GetInvoicesByApprovalStatus: Finds invoices by approval status
    • GetInvoicesPendingApproval: Gets invoices pending approval for a user
  3. The approval workflow can be triggered:

    • Manually via API call
    • Automatically based on invoice amount
    • Based on other configurable business rules

Permissions

The approval workflow system introduces new permission types:

  • invoice:approval:request: Ability to request approval for invoices
  • invoice:approval:approve: Ability to approve invoices
  • invoice:approval:reject: Ability to reject invoices
  • invoice:approval:cancel: Ability to cancel approval requests
  • approval:workflow:view: Ability to view approval workflows
  • approval:workflow:create: Ability to create approval workflows
  • approval:workflow:update: Ability to update approval workflows
  • approval:workflow:delete: Ability to delete approval workflows
  • approval:workflow:step:manage: Ability to manage workflow steps
  • approval:workflow:set:default: Ability to set a workflow as default
  • approval:delegate:manage: Ability to manage approval delegates
  • approval:actions:view: Ability to view approval actions
  • approval:workflow:assign: Ability to assign workflows to entities

Future Enhancements

The following enhancements are planned for future development:

  1. Role-based Approval: Enhanced support for role-based approvals
  2. Team-based Approval: Support for any team member to approve
  3. Amount-based Routing: Automatic workflow selection based on amount
  4. Deadline Handling: Tracking and escalation for overdue approvals
  5. Front-end Components: Approval dashboard and workflow configuration UI
  6. Parallel Approvals: Support for approval steps that can happen in parallel
  7. Conditional Routing: Dynamic approval chains based on invoice attributes
  8. Mobile Approvals: Mobile-friendly approval interface and notifications
  9. Analytics: Analytics on approval times, bottlenecks, and trends

API Usage Examples

Creating a Workflow

Endpoint: POST /api/approval/workflows

Request Body:

{
  "name": "Invoice Approval Workflow",
  "description": "Standard workflow for invoice approvals",
  "entity_type": "invoice",
  "is_active": true,
  "min_amount_threshold": 1000,
  "max_amount_threshold": 10000,
  "is_default": true
}

Response: The created workflow with its ID.

Adding a Workflow Step

Endpoint: POST /api/approval/workflows/{id}/steps

Request Body:

{
  "approver_type": "user",
  "approver_id": 123,
  "name": "Finance Manager Approval",
  "description": "Requires approval from a finance manager",
  "step_order": 1,
  "is_required": true
}

Response: The created workflow step with its ID.

Requesting Approval

Endpoint: POST /api/approval/request

Request Body:

{
  "entity_type": "invoice",
  "entity_id": 456,
  "workflow_id": 1,
  "notes": "Please review and approve this invoice"
}

Response: The created approval instance with status "pending".

Approving a Request

Endpoint: POST /api/approval/instances/{id}/approve

Request Body:

{
  "notes": "Looks good, approved."
}

Response: The updated approval instance with status changes.

Rejecting a Request

Endpoint: POST /api/approval/instances/{id}/reject

Request Body:

{
  "notes": "Invoice amount exceeds budget allocation."
}

Response: The updated approval instance with status "rejected".

Getting Pending Approvals

Endpoint: GET /api/approval/pending

Response: A list of approval instances waiting for the current user's approval.

Tips for Implementation

  1. Workflow Design: Start with simple workflows with 1-2 steps before creating complex approval chains
  2. Testing: Test each approval step with different user roles to ensure the workflow functions correctly
  3. Error Handling: Implement proper error handling for scenarios like approver unavailability
  4. Notifications: Configure email notifications to alert approvers of pending requests
  5. Dashboards: Build approval dashboards to help users track pending approvals
  6. Delegation: Use the delegation system during vacations or absences

Conclusion

The approval workflow system provides a flexible foundation for organizations to implement governance over their invoice processing. The system is designed to be extensible and can be adapted for other types of approvals beyond invoices in the future.