Skip to content

Opening Balances

Opening balances capture the starting financial position when a company begins using Moon ERP or when a new fiscal year starts. They record the balances of every active GL account, and optionally include outstanding partner invoices (receivables and payables) that carry forward from a previous system or fiscal year.

Purpose

  • Enter starting balances for all GL accounts at the beginning of a fiscal year
  • Record outstanding customer invoices (accounts receivable) and supplier invoices (accounts payable)
  • Enforce that total debits equal total credits before confirmation
  • Provide a review report summarizing balances by account classification
  • Lock confirmed opening balances to prevent accidental modification

Entity Attributes

Opening Balance

FieldTypeDescription
idintegerPrimary key
company_idintegerOwning company
fiscal_year_idintegerFiscal year these balances apply to
statusenumdraft, confirmed, locked
total_debitdecimal(12,3)Sum of all line debits (auto-calculated)
total_creditdecimal(12,3)Sum of all line credits (auto-calculated)
notestext?Additional notes
confirmed_byinteger?User who confirmed the balance
confirmed_atdatetime?When confirmed
created_atdatetimeCreation timestamp
updated_atdatetimeLast update timestamp

Opening Balance Line

FieldTypeDescription
idintegerPrimary key
company_idintegerOwning company
opening_balance_idintegerParent opening balance
account_idintegerGL account
debitdecimal(12,3)Debit amount
creditdecimal(12,3)Credit amount
partner_idinteger?Business partner (for AR/AP accounts)
cost_center_idinteger?Optional cost center
descriptionstring?Line description

Opening Balance Invoice

FieldTypeDescription
idintegerPrimary key
company_idintegerOwning company
opening_balance_idintegerParent opening balance
partner_idintegerBusiness partner
invoice_numberstringOriginal invoice number
invoice_datedate?Original invoice date
due_datedatePayment due date
amountdecimal(12,3)Invoice amount
balance_remainingdecimal(12,3)Unpaid balance
typestringreceivable or payable
descriptionstring?Invoice description

Relationships

API Endpoints

MethodPathDescription
GET/api/accounting/opening-balancesList opening balances (paginated, filterable)
POST/api/accounting/opening-balancesCreate with lines
GET/api/accounting/opening-balances/{id}Get with lines and invoices
PUT/api/accounting/opening-balances/{id}Update a draft balance
DELETE/api/accounting/opening-balances/{id}Soft-delete a draft balance
POST/api/accounting/opening-balances/{id}/confirmConfirm (validates and creates journal entry)
POST/api/accounting/opening-balances/{id}/lockLock (prevents further changes)
POST/api/accounting/opening-balances/{id}/unlockUnlock (reverts to draft)
POST/api/accounting/opening-balances/{id}/invoicesAdd a partner invoice
GET/api/accounting/opening-balances/{id}/reviewReview summary report

Query Parameters

ParameterTypeDescription
fiscal_year_idintegerFilter by fiscal year
statusstringFilter by status (draft, confirmed, locked)

State Diagram

Workflow

Request/Response Examples

POST /api/accounting/opening-balances

Create an opening balance with lines.

Request

json
{
  "fiscal_year_id": 1,
  "notes": "Opening balances migrated from legacy system",
  "lines": [
    {
      "account_id": 1,
      "debit": "50000.000",
      "credit": "0.000",
      "description": "Cash on hand"
    },
    {
      "account_id": 15,
      "debit": "120000.000",
      "credit": "0.000",
      "description": "NBK bank balance"
    },
    {
      "account_id": 30,
      "debit": "0.000",
      "credit": "100000.000",
      "description": "Capital"
    },
    {
      "account_id": 31,
      "debit": "0.000",
      "credit": "70000.000",
      "description": "Retained earnings"
    }
  ]
}

Response 201 Created

json
{
  "data": {
    "id": 1,
    "company_id": 1,
    "fiscal_year_id": 1,
    "status": "draft",
    "status_label": "Draft",
    "total_debit": "170000.000",
    "total_credit": "170000.000",
    "notes": "Opening balances migrated from legacy system",
    "confirmed_by": null,
    "confirmed_at": null,
    "lines": [
      {
        "id": 1,
        "account_id": 1,
        "debit": "50000.000",
        "credit": "0.000",
        "description": "Cash on hand"
      },
      {
        "id": 2,
        "account_id": 15,
        "debit": "120000.000",
        "credit": "0.000",
        "description": "NBK bank balance"
      }
    ],
    "fiscal_year": {
      "id": 1,
      "name": "2026"
    },
    "created_at": "2026-02-10T08:00:00.000000Z"
  }
}

POST /api/accounting/opening-balances/{id}/invoices

Add an outstanding customer invoice.

Request

json
{
  "partner_id": 8,
  "invoice_number": "INV-2025-0342",
  "invoice_date": "2025-11-15",
  "due_date": "2026-01-15",
  "amount": "3500.000",
  "balance_remaining": "3500.000",
  "type": "receivable",
  "description": "Outstanding balance from 2025"
}

Response 201 Created

json
{
  "data": {
    "id": 5,
    "opening_balance_id": 1,
    "partner_id": 8,
    "invoice_number": "INV-2025-0342",
    "invoice_date": "2025-11-15",
    "due_date": "2026-01-15",
    "amount": "3500.000",
    "balance_remaining": "3500.000",
    "type": "receivable",
    "description": "Outstanding balance from 2025"
  }
}

GET /api/accounting/opening-balances/{id}/review

Get a validation summary before confirming.

Response 200 OK

json
{
  "data": {
    "opening_balance_id": 1,
    "fiscal_year": "2026",
    "status": "draft",
    "is_balanced": true,
    "total_debit": "170000.000",
    "total_credit": "170000.000",
    "difference": "0.000",
    "by_classification": [
      { "classification": "asset", "debit": "170000.000", "credit": "0.000" },
      { "classification": "equity", "debit": "0.000", "credit": "170000.000" }
    ],
    "line_count": 4,
    "invoice_count": 1,
    "invoices_by_type": {
      "receivable": { "count": 1, "total": "3500.000" },
      "payable": { "count": 0, "total": "0.000" }
    }
  }
}

Business Rules

RuleDescription
Balanced required for confirmTotal debits must equal total credits before confirmation
Draft only editableLines can only be added/modified/deleted while in draft status
Confirm creates journal entryConfirmation generates a journal entry with all opening balance lines
Lock prevents changesLocked opening balances cannot be modified at all
Unlock returns to draftUnlocking moves the balance back to draft for corrections
Invoices on draft onlyPartner invoices can only be added while the balance is in draft
Auto-sum totalstotal_debit and total_credit are auto-calculated from lines
Invoice typesreceivable for customer invoices, payable for supplier invoices
Company scopedAll queries filter by the authenticated user's company

Moon ERP API Documentation