fix financial issues
This commit is contained in:
@@ -701,8 +701,7 @@ public function financialReport()
|
||||
]
|
||||
];
|
||||
|
||||
$url = 'https://quickchart.io/chart?c=' . urlencode(json_encode($chartData));
|
||||
file_put_contents(WRITEPATH . 'reports/bar_chart.png', file_get_contents($url));
|
||||
$this->writeChartImage('bar_chart.png', $chartData);
|
||||
}
|
||||
|
||||
private function generatePieChart(array $data)
|
||||
@@ -721,8 +720,28 @@ public function financialReport()
|
||||
]
|
||||
];
|
||||
|
||||
$this->writeChartImage('pie_chart.png', $chartData);
|
||||
}
|
||||
|
||||
private function writeChartImage(string $filename, array $chartData): void
|
||||
{
|
||||
$reportDir = WRITEPATH . 'reports';
|
||||
if (!is_dir($reportDir) && !mkdir($reportDir, 0775, true) && !is_dir($reportDir)) {
|
||||
log_message('error', 'Unable to create financial report chart directory: {dir}', ['dir' => $reportDir]);
|
||||
return;
|
||||
}
|
||||
|
||||
$url = 'https://quickchart.io/chart?c=' . urlencode(json_encode($chartData));
|
||||
file_put_contents(WRITEPATH . 'reports/pie_chart.png', file_get_contents($url));
|
||||
$image = @file_get_contents($url);
|
||||
if ($image === false || $image === '') {
|
||||
log_message('warning', 'Unable to download financial report chart from QuickChart.');
|
||||
return;
|
||||
}
|
||||
|
||||
$path = $reportDir . DIRECTORY_SEPARATOR . $filename;
|
||||
if (@file_put_contents($path, $image) === false) {
|
||||
log_message('error', 'Unable to write financial report chart image: {path}', ['path' => $path]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getFinancialSummary(?string $dateFrom = null, ?string $dateTo = null, ?string $schoolYear = null): array
|
||||
|
||||
Reference in New Issue
Block a user