• Mahmoud Aglan's avatar
    feat(accounting): billing sources — a new revenue path needs a row, not a developer · 5e36f062
    Mahmoud Aglan authored
    Removes the "this module needs code" category rather than labelling it.
    
    Most unbilled money in the ERP has one shape: a module writes a priced row into
    its own table and never tells accounting. Wiring each module by hand means a
    developer for every revenue path, forever — which is what I handed over last
    time instead of solving it.
    
    A billing source declares that shape as data: which table holds the money, which
    column is the amount, which rows are still outstanding, who owes it, and how it
    posts. One screen then lists every outstanding charge across every source and
    collects it through PaymentService — the same funnel a member payment uses, so
    it gets a receipt, treasury custody and a journal entry.
    
    Seeded and working immediately: hourly court bookings, sports subscriptions,
    lockers, facility reservations, private matches, rental invoices, annual member
    subscriptions.
    
    Edge cases handled deliberately:
    
    - No free-text SQL anywhere. Filters are structured (column / operator / value)
      rendered into prepared statements; a settings screen that accepted a WHERE
      clause would be an injection hole. Identifiers are matched against
      information_schema and a strict pattern before interpolation.
    - Every source is re-validated on save AND before every listing, because a
      migration can drop a column underneath a source that was fine yesterday. An
      invalid source is shown as broken instead of silently returning nothing.
    - The amount is re-read from the source row at collection time, never trusted
      from the form, so a stale list or a tampered field cannot set the charge.
    - Double-collection is blocked by our own billing_source_collections table
      rather than the module's paid flag — some sources have no write-back column at
      all, and a module can overwrite its own flag. The check is repeated at collect
      time to cover the gap between listing and click.
    - Partial collection only where the source allows it, never above the row total.
    - A player is not a member: a member_id that members does not have is dropped
      rather than tripping the payment foreign key.
    - Write-back is best-effort and isolated — a missing column must not undo a real
      payment, so the failure is logged and the receipt stands.
    - Zero and negative rows are excluded; an empty IN () renders as a false
      predicate rather than a syntax error.
    - Payer names resolve in two queries, not two per row.
    - A source with collections against it deactivates instead of deleting, because
      those rows are the audit trail for real money.
    
    Permission keys were read off role_permissions rather than assumed —
    payment.create does not exist in this install.
    Co-Authored-By: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
    5e36f062
Name
Last commit
Last update
.claude Loading commit data...
Another ERP that we may want to cheat from Loading commit data...
HR requests Loading commit data...
Proposal Loading commit data...
Server Connection Data Loading commit data...
app Loading commit data...
config Loading commit data...
cron Loading commit data...
database Loading commit data...
docker Loading commit data...
docs Loading commit data...
public Loading commit data...
support_tickets_downloads/support_screenshots Loading commit data...
tests Loading commit data...
tools Loading commit data...
.dockerignore Loading commit data...
.editorconfig Loading commit data...
.env Loading commit data...
.env.example Loading commit data...
.gitignore Loading commit data...
.php-cs-fixer.php Loading commit data...
BalanceSheet.html Loading commit data...
CLAUDE.md Loading commit data...
Dockerfile Loading commit data...
Makefile Loading commit data...
SYSTEM_MAP.md Loading commit data...
Sports Module System Design DETAILED.md Loading commit data...
UPGRADE_PLAN.md Loading commit data...
captain-definition Loading commit data...
cli.php Loading commit data...
composer.json Loading commit data...
composer.lock Loading commit data...
interesting_features.md Loading commit data...
phpstan.neon Loading commit data...
phpunit.xml Loading commit data...
sports activity stuff .txt Loading commit data...
sports-activity-alignment-plan.md Loading commit data...
sports-activity-smart-filtering-plan.md Loading commit data...
trial_balance_2026-01-01_to_2026-05-10.csv Loading commit data...