Skip to content

Money

Everything a driver owes in v2 is a charges row, and the daily job bills one rent charge per rental per billing day. The migration is different: a v1 bill loads as one charge, as v1 billed it (R-MON-84), on a rental only where one is found (R-MON-85), and a v1 debt with no bill is an unmatched row with no charge (R-MON-81). A payment reaches charges only through payment_allocations. Rebates, refunds and waivers are charge_adjustments. A surat hutang (debt_letters) bundles open charges. Payouts settle rent with rental companies.

Scroll a wide diagram sideways to see all of it.

Tables from elsewhere appear as names only: charge_types, company_bank_accounts, drivers, inspections, insurance_claims, legal_entities, rental_companies, rentals.

erDiagram
  charges {
    uuid id PK
    uuid driver_id FK
    uuid rental_id FK
    uuid legal_entity_id FK
    uuid charge_type_id FK
    text description
    date charge_date
    date billing_day
    date due_date
    bigint amount
    bigint company_amount
    bigint margin
    charge_status status
    uuid insurance_claim_id FK
    uuid inspection_id FK
    uuid payout_id FK
    uuid created_by FK
  }
  payments {
    uuid id PK
    uuid driver_id FK
    bigint amount
    timestamptz paid_at
    payment_method method
    uuid bank_account_id FK
    text sender_name
    text sender_account
    text proof_path
    text note
    uuid recorded_by FK
    timestamptz recorded_at
    timestamptz voided_at
    uuid voided_by FK
    text void_reason
    text migrated_from
  }
  payment_allocations {
    uuid id PK
    uuid payment_id FK
    uuid charge_id FK
    bigint amount
    bool cross_entity
    uuid allocated_by FK
    timestamptz allocated_at
  }
  charge_adjustments {
    uuid id PK
    uuid charge_id FK
    adjustment_kind kind
    bigint amount
    text reason
    text proof_path
    uuid created_by FK
  }
  payouts {
    uuid id PK
    uuid rental_company_id FK
    date period_start
    date period_end
    bigint total_amount
    payout_status status
    timestamptz paid_at
  }
  drivers ||--o{ charges : "driver_id"
  rentals |o--o{ charges : "rental_id"
  legal_entities |o--o{ charges : "legal_entity_id"
  charge_types ||--o{ charges : "charge_type_id"
  insurance_claims |o--o{ charges : "insurance_claim_id"
  payouts |o--o{ charges : "payout_id"
  drivers ||--o{ payments : "driver_id"
  company_bank_accounts |o--o{ payments : "bank_account_id"
  payments ||--o{ payment_allocations : "payment_id"
  charges ||--o{ payment_allocations : "charge_id"
  charges ||--o{ charge_adjustments : "charge_id"
  rental_companies ||--o{ payouts : "rental_company_id"

Tables from elsewhere appear as names only: charges, drivers, rentals.

erDiagram
  debt_letters {
    uuid id PK
    text number
    uuid driver_id FK
    uuid rental_id FK
    date issued_on
    date due_on
    letter_status status
    uuid issued_by FK
    text notes
  }
  debt_letter_items {
    uuid id PK
    uuid debt_letter_id FK
    uuid charge_id FK
    bigint legacy_amount
  }
  collection_calls {
    uuid id PK
    uuid driver_id FK
    uuid called_by FK
    timestamptz called_at
    call_outcome outcome
    bigint promised_amount
    date promised_on
    text note
  }
  drivers ||--o{ debt_letters : "driver_id"
  rentals |o--o{ debt_letters : "rental_id"
  debt_letters ||--o{ debt_letter_items : "debt_letter_id"
  charges ||--o{ debt_letter_items : "charge_id"
  drivers ||--o{ collection_calls : "driver_id"