rekod gadaitebus hari sama

This commit is contained in:
Nur Izzati
2025-07-09 13:46:45 +08:00
parent be4a96f9bc
commit 745db13b3b
2 changed files with 63 additions and 0 deletions
@@ -65,4 +65,64 @@ class GadaianController extends Controller
return json_encode($response);
}
public function getSummaryLaporanGadaiTebus(Request $request)
{
$startDate = $request->startDate;
$endDate = $request->endDate;
// Get active branch DBs from helper
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
// Fetch branch details with mysql info
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
->whereIn('mysql', $active_cawangan_db_connection)
->get();
// Get db connections
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
// Map branch info for response
$active_cawangan_detail = $cawangan_available->map(function ($c) {
return [
'kodcaw' => $c->kodcaw,
'details_caw' => $c->details_caw,
];
})->values()->toArray();
// Loop through each DB
$summary_data = array_map(function ($db_connection) use ($startDate, $endDate) {
$result = DB::connection($db_connection)->table('gadai as g')
->join('tebus as t', function ($join) {
$join->on(DB::raw('DATE(g.t_gadai)'), '=', DB::raw('DATE(t.t_tebus)'))
->on('g.norujukan', '=', 't.norujukan');
})
->whereDate('g.t_gadai', '>=', $startDate)
->whereDate('g.t_gadai', '<=', $endDate)
->whereDate('t.t_tebus', '>=', $startDate)
->whereDate('t.t_tebus', '<=', $endDate)
->selectRaw('
COUNT(DISTINCT g.norujukan) as total_gadai_tebus_samahari,
SUM(g.pinjaman) as jumlah_pinjaman
')
->first(); // ambil satu hasil, bukan collection
return (array) $result ?: [
'total_gadai_tebus_samahari' => 0,
'jumlah_pinjaman' => 0.00
];
}, $active_cawangan_db_connection);
// Gabung cawangan + hasil
$response = array_map(function ($cawangan_detail, $summary_row) {
return array_merge($cawangan_detail, $summary_row ?: [
'total_gadai_tebus_samahari' => 0,
'jumlah_pinjaman' => 0.00
]);
}, $active_cawangan_detail, $summary_data);
return response()->json($response);
}
}
+3
View File
@@ -51,5 +51,8 @@ $router->group(['prefix' => 'api/reports'], function () use ($router) {
$router->get('bakilelongbelumtuntut/{kod_cawangan}', ['uses' => 'LelonganController@getLaporanBakiLelongBelumTuntutCawangan']);
$router->get('bayaran-online', ['uses' => 'BayaranOnlineController']);
$router->get('bayaran-online-detail', ['uses' => 'BayaranOnlineDetailController']);
$router->get('gadaitebus', ['uses' => 'GadaianController@getSummaryLaporanGadaiTebus']);
});
});