From ec72c708cda9430d4fa80c8d7da8027f7f0cd43d Mon Sep 17 00:00:00 2001 From: Nisha Muhd Date: Thu, 15 Jan 2026 13:07:11 +0800 Subject: [PATCH] nisha-checking-wtd --- app/Http/Controllers/WTDController.php | 67 ++++++++++++++++++++++++++ routes/web.php | 3 ++ 2 files changed, 70 insertions(+) diff --git a/app/Http/Controllers/WTDController.php b/app/Http/Controllers/WTDController.php index cfd1511..b08bbc6 100644 --- a/app/Http/Controllers/WTDController.php +++ b/app/Http/Controllers/WTDController.php @@ -9,6 +9,8 @@ use App\Customer; use Illuminate\Http\Request; use Carbon\Carbon; use App\Helper; +use App\SerahBaki; +use App\WTD; use Illuminate\Support\Facades\Http; @@ -121,4 +123,69 @@ class WTDController extends Controller return response()->json($responses); } + + public function getDebugWtd(Request $request){ + + $startDate = $request->startDate ?? now()->startOfMonth()->toDateString(); + $endDate = $request->endDate ?? now()->endOfMonth()->toDateString(); + + $active_dbs = Helper::getActiveCawanganDbConnection(); + + $cawangan = Cawangan::select('kodcaw', 'details_caw', 'mysql') + ->whereIn('mysql', $active_dbs) + ->get(); + + $responses = []; + + foreach ($cawangan as $caw) { + + $db = $caw->mysql; + + $serahbaki = SerahBaki::on($db) + ->whereBetween('t_jual', [$startDate, $endDate]) + ->where('aktif', 1) + //->selectRaw("baki as serahb") + ->sum('baki');; + //->get(); + + $tuntutbaki = TuntutBaki::on($db) + ->whereBetween('tarikh', [$startDate, $endDate]) + ->where('teller', 'DM') + //->selectRaw("jumlah as tuntutb") + ->sum('jumlah'); + //->get(); + + $twtd = WTD::on($db) + ->whereBetween('tarikh', [$startDate, $endDate]) + //->selectRaw("wtd as twtd") + ->sum('wtd'); + //->get(); + + $wtd_det = []; + + $wtd_det[] = [ + "serahb" => $serahbaki, + "tuntutb" => $tuntutbaki, + "twtd" => $twtd, + ]; + + $details = collect($wtd_det) + ->values() + ->all(); + //dd($details); + + $responses[] = [ + 'kodcaw' => $caw->kodcaw, + 'details_caw' => $caw->details_caw, + //collect($details)->sum('jumlah'), + // WEB + 'serahb' => collect($details)->sum('serahb'), + 'tuntutb' => collect($details)->sum('tuntutb'), + 'twtd' => collect($details)->sum('twtd'), + //'debugwtd' => $details, + ]; + } + return response()->json($responses); + + } } diff --git a/routes/web.php b/routes/web.php index c0b35af..2c3c1be 100644 --- a/routes/web.php +++ b/routes/web.php @@ -902,6 +902,9 @@ $router->group(['prefix'=>'admin'], function () use ($router){ //laporan wtd $router->get('wtd/summaryWtd', ['uses' => 'WTDController@getSummaryWtd']); + //debugwtd + $router->get('wtd/debugWtd', ['uses' => 'WTDController@getDebugWtd']); + $router->get('audit/keuntungansebenar',['uses'=>'AdminPageController@KeuntunganSebenarExport']); $router->get('laporan/aging',['uses'=>'AdminPageController@LaporanAging']); $router->get('dashboard/aging',['uses'=>'AdminPageController@DashboardAging']);