• Mahmoud Aglan's avatar
    feat(financial): InstaPay transfers, reviewed before they become money · 2c95f617
    Mahmoud Aglan authored
    S5. The academy publishes a handle, the member transfers and records what
    they sent, and staff turn that claim into a payment only after matching it
    against the academy's own statement.
    
    An unverified screenshot must never create a Payment. `transactions` are
    immutable and recordPayment() forces status = Confirmed and posts to the
    ledger immediately, so a proof is a separate object with its own lifecycle
    and only approval calls recordPayment() — double-entry happens exactly once
    and nothing in the ledger is ever edited.
    
    **A screenshot is not evidence.** It is a convenience. The control is
    `sender_reference`, unique per academy per method behind a partial index,
    which kills replay, cross-invoice reuse and "someone else's transfer against
    my invoice" in one constraint. The reviewer types the amount from the
    statement; `amount_claimed` is what the payer said and is never what gets
    posted.
    
    Concurrency is a conditional UPDATE, not a disabled button. Two reviewers
    open the queue and both see an enabled Approve; the second one's UPDATE
    matches zero rows and raises InvalidStatusTransitionException. A row that has
    left `pending` is frozen by a BEFORE UPDATE trigger — approving a proof is
    the moral equivalent of taking cash, and Auditable::createAuditLog() takes
    its user from auth() at boot and silently writes nothing when it cannot
    resolve an academy, so the approval facts are columns on the row rather than
    an audit-log dependency.
    
    Overpayment is capped at what is due and the excess is deposited to the
    member's wallet in the same transaction. InvoiceStatus::Overpaid exists but
    nothing consumes it and it drives due_amount negative, after which
    getCollectionRate() and ParticipantBillingService start summing negatives.
    
    branch_id is NOT NULL on a proof. Revenue is branch-attributed only through
    payments, so a NULL-branch payment lands in the all-branches total and in no
    branch — the columns stop summing with no error anywhere.
    
    E6 decided as recommended: all five method CHECKs that lacked `instapay` get
    it, the till included. Reception will take an InstaPay transfer within a
    month of launch, and the failure mode of leaving the POS out is a Postgres
    23514 at the till in front of a customer. pos_transactions and
    pos_split_payments also gain `bank_transfer`, which they never had.
    
    The review queue ships before the member-facing upload, on purpose: a proof
    that can be submitted and never reviewed is a promise to a member that nobody
    is keeping.
    
    Proof files go to the private disk and are streamed by a controller that
    authorises the submitter, a co-guardian of the same member, and staff holding
    payments.approve_proof — Content-Disposition: attachment, nosniff, no-store.
    The parent excuse form wrote its medical attachments to the public disk; that
    is the mistake not to repeat.
    
    Verified against a restored copy of backups/oc_sport-20260831-081053.dump: a
    600 EGP transfer against a 500 EGP invoice posts 500 to the invoice
    (Dr 1010 Bank / Cr 4000 Training Revenue, branch attributed) and 100 to the
    wallet; duplicate reference, self-approval, zero amount, second approval and
    editing a settled row are all refused.
    
    Suite: 87 passed, 3 skipped locally; 11 InstaPay tests pass against the
    restored tenant.
    Co-Authored-By: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
    2c95f617
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...