From a2e37f5903da67ae78d6791ef38915b9d74d3553 Mon Sep 17 00:00:00 2001 From: nurafrinaalimi16 Date: Sun, 11 May 2025 16:39:11 +0800 Subject: [PATCH] rebate annur --- app/Gadai.php | 4 +- app/Http/Controllers/GadaiController.php | 6 ++- app/Http/Controllers/TebusController.php | 41 +++++++++++++++++++-- app/KadarRebet.php | 31 ++++++++++++++++ app/Support/v2/Calculation.php | 18 ++++++++- app/Support/v2/GadaiV2.php | 13 +++++-- app/Support/v2/Penebusan.php | 47 ++++++++++++++---------- app/Tebus.php | 3 +- app/TransaksiKeuntungan.php | 2 +- routes/web.php | 4 +- 10 files changed, 134 insertions(+), 35 deletions(-) create mode 100644 app/KadarRebet.php diff --git a/app/Gadai.php b/app/Gadai.php index 7f3f595..f139cd5 100644 --- a/app/Gadai.php +++ b/app/Gadai.php @@ -73,7 +73,9 @@ class Gadai extends Model 'tagkomuditi', 'tempohbayar', 'lelong_tawarruq', - 'tag_tebus' + 'tag_tebus', + 'kadarrebet', + 'diskaun' ]; /** diff --git a/app/Http/Controllers/GadaiController.php b/app/Http/Controllers/GadaiController.php index a3805af..f02788d 100644 --- a/app/Http/Controllers/GadaiController.php +++ b/app/Http/Controllers/GadaiController.php @@ -570,7 +570,7 @@ class GadaiController extends Controller $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); - $gadai_data = Gadai::on($cawangan['mysql'])->select('t_gadai','norujukan','nokp','semakbarcode','masa','berat','nilaimarhun','pinjaman','upah12','percentpinj','teller','nokp','ujrah','onepercent','tagbaru') + $gadai_data = Gadai::on($cawangan['mysql'])->select('t_gadai','norujukan','nokp','semakbarcode','masa','berat','nilaimarhun','pinjaman','upah12','percentpinj','teller','nokp','ujrah','onepercent','tagbaru','diskaun') ->where('t_gadai','>=',$request->mula) ->where('t_gadai','<=',$request->akhir) ->orderBy('t_gadai') @@ -599,7 +599,9 @@ class GadaiController extends Controller "teller"=> $gadaiData['teller'], "ujrah"=> $gadaiData['ujrah'], "onepercent"=> $gadaiData['onepercent'], - "tagbaru"=> $gadaiData['tagbaru'] + "tagbaru"=> $gadaiData['tagbaru'], + "kadar_rebet" => $gadaiData['kadarrebet'], + "diskaun" => $gadaiData['diskaun'] ]); } diff --git a/app/Http/Controllers/TebusController.php b/app/Http/Controllers/TebusController.php index 8e99e2b..1cb3606 100644 --- a/app/Http/Controllers/TebusController.php +++ b/app/Http/Controllers/TebusController.php @@ -193,7 +193,7 @@ class TebusController extends Controller $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); $tebus_data = Tebus::on($cawangan['mysql']) - ->select('tebus.t_tebus', 'gad.t_gadai','gad.hargajualan','gad.bakihargajualan','gad.bakipjm as gadaibakipjm','tebus.nilaimarhun','tebus.tagterima', 'tebus.teller','tebus.jenistebus','tebus.pinjaman','tebus.bakiupah','tebus.bakipjm','gad.norujukan','gad.nokp','tebus.jbg','tebus.ujrah','tebus.onepercent','gad.tagbaru') + ->select('tebus.t_tebus', 'gad.t_gadai','gad.hargajualan','gad.bakihargajualan','gad.bakipjm as gadaibakipjm','tebus.nilaimarhun','tebus.tagterima', 'tebus.teller','tebus.jenistebus','tebus.pinjaman','tebus.bakiupah','tebus.bakipjm','gad.norujukan','gad.nokp','tebus.jbg','tebus.ujrah','tebus.onepercent','gad.tagbaru','tebus.diskaun_rebate') ->join('gadai as gad','gad.norujukan','=','tebus.norujukan') // ->join('online_arrahn.customer as cust', function($join) // { @@ -232,7 +232,8 @@ class TebusController extends Controller "nokp"=>$tebusData['nokp'], "jbg"=>$tebusData['jbg'], "ujrah"=>$trans['ujrah_rebet'], - "onepercent"=>$trans['onepercent_rebet'] + "onepercent"=>$trans['onepercent_rebet'], + "diskaun_rebate"=>$tebusData['diskaun_rebate'], ]); } @@ -274,7 +275,8 @@ class TebusController extends Controller 'tebus.jbg', 'tebus.ujrah', 'tebus.onepercent', - 'gad.tagbaru' + 'gad.tagbaru', + 'tebus.diskaun_rebate' ) ->join('gadai as gad', 'gad.norujukan', '=', 'tebus.norujukan') ->where('tebus.t_tebus', '>=', $request->mula) @@ -310,7 +312,8 @@ class TebusController extends Controller "jbg"=>$tebusData['jbg'], "ujrah"=>$trans['ujrah_rebet'], "onepercent"=>$trans['onepercent_rebet'], - "tagbaru"=>$tebusData['tagbaru'] + "tagbaru"=>$tebusData['tagbaru'], + "diskaun_rebate"=>$tebusData['diskaun_rebate'], ]); } @@ -1638,6 +1641,21 @@ class TebusController extends Controller return response($rebet); } + public function RebetPromoCalculation($kodcaw,Request $request) + { + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first(); + + $rebet = Tebus::on($cawangan['mysql']) + ->join('gadai as db2','tebus.norujukan','=','db2.norujukan') + // ->where('tebus.t_tebus','>','2021-04-13') + ->where('tebus.t_tebus','<=',$request->tarikh) + ->where('db2.hargajualan','>','0') // tambahan 2021-05-07 + ->whereNotNull('db2.hargajualan') + ->sum('diskaun_rebate'); + + return response($rebet); + } + public function RebetCalculationLejer($kodcaw,Request $request) { $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first(); @@ -1653,6 +1671,21 @@ class TebusController extends Controller return response($rebet); } + public function RebetPromoCalculationLejer($kodcaw,Request $request) + { + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first(); + + $rebet = Tebus::on($cawangan['mysql']) + ->join('gadai as db2','tebus.norujukan','=','db2.norujukan') + ->where('tebus.t_tebus','>=',$request->mula) + ->where('tebus.t_tebus','<=',$request->hingga) + ->where('db2.hargajualan','>','0') + ->whereNotNull('db2.hargajualan') + ->sum('diskaun_rebate'); + + return response($rebet); + } + public function getUpahLamaToday($kodcaw,$norujukan) { $current = Carbon::now(); diff --git a/app/KadarRebet.php b/app/KadarRebet.php new file mode 100644 index 0000000..e4018db --- /dev/null +++ b/app/KadarRebet.php @@ -0,0 +1,31 @@ +where('pembiayaan_min', '<=', $pembiayaan) + ->where('pembiayaan_max', '>=', $pembiayaan) + ->sum('kadarrebet'); + + return $kadarrebet; + } + public function kiraanUjrahSebenar(float $nilaimarhun = 0.0,float $kadarujrah = 0.0,float $margin = 0.0){ if($kadarujrah >= 1){ @@ -61,13 +73,17 @@ class Calculation $onepercent = $this->kiraanOnePercent($pembiayaan); $ujrah_sebenar = $this->kiraanUjrahSebenar($nilaimarhun,$kadarujrah,$margin); + $discount = $this->kiraanRebetAnnur($pembiayaan); + Log::debug('discount:' . $discount); $onepercent = (!empty($onepercent)) ? $this->getRoundedMethod($onepercent) : 0; $ujrah_sebenar = (!empty($ujrah_sebenar)) ? $this->getRoundedMethod($ujrah_sebenar) : 0; $keuntungan = $onepercent + $ujrah_sebenar; - return ['keuntungan' => $keuntungan,'onepercent' => $onepercent, 'ujrah' => $ujrah_sebenar]; + $kadar_diskaun = $this->getRoundedMethod($keuntungan * ($discount/100)); + Log::debug('kadar_discount:' .$kadar_diskaun); + return ['keuntungan' => $keuntungan,'onepercent' => $onepercent, 'ujrah' => $ujrah_sebenar,'diskaun' => $kadar_diskaun]; } public function kiraanKeuntunganSebenar(float $pembiayaan = 0.0,float $nilaimarhun = 0.0,float $kadarujrah = 0.0,float $margin = 0.0){ diff --git a/app/Support/v2/GadaiV2.php b/app/Support/v2/GadaiV2.php index e212c66..fdb7e5b 100644 --- a/app/Support/v2/GadaiV2.php +++ b/app/Support/v2/GadaiV2.php @@ -99,7 +99,9 @@ class GadaiV2 $upah12 = $onepercentservices->getRoundedMethod($upah1 * 12); $ujrah = $onepercentservices->getRoundedMethod($keuntungan['ujrah']); $onepercent = $onepercentservices->getRoundedMethod($keuntungan['onepercent']); - $kadarrebet = $onepercentservices -> getRoundedMethod($keuntungan['kadarrebet']); + + $kadar_rebet = $request->input('kadar_rebate'); + $diskaun = $request->input('rebate'); $hargajualan = $request->pinjaman + $upah12; @@ -139,7 +141,8 @@ class GadaiV2 'tagbaru' => 1, 'tunggakanujrah' => $akrual['ujrah'], 'tunggakanonepercent' => $akrual['keuntungan'], - 'kadarrebet' => $kadarrebet, + 'kadarrebet' => $kadar_rebet, + 'diskaun' => $diskaun )); $new_data = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first(); @@ -211,7 +214,8 @@ class GadaiV2 $ujrah = $onepercentservices->getRoundedMethod($bilang_bln * $upah['ujrah']); $upahrebet_raw = $onepercent + $ujrah; $upahrebet_raw = $onepercentservices->getRoundedMethod($upahrebet_raw); - + $upahrebet_raw = $upahrebet_raw - $upah['diskaun']; + return $upahrebet_raw; } @@ -248,7 +252,7 @@ class GadaiV2 $keuntungan = $onepercent->kiraanKeuntunganRebet($gadai['bakipjm'],$gadai['nilaimarhun'],$gadai['kadarupah'],$gadai['margin_semasa']); $ujrahasal = $onepercent->kiraanUjrahSebenar($gadai['nilaimarhun'],$gadai['kadarupah'],$gadai['percentpinj']); - + Log::debug($keuntungan); $onepercentasal = $gadai['pinjaman'] * (1/100); $ujrahasal = $onepercent->getRoundedMethod($ujrahasal); $onepercentasal = $onepercent->getRoundedMethod($onepercentasal); @@ -297,6 +301,7 @@ class GadaiV2 'tempoh' => $gadai['tempoh'], 'beza_tempoh' => $bilang_bln, 'margin_semasa' => $margin_semasa, + 'kadardiskaun' => $keuntungan['diskaun'] ]); $transaksi_gadai = TransaksiGadai::on('mysql7')->create([ diff --git a/app/Support/v2/Penebusan.php b/app/Support/v2/Penebusan.php index 6294831..e2c2c24 100644 --- a/app/Support/v2/Penebusan.php +++ b/app/Support/v2/Penebusan.php @@ -39,33 +39,34 @@ class Penebusan $this->cawangan_info = $cawangan_info; } - public function tebusTawarruq($kodcaw,$norujukan){ - $onepercentservices = new Calculation(); + public function tebusTawarruq($kodcaw, $norujukan) +{ + $onepercentservices = new Calculation(); - $cawangan = Cawangan::on('mysql7') - ->where('kodcaw','=',$kodcaw) - ->first(); + $cawangan = Cawangan::on('mysql7') + ->where('kodcaw', '=', $kodcaw) + ->first(); - $gadai_data = Gadai::on($cawangan['mysql']) - ->where('norujukan','=',$norujukan) - ->first(); + $gadai_data = Gadai::on($cawangan['mysql']) + ->where('norujukan', '=', $norujukan) + ->first(); - $jeniskeuntungan = ($gadai_data['tagbaru'] == 1) ? 'onepercent' : 'asal'; + $jeniskeuntungan = ($gadai_data['tagbaru'] == 1) ? 'onepercent' : 'asal'; - $rebet = $this->rebetselepastawarruq($kodcaw,$norujukan,$jeniskeuntungan); - $harga_tebus = $gadai_data['bakihargajualan'] - $rebet; + $rebet = $this->rebetselepastawarruq($kodcaw, $norujukan, $jeniskeuntungan); - // $hargatebus = round($harga_tebus,PHP_ROUND_HALF_UP); - // $hargatebus = bcdiv(round($harga_tebus,2),1,1); - // $hargatebus = number_format($hargatebus,2); - // if(strpos($hargatebus,',')){ - // $hargatebus = str_replace(',','',$hargatebus); - // } + // Ambil terus dari column 'diskaun' + $diskaun = $gadai_data['diskaun'] ?? 0; - $hargatebus = $onepercentservices->getRoundedMethod($harga_tebus); + // Kira harga tebus selepas tolak rebet & diskaun + $harga_tebus = $gadai_data['bakihargajualan'] - $rebet - $diskaun; + + // Apply pembundaran + $hargatebus = $onepercentservices->getRoundedMethod($harga_tebus); + + return response()->json($hargatebus); +} - return response()->json($hargatebus); - } public function hargaTebusTawarruq($kodcaw,$norujukan){ $onepercentservices = new Calculation(); @@ -485,6 +486,9 @@ class Penebusan $gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first(); + // Ambil nilai diskaun + $diskaun = $gadai['diskaun'] ?? 0; + //check duplicate $data = Transaction::on('mysql7')->where('norujukan','=',$norujukan)->whereIn('trans_type', ['P', 'T', 'S'])->first(); @@ -516,6 +520,8 @@ class Penebusan } } + // Tolak diskaun dari harga tebus + $harga_tebus['harga'] -= $diskaun; $create_tebus = Tebus::on($cawangan['mysql'])->create([ 'kodcaw'=> $kodcaw, @@ -543,6 +549,7 @@ class Penebusan 'teller' => $request->teller, 'ujrah' => $ujrah_rebet, 'onepercent' => $onepercent_rebet, + 'diskaun_rebate' => $diskaun, // Tambah kolum simpan diskaun ]); $create_inoutmar = InOutMar::on($cawangan['mysql'])->create([ diff --git a/app/Tebus.php b/app/Tebus.php index 4d01786..e161227 100644 --- a/app/Tebus.php +++ b/app/Tebus.php @@ -52,7 +52,8 @@ class Tebus extends Model 'pinjamanterkini', 'tarikhbyrn', 'ujrah', - 'onepercent' + 'onepercent', + 'diskaun_rebate' ]; /** diff --git a/app/TransaksiKeuntungan.php b/app/TransaksiKeuntungan.php index 2fa926e..d0e8a71 100644 --- a/app/TransaksiKeuntungan.php +++ b/app/TransaksiKeuntungan.php @@ -14,7 +14,7 @@ class TransaksiKeuntungan extends Model * @var array */ protected $fillable = [ - 'norujukan','bayaran_keuntungan','tarikh_bayaran','kodcaw','bayaran_pembiayaan','keuntungan_rebet','ujrah','ujrah_rebet','onepercent','onepercent_rebet','tempoh','beza_tempoh','margin_semasa','rounded' + 'norujukan','bayaran_keuntungan','tarikh_bayaran','kodcaw','bayaran_pembiayaan','keuntungan_rebet','ujrah','ujrah_rebet','onepercent','onepercent_rebet','tempoh','beza_tempoh','margin_semasa','rounded','kadardiskaun' ]; /** diff --git a/routes/web.php b/routes/web.php index 00513ad..d2c3a5c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -528,6 +528,7 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('CalculationPendahuluanSerahan/{kodcaw}',['uses'=>'VaultController@CalculationPendahuluanSerahan']); $router->get('KeuntunganArRahn/{kodcaw}',['uses'=>'GadaiController@CalculationKeuntungan']); $router->get('RebetCalculation/{kodcaw}',['uses'=>'TebusController@RebetCalculation']); + $router->get('RebetPromoCalculation/{kodcaw}',['uses'=>'TebusController@RebetPromoCalculation']); //-- Harta Semasa --// $router->get('PinjamanDiberi/{kodcaw}',['uses'=>'GadaiController@CalculationPinjamanDiberi']); @@ -557,7 +558,8 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('PendahuluanSerahanLejer/{kodcaw}',['uses'=>'VaultController@CalculationPendahuluanSerahanLejer']); $router->get('KeuntunganArRahnLejer/{kodcaw}',['uses'=>'GadaiController@CalculationKeuntunganLejer']); $router->get('RebetCalculationLejer/{kodcaw}',['uses'=>'TebusController@RebetCalculationLejer']); - $router->get('cajlelongLejer/{kodcaw}',['uses'=>'LelongController@cajlelongcalculationLejer']); + $router->get('RebetPromoCalculationLejer/{kodcaw}',['uses'=>'TebusController@RebetPromoCalculationLejer']); + $router->get('cajlelongLejer/{kodcaw}',['uses'=>'LelongController@cajlelongcalculationLejer']); // //-- Harta Semasa --// $router->get('PinjamanDiberiLejer/{kodcaw}',['uses'=>'GadaiController@CalculationPinjamanDiberiLejer']);