• Mahmoud Aglan's avatar
    feat(settlements): settle a member's account instead of editing around it · e45bd6d7
    Mahmoud Aglan authored
    A club that ran on paper for years does not arrive in the system as a
    clean ledger. On the first academy live, 33 players were registered with
    an invoice raised and the "pay now" toggle left off — 25 of them in two
    data-entry evenings — and 27 of those are now carrying an unpaid
    registration month plus an unpaid September renewal. Nine paid for the
    federation card in instalments typed into free-text lines. Eight invoices
    were issued at zero because no price existed yet. Three people exist
    twice. None of that is a bug in one screen; it is a whole class of file
    that reality got ahead of.
    
    The desk had four tools that each did a slice: collect a payment, correct
    one invoice's amount, back-fill missing invoices, register someone who
    started months ago. None of them answers the question an operator has in
    front of a parent — this file is wrong in several ways at once, what do
    we do about all of it — so corrections were made wherever a screen
    allowed them and the ledger drifted further.
    
    SettlementService applies a reviewed set of corrections as one
    transaction and one record: money taken and never entered (on the day it
    was actually taken), a month closed for less than it was billed because
    the player joined halfway through, a month dropped entirely, a month
    nobody billed, a card or kit sold outside the system, a free-text line
    linked to the product it was really paying for, an agreed instalment
    plan, a payment sitting on the wrong month, and an overpayment held as
    wallet credit. Money moves through PaymentService so the ledger, the
    balance and the receipt all happen; stock through InventoryService; a
    waiver is written as the admin_override the roster already knows how to
    explain, leaving subtotal_amount alone so "650 of 900, discounted" still
    reads. Nothing calls auth() or session(): actor, branch and amounts are
    parameters.
    
    AccountAnomalyScanner finds the files rather than waiting for an argument
    at the desk — seven cases, worst first, each with the sentence that says
    what to check. SettlementWorklist lists them with a CSV export;
    AccountSettlementWizard puts one account on a page, proposes the
    corrections that fit what it found, shows exactly what will be collected,
    waived and billed, and demands a written reason before it writes
    anything.
    
    Both screens are gated on a new settlements.manage permission — waiving a
    month is the academy's call, and an owner should not need a platform
    administrator to make it — delivered by migration as well as seeder,
    since db:seed only runs on a first deploy.
    
    Two things the tests caught rather than production: Postgres refuses FOR
    UPDATE on an aggregate, so numbering settlements from max(id) would have
    rolled back a whole settlement the operator had already confirmed; and
    payment_plans_status_check has no 'partial', so a part-paid plan is
    active with the count saying how far along it is.
    
    Verified against a restored oc-sport tenant: 20 settlement cases and 7
    render/permission cases pass, including cross-participant access, a
    future date, an oversized payment, and a failing second action rolling
    the first one back. Full suite 298 tests, no failures.
    Co-Authored-By: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
    e45bd6d7
