feat(dashboard/rekap-so): penambahan dashboard, rekap so

This commit is contained in:
majid
2025-06-20 09:12:50 +07:00
parent 887478c751
commit 3f979aef05
8 changed files with 715 additions and 32 deletions

View File

@@ -0,0 +1,134 @@
<?php
namespace Modules\Lpj\Services;
use Modules\Lpj\Models\Laporan;
class DashboardService
{
public function getDashboardData($start_date, $end_date)
{
$countLpjInternal = $this->getTotalLpjInternal($start_date, $end_date);
$countLpjExternal = $this->getTotalLpjEksternal($start_date, $end_date);
$countResume = $this->getResumeCabang($start_date, $end_date);
return [
'count_lpj_internal' => $countLpjInternal,
'count_lpj_eksternal' => $countLpjExternal,
'count_resume' => $countResume
];
}
public function getTotalLpjInternal($start_date, $end_date)
{
$months = $this->getMonthly();
$regions = $this->getRegion();
$data = [];
foreach ($months as $index => $month) {
$monthNumber = $index + 1;
$data[$month] = [];
foreach ($regions as $region) {
if ($monthNumber > now()->month) {
$data[$month][$region] = [
'total_laporan' => 0,
'total_debiture' => 0,
];
} else {
$totalLaporan = Laporan::whereBetween('created_at', [$start_date, $end_date])
->count();
$data[$month][$region] = [
'total_laporan' => $totalLaporan,
'total_debiture' => 20,
];
}
}
}
return $data;
}
public function getPendapatanAppraisal()
{
}
public function getResumeCabang($start_date, $end_date)
{
$regions = $this->getRegion();
$status = ['batal', 'done'];
$data = [];
foreach ($status as $item) {
$data[$item] = [];
foreach ($regions as $region) {
$totalLaporan = Laporan::where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->count();
$data[$item][$region] = [
'count_report' => $totalLaporan,
];
}
}
return $data;
}
public function getTotalLpjEksternal($start_date, $end_date)
{
$months = $this->getMonthly();
$data = [];
foreach ($months as $index => $month) {
$monthNumber = $index + 1;
if ($monthNumber > now()->month) {
$data[$month] = [
'total_laporan' => 0,
'total_debiture' => 0,
];
} else {
$totalLaporan = Laporan::where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->count();
$data[$month] = [
'total_laporan' => $totalLaporan,
'total_debiture' => 20,
];
}
}
return $data;
}
private function getMonthly()
{
return [
'januari',
'februari',
'maret',
'april',
'mei',
'juni',
'juli',
'agustus',
'september',
'oktober',
'november',
'desember',
];
}
private function getRegion()
{
return [
'jabodetabek',
'non-jabodetabek',
];
}
}