Skip to content

AGT-002 β€” Commission Calculation per Agent After Voyage πŸ”΄Β #20

Description

@hajk1

After a voyage is COMPLETED, calculate each agent's commission from the orders they placed.

New endpoint:

  • GET /api/v1/voyages/{voyageId}/commissions β€” agent commission breakdown

Commission report response:

{
  "voyageNumber": "VOY-2025-001",
  "agents": [
    {
      "agentName": "Ali Hassan",
      "type": "INTERNAL",
      "commissionPercent": 5.0,
      "orderCount": 12,
      "totalOrderValueUsd": 48000.00,
      "commissionEarnedUsd": 2400.00
    },
    {
      "agentName": "FastFreight FZE",
      "type": "EXTERNAL",
      "commissionPercent": 8.0,
      "orderCount": 6,
      "totalOrderValueUsd": 30000.00,
      "commissionEarnedUsd": 2400.00
    }
  ],
  "totalCommissionsUsd": 4800.00
}

Business rules:

  • Commission = agent.commissionPercent Γ— sum of finalPriceUsd for that agent's DELIVERED
    orders on the voyage
  • Only DELIVERED orders count
  • Only COMPLETED voyages (return 409 otherwise)

Acceptance criteria:

  • Commission calculates correctly per agent
  • Mixed internal/external agents handled
  • Returns 409 for non-completed voyages
  • Tests with multiple agents and orders
  • Code is formatted

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions