From 4b426438d80fc12fe5491ff4878d413551c14e58 Mon Sep 17 00:00:00 2001 From: Nur Izzati Zulkifli Date: Tue, 19 Dec 2023 22:40:21 +0800 Subject: [PATCH] update button kemaskini data simulasi --- .../Controllers/SimulasiUjrahController.php | 58 ++++++++++++------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/SimulasiUjrahController.php b/app/Http/Controllers/SimulasiUjrahController.php index a52ab52b..6e7bdbf9 100644 --- a/app/Http/Controllers/SimulasiUjrahController.php +++ b/app/Http/Controllers/SimulasiUjrahController.php @@ -479,29 +479,36 @@ class SimulasiUjrahController extends Controller $total_untung_asal = TransaksiKeuntungan::on('main')->where('norujukan','=',$data['norujukan'])->sum('bayaran_keuntungan'); $beza_keuntungan = $total_untung_asal - $total_untung_rebet; - if($data['tempoh'] == $data['tempohbayar']){ + if($data['tempohbayar'] == 12){ $keuntungan = 0.00; - }else{ + $rounded_ujrah = 0.00; + $rounded_onepercent = 0.00; + } + elseif($data['tempoh'] == $data['tempohbayar']){ + $keuntungan = 0.00; + $rounded_ujrah = 0.00; + $rounded_onepercent = 0.00; + } + else{ //kiraan keuntungan ujrah $jeniskeuntungan = 'onepercent'; - $keuntungan = Http::get(config('app.api_url'). 'upahrebettawarruq/'.$data['kodcaw'].'/'.$data['norujukan'].'/'.$jeniskeuntungan)->json(); + $keuntungan1 = Http::get(config('app.api_url'). 'upahrebettawarruq/'.$data['kodcaw'].'/'.$data['norujukan'].'/'.$jeniskeuntungan)->json(); $ujrahonepercentrebet = Http::get(config('app.api_url'). 'kiraupahUjrahOnePercentRebate/'.$data['kodcaw'].'/'.$data['norujukan'])->json(); - $rounded_keuntungan = round(($keuntungan*100)/5,0)*5/100; + $keuntungan = round(($keuntungan1*100)/5,0)*5/100; $rounded_ujrah = round(($ujrahonepercentrebet['ujrah']*100)/5,0)*5/100; $rounded_onepercent = round(($ujrahonepercentrebet['onepercent']*100)/5,0)*5/100; - } - // dd($keuntungan); - //update dalam simulasibid - $updatetempoh = SimulasiBid::where('norujukan', $data['norujukan']) - ->where('simulasi_id', $simulasi_id) - ->first(); - $updatetempoh->jbg = $data['tempoh']; - $updatetempoh->pinjaman = $data['bakipjm']; - // $updatetempoh->bakiupah = bcdiv($keuntungan,1,1); - $updatetempoh->bakiupah = $rounded_keuntungan; - $updatetempoh->ujrah = $rounded_ujrah; - $updatetempoh->onepercent = $rounded_onepercent; - $updatetempoh->update(); + } + //update dalam simulasibid + $updatetempoh = SimulasiBid::where('norujukan', $data['norujukan']) + ->where('simulasi_id', $simulasi_id) + ->first(); + $updatetempoh->jbg = $data['tempoh']; + $updatetempoh->pinjaman = $data['bakipjm']; + // $updatetempoh->bakiupah = bcdiv($keuntungan,1,1); + $updatetempoh->bakiupah = $keuntungan; + $updatetempoh->ujrah = $rounded_ujrah; + $updatetempoh->onepercent = $rounded_onepercent; + $updatetempoh->update(); //insert loguser $loguser = new LogUser; @@ -510,7 +517,7 @@ class SimulasiUjrahController extends Controller $loguser->username = $user->username; $loguser->nama_user = $user->name; $loguser->norujukan = $data['norujukan']; - $loguser->nota = $simulasi_id.' Kemaskini Tempoh/Bakipjm/Keuntungan' ; + $loguser->nota = $simulasi_id.' Kemaskini Tempoh/Bakipjm/Keuntungan '.$rounded_ujrah ; $loguser->save(); } @@ -562,14 +569,21 @@ class SimulasiUjrahController extends Controller $total_untung_asal = TransaksiKeuntungan::on('main')->where('norujukan','=',$data['norujukan'])->sum('bayaran_keuntungan'); $beza_keuntungan = $total_untung_asal - $total_untung_rebet; - if($data['tempoh'] == $data['tempohbayar']){ + if($data['tempohbayar'] == 12){ $keuntungan = 0.00; + $rounded_ujrah = 0.00; + $rounded_onepercent = 0.00; + } + elseif($data['tempoh'] == $data['tempohbayar']){ + $keuntungan = 0.00; + $rounded_ujrah = 0.00; + $rounded_onepercent = 0.00; }else{ //kiraan keuntungan ujrah $jeniskeuntungan = 'onepercent'; - $keuntungan = Http::get(config('app.api_url'). 'upahrebettawarruq/'.$data['kodcaw'].'/'.$data['norujukan'].'/'.$jeniskeuntungan)->json(); + $keuntungan1 = Http::get(config('app.api_url'). 'upahrebettawarruq/'.$data['kodcaw'].'/'.$data['norujukan'].'/'.$jeniskeuntungan)->json(); $ujrahonepercentrebet = Http::get(config('app.api_url'). 'kiraupahUjrahOnePercentRebate/'.$data['kodcaw'].'/'.$data['norujukan'])->json(); - $rounded_keuntungan = round(($keuntungan*100)/5,0)*5/100; + $keuntungan = round(($keuntungan1*100)/5,0)*5/100; $rounded_ujrah = round(($ujrahonepercentrebet['ujrah']*100)/5,0)*5/100; $rounded_onepercent = round(($ujrahonepercentrebet['onepercent']*100)/5,0)*5/100; } @@ -581,7 +595,7 @@ class SimulasiUjrahController extends Controller $updatetempoh->jbg = $data['tempoh']; $updatetempoh->pinjaman = $data['bakipjm']; // $updatetempoh->bakiupah = bcdiv($keuntungan,1,1); - $updatetempoh->bakiupah = $rounded_keuntungan; + $updatetempoh->bakiupah = $keuntungan; $updatetempoh->ujrah = $rounded_ujrah; $updatetempoh->onepercent = $rounded_onepercent; $updatetempoh->update();