• Mahmoud Aglan's avatar
    feat(accounting): extend posting engine to the full accounting cycle · fb3097a2
    Mahmoud Aglan authored
    Generalises the revenue engine from "collection" to every stage a document
    posts at, and routes all 26 auto-posting paths through it.
    
    Two new dimensions on a rule:
    
      stage      accrual | collection | payment | refund | writeoff | transfer
      direction  inflow  → counter account DEBITED, allocation lines CREDITED
                 outflow → allocation lines DEBITED, counter account CREDITED
    
    So the same allocation maths now drives revenue, expense, receivable and
    payable postings. Contra-revenue is always a debit regardless of direction.
    
    Where the amounts are computed elsewhere and only the accounts need to be
    configurable — payroll components, treasury legs, COGS, rental legs — a
    second mechanism (PostingRouter::accountFor) resolves a configurable account
    pointer instead of forcing those through the allocator. Both are edited from
    the same screen.
    
    Dead posting paths fixed. Each of these targeted a header account, which
    JournalService refuses, and the callers only Logger::error — so they have
    been failing invisibly:
    
    - 230601 الموردون is a header → the ENTIRE procurement cycle (vendor invoice,
      vendor payment, return-to-vendor) could never post. Now 230601002.
    - 310103 حصة الشركة في التأمينات did not exist at all → payroll dropped the
      employer insurance line, then a balancing fallback silently increased the
      bank credit to force the entry to balance, misstating cash. The account is
      created, and an imbalance now refuses to post and reports instead.
    - 230804 جاري مصلحة الضرائب is a header → rental VAT could never post.
      Now 23080404 ضريبة القيمة المضافة.
    - AccountCodes::INPUT_TAX resolved to 120408 مدينو بيع أوراق مالية, an
      unrelated account. Input VAT now posts to 12041106.
    - Member write-off debited MISCELLANEOUS_REVENUE. A bad debt is an expense;
      it now posts to 3328 ديون معدومة.
    - $result['entry_id'] is never returned by JournalService (the key is
      journal_entry_id), so rental invoices, treasury settlements and treasury
      deposits never linked back to their journal entry.
    - SUB_TREASURY_CASH points at 12060102 الصندوق بالدولار, the USD box. Left
      deliberately unmapped and surfaced on the diagnostics page so finance picks
      the right EGP account rather than having one guessed for them.
    
    Accruals now also create the accounts_receivable sub-ledger row alongside the
    GL entry, which is why that table was empty against 970,592.67 EGP of
    scheduled instalments.
    
    Verified against a full clone of the production schema and chart of accounts
    in a throwaway database: all six stages post balanced entries, VAT 14%
    inclusive on 1140 yields 1000 revenue + 140 tax, a five-line split (two fixed
    + two percentage + remainder) balances to the piastre, and a 12,000 annual
    subscription produces exactly 12 monthly deferral rows summing to 12,000 with
    the recognition run posting the current period. 27 allocation unit tests pass.
    
    Seeded rules reproduce existing behaviour except where that behaviour was a
    silent failure. Unconfigured stages still fall through to the legacy path.
    Co-Authored-By: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
    fb3097a2
Name
Last commit
Last update
..
bank_accounts Loading commit data...
bank_reconciliation Loading commit data...
budgets Loading commit data...
chart_of_accounts Loading commit data...
cost_centers Loading commit data...
daily_transactions Loading commit data...
dashboard Loading commit data...
dimensions Loading commit data...
documentary_credits Loading commit data...
fiscal_years Loading commit data...
guarantees Loading commit data...
instruments Loading commit data...
journal_entries Loading commit data...
journal_types Loading commit data...
loans Loading commit data...
opening_entries Loading commit data...
period_closing Loading commit data...
portfolios Loading commit data...
reports Loading commit data...
revenue_mapping Loading commit data...
settlements Loading commit data...
statements Loading commit data...