• 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
..
Academies Loading commit data...
AcademyContracts Loading commit data...
AccessMatrix Loading commit data...
Accounting Loading commit data...
Achievements Loading commit data...
ActivitySubscriptions Loading commit data...
Alerts Loading commit data...
Archive Loading commit data...
Audit Loading commit data...
Auth Loading commit data...
Branches Loading commit data...
Carnets Loading commit data...
Cashier Loading commit data...
Children Loading commit data...
Coaches Loading commit data...
Dashboard Loading commit data...
Death Loading commit data...
Disciplines Loading commit data...
Divorce Loading commit data...
Documents Loading commit data...
Facilities Loading commit data...
FacilityDashboards Loading commit data...
FacilityGrids Loading commit data...
Fines Loading commit data...
Foreign Loading commit data...
Forms Loading commit data...
HR Loading commit data...
Honorary Loading commit data...
Installments Loading commit data...
Interviews Loading commit data...
Inventory Loading commit data...
MatchCenter Loading commit data...
MedicalBoard Loading commit data...
Members Loading commit data...
News Loading commit data...
Notifications Loading commit data...
ParentPortal Loading commit data...
Payments Loading commit data...
PlayerAffairs Loading commit data...
PlayerApi Loading commit data...
PlayerAuth Loading commit data...
PlaygroundAdmin Loading commit data...
PoolManagement Loading commit data...
Pricing Loading commit data...
Procurement Loading commit data...
Receipts Loading commit data...
Rentals Loading commit data...
Reports Loading commit data...
Reservations Loading commit data...
Roles Loading commit data...
Rules Loading commit data...
Sales Loading commit data...
Scheduling Loading commit data...
Seasonal Loading commit data...
ServiceCatalog Loading commit data...
Sessions Loading commit data...
Settings Loading commit data...
Sports Loading commit data...
SportsActivity Loading commit data...
SportsDashboard Loading commit data...
Spouses Loading commit data...
Subscriptions Loading commit data...
Support Loading commit data...
Temporary Loading commit data...
Tournaments Loading commit data...
TrainerPortal Loading commit data...
Training Loading commit data...
TrainingGroups Loading commit data...
Transfers Loading commit data...
Treasury Loading commit data...
Tutorials Loading commit data...
Users Loading commit data...
Waiver Loading commit data...
Workflow Loading commit data...