From 3be20b0e2239e7c15580d6e9e356b1b3b9326a86 Mon Sep 17 00:00:00 2001 From: hafifierahman Date: Mon, 5 Dec 2022 02:29:51 +0800 Subject: [PATCH] fix issues akrual daily and addition of monthly --- app/Http/Controllers/LaporanController.php | 80 +++++++++++++++++++++- app/Permohonan.php | 1 + routes/web.php | 3 +- 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/LaporanController.php b/app/Http/Controllers/LaporanController.php index dd2c21b..67af22e 100644 --- a/app/Http/Controllers/LaporanController.php +++ b/app/Http/Controllers/LaporanController.php @@ -1338,7 +1338,7 @@ class LaporanController extends Controller 'kodcaw' => $caw['kodcaw'], ]); - $keuntungan = $this->SemakanKeuntunganLejer($request->kodcaw,$request_generate); + $keuntungan = $this->SemakanKeuntunganLejer($caw['kodcaw'],$request_generate); $data_keuntungan = $keuntungan->getContent(); $data = json_decode($data_keuntungan, true); @@ -1348,12 +1348,12 @@ class LaporanController extends Controller $available_akru = AkruNet::on($caw['mysql']) ->where('bulan',(int)$month_generate) - ->first(); + ->first()->toArray(); try{ if($available_akru){ if($available_akru['jumlah'] !== $accrual_net){ - AkruNet::on($caw['mysql'])->where('bulan','=',$current->month) + AkruNet::on($caw['mysql'])->where('bulan','=',$month_generate) ->update(['jumlah' => $accrual_net]); } }else{ @@ -1366,6 +1366,80 @@ class LaporanController extends Controller } DB::connection($caw['mysql'])->commit(); }catch (\Throwable $e){ + DB::connection($caw['mysql'])->rollBack(); + return response($e); + } + } + + return response('succesfully generated!'); + } + + public function GenerateMonthlyAkrual(Request $request){ + + $firstmonth_behind = Carbon::now()->startOfMonth()->subMonthsNoOverflow(1); + $secondmonth_behind = Carbon::now()->startOfMonth()->subMonthsNoOverflow(2); + + $firstmonth_behind_end = Carbon::now()->endOfMonth()->subMonthsNoOverflow(1); + + $firstmonth_behind_month = $firstmonth_behind->format('m'); + $secondmonth_behind_month = $secondmonth_behind->format('m'); + $firstmonth_behind_year = $firstmonth_behind->format('Y'); + $secondmonth_behind_year = $secondmonth_behind->format('Y'); + + $firstmonth_behind_extension = $firstmonth_behind->toDateString(); + $firstmonth_behind_extension_end = $firstmonth_behind_end->toDateString(); + + $cawangan = Cawangan::on('mysql7')->where('zone',$request->zone)->get(); + + $tebuscontroller = new TebusController(); + + foreach($cawangan as $index=>$caw){ + DB::connection($caw['mysql'])->beginTransaction(); + + if($secondmonth_behind_year == 2022 && (int)$secondmonth_behind_month > 4){ + $audit_backdate = $tebuscontroller->StokAuditGenerateTerakru($secondmonth_behind_month,$caw,$secondmonth_behind_year); + } + + $result_audit_stated = $tebuscontroller->StokAuditGenerateTerakru($firstmonth_behind_month,$caw,$firstmonth_behind_year); + + $totaltunggakan_now = $result_audit_stated->sum('upahblmbyar'); + $totaltunggakan_past = $audit_backdate->sum('upahblmbyar'); + + $request_generate = new \Illuminate\Http\Request([ + 'mula' => $firstmonth_behind_extension, + 'hingga' => $firstmonth_behind_extension_end, + 'kodcaw' => $caw['kodcaw'], + ]); + + $keuntungan = $this->SemakanKeuntunganLejer($caw['kodcaw'],$request_generate); + + $data_keuntungan = $keuntungan->getContent(); + $data = json_decode($data_keuntungan, true); + + $calculation = $totaltunggakan_past - $data['keuntungan_semasa']; + $accrual_net = $totaltunggakan_now - $calculation; + + $available_akru = AkruNet::on($caw['mysql']) + ->where('bulan',(int)$firstmonth_behind_month) + ->first()->toArray(); + + try{ + if($available_akru){ + if($available_akru['jumlah'] !== $accrual_net){ + AkruNet::on($caw['mysql'])->where('bulan','=',(int)$firstmonth_behind_month) + ->update(['jumlah' => $accrual_net]); + } + }else{ + $akrunet = new AkruNet(); + $akrunet->setConnection($caw['mysql']); + $akrunet->tahun = $firstmonth_behind_year; + $akrunet->bulan = $firstmonth_behind_month; + $akrunet->jumlah = $accrual_net; + $akrunet->save(); + } + DB::connection($caw['mysql'])->commit(); + }catch (\Throwable $e){ + DB::connection($caw['mysql'])->rollBack(); return response($e); } } diff --git a/app/Permohonan.php b/app/Permohonan.php index 8f79d90..06d5d57 100644 --- a/app/Permohonan.php +++ b/app/Permohonan.php @@ -22,6 +22,7 @@ class Permohonan extends Model 'baki_petibesi', 'amaun_mohon', 'nama_pemohon', + 'jawatan_pemohon', 'tarikh_permohonan', 'tarikh_diluluskan', 'jumlah_diluluskan', diff --git a/routes/web.php b/routes/web.php index 8fda306..9b70d0b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -739,7 +739,8 @@ $router->group(['prefix'=>'admin'], function () use ($router){ $router->get('laporanllcaw/gadai',['uses'=>'AdminPageController@getLaporanGadaiAllCaw']); $router->get('laporan/akrubulan',['uses'=>'AdminPageController@getLaporanAkruBulan']); - $router->get('laporan/akrual/generatedaily',['uses'=>'LaporanController@GenerateDailyAkrual']); + $router->get('laporan/akrual/generateDaily',['uses'=>'LaporanController@GenerateDailyAkrual']); + $router->get('laporan/akrual/generateMonthly',['uses'=>'LaporanController@GenerateMonthlyAkrual']); }); $router->group(['prefix'=>'lelong'], function () use ($router){