From 0b9ec1c0ee7ce0467880337c777eb3f19b1f9f48 Mon Sep 17 00:00:00 2001 From: ISMAIL MASSERAN Date: Thu, 17 Sep 2026 08:01:16 +0800 Subject: [PATCH] DONE: merged code annur with into one codebase --- .env.annur | 28 +++++ README.md | 2 +- app/Feature.php | 3 + app/Gadai.php | 4 +- app/Http/Controllers/GadaiController.php | 8 +- app/Http/Controllers/TebusController.php | 79 +++++++++++++- app/KadarRebet.php | 18 ++++ app/Support/v2/Calculation.php | 58 +++++++++- app/Support/v2/GadaiV2.php | 40 +++++-- app/Support/v2/Penebusan.php | 64 +++++++++-- app/Tebus.php | 3 +- app/TransaksiKeuntungan.php | 2 +- ..._09_13_100000_create_kadar_rebet_table.php | 31 ++++++ ...09_13_100001_add_annur_diskaun_columns.php | 102 ++++++++++++++++++ routes/web.php | 3 + 15 files changed, 414 insertions(+), 31 deletions(-) create mode 100644 .env.annur create mode 100644 app/KadarRebet.php create mode 100644 database/migrations/2026_09_13_100000_create_kadar_rebet_table.php create mode 100644 database/migrations/2026_09_13_100001_add_annur_diskaun_columns.php diff --git a/.env.annur b/.env.annur new file mode 100644 index 0000000..a1d3da7 --- /dev/null +++ b/.env.annur @@ -0,0 +1,28 @@ +APP_NAME=Lumen +APP_ENV=production +APP_KEY=WbPGkYNmXZ6ZQplGlvl0iZ7zyW1b09xa +APP_DEBUG=true +APP_URL=https://apiannurv2.erahn.com.my +APP_TIMEZONE=Asia/Kuala_Lumpur + +LOG_CHANNEL=stack +LOG_SLACK_WEBHOOK_URL= + +DB_CONNECTION_2=mysql +DB_HOST_2=192.168.1.216 +DB_PORT_2=3306 +DB_DATABASE_2=annur_tampoi +DB_USERNAME_2=spider +DB_PASSWORD_2=arrahn@123 + +DB_CONNECTION_7=mysql +DB_HOST_7=192.168.1.216 +DB_PORT_7=3306 +DB_DATABASE_7=master_annur +DB_USERNAME_7=spider +DB_PASSWORD_7=arrahn@123 + +CACHE_DRIVER=file +QUEUE_CONNECTION=sync + +TENNANT_MASTER_DB=master_annur \ No newline at end of file diff --git a/README.md b/README.md index bd2926b..cea8ad4 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Tebus=penyelesaian penuh/ansuran docker exec -i api_arrahn_staging_mysql mysql -uroot -proot erahn_test < erahn_test.sql ``` -## Disable the cawangan in arrahn_master_db +## Disable the cawangan in arrahn_master_db using feature flag ## Feature Flag 1. Register the flag in api_arrahn/app/Feature.php diff --git a/app/Feature.php b/app/Feature.php index 398ed5f..1cccc7e 100644 --- a/app/Feature.php +++ b/app/Feature.php @@ -5,6 +5,7 @@ namespace App; class Feature { const PEMBIAYAAN_ONLINE = 'pembiayaan_online'; + const REBET_ANNUR = 'rebet_annur'; /** * Known flag keys. New features: add a constant here, then INSERT rows for pilot kodcaw. @@ -15,6 +16,7 @@ class Feature { return [ self::PEMBIAYAAN_ONLINE, + self::REBET_ANNUR, ]; } @@ -40,6 +42,7 @@ class Feature { return [ self::PEMBIAYAAN_ONLINE => 'Pembiayaan Online', + self::REBET_ANNUR => 'Rebet / diskaun Annur', ]; } diff --git a/app/Gadai.php b/app/Gadai.php index ccb9ca1..be4a77e 100644 --- a/app/Gadai.php +++ b/app/Gadai.php @@ -78,7 +78,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 c33f375..34195ee 100644 --- a/app/Http/Controllers/GadaiController.php +++ b/app/Http/Controllers/GadaiController.php @@ -537,7 +537,7 @@ class GadaiController extends Controller public function getLaporanGadai($kodcaw,$tarikh){ $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); - $gadai_data = Gadai::on($cawangan['mysql'])->select('cara_terima','t_gadai','norujukan','nokp','semakbarcode','masa','berat','nilaimarhun','pinjaman','upah12','percentpinj','teller','nokp','ujrah','onepercent') + $gadai_data = Gadai::on($cawangan['mysql'])->select('cara_terima','t_gadai','norujukan','nokp','semakbarcode','masa','berat','nilaimarhun','pinjaman','upah12','percentpinj','teller','nokp','ujrah','onepercent','kadarrebet','diskaun') ->where('t_gadai','=',$tarikh) ->orderBy('teller') ->orderBy('sirig') @@ -564,7 +564,9 @@ class GadaiController extends Controller "alamat1"=> $customer_info['alamat1'], "teller"=> $gadaiData['teller'], "onepercent"=> $gadaiData['onepercent'], - "ujrah"=> $gadaiData['ujrah'] + "ujrah"=> $gadaiData['ujrah'], + "kadarrebet"=> $gadaiData['kadarrebet'], + "diskaun"=> $gadaiData['diskaun'] ]); } } @@ -642,6 +644,8 @@ class GadaiController extends Controller "teller"=> $g->teller, "ujrah"=> $g->ujrah, "onepercent"=> $g->onepercent, + "kadarrebet"=> $g->kadarrebet, + "diskaun"=> $g->diskaun, "tagbaru"=> $g->tagbaru, "kodkerja"=> optional($customer)->kodkerja, "bangsa"=> optional($customer)->bangsa, diff --git a/app/Http/Controllers/TebusController.php b/app/Http/Controllers/TebusController.php index 512ccd8..90ced88 100644 --- a/app/Http/Controllers/TebusController.php +++ b/app/Http/Controllers/TebusController.php @@ -20,6 +20,7 @@ use App\Panjar; use App\HargaEmas; use App\Moratorium; use App\Audit; +use App\Feature; use App\LookupWakil; use App\StokAudit1; @@ -193,7 +194,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 +233,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 +276,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 +313,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'], ]); } @@ -1672,6 +1676,53 @@ class TebusController extends Controller return response($rebet); } + public function RebetPromoCalculation($kodcaw, Request $request) + { + $kodcaw = $request->kodcaw ?: $kodcaw; + if (!Feature::enabled($kodcaw, Feature::REBET_ANNUR)) { + return response(0); + } + + $cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $kodcaw)->first(); + + $rebet = Tebus::on($cawangan['mysql']) + ->join('gadai as db2', 'tebus.norujukan', '=', 'db2.norujukan') + ->where('tebus.t_tebus', '<=', $request->tarikh) + ->where('db2.hargajualan', '>', '0') + ->whereNotNull('db2.hargajualan') + ->sum('diskaun_rebate'); + + return response($rebet); + } + + public function PelarasanRebate($kodcaw, Request $request) + { + $kodcaw = $request->kodcaw ?: $kodcaw; + if (!Feature::enabled($kodcaw, Feature::REBET_ANNUR)) { + return response(0); + } + + $cawangan = Cawangan::on('mysql7') + ->where('kodcaw', $kodcaw) + ->first(); + + $tarikhLaporan = Carbon::parse($request->tarikh)->toDateString(); + $tarikhTamatPelarasan = '2026-09-02'; + $tarikhAkhir = $tarikhLaporan > $tarikhTamatPelarasan + ? $tarikhTamatPelarasan + : $tarikhLaporan; + + $rebet = Tebus::on($cawangan['mysql']) + ->join('gadai as db2', 'tebus.norujukan', '=', 'db2.norujukan') + ->whereDate('tebus.t_tebus', '>=', '2025-05-13') + ->whereDate('tebus.t_tebus', '<=', $tarikhAkhir) + ->where('db2.hargajualan', '>', 0) + ->whereDate('db2.t_gadai', '>', '2023-05-21') + ->sum('tebus.diskaun_rebate'); + + return response($rebet); + } + public function RebetCalculationLejer($kodcaw,Request $request) { $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first(); @@ -1687,6 +1738,26 @@ class TebusController extends Controller return response($rebet); } + public function RebetPromoCalculationLejer($kodcaw, Request $request) + { + $kodcaw = $request->kodcaw ?: $kodcaw; + if (!Feature::enabled($kodcaw, Feature::REBET_ANNUR)) { + return response(0); + } + + $cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $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..e1cd20d --- /dev/null +++ b/app/KadarRebet.php @@ -0,0 +1,18 @@ +one_percent = $this->getKadarUpah($nilaimarhun); @@ -66,8 +69,59 @@ class Calculation $ujrah_sebenar = (!empty($ujrah_sebenar)) ? $this->getRoundedMethod($ujrah_sebenar) : 0; $keuntungan = $onepercent + $ujrah_sebenar; + $annur = $this->kiraanDiskaunAnnur($kodcaw, $pembiayaan, $keuntungan); - return ['keuntungan' => $keuntungan,'onepercent' => $onepercent, 'ujrah' => $ujrah_sebenar]; + return [ + 'keuntungan' => $keuntungan, + 'onepercent' => $onepercent, + 'ujrah' => $ujrah_sebenar, + 'diskaun' => $annur['diskaun'], + 'kadarrebet' => $annur['kadarrebet'], + ]; + } + + /** + * Annur promotional discount. Other cawangan get 0 unless rebet_annur is enabled. + */ + public function kiraanDiskaunAnnur($kodcaw, float $pembiayaan = 0.0, float $keuntungan = 0.0) + { + $empty = ['kadarrebet' => 0, 'diskaun' => 0]; + + try { + if (!$kodcaw || !Feature::enabled($kodcaw, Feature::REBET_ANNUR)) { + return $empty; + } + } catch (\Exception $e) { + return $empty; + } + + $percent = $this->kiraanRebetAnnur($pembiayaan); + if ($percent <= 0 || $keuntungan <= 0) { + return ['kadarrebet' => $percent, 'diskaun' => 0]; + } + + return [ + 'kadarrebet' => $percent, + 'diskaun' => $this->getRoundedMethod($keuntungan * ($percent / 100)), + ]; + } + + private function kiraanRebetAnnur(float $pembiayaan = 0.0) + { + try { + if (!Schema::connection('mysql7')->hasTable('kadar_rebet')) { + return 0; + } + + $kadarrebet = KadarRebet::on('mysql7') + ->where('pembiayaan_min', '<=', $pembiayaan) + ->where('pembiayaan_max', '>=', $pembiayaan) + ->sum('kadarrebet'); + + return (float) $kadarrebet; + } catch (\Exception $e) { + return 0; + } } 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 b3febe1..7c17ca5 100644 --- a/app/Support/v2/GadaiV2.php +++ b/app/Support/v2/GadaiV2.php @@ -5,6 +5,7 @@ namespace App\Support\v2; use App\Audit; use App\Cawangan; use App\Customer; +use App\Feature; use App\KadarUpah; use App\Support\v2\Calculation; use Carbon\Carbon; @@ -137,14 +138,13 @@ if (is_null($kadar_raw)) { $upah12 = $onepercentservices->getRoundedMethod($upah1 * 12); $ujrah = $onepercentservices->getRoundedMethod($keuntungan['ujrah']); $onepercent = $onepercentservices->getRoundedMethod($keuntungan['onepercent']); + $annur = $onepercentservices->kiraanDiskaunAnnur($request->kodcaw, $request->pinjaman, $keuntungan['keuntungan']); $hargajualan = $request->pinjaman + $upah12; $akrual = $this->kiraupahTawarruqStokAuditUjrahOnePercent(0.5,0,$kadar_raw,$request->pinjaman,$total_nilai_marhun,$margin_pinjam); - $gadai = Gadai::on($cawangan['mysql']) - ->where('norujukan','=',$norujukan) - ->update(array( + $gadaiFields = [ 'nilaimarhun' => $total_nilai_marhun, 'berat'=> $total_berat, 'pinjaman' => $request->pinjaman, @@ -176,7 +176,23 @@ if (is_null($kadar_raw)) { 'tagbaru' => 1, 'tunggakanujrah' => $akrual['ujrah'], 'tunggakanonepercent' => $akrual['keuntungan'], - )); + ]; + if (Feature::enabled($request->kodcaw, Feature::REBET_ANNUR)) { + $requestedKadar = (float) $request->input('kadar_rebate', 0); + $requestedDiskaun = (float) $request->input('rebate', 0); + + if ($requestedKadar > 0 || $requestedDiskaun > 0) { + $gadaiFields['kadarrebet'] = $requestedKadar; + $gadaiFields['diskaun'] = $requestedDiskaun; + } elseif (($request->transaction ?? '') === 'Daftar Gadai') { + $gadaiFields['kadarrebet'] = $annur['kadarrebet']; + $gadaiFields['diskaun'] = $annur['diskaun']; + } + } + + $gadai = Gadai::on($cawangan['mysql']) + ->where('norujukan','=',$norujukan) + ->update($gadaiFields); $new_data = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first(); @@ -240,14 +256,15 @@ if (is_null($kadar_raw)) { } $bilang_bln = $tempoh - $gadai_data['tempohbayar']; - $upah = $onepercentservices->kiraanKeuntunganRebet($gadai_data['bakipjm'],$gadai_data['nilaimarhun'],$gadai_data['kadarupah'],$gadai_data['margin_semasa']); + $upah = $onepercentservices->kiraanKeuntunganRebet($gadai_data['bakipjm'],$gadai_data['nilaimarhun'],$gadai_data['kadarupah'],$gadai_data['margin_semasa'], $this->kodcaw); //$upahrebet_raw = $bilang_bln * $upah['keuntungan']; $onepercent = $onepercentservices->getRoundedMethod($bilang_bln * $upah['onepercent']); $ujrah = $onepercentservices->getRoundedMethod($bilang_bln * $upah['ujrah']); $upahrebet_raw = $onepercent + $ujrah; $upahrebet_raw = $onepercentservices->getRoundedMethod($upahrebet_raw); - + $upahrebet_raw = $upahrebet_raw - ($upah['diskaun'] ?? 0); + return $upahrebet_raw; } @@ -282,7 +299,7 @@ if (is_null($kadar_raw)) { $margin_semasa = ($gadai['bakipjm'] / $gadai['nilaimarhun']) * 100; - $keuntungan = $onepercent->kiraanKeuntunganRebet($gadai['bakipjm'],$gadai['nilaimarhun'],$gadai['kadarupah'],$gadai['margin_semasa']); + $keuntungan = $onepercent->kiraanKeuntunganRebet($gadai['bakipjm'],$gadai['nilaimarhun'],$gadai['kadarupah'],$gadai['margin_semasa'], $kodcaw); $ujrahasal = $onepercent->kiraanUjrahSebenar($gadai['nilaimarhun'],$gadai['kadarupah'],$gadai['percentpinj']); $onepercentasal = $gadai['pinjaman'] * (1/100); @@ -319,7 +336,7 @@ if (is_null($kadar_raw)) { $keun = $onepercent->getRoundedMethod($onepercentasal * $bilang_bln); $keuntungan_rebate = $onepercent->getRoundedMethod($keuntungan['onepercent'] * $bilang_bln); - $transaction_upah = TransaksiKeuntungan::on('mysql7')->create([ + $transactionUpahFields = [ 'norujukan' => $norujukan, 'bayaran_keuntungan' => $upahsemasa, 'bayaran_pembiayaan' => $baki_bayaran, @@ -333,7 +350,12 @@ if (is_null($kadar_raw)) { 'tempoh' => $gadai['tempoh'], 'beza_tempoh' => $bilang_bln, 'margin_semasa' => $margin_semasa, - ]); + ]; + if (Feature::enabled($kodcaw, Feature::REBET_ANNUR)) { + $transactionUpahFields['kadardiskaun'] = $keuntungan['diskaun'] ?? 0; + } + + $transaction_upah = TransaksiKeuntungan::on('mysql7')->create($transactionUpahFields); $transaksi_gadai = TransaksiGadai::on('mysql7')->create([ 'kodcaw' => $old_data['kodcaw'], diff --git a/app/Support/v2/Penebusan.php b/app/Support/v2/Penebusan.php index 6294831..0afe15d 100644 --- a/app/Support/v2/Penebusan.php +++ b/app/Support/v2/Penebusan.php @@ -5,6 +5,7 @@ namespace App\Support\v2; use App\Advansur; use App\Audit; use App\Cawangan; +use App\Feature; use App\KadarUpah; use App\Support\v2\Calculation; use Carbon\Carbon; @@ -39,6 +40,32 @@ class Penebusan $this->cawangan_info = $cawangan_info; } + private function diskaunAnnur($kodcaw, $gadai) + { + try { + if (!Feature::enabled($kodcaw, Feature::REBET_ANNUR)) { + return 0.0; + } + } catch (\Exception $e) { + return 0.0; + } + + return (float) ($gadai['diskaun'] ?? 0); + } + + private function tebusAnnurFields($kodcaw, $diskaun) + { + try { + if (!Feature::enabled($kodcaw, Feature::REBET_ANNUR)) { + return []; + } + } catch (\Exception $e) { + return []; + } + + return ['diskaun_rebate' => $diskaun]; + } + public function tebusTawarruq($kodcaw,$norujukan){ $onepercentservices = new Calculation(); @@ -53,7 +80,8 @@ class Penebusan $jeniskeuntungan = ($gadai_data['tagbaru'] == 1) ? 'onepercent' : 'asal'; $rebet = $this->rebetselepastawarruq($kodcaw,$norujukan,$jeniskeuntungan); - $harga_tebus = $gadai_data['bakihargajualan'] - $rebet; + $diskaun = $this->diskaunAnnur($kodcaw, $gadai_data); + $harga_tebus = $gadai_data['bakihargajualan'] - $rebet - $diskaun; // $hargatebus = round($harga_tebus,PHP_ROUND_HALF_UP); // $hargatebus = bcdiv(round($harga_tebus,2),1,1); @@ -485,6 +513,8 @@ class Penebusan $gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first(); + $diskaun = $this->diskaunAnnur($kodcaw, $gadai); + //check duplicate $data = Transaction::on('mysql7')->where('norujukan','=',$norujukan)->whereIn('trans_type', ['P', 'T', 'S'])->first(); @@ -502,7 +532,6 @@ class Penebusan $harga_tebus = $this->hargaTebusTawarruq($kodcaw,$norujukan,$request->jeniskeuntungan); $upah_tebus = $this->kiraupahTawarruq($norujukan); $upah_rebet = $this->kiraUpahRebetSebenar($kodcaw,$norujukan); - $upah_rebet_sebenar = $harga_tebus['harga'] - $gadai['bakipjm']; if($request->jeniskeuntungan == 'onepercent'){ $array_onepercent = $this->kiraupahUjrahOnePercent($kodcaw,$norujukan); @@ -514,10 +543,15 @@ class Penebusan $ujrah = $array_onepercent['ujrah']; $onepercent = $array_onepercent['onepercent']; } + + $harga_tebus['harga'] -= $diskaun; + $upah_rebet_sebenar = $harga_tebus['harga'] - $gadai['bakipjm']; } + $bayaran_keuntungan_bersih = max(0, $upah_rebet_sebenar); - $create_tebus = Tebus::on($cawangan['mysql'])->create([ + + $create_tebus = Tebus::on($cawangan['mysql'])->create(array_merge([ 'kodcaw'=> $kodcaw, 'norujukan'=> $norujukan, 'nopelanggan' => $request->nopelanggan, @@ -543,7 +577,7 @@ class Penebusan 'teller' => $request->teller, 'ujrah' => $ujrah_rebet, 'onepercent' => $onepercent_rebet, - ]); + ], $this->tebusAnnurFields($kodcaw, $diskaun))); $create_inoutmar = InOutMar::on($cawangan['mysql'])->create([ 'tarikh' => $current->toDateString(), @@ -561,7 +595,7 @@ class Penebusan $transaction_upah = TransaksiKeuntungan::on('mysql7')->create([ 'norujukan' => $norujukan, - 'bayaran_keuntungan' => $upah_tebus, + 'bayaran_keuntungan' => $bayaran_keuntungan_bersih, 'bayaran_pembiayaan' => $gadai['bakipjm'], 'keuntungan_rebet' => $upah_rebet_sebenar, 'tarikh_bayaran'=> $current, @@ -651,6 +685,8 @@ class Penebusan $gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first(); + $diskaun = $this->diskaunAnnur($kodcaw, $gadai); + //check duplicate $data = Transaction::on('mysql7')->where('norujukan','=',$norujukan)->where('trans_type','=','AT')->first(); @@ -668,7 +704,6 @@ class Penebusan $harga_tebus = $this->hargaTebusTawarruq($kodcaw,$norujukan,$request->jeniskeuntungan); $upah_tebus = $this->kiraupahTawarruq($norujukan); $upah_rebet = $this->kiraUpahRebetSebenar($kodcaw,$norujukan); - $upah_rebet_sebenar = $harga_tebus['harga'] - $gadai['bakipjm']; if($request->jeniskeuntungan == 'onepercent'){ $array_onepercent = $this->kiraupahUjrahOnePercent($kodcaw,$norujukan); @@ -681,6 +716,9 @@ class Penebusan $ujrah = $array_onepercent['ujrah']; $onepercent = $array_onepercent['onepercent']; } + + $harga_tebus['harga'] -= $diskaun; + $upah_rebet_sebenar = $harga_tebus['harga'] - $gadai['bakipjm']; } $update_gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->update(array( @@ -690,7 +728,7 @@ class Penebusan // $upah_rebet = $this->kiraUpahRebet($kodcaw,$norujukan); - $create_tebus = Tebus::on($cawangan['mysql'])->create([ + $create_tebus = Tebus::on($cawangan['mysql'])->create(array_merge([ 'kodcaw'=> $kodcaw, 'norujukan'=> $norujukan, 'nopelanggan' => $request->nopelanggan, @@ -716,7 +754,7 @@ class Penebusan 'teller' => $request->teller, 'ujrah' => $ujrah_rebet, 'onepercent' => $onepercent_rebet, - ]); + ], $this->tebusAnnurFields($kodcaw, $diskaun))); $create_inoutmar = InOutMar::on($cawangan['mysql'])->create([ 'tarikh' => $current->toDateString(), @@ -734,9 +772,11 @@ class Penebusan $bayaran_pembiayaan = $request->totalbayaran - $request->bakiupah; + $bayaran_keuntungan_bersih = max(0, $upah_rebet_sebenar); + $transaction_upah = TransaksiKeuntungan::on('mysql7')->create([ 'norujukan' => $norujukan, - 'bayaran_keuntungan' => $upah_tebus, + 'bayaran_keuntungan' => $bayaran_keuntungan_bersih, 'bayaran_pembiayaan' => $bayaran_pembiayaan, 'keuntungan_rebet' => $upah_rebet_sebenar, 'tarikh_bayaran'=> $current, @@ -1131,12 +1171,16 @@ class Penebusan $onepercent_rebet = $array_onepercent_rebet['onepercent'] - $upah_rebet['onepercent']; $ujrah_rebet = $array_onepercent_rebet['ujrah'] - $upah_rebet['ujrah']; + $diskaun = $this->diskaunAnnur($kodcaw, $gadai); + $harga_tebus['harga'] -= $diskaun; $upah_rebet_sebenar = $harga_tebus['harga'] - $gadai['bakipjm']; + $bayaran_keuntungan_bersih = max(0, $upah_rebet_sebenar); + try{ TransaksiKeuntungan::on('mysql7')->create([ 'norujukan' => $norujukan, - 'bayaran_keuntungan' => $upah_tebus, + 'bayaran_keuntungan' => $bayaran_keuntungan_bersih, 'bayaran_pembiayaan' => $bayaran_pembiayaan, 'keuntungan_rebet' => $upah_rebet_sebenar, 'tarikh_bayaran'=> $current, 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/database/migrations/2026_09_13_100000_create_kadar_rebet_table.php b/database/migrations/2026_09_13_100000_create_kadar_rebet_table.php new file mode 100644 index 0000000..53289c4 --- /dev/null +++ b/database/migrations/2026_09_13_100000_create_kadar_rebet_table.php @@ -0,0 +1,31 @@ +hasTable('kadar_rebet')) { + return; + } + + Schema::connection('mysql7')->create('kadar_rebet', function (Blueprint $table) { + $table->increments('id'); + $table->decimal('pembiayaan_min', 12, 2)->default(0); + $table->decimal('pembiayaan_max', 12, 2)->default(0); + $table->decimal('kadarrebet', 8, 4)->default(0); + }); + } + + public function down() + { + Schema::connection('mysql7')->dropIfExists('kadar_rebet'); + } +} diff --git a/database/migrations/2026_09_13_100001_add_annur_diskaun_columns.php b/database/migrations/2026_09_13_100001_add_annur_diskaun_columns.php new file mode 100644 index 0000000..6cf52d3 --- /dev/null +++ b/database/migrations/2026_09_13_100001_add_annur_diskaun_columns.php @@ -0,0 +1,102 @@ +getPdo(); + return true; + } catch (\Exception $e) { + return false; + } + }); + } + + public function up() + { + foreach ($this->getActiveDB() as $dbase) { + if (Schema::connection($dbase)->hasTable('gadai')) { + $addKadar = !Schema::connection($dbase)->hasColumn('gadai', 'kadarrebet'); + $addDiskaun = !Schema::connection($dbase)->hasColumn('gadai', 'diskaun'); + if ($addKadar || $addDiskaun) { + Schema::connection($dbase)->table('gadai', function (Blueprint $table) use ($addKadar, $addDiskaun) { + if ($addKadar) { + $table->decimal('kadarrebet', 8, 4)->nullable()->default(0); + } + if ($addDiskaun) { + $table->decimal('diskaun', 12, 2)->nullable()->default(0); + } + }); + } + } + + if ( + Schema::connection($dbase)->hasTable('tebus') + && !Schema::connection($dbase)->hasColumn('tebus', 'diskaun_rebate') + ) { + Schema::connection($dbase)->table('tebus', function (Blueprint $table) { + $table->decimal('diskaun_rebate', 12, 2)->nullable()->default(0); + }); + } + } + + if ( + Schema::connection('mysql7')->hasTable('transaksi_keuntungan') + && !Schema::connection('mysql7')->hasColumn('transaksi_keuntungan', 'kadardiskaun') + ) { + Schema::connection('mysql7')->table('transaksi_keuntungan', function (Blueprint $table) { + $table->decimal('kadardiskaun', 12, 2)->nullable()->default(0); + }); + } + } + + public function down() + { + foreach ($this->getActiveDB() as $dbase) { + if (Schema::connection($dbase)->hasTable('gadai')) { + Schema::connection($dbase)->table('gadai', function (Blueprint $table) use ($dbase) { + $drops = []; + if (Schema::connection($dbase)->hasColumn('gadai', 'kadarrebet')) { + $drops[] = 'kadarrebet'; + } + if (Schema::connection($dbase)->hasColumn('gadai', 'diskaun')) { + $drops[] = 'diskaun'; + } + if ($drops) { + $table->dropColumn($drops); + } + }); + } + + if ( + Schema::connection($dbase)->hasTable('tebus') + && Schema::connection($dbase)->hasColumn('tebus', 'diskaun_rebate') + ) { + Schema::connection($dbase)->table('tebus', function (Blueprint $table) { + $table->dropColumn('diskaun_rebate'); + }); + } + } + + if ( + Schema::connection('mysql7')->hasTable('transaksi_keuntungan') + && Schema::connection('mysql7')->hasColumn('transaksi_keuntungan', 'kadardiskaun') + ) { + Schema::connection('mysql7')->table('transaksi_keuntungan', function (Blueprint $table) { + $table->dropColumn('kadardiskaun'); + }); + } + } +} diff --git a/routes/web.php b/routes/web.php index 4c2ff8f..2aa7084 100644 --- a/routes/web.php +++ b/routes/web.php @@ -580,6 +580,8 @@ $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']); + $router->get('PelarasanRebate/{kodcaw}',['uses'=>'TebusController@PelarasanRebate']); //-- Harta Semasa --// $router->get('PinjamanDiberi/{kodcaw}',['uses'=>'GadaiController@CalculationPinjamanDiberi']); @@ -610,6 +612,7 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('ModalOnlineLejer/{kodcaw}', ['uses' => 'VaultController@CalculationModalOnlineLejer']); $router->get('KeuntunganArRahnLejer/{kodcaw}',['uses'=>'GadaiController@CalculationKeuntunganLejer']); $router->get('RebetCalculationLejer/{kodcaw}',['uses'=>'TebusController@RebetCalculationLejer']); + $router->get('RebetPromoCalculationLejer/{kodcaw}',['uses'=>'TebusController@RebetPromoCalculationLejer']); $router->get('cajlelongLejer/{kodcaw}',['uses'=>'LelongController@cajlelongcalculationLejer']); // //-- Harta Semasa --//