Name
Last commit
Last update
..
2024_01_01_000001_create_academies_table.php Loading commit data...
2024_01_01_000002_create_users_table.php Loading commit data...
2024_01_01_000003_create_cache_and_jobs_tables.php Loading commit data...
2024_01_01_000004_create_branches_table.php Loading commit data...
2024_01_01_000005_create_roles_and_permissions_tables.php Loading commit data...
2024_01_01_000006_create_people_table.php Loading commit data...
2024_01_01_000007_create_guardians_table.php Loading commit data...
2024_01_01_000008_add_phase1_columns_to_users_table.php Loading commit data...
2024_01_01_000009_create_login_history_table.php Loading commit data...
2024_01_01_000010_create_financial_accounts_table.php Loading commit data...
2024_01_01_000011_create_invoices_table.php Loading commit data...
2024_01_01_000012_create_payments_table.php Loading commit data...
2024_01_01_000013_create_transactions_table.php Loading commit data...
2024_01_01_000014_create_wallets_table.php Loading commit data...
2024_01_01_000015_create_payment_plans_table.php Loading commit data...
2024_01_01_000016_create_activities_table.php Loading commit data...
2024_01_01_000017_create_participants_table.php Loading commit data...
2024_01_01_000018_create_guardian_participant_table.php Loading commit data...
2024_01_01_000019_create_training_programs_table.php Loading commit data...
2024_01_01_000020_create_training_groups_table.php Loading commit data...
2024_01_01_000021_create_training_schedules_table.php Loading commit data...
2024_01_01_000022_create_training_sessions_table.php Loading commit data...
2024_01_01_000023_create_enrollments_table.php Loading commit data...
2024_01_01_000024_create_waitlists_table.php Loading commit data...
2024_01_01_000025_create_holidays_table.php Loading commit data...
2024_01_01_000026_create_cash_sessions_table.php Loading commit data...
2024_01_01_000027_create_facilities_table.php Loading commit data...
2024_01_01_000028_create_space_layouts_and_segments_table.php Loading commit data...
2024_01_01_000029_create_space_reservations_table.php Loading commit data...
2024_01_01_000030_create_assignments_table.php Loading commit data...
2024_01_01_000031_create_attendance_records_table.php Loading commit data...
2024_01_01_000032_create_base_prices_table.php Loading commit data...
2024_01_01_000033_create_pricing_rules_table.php Loading commit data...
2024_01_01_000034_create_promotions_and_coupons_table.php Loading commit data...
2024_01_01_000035_create_pos_transactions_table.php Loading commit data...
2024_01_01_000036_create_products_and_categories_table.php Loading commit data...
2024_01_01_000037_create_warehouses_and_inventory_levels_table.php Loading commit data...
2024_01_01_000038_create_inventory_movements_table.php Loading commit data...
2024_01_01_000039_create_purchase_orders_table.php Loading commit data...
2024_01_01_000040_create_kits_table.php Loading commit data...
2024_01_01_000041_create_stock_counts_table.php Loading commit data...
2024_01_01_000042_create_notifications_system_table.php Loading commit data...
2024_01_01_000043_create_audit_logs_table.php Loading commit data...
2024_01_01_000044_create_evaluations_table.php Loading commit data...
2024_01_01_000045_create_system_settings_table.php Loading commit data...
2024_01_01_000046_add_monthly_rental_cost_to_facilities.php Loading commit data...
2024_01_01_000047_create_receipt_templates_and_branch_settings.php Loading commit data...
2024_01_01_000048_add_service_fee_to_transactions_and_invoices.php Loading commit data...
2024_01_01_000049_add_branch_id_to_participants_and_payments.php Loading commit data...
2024_01_01_000050_simplify_membership_type_and_add_membership_id.php Loading commit data...
2024_01_01_000051_add_cash_session_id_to_payments.php Loading commit data...
2024_01_01_000052_rename_program_id_to_training_program_id_on_training_groups.php Loading commit data...
2024_01_01_000053_create_employees_table.php Loading commit data...
2024_01_01_000054_create_trainers_table.php Loading commit data...
2024_01_01_000055_create_trainer_qualifications_table.php Loading commit data...
2024_01_01_000056_create_trainer_availability_table.php Loading commit data...
2024_01_01_000057_create_documents_table.php Loading commit data...
2024_01_01_000060_alter_trainers_make_employee_nullable.php Loading commit data...
2024_01_01_000061_create_trainer_compensations_table.php Loading commit data...
2024_01_01_000062_create_payroll_periods_table.php Loading commit data...
2024_01_01_000063_create_payslips_table.php Loading commit data...
2024_01_01_000064_create_payslip_items_table.php Loading commit data...
2024_01_01_000065_create_trainer_advances_table.php Loading commit data...
2024_01_01_000066_create_trainer_rate_history_table.php Loading commit data...
2024_01_01_000067_add_label_ar_to_system_settings_table.php Loading commit data...
2024_01_01_000070_create_media_table.php Loading commit data...
2024_01_01_000071_add_default_trainer_to_training_programs.php Loading commit data...
2024_01_01_000071_create_website_settings_table.php Loading commit data...
2024_01_01_000072_create_website_sections_table.php Loading commit data...
2024_01_01_000073_create_website_testimonials_table.php Loading commit data...
2024_01_01_000074_create_website_faqs_table.php Loading commit data...
2024_01_01_000075_create_website_news_table.php Loading commit data...
2024_01_01_000076_create_website_partners_table.php Loading commit data...
2024_01_01_000077_create_contact_submissions_table.php Loading commit data...
2024_01_01_000078_create_whatsapp_messages_table.php Loading commit data...
2024_01_01_000079_add_billing_fields_to_programs_and_enrollments.php Loading commit data...
2024_01_01_000080_add_governorate_to_people_table.php Loading commit data...
2026_07_16_162146_add_is_essential_to_products_table.php Loading commit data...
2026_07_16_180000_add_delivery_tracking_to_invoice_items.php Loading commit data...
2026_07_16_200000_add_annual_billing_to_products_table.php Loading commit data...
2026_07_16_210000_add_installment_amounts_to_product_installment_plans.php Loading commit data...
2026_07_17_000001_widen_training_groups_code_column.php Loading commit data...
2026_07_22_000001_create_facility_rent_payments_table.php Loading commit data...
2026_07_22_000002_create_expenses_table.php Loading commit data...
2026_07_22_000003_add_expense_permissions.php Loading commit data...
2026_07_24_000001_create_events_table.php Loading commit data...
2026_07_24_000002_create_event_registrations_table.php Loading commit data...
2026_07_24_000003_add_event_media_collections.php Loading commit data...
2026_07_24_000004_add_event_permissions.php Loading commit data...
2026_07_24_100001_add_locations_to_events.php Loading commit data...
2026_07_24_100002_default_website_published_true.php Loading commit data...
2026_07_25_000001_add_print_count_to_invoices_and_payments.php Loading commit data...
2026_07_25_000001_website_builder_v2_phase_a.php Loading commit data...
2026_07_25_100001_website_builder_v2_phase_b.php Loading commit data...
2026_07_25_200001_website_builder_v2_phase_c.php Loading commit data...
2026_07_26_000001_add_events_section_key.php Loading commit data...
2026_07_27_000001_create_device_tokens_table.php Loading commit data...
2026_07_27_000002_add_channel_push_to_notification_preferences.php Loading commit data...
2026_07_27_000003_create_contact_messages_table.php Loading commit data...
2026_07_27_000004_seed_mobile_app_system_settings.php Loading commit data...
2026_07_27_000005_create_service_requests_table.php Loading commit data...
2026_07_27_100001_create_push_announcements_table.php Loading commit data...
2026_07_27_100002_create_push_analytics_table.php Loading commit data...
2026_07_28_000001_drop_membership_id_unique_index.php Loading commit data...
2026_08_02_000001_add_partial_payment_to_products_table.php Loading commit data...
2026_08_02_000002_add_partially_paid_to_pos_payment_status.php Loading commit data...
2026_08_09_000001_add_external_revenue_to_expenses_category.php Loading commit data...
2026_08_09_000002_add_collected_by_to_invoices.php Loading commit data...
2026_08_10_000001_add_preferred_branch_to_users.php Loading commit data...
2026_08_10_000002_add_status_to_expenses.php Loading commit data...
2026_08_13_000001_enable_partial_payment_all_products.php Loading commit data...
2026_08_14_000001_add_attachment_to_expenses.php Loading commit data...
2026_08_19_000001_add_is_free_to_participants.php Loading commit data...
2026_08_30_000001_pricing_discount_overhaul.php Loading commit data...
2026_08_30_000002_seed_pricing_discount_settings.php Loading commit data...
2026_08_30_000003_facility_activities_and_default_layouts.php Loading commit data...
2026_08_30_000004_normalize_user_credentials.php Loading commit data...
2026_08_31_000001_add_attachment_metadata_to_expenses.php Loading commit data...
2026_08_31_000001_create_website_pages_and_blocks.php Loading commit data...
2026_08_31_000001_trim_stray_whitespace_from_names.php Loading commit data...
2026_08_31_000002_add_subject_to_contact_submissions.php Loading commit data...
2026_08_31_000003_create_website_menus.php Loading commit data...
2026_09_01_000001_add_branches_view_all_permission.php Loading commit data...
2026_09_01_000002_backfill_pos_invoice_item_types.php Loading commit data...
2026_09_01_000003_create_program_products_table.php Loading commit data...
2026_09_01_000004_bundle_registration_product_to_team_programs.php Loading commit data...
2026_09_01_000005_revoke_mobile_api_tokens.php Loading commit data...
2026_09_02_000001_backfill_freetext_product_invoice_items.php Loading commit data...
2026_09_03_000001_seed_financial_accounts_for_every_academy.php Loading commit data...
2026_09_03_000002_branch_attribution_for_money.php Loading commit data...
2026_09_03_000003_tenancy_invariant_repairs.php Loading commit data...
2026_09_03_000004_reconcile_check_vocabularies.php Loading commit data...
2026_09_03_000005_create_invoice_number_counters.php Loading commit data...
2026_09_03_000006_repair_mobile_invoice_item_totals.php Loading commit data...
2026_09_04_000001_branding_single_source_of_truth.php Loading commit data...
2026_09_05_000001_add_player_role_and_portal_permissions.php Loading commit data...
2026_09_05_000002_create_portal_invitations.php Loading commit data...
2026_09_06_000001_add_channel_to_published_content.php Loading commit data...
2026_09_07_000001_create_checkin_infrastructure.php Loading commit data...
2026_09_08_000001_add_instapay_payment_method.php Loading commit data...
2026_09_08_000002_create_payment_proofs.php Loading commit data...
2026_09_09_000001_allow_web_push_device_tokens.php Loading commit data...
2026_09_10_000001_create_consents_and_deletion_requests.php Loading commit data...
2026_09_10_000002_excuses_are_service_requests.php Loading commit data...
2026_09_11_000001_self_registration_infrastructure.php Loading commit data...
2026_09_12_000001_add_branch_presentation_and_season_window.php Loading commit data...
2026_09_12_000002_add_navbar_and_footer_presentation_settings.php Loading commit data...
2026_09_12_000003_allow_glass_navbar_style.php Loading commit data...
2026_09_12_000004_add_english_navbar_cta_text.php Loading commit data...
2026_09_13_000001_branch_isolation_columns_and_backfill.php Loading commit data...
2026_09_13_000002_branch_owns_the_catalogue.php Loading commit data...
2026_09_13_000003_split_programmes_shared_between_branches.php Loading commit data...
2026_09_14_000001_create_settlements_table.php Loading commit data...
2026_09_14_000002_add_settlements_manage_permission.php Loading commit data...