Commit 7742db39 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix: PaymentService auto-fills payer from invoice when not provided

CollectPaymentWizard and ReconciliationWizard were creating payments
without payer_type/payer_id, making them invisible on participant
profiles. Now PaymentService inherits payer from the invoice's
billable when callers omit it. Also auto-generates reference if empty.

Fixed 113 orphaned payments in production.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 29f298f0
......@@ -20,6 +20,19 @@ public function __construct(
public function recordPayment(array $data, User $creator): Payment
{
return DB::transaction(function () use ($data, $creator) {
if (empty($data['payer_type']) && !empty($data['invoice_id'])) {
$invoice = Invoice::find($data['invoice_id']);
if ($invoice) {
$data['payer_type'] = $invoice->billable_type;
$data['payer_id'] = $invoice->billable_id;
$data['academy_id'] ??= $invoice->academy_id;
}
}
if (empty($data['reference'])) {
$data['reference'] = 'PAY-' . now()->format('YmdHis') . '-' . $data['invoice_id'];
}
$payment = Payment::create([
...$data,
'status' => PaymentStatus::Confirmed,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment