From 004130db85824a0b05d0bc0bb0196dc0e83197f6 Mon Sep 17 00:00:00 2001 From: hafifierahman Date: Mon, 24 Feb 2025 21:28:25 +0800 Subject: [PATCH] fix report about GC not responding without chunk and for currentProfit check for year too not only for month --- .../Reports/Account/GeneralLedger.php | 4 +- app/Services/Reports/ImbangDugaService.php | 71 +++++++++++++++++-- app/Services/Reports/OnePercentService.php | 2 +- 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/app/Services/Reports/Account/GeneralLedger.php b/app/Services/Reports/Account/GeneralLedger.php index f7ebc94..e98e34c 100644 --- a/app/Services/Reports/Account/GeneralLedger.php +++ b/app/Services/Reports/Account/GeneralLedger.php @@ -518,7 +518,7 @@ class GeneralLedger $mulaCarbon = new Carbon($this->mula); $hinggaCarbon = new Carbon($this->hingga); - if($this->isFullMonth($this->mula,$this->hingga) && $mulaCarbon->month < 10){ + if($this->isFullMonth($this->mula,$this->hingga) && $mulaCarbon->month < 10 && $mulaCarbon->year == 2024){ $lastDayOfPreviousMonth = $mulaCarbon->subMonth()->endOfMonth(); $balancesheet_previousmonth = imbangdugabackup::on($cawangan['mysql'])->where('tarikh',$lastDayOfPreviousMonth->toDateString())->first()->toArray(); @@ -714,7 +714,7 @@ class GeneralLedger $t_gadai = Carbon::parse($gadai->t_gadai); $t_bayaran = Carbon::parse($trans->tarikh_bayaran); - if ($t_gadai->month === $t_bayaran->month) { + if ($t_gadai->month === $t_bayaran->month && $t_gadai->year === $t_bayaran->year) { return false; }else{ return true; diff --git a/app/Services/Reports/ImbangDugaService.php b/app/Services/Reports/ImbangDugaService.php index 32eb089..a349f8b 100644 --- a/app/Services/Reports/ImbangDugaService.php +++ b/app/Services/Reports/ImbangDugaService.php @@ -223,7 +223,7 @@ class ImbangDugaService $t_gadai = Carbon::parse($gadai->t_gadai); $t_bayaran = Carbon::parse($trans->tarikh_bayaran); - if ($t_gadai->month === $t_bayaran->month) { + if ($t_gadai->month === $t_bayaran->month && $t_gadai->year === $t_bayaran->year) { return false; }else{ return true; @@ -239,8 +239,17 @@ class ImbangDugaService $ujrah_rebet = $this->filterCollection($keuntungan_semasa_collection, 'T', 'ujrah_rebet'); $onepercent_rebet = $this->filterCollection($keuntungan_semasa_collection, 'T', 'onepercent_rebet'); - $total_onepercent = $onepercent + $onepercent_rebet; - $total_ujrah = $ujrah + $ujrah_rebet; + $upahlelong = Lelong::on($cawangan['mysql']) + ->selectRaw('SUM(ujrah) as ujrah,SUM(onepercent) as onepercent') + ->where([['tagujrah','=',1],['t_jual','>=',$start],['t_jual','<=',$end]]) + ->whereYear('t_jual','=',$year) + ->get()->toArray(); + + $ujrah_lelong = (empty($upahlelong)) ? 0 : $upahlelong[0]['ujrah']; + $onepercent_lelong = (empty($upahlelong)) ? 0 : $upahlelong[0]['onepercent']; + + $total_onepercent = $onepercent + $onepercent_rebet + $onepercent_lelong; + $total_ujrah = $ujrah + $ujrah_rebet + $ujrah_lelong; return ['ujrah' => $total_ujrah, 'onepercent' => $total_onepercent]; } @@ -318,8 +327,17 @@ class ImbangDugaService $month = (clone $tarikh)->month; $lastDayPreviousMonth = $tarikh->subMonthsNoOverflow()->endOfMonth()->toDateString(); + $lastEndYear = $tarikh->subMonthsNoOverflow()->endOfMonth(); + $lastYear = Carbon::now()->subYear()->year; - $get_imbangduga = imbangdugabackup::on($cawangan['mysql'])->where('tarikh',$lastDayPreviousMonth)->first()->toArray(); + //$get_imbangduga = imbangdugabackup::on($cawangan['mysql'])->where('tarikh',$lastDayPreviousMonth)->first()->toArray(); + + /* Added because if the last month is not the same year */ + if($lastEndYear->year != $lastYear){ + $get_imbangduga = imbangdugabackup::on($cawangan['mysql'])->where('tarikh',$lastDayPreviousMonth)->first()->toArray(); + }else{ + $get_imbangduga['keun_sebenar'] = 0; + } $collection_trans = Transaction::on('mysql7') ->leftJoin('transaksi_keuntungan as trans', function ($join) { @@ -608,6 +626,51 @@ class ImbangDugaService $current = Carbon::now(); $current = new Carbon(); + if($this->kodcaw == 'GC'){ + $transaksi_data = []; + TransaksiKeuntungan::on('mysql7') + ->where('tarikh_bayaran', '<=', $daterequest) + ->where('kodcaw', $this->kodcaw) + ->chunk(1000, function ($transactions) use (&$transaksi_data) { + $transaksi_data = array_merge($transaksi_data, $transactions->pluck('norujukan')->toArray()); + }); + + $gadaiData = []; + $chunkedTransaksiData = array_chunk($transaksi_data, 1000); + + foreach ($chunkedTransaksiData as $chunk) { + Gadai::on($cawangan['mysql']) + ->whereIn('norujukan', $chunk) + ->where(function ($query) { + $query->where([ + ['sttebus', '=', ''], + ['hargajualan', '<>', null] + ]) + ->orWhere([ + ['sttebus', '!=', ''], + ['t_update', '>', $this->tarikh], + ['hargajualan', '<>', null] + ]); + }) + ->orderBy('norujukan') + ->chunk(1000, function ($gadaiChunk) use (&$gadaiData) { + $gadaiData = array_merge($gadaiData, $gadaiChunk->pluck('norujukan')->toArray()); + }); + } + + $totalPembiayaan = 0; + $chunkedGadaiData = array_chunk($gadaiData, 1000); + + foreach ($chunkedGadaiData as $chunk) { + $totalPembiayaan += TransaksiKeuntungan::on('mysql7') + ->whereIn('norujukan', $chunk) + ->where('tarikh_bayaran', '<=', $daterequest) + ->sum('bayaran_pembiayaan'); + } + + return $totalPembiayaan; + } + $transaksi_data = TransaksiKeuntungan::on('mysql7') ->where('tarikh_bayaran' ,'<=', $daterequest) ->where('kodcaw',$this->kodcaw) diff --git a/app/Services/Reports/OnePercentService.php b/app/Services/Reports/OnePercentService.php index caf62ce..c747c07 100644 --- a/app/Services/Reports/OnePercentService.php +++ b/app/Services/Reports/OnePercentService.php @@ -398,7 +398,7 @@ class OnePercentService $t_gadai = Carbon::parse($gadai->t_gadai); $t_bayaran = Carbon::parse($trans->tarikh_bayaran); - if ($t_gadai->month === $t_bayaran->month) { + if ($t_gadai->month === $t_bayaran->month && $t_gadai->year === $t_bayaran->year) { return false; }else{ return true;