Fix Laravel Pint formatting
This commit is contained in:
@@ -9,7 +9,6 @@ use App\Models\Enrollment;
|
||||
use App\Models\EventCharges;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Refund;
|
||||
use App\Models\Student;
|
||||
use App\Models\StudentClass;
|
||||
use App\Models\User;
|
||||
@@ -21,8 +20,7 @@ class InvoicePdfService
|
||||
public function __construct(
|
||||
private InvoiceConfigService $config,
|
||||
private InvoiceGradeService $grades
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function buildPdf(int $invoiceId): string
|
||||
{
|
||||
@@ -42,7 +40,7 @@ class InvoicePdfService
|
||||
private function prepareInvoiceData(int $invoiceId): array
|
||||
{
|
||||
$invoice = Invoice::query()->find($invoiceId);
|
||||
if (!$invoice) {
|
||||
if (! $invoice) {
|
||||
return ['error' => 'No invoice was generated. Please contact the school administration.'];
|
||||
}
|
||||
|
||||
@@ -69,7 +67,7 @@ class InvoicePdfService
|
||||
$payments = $paymentsQuery->get()->map(fn ($r) => $r->toArray())->all();
|
||||
|
||||
$parent = User::query()->find($parentId);
|
||||
if (!$parent) {
|
||||
if (! $parent) {
|
||||
return ['error' => 'Parent associated with the invoice was not found.'];
|
||||
}
|
||||
|
||||
@@ -89,7 +87,7 @@ class InvoicePdfService
|
||||
|
||||
foreach ($enrollments as $enrollment) {
|
||||
$student = Student::query()->find($enrollment['student_id']);
|
||||
if (!$student) {
|
||||
if (! $student) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -112,11 +110,13 @@ class InvoicePdfService
|
||||
|
||||
$registeredKids = array_values(array_filter($registeredKids, function ($student) use ($schoolYear) {
|
||||
$sid = (int) ($student['student_id'] ?? 0);
|
||||
|
||||
return $sid > 0 && StudentClass::hasNonEventAssignment($sid, $schoolYear);
|
||||
}));
|
||||
|
||||
$withdrawnKids = array_values(array_filter($withdrawnKids, function ($student) use ($schoolYear) {
|
||||
$sid = (int) ($student['student_id'] ?? 0);
|
||||
|
||||
return $sid > 0 && StudentClass::hasNonEventAssignment($sid, $schoolYear);
|
||||
}));
|
||||
|
||||
@@ -148,8 +148,10 @@ class InvoicePdfService
|
||||
if ($isRegular) {
|
||||
$fee = $regularCount === 0 ? $firstFee : $secondFee;
|
||||
$regularCount++;
|
||||
|
||||
return $fee;
|
||||
}
|
||||
|
||||
return $youthFee;
|
||||
};
|
||||
|
||||
@@ -160,7 +162,7 @@ class InvoicePdfService
|
||||
$studentCharges[$student['student_id']] = ['unit_fee' => $unitFee, 'refund' => 0];
|
||||
}
|
||||
|
||||
if (!$refundAllowed) {
|
||||
if (! $refundAllowed) {
|
||||
foreach ($withdrawnKids as $student) {
|
||||
$gradeName = (string) ($student['grade'] ?? '');
|
||||
$gradeLevel = $this->grades->gradeLevelInt($gradeName);
|
||||
@@ -173,7 +175,7 @@ class InvoicePdfService
|
||||
|
||||
$studentIds = array_values(array_unique(array_map(static fn ($r) => (int) ($r['student_id'] ?? 0), array_merge($registeredKids, $withdrawnKids))));
|
||||
$schoolIdMap = [];
|
||||
if (!empty($studentIds)) {
|
||||
if (! empty($studentIds)) {
|
||||
$rows = Student::query()->whereIn('id', $studentIds)->get(['id', 'school_id'])->all();
|
||||
foreach ($rows as $row) {
|
||||
$schoolIdMap[(int) $row->id] = $row->school_id ?? 'N/A';
|
||||
@@ -222,9 +224,9 @@ class InvoicePdfService
|
||||
$signed = abs($signed);
|
||||
}
|
||||
|
||||
$lineDate = !empty($ac['created_at'])
|
||||
$lineDate = ! empty($ac['created_at'])
|
||||
? date('Y-m-d', strtotime($ac['created_at']))
|
||||
: (!empty($invoice->created_at) ? local_date($invoice->created_at, 'Y-m-d') : local_date(utc_now(), 'Y-m-d'));
|
||||
: (! empty($invoice->created_at) ? local_date($invoice->created_at, 'Y-m-d') : local_date(utc_now(), 'Y-m-d'));
|
||||
|
||||
$desc = $ac['description'] ?? '';
|
||||
if ($desc === '') {
|
||||
@@ -270,7 +272,7 @@ class InvoicePdfService
|
||||
$additionalChargesTotal = (float) ($data['additionalChargesTotal'] ?? 0);
|
||||
$refundsPaidTotal = (float) ($data['refundsPaidTotal'] ?? 0);
|
||||
|
||||
$pdf = new \FPDF();
|
||||
$pdf = new \FPDF;
|
||||
$pdf->AddPage();
|
||||
$pdf->SetFont('Arial', 'B', 16);
|
||||
$pdf->Cell(0, 10, 'Invoice', 0, 1, 'C');
|
||||
@@ -279,7 +281,7 @@ class InvoicePdfService
|
||||
$pdf->SetFont('Arial', 'B', 12);
|
||||
$pdf->Cell(40, 6, 'Parent Name:', 0, 0, 'L');
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->Cell(0, 6, ($parent['firstname'] ?? '') . ' ' . ($parent['lastname'] ?? ''), 0, 1, 'L');
|
||||
$pdf->Cell(0, 6, ($parent['firstname'] ?? '').' '.($parent['lastname'] ?? ''), 0, 1, 'L');
|
||||
|
||||
$pdf->SetFont('Arial', 'B', 12);
|
||||
$pdf->Cell(40, 6, 'Invoice Number:', 0, 0, 'L');
|
||||
@@ -306,7 +308,7 @@ class InvoicePdfService
|
||||
|
||||
$tz = new \DateTimeZone($this->config->getTimezone());
|
||||
$toLocal = function (?string $raw) use ($tz): \DateTimeImmutable {
|
||||
if (!$raw) {
|
||||
if (! $raw) {
|
||||
return new \DateTimeImmutable('now', $tz);
|
||||
}
|
||||
try {
|
||||
@@ -319,24 +321,24 @@ class InvoicePdfService
|
||||
foreach ($registeredKids as $student) {
|
||||
$id = $student['student_id'];
|
||||
$unit = (float) ($studentCharges[$id]['unit_fee'] ?? 0.0);
|
||||
$name = $student['student_firstname'] . ' ' . $student['student_lastname'];
|
||||
$name = $student['student_firstname'].' '.$student['student_lastname'];
|
||||
$gradeName = ClassSection::getClassSectionNameByClassId($student['grade']) ?? $student['grade'];
|
||||
$push($toLocal($invoice['created_at'] ?? null), 'Registration of "' . $name . '" in ' . $gradeName, $unit, 'registration');
|
||||
$push($toLocal($invoice['created_at'] ?? null), 'Registration of "'.$name.'" in '.$gradeName, $unit, 'registration');
|
||||
}
|
||||
|
||||
foreach ($events as $event) {
|
||||
$studentName = 'N/A';
|
||||
if (!empty($event['student_id'])) {
|
||||
if (! empty($event['student_id'])) {
|
||||
foreach ($students as $st) {
|
||||
if (($st['student_id'] ?? null) == $event['student_id']) {
|
||||
$studentName = $st['student_firstname'] . ' ' . $st['student_lastname'];
|
||||
$studentName = $st['student_firstname'].' '.$st['student_lastname'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$amount = (float) ($event['charged'] ?? 0.0);
|
||||
$eventName = $event['event_name'] ?? 'Event';
|
||||
$push($toLocal($event['created_at'] ?? null), 'Event ' . $eventName . ' for "' . $studentName . '"', $amount, 'event');
|
||||
$push($toLocal($event['created_at'] ?? null), 'Event '.$eventName.' for "'.$studentName.'"', $amount, 'event');
|
||||
}
|
||||
|
||||
foreach ($additionalChargeLines as $line) {
|
||||
@@ -347,7 +349,7 @@ class InvoicePdfService
|
||||
foreach ($payments as $payment) {
|
||||
$amount = (float) ($payment['paid_amount'] ?? 0.0);
|
||||
$totalPaid += $amount;
|
||||
$push($toLocal($payment['payment_date'] ?? null), 'Payment (' . ($payment['payment_method'] ?? 'Payment') . ')', -$amount, 'payment');
|
||||
$push($toLocal($payment['payment_date'] ?? null), 'Payment ('.($payment['payment_method'] ?? 'Payment').')', -$amount, 'payment');
|
||||
}
|
||||
|
||||
$totalDiscount = 0.0;
|
||||
@@ -377,6 +379,7 @@ class InvoicePdfService
|
||||
return $pa <=> $pb;
|
||||
}
|
||||
$cmp = $a['dt'] <=> $b['dt'];
|
||||
|
||||
return $cmp !== 0 ? $cmp : ($a['seq'] <=> $b['seq']);
|
||||
});
|
||||
|
||||
@@ -384,7 +387,7 @@ class InvoicePdfService
|
||||
foreach ($transactions as $t) {
|
||||
$pdf->Cell(30, 7, $t['dt']->format('m-d-Y'), 1);
|
||||
$pdf->Cell(130, 7, $t['description'], 1);
|
||||
$pdf->Cell(30, 7, ($t['amount'] < 0 ? '-$' : '$') . number_format(abs($t['amount']), 2), 1, 1, 'R');
|
||||
$pdf->Cell(30, 7, ($t['amount'] < 0 ? '-$' : '$').number_format(abs($t['amount']), 2), 1, 1, 'R');
|
||||
}
|
||||
|
||||
$tuitionSubtotal = 0.0;
|
||||
@@ -406,38 +409,38 @@ class InvoicePdfService
|
||||
$pdf->SetFont('Arial', 'B', 12);
|
||||
$pdf->Cell(160, 7, 'Total Charges:', 0, 0, 'R');
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->Cell(30, 7, '$' . number_format($totalAmount, 2), 0, 1, 'R');
|
||||
$pdf->Cell(30, 7, '$'.number_format($totalAmount, 2), 0, 1, 'R');
|
||||
|
||||
$pdf->SetFont('Arial', 'B', 12);
|
||||
$pdf->Cell(160, 7, 'Total Paid:', 0, 0, 'R');
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->Cell(30, 7, '$' . number_format($totalPaid, 2), 0, 1, 'R');
|
||||
$pdf->Cell(30, 7, '$'.number_format($totalPaid, 2), 0, 1, 'R');
|
||||
|
||||
if ($totalDiscount > 0) {
|
||||
$pdf->SetFont('Arial', 'B', 12);
|
||||
$pdf->Cell(160, 7, 'Total Discount:', 0, 0, 'R');
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->Cell(30, 7, '$' . number_format($totalDiscount, 2), 0, 1, 'R');
|
||||
$pdf->Cell(30, 7, '$'.number_format($totalDiscount, 2), 0, 1, 'R');
|
||||
}
|
||||
|
||||
if ($refundsPaidTotal > 0) {
|
||||
$pdf->SetFont('Arial', 'B', 12);
|
||||
$pdf->Cell(160, 7, 'Refunds Paid:', 0, 0, 'R');
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->Cell(30, 7, '$' . number_format($refundsPaidTotal, 2), 0, 1, 'R');
|
||||
$pdf->Cell(30, 7, '$'.number_format($refundsPaidTotal, 2), 0, 1, 'R');
|
||||
}
|
||||
|
||||
$pdf->SetFont('Arial', 'B', 12);
|
||||
$pdf->Cell(160, 7, 'Balance Due:', 0, 0, 'R');
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->Cell(30, 7, '$' . number_format($balance, 2), 0, 1, 'R');
|
||||
$pdf->Cell(30, 7, '$'.number_format($balance, 2), 0, 1, 'R');
|
||||
|
||||
return $pdf->Output('S');
|
||||
}
|
||||
|
||||
private function renderErrorPdf(string $message): string
|
||||
{
|
||||
$pdf = new \FPDF();
|
||||
$pdf = new \FPDF;
|
||||
$pdf->AddPage();
|
||||
$pdf->SetFont('Arial', 'B', 16);
|
||||
$pdf->Cell(0, 10, 'Error', 0, 1, 'C');
|
||||
|
||||
Reference in New Issue
Block a user