Fix Laravel Pint formatting

This commit is contained in:
root
2026-06-09 00:03:03 -04:00
parent 8d4d610b82
commit b5fd4a4ca1
1414 changed files with 11317 additions and 10201 deletions
@@ -10,8 +10,7 @@ class FinancialSummaryService
{
public function __construct(
private FinancialDonationRecipientService $donationRecipients
) {
}
) {}
public function getSummary(?string $dateFrom, ?string $dateTo, ?string $schoolYear): array
{
@@ -19,10 +18,10 @@ class FinancialSummaryService
$derivedDateFrom = null;
$derivedDateTo = null;
if (!empty($schoolYear) && empty($dateFrom) && empty($dateTo)) {
if (! empty($schoolYear) && empty($dateFrom) && empty($dateTo)) {
if (preg_match('/^(\\d{4})[^\\d]?(\\d{4})$/', $schoolYear, $m)) {
$derivedDateFrom = $m[1] . '-01-01';
$derivedDateTo = $m[2] . '-12-31';
$derivedDateFrom = $m[1].'-01-01';
$derivedDateTo = $m[2].'-12-31';
}
}
@@ -30,10 +29,10 @@ class FinancialSummaryService
$invoiceDateTo = $dateTo ?: $derivedDateTo;
$invoiceQuery = DB::table('invoices')->where('school_year', $schoolYear);
if (!empty($invoiceDateFrom)) {
if (! empty($invoiceDateFrom)) {
$invoiceQuery->whereRaw('DATE(COALESCE(issue_date, created_at)) >= ?', [$invoiceDateFrom]);
}
if (!empty($invoiceDateTo)) {
if (! empty($invoiceDateTo)) {
$invoiceQuery->whereRaw('DATE(COALESCE(issue_date, created_at)) <= ?', [$invoiceDateTo]);
}
$invoices = $invoiceQuery->get()->map(fn ($row) => (array) $row)->all();
@@ -41,6 +40,7 @@ class FinancialSummaryService
$invoiceIds = array_values(array_unique(array_filter(array_map(static function ($row) {
$id = (int) ($row['id'] ?? 0);
return $id > 0 ? $id : null;
}, $invoices))));
@@ -54,7 +54,7 @@ class FinancialSummaryService
$paidByInvoice = [];
$discountByInvoice = [];
$refundByInvoice = [];
if (!empty($invoiceIds)) {
if (! empty($invoiceIds)) {
$paidByInvoice = $this->paymentsByInvoiceIds($invoiceIds, $schoolYear, $invoiceDateFrom, $invoiceDateTo);
$discountByInvoice = $this->discountsByInvoiceIds($invoiceIds, $dateFrom, $dateTo);
$refundByInvoice = $this->refundsByInvoiceIds($invoiceIds, $dateFrom, $dateTo);
@@ -99,14 +99,15 @@ class FinancialSummaryService
->where('ac.school_year', $schoolYear)
->where('ac.status', '!=', 'void');
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$query->whereRaw('DATE(ac.due_date) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$query->whereRaw('DATE(ac.due_date) <= ?', [$dateTo]);
}
$row = (array) $query->first();
return (float) ($row['amount'] ?? 0);
}
@@ -123,10 +124,10 @@ class FinancialSummaryService
})
->groupBy('ac.parent_id');
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$query->whereRaw('DATE(ac.due_date) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$query->whereRaw('DATE(ac.due_date) <= ?', [$dateTo]);
}
@@ -146,10 +147,10 @@ class FinancialSummaryService
private function sumPayments(string $schoolYear, ?string $dateFrom, ?string $dateTo): float
{
$query = DB::table('payments')->where('school_year', $schoolYear);
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$query->whereRaw('DATE(payment_date) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$query->whereRaw('DATE(payment_date) <= ?', [$dateTo]);
}
@@ -166,6 +167,7 @@ class FinancialSummaryService
}
$row = (array) $query->selectRaw('COALESCE(SUM(paid_amount), 0) AS paid_amount')->first();
return (float) ($row['paid_amount'] ?? 0);
}
@@ -176,10 +178,10 @@ class FinancialSummaryService
->whereIn('invoice_id', $invoiceIds)
->where('school_year', $schoolYear);
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$query->whereRaw('DATE(payment_date) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$query->whereRaw('DATE(payment_date) <= ?', [$dateTo]);
}
@@ -203,6 +205,7 @@ class FinancialSummaryService
$map[$invoiceId] = (float) ($row['total_paid'] ?? 0);
}
}
return $map;
}
@@ -212,10 +215,10 @@ class FinancialSummaryService
->selectRaw('invoice_id, COALESCE(SUM(discount_amount),0) AS total_disc')
->whereIn('invoice_id', $invoiceIds);
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$query->whereRaw('DATE(COALESCE(used_at, created_at)) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$query->whereRaw('DATE(COALESCE(used_at, created_at)) <= ?', [$dateTo]);
}
@@ -227,6 +230,7 @@ class FinancialSummaryService
$map[$invoiceId] = (float) ($row['total_disc'] ?? 0);
}
}
return $map;
}
@@ -237,10 +241,10 @@ class FinancialSummaryService
->whereIn('invoice_id', $invoiceIds)
->whereIn('status', ['Partial', 'Paid']);
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$query->whereRaw('DATE(COALESCE(refunded_at, created_at)) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$query->whereRaw('DATE(COALESCE(refunded_at, created_at)) <= ?', [$dateTo]);
}
@@ -252,20 +256,22 @@ class FinancialSummaryService
$map[$invoiceId] = (float) ($row['total_refund'] ?? 0);
}
}
return $map;
}
private function sumExpenses(string $schoolYear, ?string $dateFrom, ?string $dateTo): float
{
$query = DB::table('expenses')->where('school_year', $schoolYear);
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$query->whereRaw('DATE(created_at) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$query->whereRaw('DATE(created_at) <= ?', [$dateTo]);
}
$row = (array) $query->selectRaw('COALESCE(SUM(amount), 0) AS amount')->first();
return (float) ($row['amount'] ?? 0);
}
@@ -277,7 +283,7 @@ class FinancialSummaryService
->selectRaw('COALESCE(SUM(r.amount),0) AS amount')
->leftJoin('expenses as e', 'e.id', '=', 'r.expense_id');
if (!empty($schoolYear)) {
if (! empty($schoolYear)) {
$query->where(function ($q) use ($schoolYear, $normalizedYear) {
$q->where(function ($q2) use ($schoolYear, $normalizedYear) {
$q2->where('r.school_year', $schoolYear)
@@ -298,10 +304,10 @@ class FinancialSummaryService
});
}
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$query->whereRaw('DATE(COALESCE(r.created_at, e.created_at)) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$query->whereRaw('DATE(COALESCE(r.created_at, e.created_at)) <= ?', [$dateTo]);
}
@@ -317,7 +323,7 @@ class FinancialSummaryService
->whereNull('bi.unassigned_at')
->whereNull('r.id');
if (!empty($schoolYear)) {
if (! empty($schoolYear)) {
$batchFallback->where(function ($q) use ($schoolYear, $normalizedYear) {
$q->where('e.school_year', $schoolYear)
->orWhereRaw(
@@ -327,10 +333,10 @@ class FinancialSummaryService
});
}
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$batchFallback->whereRaw('DATE(COALESCE(e.created_at, b.closed_at)) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$batchFallback->whereRaw('DATE(COALESCE(e.created_at, b.closed_at)) <= ?', [$dateTo]);
}
@@ -346,10 +352,10 @@ class FinancialSummaryService
->where('school_year', $schoolYear)
->where('category', 'Donation');
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$expenseQuery->whereRaw('DATE(created_at) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$expenseQuery->whereRaw('DATE(created_at) <= ?', [$dateTo]);
}
@@ -358,14 +364,14 @@ class FinancialSummaryService
$donationReimb = 0.0;
$recipientIds = $this->donationRecipients->recipientIds();
if (!empty($recipientIds)) {
if (! empty($recipientIds)) {
$normalizedYear = preg_replace('/[^0-9]/', '', (string) $schoolYear);
$donationQuery = DB::table('reimbursements as r')
->selectRaw('COALESCE(SUM(r.amount),0) AS amount')
->leftJoin('expenses as e', 'e.id', '=', 'r.expense_id')
->whereIn('r.reimbursed_to', $recipientIds);
if (!empty($schoolYear)) {
if (! empty($schoolYear)) {
$donationQuery->where(function ($q) use ($schoolYear, $normalizedYear) {
$q->where(function ($q2) use ($schoolYear, $normalizedYear) {
$q2->where('r.school_year', $schoolYear)
@@ -386,10 +392,10 @@ class FinancialSummaryService
});
}
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$donationQuery->whereRaw('DATE(COALESCE(r.created_at, e.created_at)) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$donationQuery->whereRaw('DATE(COALESCE(r.created_at, e.created_at)) <= ?', [$dateTo]);
}
@@ -410,14 +416,15 @@ class FinancialSummaryService
->whereIn('status', ['Partial', 'Paid'])
->whereNotNull('refund_paid_amount');
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$query->whereRaw('DATE(COALESCE(refunded_at, created_at)) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$query->whereRaw('DATE(COALESCE(refunded_at, created_at)) <= ?', [$dateTo]);
}
$row = (array) $query->selectRaw('COALESCE(SUM(refund_paid_amount),0) AS refund_paid_amount')->first();
return (float) ($row['refund_paid_amount'] ?? 0);
}
@@ -427,14 +434,15 @@ class FinancialSummaryService
->join('invoices as i', 'i.id', '=', 'du.invoice_id')
->where('i.school_year', $schoolYear);
if (!empty($dateFrom)) {
if (! empty($dateFrom)) {
$query->whereRaw('DATE(COALESCE(du.used_at, du.created_at)) >= ?', [$dateFrom]);
}
if (!empty($dateTo)) {
if (! empty($dateTo)) {
$query->whereRaw('DATE(COALESCE(du.used_at, du.created_at)) <= ?', [$dateTo]);
}
$row = (array) $query->selectRaw('COALESCE(SUM(du.discount_amount),0) AS discount_amount')->first();
return (float) ($row['discount_amount'] ?? 0);
}
@@ -454,14 +462,14 @@ class FinancialSummaryService
$ref = (float) ($refundByInvoice[$invoiceId] ?? 0);
$balance = max(0.0, round($total - $disc - $paid - $ref, 2));
if (!isset($parentBalances[$parentId])) {
if (! isset($parentBalances[$parentId])) {
$parentBalances[$parentId] = 0.0;
}
$parentBalances[$parentId] += $balance;
}
foreach ($extraByParent as $parentId => $extra) {
if (!isset($parentBalances[$parentId])) {
if (! isset($parentBalances[$parentId])) {
$parentBalances[$parentId] = 0.0;
}
$parentBalances[$parentId] += (float) $extra;