From 4d9fe3b9f4a1b77e1ac9cfc7522fa76b84424152 Mon Sep 17 00:00:00 2001 From: hafifierahman Date: Wed, 9 Oct 2024 08:04:21 +0800 Subject: [PATCH] fix skit2 --- .../Reports/Account/GeneralLedger.php | 94 ++++++++++++++++ app/Services/Reports/AccountService.php | 103 +++++++++++++++++- app/Services/Reports/OnePercentService.php | 2 +- 3 files changed, 195 insertions(+), 4 deletions(-) diff --git a/app/Services/Reports/Account/GeneralLedger.php b/app/Services/Reports/Account/GeneralLedger.php index abe0e49..0254e26 100644 --- a/app/Services/Reports/Account/GeneralLedger.php +++ b/app/Services/Reports/Account/GeneralLedger.php @@ -628,4 +628,98 @@ class GeneralLedger return $wtd; } + public function getTotalKeuntungan() : Float{ + + /* Keuntungan Semasa */ + $keuntungan_semasa = $this->CurrentProfit($this->mula,$this->hingga,$this->kodcaw); + $totalkeuntungan=$keuntungan_semasa['onepercent']; + + return $totalkeuntungan; + } + + public function getTotalUjrah() : Float{ + + /* Keuntungan Semasa */ + $keuntungan_semasa = $this->CurrentProfit($this->mula,$this->hingga,$this->kodcaw); + $totalujrah = $keuntungan_semasa['ujrah']; + + + return $totalujrah; + } + + public function CurrentProfit($start,$end,$kodcaw){ + + $start = new Carbon($start); + $year = $start->format('Y'); + + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); + + $collection_trans = TransaksiKeuntungan::on('mysql7') + ->leftJoin('transaction as trans', function($join) + { + $join->on('transaksi_keuntungan.norujukan', '=', 'trans.norujukan'); + $join->on('transaksi_keuntungan.tarikh_bayaran', '=', 'trans.created_at'); + }) + ->where('trans.kodcaw','=',$kodcaw) + ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'<=', $end) + ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'>=', $start) + ->whereYear('transaksi_keuntungan.tarikh_bayaran','=',$year) + ->get(); + + $array_norujukan = $collection_trans->pluck('norujukan')->toArray(); + + $collection_gadai = Gadai::on($cawangan['mysql'])->whereIn('norujukan',$array_norujukan)->get(); + + /* filtering untuk gadai yang ditebus pada bukan bulan yang sama */ + $keuntungan_semasa_collection = $collection_trans->filter(function ($trans) use ($collection_gadai) { + + foreach ($collection_gadai as $gadai) { + if($gadai->norujukan === $trans->norujukan){ + $t_gadai = Carbon::parse($gadai->t_gadai); + $t_bayaran = Carbon::parse($trans->tarikh_bayaran); + + if ($t_gadai->month === $t_bayaran->month) { + return false; + }else{ + return true; + } + } + } + return false; + }); + + + $ujrah = $this->filterCollection($keuntungan_semasa_collection,'A','ujrah'); + $onepercent = $this->filterCollection($keuntungan_semasa_collection,'A','onepercent'); + $ujrah_rebet = $this->filterCollection($keuntungan_semasa_collection,'T','ujrah_rebet'); + $onepercent_rebet = $this->filterCollection($keuntungan_semasa_collection,'T','onepercent_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]; + } + + private function filterCollection($collection,$type,$sumtype) : Float{ + + $array_type = ['T','S','P','AT']; + return $collection->filter(function ($item) use($type,$array_type) { + if($type == 'T') + return in_array($item->trans_type, $array_type); + + return $item->trans_type === $type; + })->sum($sumtype); + } + + + } \ No newline at end of file diff --git a/app/Services/Reports/AccountService.php b/app/Services/Reports/AccountService.php index 28e368a..ffc50ca 100644 --- a/app/Services/Reports/AccountService.php +++ b/app/Services/Reports/AccountService.php @@ -27,11 +27,108 @@ class AccountService{ $real_profit = $gledger->getKeuntunganSebenar(); $current_profit = $gledger->SemakanKeuntunganLejer(); $unclaimed_money =$gledger->getwtdLejer(); + $akrual_onepercent = $gledger->getTotalKeuntungan(); + $akrual_ujrah = $gledger->getTotalUjrah(); - $debit = 0; - $credit = 0; + $debit = /* $loan_given['Gadai'] + */ $loan_tawarruq['Gadai'] + $advance_payment['keluar'] + + $submission['serahan'] + $cash['bds'] + $cash['perubatan'] + $cash['keraian'] + + $remain_auction['rugi'] + $remain_auction['bakilelong']; + $credit = /* $loan_given['Tebus'] + */ $loan_tawarruq['Tebus'] + $advance_payment['masuk'] + + $remain_auction['rugilelong'] + $remain_auction['baki'] + $real_profit + + $current_profit['keuntungan_semasa'] + $submission['pendahuluan'] + $remain_auction['caslelong'] + + $current_profit['keuntungan_sebenar'] + $unclaimed_money + $akrual_onepercent + $akrual_ujrah; - dd($loan_given,$loan_tawarruq,$advance_payment,$submission,$cash,$remain_auction,$real_profit,$current_profit,$unclaimed_money); + $cash_credit = $debit; + $cash_debit = $credit; + + + $total_cash = $cash_debit - $cash_credit; + $total_loan_tawarruq = $loan_tawarruq['Gadai'] - $loan_tawarruq['Tebus']; + $total_advance_payment = $advance_payment['keluar'] - $advance_payment['masuk']; + $total_remain_auction_loss = $remain_auction['rugi'] - $remain_auction['rugilelong']; + $total_remain_auction = $remain_auction['bakilelong'] - $remain_auction['baki']; + + dd($BSheetPreviousMonth); + + /* Previous Balance Sheets With Total General Ledger */ + + /* Harta Semasa positive */ + $temp_tunaiditangan = $BSheetPreviousMonth['tunaiditangan'] + $total_cash; + $temp_pembiayaantawarruq = $BSheetPreviousMonth['pembiayaantawarruq'] + $total_loan_tawarruq; + $temp_bayaranpendahuluan = $BSheetPreviousMonth['bayaranpendahuluan'] + $total_advance_payment; + $temp_pinjamankoop = $BSheetPreviousMonth['pinjamankoop']; + $temp_emaspalsu = $BSheetPreviousMonth['emaspalsu']; + $temp_penghutangkaki = $BSheetPreviousMonth['penghutangkaki']; + $temp_phapuskira = $BSheetPreviousMonth['phapuskira']; + $temp_belian1stop = $BSheetPreviousMonth['belian1stop']; + $temp_keun_penggadai = $BSheetPreviousMonth['keun_penggadai']; + $temp_serahan = $BSheetPreviousMonth['serahan']; + + + /* Tanggungan Semasa negative */ + $temp_pend_terakru = $BSheetPreviousMonth['pend_terakru']; + $temp_bds = $BSheetPreviousMonth['bds']; + $temp_perubatan = $BSheetPreviousMonth['perubatan']; + $temp_keraian = $BSheetPreviousMonth['keraian']; + $temp_rugilelong = $BSheetPreviousMonth['rugilelong']; + $temp_bakilelong = $BSheetPreviousMonth['bakilelong']; + $temp_wtd = $BSheetPreviousMonth['wtd']; + $temp_untungrugiterkumpul = $BSheetPreviousMonth['untungrugiterkumpul']; + $temp_keun_sebenar = $BSheetPreviousMonth['keun_sebenar']; + $temp_pendahuluan = $BSheetPreviousMonth['pendahuluan']; + $temp_cajlelong = $BSheetPreviousMonth['cajlelong']; + $temp_cajperkhidmatan = $BSheetPreviousMonth['cajperkhidmatan']; + $temp_cajlelongxtra = $BSheetPreviousMonth['cajlelongxtra']; + $temp_upahsimpan = $BSheetPreviousMonth['upahsimpan']; + $temp_bakilelong = $BSheetPreviousMonth['bakilelong']; + $temp_kerugianlelong = $BSheetPreviousMonth['kerugianlelong']; + $temp_jualan1stop = $BSheetPreviousMonth['jualan1stop']; + $temp_hapuskira = $BSheetPreviousMonth['hapuskira']; + $temp_onepercent = $BSheetPreviousMonth['onepercent']; + $temp_ujrah = $BSheetPreviousMonth['ujrah']; + + + + + + /* Current Balance Sheets */ + + $temp_tunaiditangan = $BSheetPreviousMonth['tunaiditangan']; + $temp_pembiayaantawarruq = $BSheetPreviousMonth['pembiayaantawarruq']; + $temp_bayaranpendahuluan = $BSheetPreviousMonth['bayaranpendahuluan']; + $temp_pinjamankoop = $BSheetPreviousMonth['pinjamankoop']; + $temp_emaspalsu = $BSheetPreviousMonth['emaspalsu']; + $temp_penghutangkaki = $BSheetPreviousMonth['penghutangkaki']; + $temp_phapuskira = $BSheetPreviousMonth['phapuskira']; + $temp_belian1stop = $BSheetPreviousMonth['belian1stop']; + $temp_keun_penggadai = $BSheetPreviousMonth['keun_penggadai']; + $temp_serahan = $BSheetPreviousMonth['serahan']; + $temp_pend_terakru = $BSheetPreviousMonth['pend_terakru']; + $temp_bds = $BSheetPreviousMonth['bds']; + $temp_perubatan = $BSheetPreviousMonth['perubatan']; + $temp_keraian = $BSheetPreviousMonth['keraian']; + $temp_rugilelong = $BSheetPreviousMonth['rugilelong']; + $temp_bakilelong = $BSheetPreviousMonth['bakilelong']; + $temp_wtd = $BSheetPreviousMonth['wtd']; + $temp_untungrugiterkumpul = $BSheetPreviousMonth['untungrugiterkumpul']; + $temp_keun_sebenar = $BSheetPreviousMonth['keun_sebenar']; + $temp_pendahuluan = $BSheetPreviousMonth['pendahuluan']; + $temp_cajlelong = $BSheetPreviousMonth['cajlelong']; + $temp_cajperkhidmatan = $BSheetPreviousMonth['cajperkhidmatan']; + $temp_cajlelongxtra = $BSheetPreviousMonth['cajlelongxtra']; + $temp_upahsimpan = $BSheetPreviousMonth['upahsimpan']; + $temp_bakilelong = $BSheetPreviousMonth['bakilelong']; + $temp_kerugianlelong = $BSheetPreviousMonth['kerugianlelong']; + $temp_jualan1stop = $BSheetPreviousMonth['jualan1stop']; + $temp_hapuskira = $BSheetPreviousMonth['hapuskira']; + $temp_onepercent = $BSheetPreviousMonth['onepercent']; + $temp_ujrah = $BSheetPreviousMonth['ujrah']; + + + + dd($total_cash,$total_loan_tawarruq,$total_advance_payment,$total_remain_auction,$total_remain_auction_loss); + + dd($debit,$credit); } } \ No newline at end of file diff --git a/app/Services/Reports/OnePercentService.php b/app/Services/Reports/OnePercentService.php index 1d718cf..30dddda 100644 --- a/app/Services/Reports/OnePercentService.php +++ b/app/Services/Reports/OnePercentService.php @@ -398,7 +398,7 @@ class OnePercentService if ($t_gadai->month === $t_bayaran->month) { return false; - }{ + }else{ return true; } }