fix apply the plan docs/alrahma_api_fix_plan_school_year_only_v7
API CI/CD / Validate (composer + pint) (push) Successful in 3m10s
API CI/CD / Test (PHPUnit) (push) Failing after 6m49s
API CI/CD / Build frontend assets (push) Successful in 1m3s
API CI/CD / Security audit (push) Failing after 1m0s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 3m10s
API CI/CD / Test (PHPUnit) (push) Failing after 6m49s
API CI/CD / Build frontend assets (push) Successful in 1m3s
API CI/CD / Security audit (push) Failing after 1m0s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
This commit is contained in:
@@ -6,9 +6,10 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class FamilyFinanceService
|
||||
{
|
||||
public function loadFinancialsForParents(array $parentIds, int $paymentLimit = 10): array
|
||||
public function loadFinancialsForParents(array $parentIds, string $schoolYear, int $paymentLimit = 10): array
|
||||
{
|
||||
$parentIds = array_values(array_filter(array_map('intval', $parentIds)));
|
||||
$schoolYear = trim($schoolYear);
|
||||
|
||||
if (empty($parentIds)) {
|
||||
return [
|
||||
@@ -20,6 +21,8 @@ class FamilyFinanceService
|
||||
'total_amount' => 0.0,
|
||||
'paid_amount' => 0.0,
|
||||
'balance' => 0.0,
|
||||
'positive_unpaid_balance' => 0.0,
|
||||
'credit_balance' => 0.0,
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -27,6 +30,7 @@ class FamilyFinanceService
|
||||
$invRows = DB::table('invoices')
|
||||
->select('id', 'parent_id', 'invoice_number', 'status', 'total_amount', 'paid_amount', 'balance', 'issue_date', 'due_date')
|
||||
->whereIn('parent_id', $parentIds)
|
||||
->when($schoolYear !== '', fn ($query) => $query->where('school_year', $schoolYear))
|
||||
->orderBy('issue_date', 'DESC')
|
||||
->get()
|
||||
->map(fn ($r) => (array) $r)
|
||||
@@ -38,19 +42,29 @@ class FamilyFinanceService
|
||||
'total_amount' => 0.0,
|
||||
'paid_amount' => 0.0,
|
||||
'balance' => 0.0,
|
||||
'positive_unpaid_balance' => 0.0,
|
||||
'credit_balance' => 0.0,
|
||||
];
|
||||
foreach ($invRows as $ir) {
|
||||
$invoiceMap[(int) ($ir['id'] ?? 0)] = (string) ($ir['invoice_number'] ?? '');
|
||||
$balance = (float) ($ir['balance'] ?? 0);
|
||||
$summary['invoices_count']++;
|
||||
$summary['total_amount'] += (float) ($ir['total_amount'] ?? 0);
|
||||
$summary['paid_amount'] += (float) ($ir['paid_amount'] ?? 0);
|
||||
$summary['balance'] += (float) ($ir['balance'] ?? 0);
|
||||
$summary['balance'] += $balance;
|
||||
if ($balance > 0) {
|
||||
$summary['positive_unpaid_balance'] += $balance;
|
||||
} elseif ($balance < 0) {
|
||||
$summary['credit_balance'] += abs($balance);
|
||||
}
|
||||
}
|
||||
|
||||
$payRows = DB::table('payments')
|
||||
->select('id', 'parent_id', 'invoice_id', 'paid_amount', 'balance', 'payment_method', 'payment_date', 'status')
|
||||
->whereIn('parent_id', $parentIds)
|
||||
->orderBy('payment_date', 'DESC')
|
||||
$payRows = DB::table('payments as p')
|
||||
->join('invoices as i', 'i.id', '=', 'p.invoice_id')
|
||||
->select('p.id', 'p.parent_id', 'p.invoice_id', 'p.paid_amount', 'p.balance', 'p.payment_method', 'p.payment_date', 'p.status')
|
||||
->whereIn('p.parent_id', $parentIds)
|
||||
->when($schoolYear !== '', fn ($query) => $query->where('i.school_year', $schoolYear))
|
||||
->orderBy('p.payment_date', 'DESC')
|
||||
->limit($paymentLimit)
|
||||
->get()
|
||||
->map(fn ($r) => (array) $r)
|
||||
|
||||
Reference in New Issue
Block a user