From f57f2da1c44f1c2f5d5fcef6273ba0d41d32e270 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Tue, 16 Jul 2024 16:01:53 +0800 Subject: [PATCH 01/18] Handle erors on marhun service, and pembiayaan service --- app/Services/MarhunService.php | 3 ++- app/Services/PembiayaanService.php | 11 ++++++++++- resources/views/modal/marhun.blade.php | 23 ++++++++++++----------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/Services/MarhunService.php b/app/Services/MarhunService.php index f3e3bd5..223b4a5 100644 --- a/app/Services/MarhunService.php +++ b/app/Services/MarhunService.php @@ -23,7 +23,8 @@ class MarhunService }); }; - $marhunDetailsResponse = array_map(fn($x) => array_merge([], ...$x->json()), $getMarhunDetails()); + $marhunDetailsResponse = array_map(fn($x) => $x->json() == null ? [] : $x->Json(), $getMarhunDetails()); + $marhunDetailsResponse = array_map(fn($x) => array_merge([], ...$x), $marhunDetailsResponse); $formatMarhunDetailData = function ($x) { $getMarhunTypeFullName = function ($code) { diff --git a/app/Services/PembiayaanService.php b/app/Services/PembiayaanService.php index ee37acf..5398c20 100644 --- a/app/Services/PembiayaanService.php +++ b/app/Services/PembiayaanService.php @@ -165,9 +165,18 @@ class PembiayaanService }; $pembiayaanAkanDilelong = array_filter($getPembiayaanAkanDilelong(), $isCurrentDateGreaterThanEqual3DaysBeforeLelong); + $norujukanAkanDilelong = array_map(fn($x) => $x->norujukan, $pembiayaanAkanDilelong); - $pembiayaanInFasa2 = array_filter($getPembiayaanAkanDilelong(), fn($x) => $x->fasa == 2); + $setDefaultFasaIfNotAvailable = function($x){ + if(! isset($x->fasa)){ + $x->fasa = 1; + } + return $x; + }; + + $pembiayaanWithFasa = array_map($setDefaultFasaIfNotAvailable, $getPembiayaanAkanDilelong()); + $pembiayaanInFasa2 = array_filter($pembiayaanWithFasa, fn($x) => $x->fasa == 2); $norujukanInFasa2 = array_map(fn($x) => $x->norujukan, $pembiayaanInFasa2); $getPayableUjrahBranches = fn() => Http::arrahn()->get('/api/payable-ujrah-branches')->json(); diff --git a/resources/views/modal/marhun.blade.php b/resources/views/modal/marhun.blade.php index f338d72..321c937 100644 --- a/resources/views/modal/marhun.blade.php +++ b/resources/views/modal/marhun.blade.php @@ -193,10 +193,10 @@ $('#norujukan_modal').val(data.norujukan); $('#pinjaman_modal').val(data.pinjaman); $('#marhunModal').modal('show'); - + $('#tablehistorybayaran').DataTable().clear().destroy(); let table_bayaran_history = $('#tablehistorybayaran').DataTable(); - + $('#biasa').DataTable().clear().destroy(); let table_marhun = $('#biasa').DataTable(); @@ -207,7 +207,7 @@ `RM ${x.duit_masuk} `, ]).draw(false) }); - + data.marhun_details.forEach((x, index) => { table_marhun.row.add([ index + 1, @@ -222,20 +222,21 @@ }; document.addEventListener('DOMContentLoaded', function() { - - document.querySelectorAll('a.marhun-detail-link').forEach(x => x.addEventListener('click', showMarhunDetailModal)) - + + + $('#main-table').on('click', 'a.marhun-detail-link', function(e) { + showMarhunDetailModal(e) + }); + }); - + document.querySelector('#marhunModal .modal-footer button').addEventListener('click', function(e) { e.preventDefault(); $('#marhunModal').modal('hide'); - }); - + }); + document.querySelector('#marhunModal').addEventListener('hidden.bs.modal', function(e) { document.querySelector('#marhunModal .modal-header a[aria-controls="pills-marhun"]').click(); }); - - ') @endpush From d4573d78ac18d0eef5d2bad95fa5e59b2f281163 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Thu, 18 Jul 2024 09:15:20 +0800 Subject: [PATCH 02/18] Codebase update - Fix select sag to pay on multiple page not selected in checkout payment - Fix marhun modal data not display - Fix load upah tawarruq for jeniskeuntungan onepercent or asal - Add exception when billplz credential is incorrectly entered --- app/Http/Controllers/BayaranController.php | 39 +++++++++++++++- app/Services/BillplzService.php | 9 +++- app/Services/MarhunService.php | 37 +++++++-------- app/Services/PembiayaanService.php | 45 ++++++++++++++---- config/services.php | 4 +- .../includes/bayaran/pembayaransag.blade.php | 3 +- resources/views/includes/home.blade.php | 46 ++++++++++++++++--- .../table-pembiayaan-akan-dilelong.blade.php | 2 +- .../partials/table-pembiayaan.blade.php | 4 +- 9 files changed, 145 insertions(+), 44 deletions(-) diff --git a/app/Http/Controllers/BayaranController.php b/app/Http/Controllers/BayaranController.php index fe35372..9598d94 100644 --- a/app/Http/Controllers/BayaranController.php +++ b/app/Http/Controllers/BayaranController.php @@ -12,18 +12,22 @@ use Money\Money; class BayaranController extends Controller { + public function PembayaranAction(Request $request) { + $totalSagInCartInput = $request->totalSagInCartInput; $validated = $request->validate([ - 'chkboxsag' => 'required', + 'totalSagInCartInput' => 'required', ]); - $norujukanList = $request->chkboxsag; + $norujukanList = json_decode($request->totalSagInCartInput); $arraybayar = array_map(fn($x) => Http::arrahn()->get('/api/gadai/norujukan/' . $x)->json()[0][0], $norujukanList); + $arraybayar = $this->setUpahTawarruq($arraybayar); + $norujukanRecentlyAttemptPayment = array_map( fn($x) => Http::arrahn()->get('/portal/searchsagonline/', ['norujukan' => $x])->json(), $norujukanList @@ -83,6 +87,7 @@ class BayaranController extends Controller return Money::MYR($sum())->add($billPlzTransactionFee); }; + $bill = $billplzService->createBill([ $customerEmail, $customerPhoneNumber, @@ -281,4 +286,34 @@ class BayaranController extends Controller return view('includes.bayaran.senaraibayaransag', compact('belum_tebus', 'api_url')); } + + private function setUpahTawarruq($pembiayaan) + { + $getJenisKeuntungan = function($x){ + + $jenisKeuntungan = [ + '1' => 'onepercent', + '0' => 'asal', + ]; + + return $jenisKeuntungan[$x['tagbaru']]; + }; + + $getUpahTawarruqPerPembiayaan = function($x) use($getJenisKeuntungan){ + $jenisKeuntungan = $getJenisKeuntungan($x); + $upahTawarruq = Http::arrahn()->get('/api/upahtawarruq/'.$x['kodcaw'].'/'.$x['norujukan'], ['jeniskeuntungan' => $jenisKeuntungan])->json(); + + if($jenisKeuntungan == 'onepercent'){ + $x['upah_tawarruq'] = $upahTawarruq['pendapatan'] + $upahTawarruq['keuntungan']; + } + + if($jenisKeuntungan == 'asal'){ + $x['upah_tawarruq'] = $upahTawarruq; + } + + return $x; + }; + + return array_map($getUpahTawarruqPerPembiayaan, $pembiayaan); + } } diff --git a/app/Services/BillplzService.php b/app/Services/BillplzService.php index 1447b6a..68f25cb 100644 --- a/app/Services/BillplzService.php +++ b/app/Services/BillplzService.php @@ -48,7 +48,14 @@ class BillplzService $this->redirectUrl, ]; - return $this->client->bill()->create(...$composed_data)->toArray(); + + try{ + return $this->client->bill()->create(...$composed_data)->toArray(); + } catch(\Exception $e){ + if($e->getCode() === 404){ + throw new \ErrorException('Please check your billplz payment gateway collection. Ensure that api_key, x_signature, and collection_id are correctly entered'); + }; + } } public function redirect($request) diff --git a/app/Services/MarhunService.php b/app/Services/MarhunService.php index 223b4a5..b114851 100644 --- a/app/Services/MarhunService.php +++ b/app/Services/MarhunService.php @@ -2,7 +2,6 @@ namespace App\Services; -use Illuminate\Http\Client\Pool; use Illuminate\Support\Facades\Http; class MarhunService @@ -15,31 +14,29 @@ class MarhunService public function getMarhunDetails() { - $getMarhunDetails = function () { - return Http::pool(function (Pool $pool) { - foreach ($this->norujukanList as $norujukan) { - $pool->get(config('api.url') . '/api/marhun/' . $norujukan); - } - }); + $getMarhunDetails = function ($x) { + return Http::arrahn()->get('/api/marhun/' . $x)->json(); }; - - $marhunDetailsResponse = array_map(fn($x) => $x->json() == null ? [] : $x->Json(), $getMarhunDetails()); - $marhunDetailsResponse = array_map(fn($x) => array_merge([], ...$x), $marhunDetailsResponse); - - $formatMarhunDetailData = function ($x) { - $getMarhunTypeFullName = function ($code) { - - $marhun = Http::get(config('api.url') . '/api/jemas/nama_marhun', ['marhun' => $code])->json()['descpt']; - return $marhun; - }; - + + $getMarhunTypeFullName = function ($code) { + return Http::arrahn()->get('/api/jemas/nama_marhun', ['marhun' => $code['marhun']])->json()['descpt']; + }; + + $formatMarhunDetailData = function ($x) use($getMarhunTypeFullName) { return array_map(function ($y) use ($getMarhunTypeFullName) { - $y['marhun'] = $getMarhunTypeFullName($y['marhun']); + $y['marhun'] = $getMarhunTypeFullName($y); return $y; }, $x); }; - return array_map($formatMarhunDetailData, $marhunDetailsResponse); + $marhunDetailPipelines = [ + fn($x) => array_map($getMarhunDetails, $x), + fn($x) => array_map(fn($y) => $x == null ? [] : $y, $x), + fn($x) => array_map(fn($y) => array_merge([], ...$y), $x), + fn($x) => array_map($formatMarhunDetailData, $x), + ]; + + return array_reduce($marhunDetailPipelines, fn($x, $y) => $y($x), $this->norujukanList); } public static function from($norujukanList) diff --git a/app/Services/PembiayaanService.php b/app/Services/PembiayaanService.php index 5398c20..9f083b1 100644 --- a/app/Services/PembiayaanService.php +++ b/app/Services/PembiayaanService.php @@ -22,19 +22,48 @@ class PembiayaanService $getPembiayaan = fn() => (new InformationController())->pembiayaanakandilelong()->getData(); } - $pembiayaan = $this->formatPembiayaanData($getPembiayaan()); + $pembiayaan = array_filter($getPembiayaan(), fn($x) => $x->hargajualan != null || $x->hargajualan != 0); + $pembiayaan = $this->setUpahTawarruq($pembiayaan); + $pembiayaan = $this->formatPembiayaanData($pembiayaan); $pembiayaan = $this->attachMarhunModalData($pembiayaan); $pembiayaan = $this->checkPembiayaanPaymentDisabled($pembiayaan); return $pembiayaan; + } + private function setUpahTawarruq($pembiayaan) + { + $getJenisKeuntungan = function($x){ + + $jenisKeuntungan = [ + '1' => 'onepercent', + '0' => 'asal', + ]; + + return $jenisKeuntungan[$x->tagbaru]; + }; + + $getUpahTawarruqPerPembiayaan = function($x) use($getJenisKeuntungan){ + $jenisKeuntungan = $getJenisKeuntungan($x); + $upahTawarruq = Http::arrahn()->get('/api/upahtawarruq/'.$x->kodcaw.'/'.$x->norujukan, ['jeniskeuntungan' => $jenisKeuntungan])->json(); + + if($jenisKeuntungan == 'onepercent'){ + $x->upah_tawarruq = $upahTawarruq['pendapatan'] + $upahTawarruq['keuntungan']; + } + + if($jenisKeuntungan == 'asal'){ + $x->upah_tawarruq = $upahTawarruq; + } + + return $x; + }; + + return array_map($getUpahTawarruqPerPembiayaan, $pembiayaan); } private function formatPembiayaanData($pembiayaan) { - $allCawangan = Http::withOptions(['verify' => config('app.api_verify')]) - ->get(config('api.url') . '/api/cawangan') - ->json(); + $allCawangan = Http::arrahn()->get('/api/cawangan')->json(); $setCawanganFullName = function ($pembiayaan) use ($allCawangan) { $cawangan = array_filter($allCawangan, fn($x) => $x['kodcaw'] === $pembiayaan->kodcaw); @@ -42,8 +71,8 @@ class PembiayaanService return $pembiayaan; }; - $setKeuntunganFormatted = function ($pembiayaan) { - $pembiayaan->keuntungan_formatted = number_format((float) $pembiayaan->keuntungan, 2, '.', ''); + $setUpahTawarruqFormatted = function ($pembiayaan) { + $pembiayaan->upah_tawarruq_formatted = number_format((float) $pembiayaan->upah_tawarruq, 2, '.', ''); return $pembiayaan; }; @@ -61,9 +90,9 @@ class PembiayaanService return $pembiayaan; }; - $formatted = array_map(function ($x) use ($setCawanganFullName, $setKeuntunganFormatted, $setTarikhAkhir, $setTLelongFormatted) { + $formatted = array_map(function ($x) use ($setCawanganFullName, $setUpahTawarruqFormatted, $setTarikhAkhir, $setTLelongFormatted) { $x = $setCawanganFullName($x); - $x = $setKeuntunganFormatted($x); + $x = $setUpahTawarruqFormatted($x); $x = $setTarikhAkhir($x); $x = $setTLelongFormatted($x); return $x; diff --git a/config/services.php b/config/services.php index 1bde05b..833feeb 100644 --- a/config/services.php +++ b/config/services.php @@ -34,12 +34,12 @@ return [ 'production' => [ 'api_key' => env('BILLPLZ_PRODUCTION_API_KEY', 'f3e82fe1-a422-4660-97f0-65cc59ff6c47'), 'x_signature' => env('BILLPLZ_PRODUCTION_X_SIGNATURE', 'S-alZUbzmD2_TF3vmrRqgehQ'), - 'collection_id' => env('BILLPLZ_PRODUCTION_COLLECTION_ID', 'z0r4kjhi'), + 'collection_id' => env('BILLPLZ_SANDBOX_COLLECTION_ID', '5aosv2dg'), ], 'sandbox' => [ 'api_key' => env('BILLPLZ_SANDBOX_API_KEY', 'abecfd0c-98d8-4635-abc2-2fcba8c60c11'), 'x_signature' => env('BILLPLZ_SANDBOX_X_SIGNATURE', 'S-GWr7z03XjAhqPsFfu_H5nQ'), - 'collection_id' => env('BILLPLZ_SANDBOX_COLLECTION_ID', '5aosv2dg'), + 'collection_id' => env('BILLPLZ_PRODUCTION_COLLECTION_ID', 'z0r4kjhi'), ], ], diff --git a/resources/views/includes/bayaran/pembayaransag.blade.php b/resources/views/includes/bayaran/pembayaransag.blade.php index 592bee5..3926492 100644 --- a/resources/views/includes/bayaran/pembayaransag.blade.php +++ b/resources/views/includes/bayaran/pembayaransag.blade.php @@ -85,8 +85,9 @@ {{ $t_akhir }} @php - $upahtawarruq = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/upahtawarruq/'. $bayar['kodcaw'] . '/' . $bayar['norujukan'])->json(); + $upahtawarruq = $bayar['upah_tawarruq']; $upahtawarruq = floatval(str_replace(',','',$upahtawarruq)); + $totalupahasal = $totalupahasal + $upahtawarruq; diff --git a/resources/views/includes/home.blade.php b/resources/views/includes/home.blade.php index ef08b1f..39a3fcd 100644 --- a/resources/views/includes/home.blade.php +++ b/resources/views/includes/home.blade.php @@ -39,7 +39,7 @@
@csrf - @error('chkboxsag') + @error('totalSagInCart') @endsection diff --git a/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php b/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php index a7e4266..b4c6648 100644 --- a/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php +++ b/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php @@ -12,7 +12,7 @@ @foreach ($pembiayaan as $data) - disabled_payment ? 'disabled' : '' }} /> diff --git a/resources/views/includes/partials/table-pembiayaan.blade.php b/resources/views/includes/partials/table-pembiayaan.blade.php index efcc526..c059049 100644 --- a/resources/views/includes/partials/table-pembiayaan.blade.php +++ b/resources/views/includes/partials/table-pembiayaan.blade.php @@ -14,7 +14,7 @@ @foreach ($pembiayaan as $data) - disabled_payment ? 'disabled' : '' }} /> @@ -26,7 +26,7 @@ {{ $data->tempoh }} {{ $data->tarikh_akhir }} - {{ $data->keuntungan_formatted }} + {{ $data->upah_tawarruq_formatted }} {{ $data->cawangan_name }} @endforeach From 3385328504bf1932176ce38b744c12cd7dad4271 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Thu, 18 Jul 2024 12:15:24 +0800 Subject: [PATCH 03/18] Fix keuntungan formula for ujrah payment --- app/Http/Controllers/BayaranController.php | 2 +- app/Services/PembiayaanService.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/BayaranController.php b/app/Http/Controllers/BayaranController.php index 9598d94..01a9c23 100644 --- a/app/Http/Controllers/BayaranController.php +++ b/app/Http/Controllers/BayaranController.php @@ -304,7 +304,7 @@ class BayaranController extends Controller $upahTawarruq = Http::arrahn()->get('/api/upahtawarruq/'.$x['kodcaw'].'/'.$x['norujukan'], ['jeniskeuntungan' => $jenisKeuntungan])->json(); if($jenisKeuntungan == 'onepercent'){ - $x['upah_tawarruq'] = $upahTawarruq['pendapatan'] + $upahTawarruq['keuntungan']; + $x['upah_tawarruq'] = $upahTawarruq['keuntungan'] + $upahTawarruq['ujrah']; } if($jenisKeuntungan == 'asal'){ diff --git a/app/Services/PembiayaanService.php b/app/Services/PembiayaanService.php index 9f083b1..c8b37d4 100644 --- a/app/Services/PembiayaanService.php +++ b/app/Services/PembiayaanService.php @@ -48,7 +48,7 @@ class PembiayaanService $upahTawarruq = Http::arrahn()->get('/api/upahtawarruq/'.$x->kodcaw.'/'.$x->norujukan, ['jeniskeuntungan' => $jenisKeuntungan])->json(); if($jenisKeuntungan == 'onepercent'){ - $x->upah_tawarruq = $upahTawarruq['pendapatan'] + $upahTawarruq['keuntungan']; + $x->upah_tawarruq = $upahTawarruq['keuntungan'] + $upahTawarruq['ujrah']; } if($jenisKeuntungan == 'asal'){ From 429ade00f01f1add4fa9bbdb751b7a605280d883 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Thu, 18 Jul 2024 14:15:19 +0800 Subject: [PATCH 04/18] Add command to update transaction in arrahn master table, edit updateUnsuccess command to conform to psr-4 --- .../Commands/UpdateTransactionMaster.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/Console/Commands/UpdateTransactionMaster.php diff --git a/app/Console/Commands/UpdateTransactionMaster.php b/app/Console/Commands/UpdateTransactionMaster.php new file mode 100644 index 0000000..2a6a4c7 --- /dev/null +++ b/app/Console/Commands/UpdateTransactionMaster.php @@ -0,0 +1,50 @@ +get('/api/transaction/online/update')->json(); + + if($updateOnline == 'successful'){ + return 0; + }else{ + Log::error('Update transaction master failed'); + } + } +} From ff80f674d2d4d3c1d643992ca81b4a32bd05772e Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Thu, 18 Jul 2024 14:46:22 +0800 Subject: [PATCH 05/18] Update codebase - update env.example add important missing parameters - add config for lelong api - update InformationController to use lelong api config --- .env.example | 14 ++++++++------ app/Http/Controllers/InformationController.php | 7 ++----- config/api-lelong.php | 4 ++++ 3 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 config/api-lelong.php diff --git a/.env.example b/.env.example index 44853cd..9ad5c0d 100644 --- a/.env.example +++ b/.env.example @@ -3,16 +3,18 @@ APP_ENV=local APP_KEY= APP_DEBUG=true APP_URL=http://localhost +API_URL=http://localhost +API_LELONG_URL=http://localhost LOG_CHANNEL=stack LOG_LEVEL=debug -DB_CONNECTION=mysql -DB_HOST=127.0.0.1 -DB_PORT=3306 -DB_DATABASE=laravel -DB_USERNAME=root -DB_PASSWORD= +DB_CONNECTION_MYSQL=mysql +DB_HOST_MYSQL=127.0.0.1 +DB_PORT_MYSQL=3306 +DB_DATABASE_MYSQL=laravel +DB_USERNAME_MYSQL=root +DB_PASSWORD_MYSQL= BROADCAST_DRIVER=log CACHE_DRIVER=file diff --git a/app/Http/Controllers/InformationController.php b/app/Http/Controllers/InformationController.php index 9a23d3b..ce1d23c 100644 --- a/app/Http/Controllers/InformationController.php +++ b/app/Http/Controllers/InformationController.php @@ -41,8 +41,7 @@ class InformationController extends Controller if(isset($CustomerInfo['lelong'])){ if(sizeof($CustomerInfo['lelong']) > 0){ foreach($CustomerInfo['lelong'] as $index=>$lelong){ - // $array_lelong = Http::withOptions(['verify' => config('app.api_verify')])->get('https://adminbid.arrahn.com.my/api/portalApi',['norujukan' => $lelong['norujukan']])->json(); - $array_lelong = Http::withOptions(['verify' => config('app.api_verify')])->get('https://niklah.arrahn.com.my/api/portalApi',['norujukan' => $lelong['norujukan']])->json(); + $array_lelong = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api-lelong.url') . '/api/portalApi',['norujukan' => $lelong['norujukan']])->json(); if($array_lelong['lelong'] !== null){ $CustomerInfo['lelong'][$index] = collect($lelong)->merge($array_lelong['lelong'])->toArray(); @@ -89,8 +88,7 @@ class InformationController extends Controller if(isset($CustomerInfo['lelong'])){ if(sizeof($CustomerInfo['lelong']) > 0){ foreach($CustomerInfo['lelong'] as $index=>$lel){ - $array_lelong = Http::withOptions(['verify' => config('app.api_verify')])->get('https://niklah.arrahn.com.my/api/portalApi',['norujukan' => $lel['norujukan']])->json(); - // $array_lelong = Http::withOptions(['verify' => config('app.api_verify')])->get('http://lelong.test/api/portalApi/',['norujukan' => $lel['norujukan']]); + $array_lelong = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api-lelong.url') . '/api/portalApi',['norujukan' => $lel['norujukan']])->json(); if($array_lelong['lelong'] !== null){ $CustomerInfo['lelong'][$index] = collect($lel)->merge($array_lelong['lelong'])->toArray(); } @@ -112,4 +110,3 @@ class InformationController extends Controller return view('auth.termasyarat', compact('termasyarat')); } } - diff --git a/config/api-lelong.php b/config/api-lelong.php new file mode 100644 index 0000000..6114358 --- /dev/null +++ b/config/api-lelong.php @@ -0,0 +1,4 @@ + env('API_LELONG_URL', 'https://niklah.arrahn.com.my') +]; From 772db802827076be9e575eb8d62e7986575e3d77 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Fri, 19 Jul 2024 08:45:20 +0800 Subject: [PATCH 06/18] Fix response status checking --- app/Console/Commands/UpdateTransactionMaster.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/UpdateTransactionMaster.php b/app/Console/Commands/UpdateTransactionMaster.php index 2a6a4c7..37866db 100644 --- a/app/Console/Commands/UpdateTransactionMaster.php +++ b/app/Console/Commands/UpdateTransactionMaster.php @@ -41,7 +41,7 @@ class UpdateTransactionMaster extends Command { $updateOnline = Http::arrahn()->get('/api/transaction/online/update')->json(); - if($updateOnline == 'successful'){ + if($updateOnline == 'success'){ return 0; }else{ Log::error('Update transaction master failed'); From 40bdf870b96a587f35bf4dcd693079fabed6a780 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Fri, 19 Jul 2024 09:36:33 +0800 Subject: [PATCH 07/18] Change default url for API_LELONG_URL in .env.example --- .env.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 9ad5c0d..a42d7e0 100644 --- a/.env.example +++ b/.env.example @@ -3,8 +3,8 @@ APP_ENV=local APP_KEY= APP_DEBUG=true APP_URL=http://localhost -API_URL=http://localhost -API_LELONG_URL=http://localhost +API_URL=http://api_arrahn.test +API_LELONG_URL=https://niklah.arrahn.com.my LOG_CHANNEL=stack LOG_LEVEL=debug From 8b40d304310302f37cefe794a8e277ff160f4a20 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Fri, 19 Jul 2024 09:39:31 +0800 Subject: [PATCH 08/18] Skip assign lelong whenever api lelong returns null response if no lelong data for norujukan --- app/Http/Controllers/InformationController.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/InformationController.php b/app/Http/Controllers/InformationController.php index ce1d23c..ba8b16a 100644 --- a/app/Http/Controllers/InformationController.php +++ b/app/Http/Controllers/InformationController.php @@ -41,7 +41,11 @@ class InformationController extends Controller if(isset($CustomerInfo['lelong'])){ if(sizeof($CustomerInfo['lelong']) > 0){ foreach($CustomerInfo['lelong'] as $index=>$lelong){ - $array_lelong = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api-lelong.url') . '/api/portalApi',['norujukan' => $lelong['norujukan']])->json(); + $array_lelong = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api-lelong.url') . '/api/portalApi',['norujukan' => $lelong['norujukan']])->json(); + + if($array_lelong === null){ + continue; + } if($array_lelong['lelong'] !== null){ $CustomerInfo['lelong'][$index] = collect($lelong)->merge($array_lelong['lelong'])->toArray(); @@ -89,6 +93,11 @@ class InformationController extends Controller if(sizeof($CustomerInfo['lelong']) > 0){ foreach($CustomerInfo['lelong'] as $index=>$lel){ $array_lelong = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api-lelong.url') . '/api/portalApi',['norujukan' => $lel['norujukan']])->json(); + + if($array_lelong === null){ + continue; + } + if($array_lelong['lelong'] !== null){ $CustomerInfo['lelong'][$index] = collect($lel)->merge($array_lelong['lelong'])->toArray(); } From 29c1d42891b99d239d1491e76d22a27dd79a2008 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Fri, 19 Jul 2024 10:03:04 +0800 Subject: [PATCH 09/18] Filter out lelong that only have hargajualan that is null --- app/Http/Controllers/HomeController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 1063e4c..35a472f 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -36,6 +36,9 @@ class HomeController extends Controller ->json(); ['gadai' => $customer_gadai, 'lelong' => $customer_lelong] = $customerInfo; + + // only get lelong that is harga jualan that is not null or 0 + $customer_lelong = array_filter($customer_lelong, fn($x) => $x['hargajualan'] != null && $x['hargajualan'] != 0); $formatMoney = fn($x) => number_format($x, 2); $getTotal = fn($x) => array_reduce($x, fn($accumulator, $current_item) => $accumulator + $current_item['bakipjm'], 0); From 23df3df81c6900c2212b7a0c96d4267487fe3115 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Fri, 19 Jul 2024 10:03:25 +0800 Subject: [PATCH 10/18] Reformat code --- app/Services/PembiayaanService.php | 70 +++++++++++++++--------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/app/Services/PembiayaanService.php b/app/Services/PembiayaanService.php index c8b37d4..00346a2 100644 --- a/app/Services/PembiayaanService.php +++ b/app/Services/PembiayaanService.php @@ -22,8 +22,8 @@ class PembiayaanService $getPembiayaan = fn() => (new InformationController())->pembiayaanakandilelong()->getData(); } - $pembiayaan = array_filter($getPembiayaan(), fn($x) => $x->hargajualan != null || $x->hargajualan != 0); - $pembiayaan = $this->setUpahTawarruq($pembiayaan); + $pembiayaan = array_filter($getPembiayaan(), fn($x) => $x->hargajualan != null || $x->hargajualan != 0); + $pembiayaan = $this->setUpahTawarruq($pembiayaan); $pembiayaan = $this->formatPembiayaanData($pembiayaan); $pembiayaan = $this->attachMarhunModalData($pembiayaan); $pembiayaan = $this->checkPembiayaanPaymentDisabled($pembiayaan); @@ -33,32 +33,32 @@ class PembiayaanService private function setUpahTawarruq($pembiayaan) { - $getJenisKeuntungan = function($x){ + $getJenisKeuntungan = function ($x) { - $jenisKeuntungan = [ - '1' => 'onepercent', - '0' => 'asal', - ]; + $jenisKeuntungan = [ + '1' => 'onepercent', + '0' => 'asal', + ]; - return $jenisKeuntungan[$x->tagbaru]; - }; + return $jenisKeuntungan[$x->tagbaru]; + }; - $getUpahTawarruqPerPembiayaan = function($x) use($getJenisKeuntungan){ - $jenisKeuntungan = $getJenisKeuntungan($x); - $upahTawarruq = Http::arrahn()->get('/api/upahtawarruq/'.$x->kodcaw.'/'.$x->norujukan, ['jeniskeuntungan' => $jenisKeuntungan])->json(); + $getUpahTawarruqPerPembiayaan = function ($x) use ($getJenisKeuntungan) { + $jenisKeuntungan = $getJenisKeuntungan($x); + $upahTawarruq = Http::arrahn()->get('/api/upahtawarruq/' . $x->kodcaw . '/' . $x->norujukan, ['jeniskeuntungan' => $jenisKeuntungan])->json(); - if($jenisKeuntungan == 'onepercent'){ - $x->upah_tawarruq = $upahTawarruq['keuntungan'] + $upahTawarruq['ujrah']; - } + if ($jenisKeuntungan == 'onepercent') { + $x->upah_tawarruq = $upahTawarruq['keuntungan'] + $upahTawarruq['ujrah']; + } - if($jenisKeuntungan == 'asal'){ - $x->upah_tawarruq = $upahTawarruq; - } + if ($jenisKeuntungan == 'asal') { + $x->upah_tawarruq = $upahTawarruq; + } - return $x; - }; + return $x; + }; - return array_map($getUpahTawarruqPerPembiayaan, $pembiayaan); + return array_map($getUpahTawarruqPerPembiayaan, $pembiayaan); } private function formatPembiayaanData($pembiayaan) @@ -100,7 +100,7 @@ class PembiayaanService return $formatted; } - + private function attachMarhunModalData($pembiayaan) { $marhunModalData = $this->getMarhunModalData($pembiayaan); @@ -145,7 +145,7 @@ class PembiayaanService $marhunDetails, $bayaranHistoryDetails, ); - + } private function getNorujukanRecentlyAttemptPayment($norujukanList) @@ -194,24 +194,23 @@ class PembiayaanService }; $pembiayaanAkanDilelong = array_filter($getPembiayaanAkanDilelong(), $isCurrentDateGreaterThanEqual3DaysBeforeLelong); - + $norujukanAkanDilelong = array_map(fn($x) => $x->norujukan, $pembiayaanAkanDilelong); - - $setDefaultFasaIfNotAvailable = function($x){ - if(! isset($x->fasa)){ + + $setDefaultFasaIfNotAvailable = function ($x) { + if (!isset($x->fasa)) { $x->fasa = 1; } return $x; }; - + $pembiayaanWithFasa = array_map($setDefaultFasaIfNotAvailable, $getPembiayaanAkanDilelong()); $pembiayaanInFasa2 = array_filter($pembiayaanWithFasa, fn($x) => $x->fasa == 2); $norujukanInFasa2 = array_map(fn($x) => $x->norujukan, $pembiayaanInFasa2); - + $getPayableUjrahBranches = fn() => Http::arrahn()->get('/api/payable-ujrah-branches')->json(); $branchesNotPermitPaymentUjrah = array_filter($getPayableUjrahBranches(), fn($x) => $x['gadaian_ujrah_payable'] == 0); - $kodCawanganBranchesNotPermitPaymentUjrah = array_map(fn($x) => $x['kodcaw'], $branchesNotPermitPaymentUjrah); - + $kodCawanganBranchesNotPermitPaymentUjrah = array_map(fn($x) => $x['kodcaw'], $branchesNotPermitPaymentUjrah); $isNorujukanPaymentRecentlyAttempted = function ($x) use ($norujukanRecentlyAttemptPayment) { return in_array($x->norujukan, $norujukanRecentlyAttemptPayment); @@ -228,17 +227,16 @@ class PembiayaanService $isNorujukanIsInFasa2 = function ($x) use ($norujukanInFasa2) { return in_array($x->norujukan, $norujukanInFasa2); }; - + $isCawanganNotPermitUjrahPayment = function ($x) use ($kodCawanganBranchesNotPermitPaymentUjrah, $isNorujukanUjrah) { - - if($isNorujukanUjrah($x)){ + + if ($isNorujukanUjrah($x)) { return in_array($x->kodcaw, $kodCawanganBranchesNotPermitPaymentUjrah); } - + return false; }; - return array_map(function ($x) use ($isNorujukanPaymentRecentlyAttempted, $isNorujukanAkanDilelong, $isNorujukanIsInFasa2, $isCawanganNotPermitUjrahPayment) { $x->disabled_payment = false; From 3b024dbddce2c76061f3fe5877e43e11a715b9c5 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Fri, 19 Jul 2024 11:41:42 +0800 Subject: [PATCH 11/18] Sort billplz review data date descending --- app/Services/BillplzService.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Services/BillplzService.php b/app/Services/BillplzService.php index 68f25cb..74d665a 100644 --- a/app/Services/BillplzService.php +++ b/app/Services/BillplzService.php @@ -3,6 +3,7 @@ namespace App\Services; use Billplz\Client; +use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Http; @@ -93,7 +94,13 @@ class BillplzService public function getBillplzTransactionReview($date) { + $date = Carbon::now()->subDays(8)->toDateString(); $arrahnTransactions = $this->getArrahnTransactions($date); + + // sort array by tarikh desc and masa key desc + array_multisort(array_column($arrahnTransactions, 'tarikh'), SORT_DESC, array_column($arrahnTransactions, 'masa'), SORT_DESC, $arrahnTransactions); + + $arrahnTransactionsGroupedByBill = collect($arrahnTransactions)->groupBy('billplz_id'); $billplzID = $arrahnTransactionsGroupedByBill->keys(); $billplzTransactions = $this->getTransactions($date); From 7226b63a4c27e8cf2b0b1a59c5aecdd75fcc1634 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Fri, 19 Jul 2024 11:57:31 +0800 Subject: [PATCH 12/18] Add masa attempt baya and masa attempt bayar for billplz transaction review --- app/Services/BillplzService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Services/BillplzService.php b/app/Services/BillplzService.php index 74d665a..6609b51 100644 --- a/app/Services/BillplzService.php +++ b/app/Services/BillplzService.php @@ -124,6 +124,8 @@ class BillplzService 'customer_name' => $transaction['customer_name'], 'status' => $transaction['status'], 'paid_at' => $transaction['paid_at'], + 'tarikh_attempt_bayar' => $transaction['tarikh'], + 'masa_attempt_bayar' => $transaction['masa'], 'portal' => $transaction['tagportal'] == 1 ? 'Arrahn Pay' : 'SPARE', ]; }); From 82a906ae1a9ebc208d6f2da809c68c3a18b2dbb3 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Thu, 25 Jul 2024 15:49:26 +0800 Subject: [PATCH 13/18] Add backend validation when customer attempt to pay. Blocks payment that should be disabled but passes the front end validations --- app/Http/Controllers/BayaranController.php | 80 ++++++------------- app/Http/Requests/PaymentRequest.php | 65 +++++++++++++++ .../CawanganPermitUjrahPayment.php | 61 ++++++++++++++ .../PaymentRules/NorujukanBukanFasa2.php | 58 ++++++++++++++ .../NorujukanContractNotExceed12Month.php | 45 +++++++++++ .../NorujukanNotAttemptPaymentRecently.php | 72 +++++++++++++++++ .../NorujukanTidakAkanDilelong.php | 64 +++++++++++++++ app/Rules/PaymentRules/PaymentNotUjrah.php | 50 ++++++++++++ .../PaymentRules/PilihMinimumSatuSAG.php | 44 ++++++++++ resources/views/includes/home.blade.php | 4 +- 10 files changed, 487 insertions(+), 56 deletions(-) create mode 100644 app/Http/Requests/PaymentRequest.php create mode 100644 app/Rules/PaymentRules/CawanganPermitUjrahPayment.php create mode 100644 app/Rules/PaymentRules/NorujukanBukanFasa2.php create mode 100644 app/Rules/PaymentRules/NorujukanContractNotExceed12Month.php create mode 100644 app/Rules/PaymentRules/NorujukanNotAttemptPaymentRecently.php create mode 100644 app/Rules/PaymentRules/NorujukanTidakAkanDilelong.php create mode 100644 app/Rules/PaymentRules/PaymentNotUjrah.php create mode 100644 app/Rules/PaymentRules/PilihMinimumSatuSAG.php diff --git a/app/Http/Controllers/BayaranController.php b/app/Http/Controllers/BayaranController.php index 01a9c23..654ad75 100644 --- a/app/Http/Controllers/BayaranController.php +++ b/app/Http/Controllers/BayaranController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Http\Requests\PaymentRequest; use App\Services\BillplzService; use Carbon\Carbon; use Illuminate\Http\Client\Pool; @@ -12,41 +13,13 @@ use Money\Money; class BayaranController extends Controller { - - public function PembayaranAction(Request $request) + public function PembayaranAction(PaymentRequest $request) { - $totalSagInCartInput = $request->totalSagInCartInput; - - $validated = $request->validate([ - 'totalSagInCartInput' => 'required', - ]); - - $norujukanList = json_decode($request->totalSagInCartInput); - - $arraybayar = array_map(fn($x) => Http::arrahn()->get('/api/gadai/norujukan/' . $x)->json()[0][0], $norujukanList); - - $arraybayar = $this->setUpahTawarruq($arraybayar); - - $norujukanRecentlyAttemptPayment = array_map( - fn($x) => Http::arrahn()->get('/portal/searchsagonline/', ['norujukan' => $x])->json(), - $norujukanList - ); - - $isNorujukanRecentlyAttemptPayment = in_array(true, $norujukanRecentlyAttemptPayment); - - if ($isNorujukanRecentlyAttemptPayment) { - return redirect()->route('home')->with('errorsagonline', 'Sila Tunggu Sebentar!'); - } - - $gadaiContractExceed12Month = array_filter($arraybayar, fn($x) => $x['tempoh'] >= 12); - - $isGadaiContractExceed12Month = sizeof($gadaiContractExceed12Month) > 0; - - if ($isGadaiContractExceed12Month) { - return redirect()->route('home')->with('error', 'SAG Yang Dipilih Akan/Telah Tamat Kontrak 12 Bulan. Sila Hadir Ke Kaunter Cawangan Untuk Pembayaran/Penebusan.'); - } - + $request->validated(); + + $arraybayar = $this->setUpahTawarruq($request->getPembiayaanFromNorujukan()); + return view('includes.bayaran.pembayaransag', compact('arraybayar')); } @@ -87,7 +60,6 @@ class BayaranController extends Controller return Money::MYR($sum())->add($billPlzTransactionFee); }; - $bill = $billplzService->createBill([ $customerEmail, $customerPhoneNumber, @@ -242,7 +214,7 @@ class BayaranController extends Controller public function successPayment(Request $request) { $transactionOnline = $request->transactionOnline; - + $arraygadai = array_map( fn($x) => Http::arrahn()->get('/api/gadai/norujukan/' . $x['norujukan'])->json()[0][0], $transactionOnline @@ -289,31 +261,31 @@ class BayaranController extends Controller private function setUpahTawarruq($pembiayaan) { - $getJenisKeuntungan = function($x){ + $getJenisKeuntungan = function ($x) { - $jenisKeuntungan = [ - '1' => 'onepercent', - '0' => 'asal', - ]; + $jenisKeuntungan = [ + '1' => 'onepercent', + '0' => 'asal', + ]; - return $jenisKeuntungan[$x['tagbaru']]; - }; + return $jenisKeuntungan[$x['tagbaru']]; + }; - $getUpahTawarruqPerPembiayaan = function($x) use($getJenisKeuntungan){ - $jenisKeuntungan = $getJenisKeuntungan($x); - $upahTawarruq = Http::arrahn()->get('/api/upahtawarruq/'.$x['kodcaw'].'/'.$x['norujukan'], ['jeniskeuntungan' => $jenisKeuntungan])->json(); + $getUpahTawarruqPerPembiayaan = function ($x) use ($getJenisKeuntungan) { + $jenisKeuntungan = $getJenisKeuntungan($x); + $upahTawarruq = Http::arrahn()->get('/api/upahtawarruq/' . $x['kodcaw'] . '/' . $x['norujukan'], ['jeniskeuntungan' => $jenisKeuntungan])->json(); - if($jenisKeuntungan == 'onepercent'){ - $x['upah_tawarruq'] = $upahTawarruq['keuntungan'] + $upahTawarruq['ujrah']; - } + if ($jenisKeuntungan == 'onepercent') { + $x['upah_tawarruq'] = $upahTawarruq['keuntungan'] + $upahTawarruq['ujrah']; + } - if($jenisKeuntungan == 'asal'){ - $x['upah_tawarruq'] = $upahTawarruq; - } + if ($jenisKeuntungan == 'asal') { + $x['upah_tawarruq'] = $upahTawarruq; + } - return $x; - }; + return $x; + }; - return array_map($getUpahTawarruqPerPembiayaan, $pembiayaan); + return array_map($getUpahTawarruqPerPembiayaan, $pembiayaan); } } diff --git a/app/Http/Requests/PaymentRequest.php b/app/Http/Requests/PaymentRequest.php new file mode 100644 index 0000000..e2212eb --- /dev/null +++ b/app/Http/Requests/PaymentRequest.php @@ -0,0 +1,65 @@ +selectedPembiayaan = $this->getPembiayaanFromNorujukan(); + $this->pembiayaanAkanDilelong = $this->getPembiayaanAkanDilelong(); + + return [ + 'totalSagInCartInput' => [ + new PilihMinimumSatuSAG, + new NorujukanTidakAkanDilelong($this->pembiayaanAkanDilelong), + new NorujukanBukanFasa2($this->pembiayaanAkanDilelong), + new NorujukanNotAttemptPaymentRecently, + new CawanganPermitUjrahPayment($this->selectedPembiayaan), + new PaymentNotUjrah($this->selectedPembiayaan), + new NorujukanContractNotExceed12Month($this->selectedPembiayaan), + ] + ]; + } + + public function getPembiayaanFromNorujukan() + { + $norujukanList = json_decode($this->totalSagInCartInput); + + return array_map(fn($x) => Http::arrahn()->get('/api/gadai/norujukan/' . $x)->json()[0][0], $norujukanList); + } + + public function getPembiayaanAkanDilelong() + { + return (new InformationController())->pembiayaanakandilelong()->getData(); + } +} diff --git a/app/Rules/PaymentRules/CawanganPermitUjrahPayment.php b/app/Rules/PaymentRules/CawanganPermitUjrahPayment.php new file mode 100644 index 0000000..b7ce8ca --- /dev/null +++ b/app/Rules/PaymentRules/CawanganPermitUjrahPayment.php @@ -0,0 +1,61 @@ +pembiayaan = $pembiayaan; + } + + /** + * Determine if the validation rule passes. + * + * @param string $attribute + * @param mixed $value + * @return bool + */ + public function passes($attribute, $value) + { + $getPayableUjrahBranches = fn() => Http::arrahn()->get('/api/payable-ujrah-branches')->json(); + $branchesNotPermitPaymentUjrah = array_filter($getPayableUjrahBranches(), fn($x) => $x['gadaian_ujrah_payable'] == 0); + $kodCawanganBranchesNotPermitPaymentUjrah = array_map(fn($x) => $x['kodcaw'], $branchesNotPermitPaymentUjrah); + + $isNorujukanUjrah = fn($x) => $x['tagbaru'] === 1 ? true : false; + + $isCawanganNotPermitUjrahPayment = function ($x) use ($kodCawanganBranchesNotPermitPaymentUjrah, $isNorujukanUjrah) { + + if ($isNorujukanUjrah($x)) { + return in_array($x['kodcaw'], $kodCawanganBranchesNotPermitPaymentUjrah); + } + + return false; + }; + + $cawanganNotPermitUjrahPayment = array_filter($this->pembiayaan, fn($x) => $isCawanganNotPermitUjrahPayment($x)); + + return sizeof($cawanganNotPermitUjrahPayment) == 0; + + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'Tidak dibenarkan pembayaran ujrah!'; + } +} diff --git a/app/Rules/PaymentRules/NorujukanBukanFasa2.php b/app/Rules/PaymentRules/NorujukanBukanFasa2.php new file mode 100644 index 0000000..7c984df --- /dev/null +++ b/app/Rules/PaymentRules/NorujukanBukanFasa2.php @@ -0,0 +1,58 @@ +pembiayaanAkanDilelong = $pembiayaanAkanDilelong; + } + + /** + * Determine if the validation rule passes. + * + * @param string $attribute + * @param mixed $value + * @return bool + */ + public function passes($attribute, $value) + { + $norujukanToPay = json_decode($value); + + $setDefaultFasaIfNotAvailable = function ($x) { + if (!isset($x->fasa)) { + $x->fasa = 1; + } + return $x; + }; + + $pembiayaanWithFasa = array_map($setDefaultFasaIfNotAvailable, $this->pembiayaanAkanDilelong); + $pembiayaanInFasa2 = array_filter($pembiayaanWithFasa, fn($x) => $x->fasa == 2); + $norujukanInFasa2 = array_map(fn($x) => $x->norujukan, $pembiayaanInFasa2); + + $pembiayaanFasa2 = array_filter($norujukanToPay, fn($x) => in_array($x, $norujukanInFasa2)); + + return sizeof($pembiayaanFasa2) == 0; + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'No pembiayaan dalam kategori fasa 2, sila ke kaunter'; + } +} diff --git a/app/Rules/PaymentRules/NorujukanContractNotExceed12Month.php b/app/Rules/PaymentRules/NorujukanContractNotExceed12Month.php new file mode 100644 index 0000000..e9a3adb --- /dev/null +++ b/app/Rules/PaymentRules/NorujukanContractNotExceed12Month.php @@ -0,0 +1,45 @@ +pembiayaan = $pembiayaan; + } + + /** + * Determine if the validation rule passes. + * + * @param string $attribute + * @param mixed $value + * @return bool + */ + public function passes($attribute, $value) + { + $gadaiContractExceed12Month = array_filter($this->pembiayaan, fn($x) => $x['tempoh'] >= 12); + + return sizeof($gadaiContractExceed12Month) == 0; + + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'SAG Yang Dipilih Akan/Telah Tamat Kontrak 12 Bulan. Sila Hadir Ke Kaunter Cawangan Untuk Pembayaran/Penebusan.'; + } +} diff --git a/app/Rules/PaymentRules/NorujukanNotAttemptPaymentRecently.php b/app/Rules/PaymentRules/NorujukanNotAttemptPaymentRecently.php new file mode 100644 index 0000000..7ebdde8 --- /dev/null +++ b/app/Rules/PaymentRules/NorujukanNotAttemptPaymentRecently.php @@ -0,0 +1,72 @@ +getNorujukanRecentlyAttemptPayment($norujukanToPay); + + return sizeof($norujukanRecentlyAttemptPayment) == 0; + + } + + private function getNorujukanRecentlyAttemptPayment($norujukanList) + { + $getRecentlyAttemptPayment = function () use ($norujukanList) { + return Http::pool(function (Pool $pool) use ($norujukanList) { + foreach ($norujukanList as $norujukan) { + $pool->get(config('api.url') . '/portal/searchsagonline/', ['norujukan' => $norujukan]); + } + }); + }; + + $recentlyAttemptPaymentResponse = array_map( + fn($x, $y) => ['norujukan' => $x, 'isRecentlyAttemptPayment' => $y->json()], + $norujukanList, + $getRecentlyAttemptPayment() + ); + + $filterRecentlyAttemptPayment = array_filter( + $recentlyAttemptPaymentResponse, + fn($x) => $x['isRecentlyAttemptPayment'] === true + ); + + return array_map(fn($x) => $x['norujukan'], $filterRecentlyAttemptPayment); + + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'Sila Tunggu Sebentar!'; + } +} diff --git a/app/Rules/PaymentRules/NorujukanTidakAkanDilelong.php b/app/Rules/PaymentRules/NorujukanTidakAkanDilelong.php new file mode 100644 index 0000000..5fa9d95 --- /dev/null +++ b/app/Rules/PaymentRules/NorujukanTidakAkanDilelong.php @@ -0,0 +1,64 @@ +pembiayaanAkanDilelong = $pembiayaanAkanDilelong; + } + + /** + * Determine if the validation rule passes. + * + * @param string $attribute + * @param mixed $value + * @return bool + */ + public function passes($attribute, $value) + { + + $norujukanToPay = json_decode($value); + + $isCurrentDateGreaterThanEqual3DaysBeforeLelong = function ($x) { + $tarikhLelong = Carbon::parse($x->t_lelong); + $currentDate = Carbon::now(); + + if ($currentDate->gte($tarikhLelong->subDays(3))) { + return true; + } + + return false; + + }; + + $dataFromPembiayaanAkanDilelong = array_filter($this->pembiayaanAkanDilelong, fn($x) => in_array($x->norujukan, $norujukanToPay)); + + $pembiayaanAkanDilelong = array_filter($dataFromPembiayaanAkanDilelong, $isCurrentDateGreaterThanEqual3DaysBeforeLelong); + + return sizeof($pembiayaanAkanDilelong) == 0; + + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'No pembiayaan akan dilelong, sila ke kaunter'; + } +} diff --git a/app/Rules/PaymentRules/PaymentNotUjrah.php b/app/Rules/PaymentRules/PaymentNotUjrah.php new file mode 100644 index 0000000..a8a5fae --- /dev/null +++ b/app/Rules/PaymentRules/PaymentNotUjrah.php @@ -0,0 +1,50 @@ +pembiayaan = $pembiayaan; + } + + /** + * Determine if the validation rule passes. + * + * @param string $attribute + * @param mixed $value + * @return bool + */ + public function passes($attribute, $value) + { + $norujukanToPay = json_decode($value); + + $isNorujukanUjrah = fn ($x) => $x['tagbaru'] === 1 ? true : false; + + $norujukanUjrah = array_filter($this->pembiayaan, fn($x) => $isNorujukanUjrah($x)); + + return sizeof($norujukanUjrah) == 0; + + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'Tidak dibenarkan pembayaran ujrah!'; + } +} diff --git a/app/Rules/PaymentRules/PilihMinimumSatuSAG.php b/app/Rules/PaymentRules/PilihMinimumSatuSAG.php new file mode 100644 index 0000000..d5a059d --- /dev/null +++ b/app/Rules/PaymentRules/PilihMinimumSatuSAG.php @@ -0,0 +1,44 @@ + 0; + + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'Sila pilih salah satu checkbox di atas terlebih dahulu!'; + } +} diff --git a/resources/views/includes/home.blade.php b/resources/views/includes/home.blade.php index 39a3fcd..5a5d6e6 100644 --- a/resources/views/includes/home.blade.php +++ b/resources/views/includes/home.blade.php @@ -39,12 +39,12 @@ @csrf - @error('totalSagInCart') + @error('totalSagInCartInput')