From 745db13b3b67e56c9644209785bca50315dfb199 Mon Sep 17 00:00:00 2001 From: Nur Izzati Date: Wed, 9 Jul 2025 13:46:45 +0800 Subject: [PATCH] rekod gadaitebus hari sama --- .../Controllers/Reports/GadaianController.php | 60 +++++++++++++++++++ routes/report.php | 3 + 2 files changed, 63 insertions(+) diff --git a/app/Http/Controllers/Reports/GadaianController.php b/app/Http/Controllers/Reports/GadaianController.php index 149de0d..048c7b9 100644 --- a/app/Http/Controllers/Reports/GadaianController.php +++ b/app/Http/Controllers/Reports/GadaianController.php @@ -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); +} + } diff --git a/routes/report.php b/routes/report.php index 296afe7..c122cec 100644 --- a/routes/report.php +++ b/routes/report.php @@ -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']); + }); });