Skip to content

Accounts Receivable & Payable

Accounts receivable (AR) and accounts payable (AP) track what customers owe the company and what the company owes its suppliers. Rather than maintaining separate AR/AP sub-ledgers, Moon ERP derives these balances directly from journal entry lines posted against partner-linked accounts. This provides a single source of truth and eliminates reconciliation between sub-ledgers and the general ledger.

Purpose

  • View aggregated AR balances (what customers owe) and AP balances (what is owed to suppliers)
  • Generate detailed partner statements showing all transactions with a running balance
  • Execute netting operations to offset AR and AP for partners who are both customer and supplier
  • Support the aging report for overdue analysis (see Reports)

How AR/AP Works

AR and AP balances are computed from posted journal entry lines:

  • Accounts Receivable: Journal entry lines on accounts classified as receivable, grouped by partner
  • Accounts Payable: Journal entry lines on accounts classified as payable, grouped by partner

There are no separate AR/AP tables. The data comes entirely from the journal_entry_lines table, filtered by account classification and partner.

API Endpoints

MethodPathDescription
GET/api/accounting/ar/balancesAll customer AR balances
GET/api/accounting/ap/balancesAll supplier AP balances
GET/api/accounting/ar/statement/{partnerId}AR statement for a specific partner
GET/api/accounting/ap/statement/{partnerId}AP statement for a specific partner
POST/api/accounting/nettingExecute AR/AP netting for a partner

Query Parameters for Statements

ParameterTypeRequiredDescription
start_datedateYesPeriod start date
end_datedateYesPeriod end date

Request/Response Examples

GET /api/accounting/ar/balances

Retrieve all customer receivable balances.

Response 200 OK

json
{
  "data": [
    {
      "partner_id": 8,
      "partner_name": "Al Safat Trading",
      "partner_name_ar": "شركة الصفاة التجارية",
      "account_id": 10,
      "account_code": "1301001",
      "account_name": "Accounts Receivable",
      "total_debit": "25000.000",
      "total_credit": "18000.000",
      "balance": "7000.000"
    },
    {
      "partner_id": 12,
      "partner_name": "Gulf Construction Co.",
      "partner_name_ar": "شركة الخليج للمقاولات",
      "account_id": 10,
      "account_code": "1301001",
      "account_name": "Accounts Receivable",
      "total_debit": "15000.000",
      "total_credit": "15000.000",
      "balance": "0.000"
    }
  ]
}

GET /api/accounting/ap/balances

Retrieve all supplier payable balances.

Response 200 OK

json
{
  "data": [
    {
      "partner_id": 5,
      "partner_name": "Office Supplies Ltd",
      "partner_name_ar": "شركة مستلزمات المكاتب",
      "account_id": 25,
      "account_code": "2101001",
      "account_name": "Accounts Payable",
      "total_debit": "3000.000",
      "total_credit": "8500.000",
      "balance": "5500.000"
    }
  ]
}

GET /api/accounting/ar/statement/{partnerId}

Get a detailed AR statement for a partner.

Request

GET /api/accounting/ar/statement/8?start_date=2026-01-01&end_date=2026-12-31

Response 200 OK

json
{
  "data": {
    "partner_id": 8,
    "partner_name": "Al Safat Trading",
    "partner_name_ar": "شركة الصفاة التجارية",
    "period": {
      "start_date": "2026-01-01",
      "end_date": "2026-12-31"
    },
    "opening_balance": "0.000",
    "transactions": [
      {
        "date": "2026-01-15",
        "entry_number": "JE-2026-0015",
        "reference": "INV-001",
        "description": "Sales invoice",
        "debit": "10000.000",
        "credit": "0.000",
        "running_balance": "10000.000"
      },
      {
        "date": "2026-02-01",
        "entry_number": "JE-2026-0028",
        "reference": "REC-005",
        "description": "Customer payment received",
        "debit": "0.000",
        "credit": "8000.000",
        "running_balance": "2000.000"
      },
      {
        "date": "2026-02-10",
        "entry_number": "JE-2026-0035",
        "reference": "INV-012",
        "description": "Sales invoice - February",
        "debit": "15000.000",
        "credit": "0.000",
        "running_balance": "17000.000"
      },
      {
        "date": "2026-02-15",
        "entry_number": "JE-2026-0041",
        "reference": "REC-008",
        "description": "Customer payment received",
        "debit": "0.000",
        "credit": "10000.000",
        "running_balance": "7000.000"
      }
    ],
    "closing_balance": "7000.000",
    "total_debit": "25000.000",
    "total_credit": "18000.000"
  }
}

POST /api/accounting/netting

Execute netting to offset AR against AP for a partner.

Request

json
{
  "partner_id": 8,
  "amount": "3000.000"
}

Response 201 Created

json
{
  "data": {
    "id": 130,
    "entry_number": "JE-2026-0130",
    "date": "2026-02-16",
    "description": "Netting - Al Safat Trading",
    "status": "posted",
    "lines": [
      {
        "account_id": 25,
        "debit": "3000.000",
        "credit": "0.000",
        "description": "Netting: reduce AP"
      },
      {
        "account_id": 10,
        "debit": "0.000",
        "credit": "3000.000",
        "description": "Netting: reduce AR"
      }
    ]
  },
  "message": "Netting executed successfully"
}

Netting Explained

Netting is used when a business partner acts as both a customer (AR) and a supplier (AP). Instead of paying each balance separately, the smaller balance is offset against the larger one.

The netting journal entry:

  • Debits the AP account (reduces what you owe)
  • Credits the AR account (reduces what they owe you)

Business Rules

RuleDescription
Derived from GLAR/AP balances are calculated from posted journal entry lines, not separate tables
Partner requiredStatements require a valid partner ID
Date range requiredStatement endpoints require start_date and end_date
Netting requires both balancesPartner must have both an AR and AP balance to execute netting
Netting amount limitNetting amount cannot exceed the smaller of the two balances
Netting creates journal entryA posted journal entry is created to record the offset
Company scopedAll data is filtered by the authenticated user's company
Running balanceStatement transactions are ordered by date with a running balance

Moon ERP API Documentation