e0dfc3ec82
API CI/CD / Validate (composer + pint) (push) Successful in 3m15s
API CI/CD / Test (PHPUnit) (push) Failing after 5m4s
API CI/CD / Build frontend assets (push) Successful in 1m3s
API CI/CD / Security audit (push) Failing after 49s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
72 lines
2.4 KiB
PHP
72 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Finance;
|
|
|
|
class FinancialPdfReportService
|
|
{
|
|
public function __construct(private FinancialChartService $charts) {}
|
|
|
|
public function buildPdf(array $summary): string
|
|
{
|
|
$this->loadFpdf();
|
|
|
|
$pdf = new \FPDF;
|
|
$pdf->AddPage();
|
|
$pdf->SetFont('Arial', 'B', 16);
|
|
$pdf->Cell(0, 10, 'Financial Report for School Year: '.($summary['schoolYear'] ?? ''), 0, 1, 'C');
|
|
|
|
$pdf->Ln(10);
|
|
$pdf->SetFont('Arial', 'B', 12);
|
|
$pdf->Cell(130, 10, 'Description', 1);
|
|
$pdf->Cell(60, 10, 'Amount (USD)', 1);
|
|
$pdf->Ln();
|
|
|
|
$rows = [
|
|
'Total Charges' => $summary['totalCharges'] ?? 0,
|
|
'Total Extra Charges' => $summary['totalExtraCharges'] ?? 0,
|
|
'Total Discounts' => $summary['totalDiscounts'] ?? 0,
|
|
'Total Refunds' => $summary['totalRefunds'] ?? 0,
|
|
'Total Expenses' => $summary['totalExpenses'] ?? 0,
|
|
'Total Reimbursements' => $summary['totalReimbursements'] ?? 0,
|
|
'Donation to School (Masjid/Donation reimbursements)' => $summary['donationToSchool'] ?? 0,
|
|
'Net Amount (Earned Income)' => $summary['netAmount'] ?? 0,
|
|
'Amount Collected (Paid)' => $summary['amountCollected'] ?? 0,
|
|
'Amount Unpaid (Outstanding)' => $summary['totalUnpaid'] ?? 0,
|
|
];
|
|
|
|
$pdf->SetFont('Arial', '', 11);
|
|
foreach ($rows as $label => $amount) {
|
|
$pdf->Cell(130, 10, $label, 1);
|
|
$pdf->Cell(60, 10, '$'.number_format((float) $amount, 2), 1);
|
|
$pdf->Ln();
|
|
}
|
|
|
|
$barChart = $this->charts->generateBarChart($summary);
|
|
if (! empty($barChart) && file_exists($barChart)) {
|
|
$pdf->Ln(10);
|
|
$pdf->SetFont('Arial', 'B', 12);
|
|
$pdf->Cell(0, 10, 'Summary Graph', 0, 1);
|
|
$pdf->Image($barChart, null, null, 180);
|
|
}
|
|
|
|
$pieChart = $this->charts->generatePieChart($summary);
|
|
if (! empty($pieChart) && file_exists($pieChart)) {
|
|
$pdf->Ln(10);
|
|
$pdf->SetFont('Arial', 'B', 12);
|
|
$pdf->Cell(0, 10, 'Expense Breakdown', 0, 1);
|
|
$pdf->Image($pieChart, null, null, 120);
|
|
}
|
|
|
|
return $pdf->Output('S');
|
|
}
|
|
|
|
private function loadFpdf(): void
|
|
{
|
|
if (class_exists('FPDF', false)) {
|
|
return;
|
|
}
|
|
|
|
require_once base_path('app/ThirdParty/fpdf/fpdf.php');
|
|
}
|
|
}
|