backend validation for arrahnpay
This commit is contained in:
@@ -86,6 +86,12 @@ class BayaranController extends Controller
|
|||||||
{
|
{
|
||||||
['email' => $customerEmail, 'notel' => $customerPhoneNumber, 'name' => $customerName, 'icno' => $customerIcno] = auth()->user()->toArray();
|
['email' => $customerEmail, 'notel' => $customerPhoneNumber, 'name' => $customerName, 'icno' => $customerIcno] = auth()->user()->toArray();
|
||||||
|
|
||||||
|
#Validate the request
|
||||||
|
$error = $this->validateRequest($request);
|
||||||
|
if ($error) {
|
||||||
|
return redirect()->route('buffer')->with(['errorvalidate' => $error]);
|
||||||
|
}
|
||||||
|
|
||||||
$bayaranArrahn = array_filter($request->txtjenisbayaran, fn($x) => $x == 'arrahn');
|
$bayaranArrahn = array_filter($request->txtjenisbayaran, fn($x) => $x == 'arrahn');
|
||||||
$bayaranOthers = array_filter($request->txtjenisbayaran, fn($x) => $x != 'arrahn');
|
$bayaranOthers = array_filter($request->txtjenisbayaran, fn($x) => $x != 'arrahn');
|
||||||
|
|
||||||
@@ -615,4 +621,82 @@ class BayaranController extends Controller
|
|||||||
|
|
||||||
return $exist_carts;
|
return $exist_carts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function validateRequest($request)
|
||||||
|
{
|
||||||
|
$CallableHttp = $request->txtcompany == 'pkb'
|
||||||
|
? Http::arrahn()
|
||||||
|
: Http::arrahn_koop();
|
||||||
|
|
||||||
|
if (
|
||||||
|
!is_array($request->txtnorujukanhidden) ||
|
||||||
|
!is_array($request->txtbayaranhidden) ||
|
||||||
|
!is_array($request->txtkodcawhidden) ||
|
||||||
|
count($request->txtnorujukanhidden) !== count($request->txtbayaranhidden) ||
|
||||||
|
count($request->txtnorujukanhidden) !== count($request->txtkodcawhidden)
|
||||||
|
) {
|
||||||
|
Log::error('Jumlah bayaran, norujukan dan kod cawangan tidak sepadan.', [
|
||||||
|
'txtnorujukanhidden' => $request->txtnorujukanhidden,
|
||||||
|
'txtbayaranhidden' => $request->txtbayaranhidden,
|
||||||
|
'txtkodcawhidden' => $request->txtkodcawhidden,
|
||||||
|
]);
|
||||||
|
return 'Sila Pilih Sekali Lagi.';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($request->txtnorujukanhidden as $index => $x) {
|
||||||
|
$array_gadai = $CallableHttp->get('/api/gadai/norujukan/' . $request->txtkodcawhidden[$index] . '/' . $x)->json();
|
||||||
|
|
||||||
|
if (empty($array_gadai)) {
|
||||||
|
Log::error('norujukan tidak dijumpai.', [
|
||||||
|
'norujukan' => $x,
|
||||||
|
'kodcaw' => $request->txtkodcawhidden[$index],
|
||||||
|
]);
|
||||||
|
|
||||||
|
return 'Sila Pilih Sekali lagi. Dan pastikan salah satu sahaja dipilih untuk ruangan PKB dan KOPKB.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$array_gadai = $array_gadai[0];
|
||||||
|
if (in_array($array_gadai['sttebus'], ['T', 'L'])) {
|
||||||
|
Log::error('Norujukan sudah ditebus.', [
|
||||||
|
'norujukan' => $x,
|
||||||
|
'kodcaw' => $request->txtkodcawhidden[$index],
|
||||||
|
]);
|
||||||
|
return 'Norujukan' . $x . ' sudah ditebus.';
|
||||||
|
}else{
|
||||||
|
$payment = (float) $request->txtbayaranhidden[$index];
|
||||||
|
$remain_loan = (float) $array_gadai['bakipjm'];
|
||||||
|
$nm = (float) $array_gadai['nilaimarhun'];
|
||||||
|
$profit = 0;
|
||||||
|
|
||||||
|
$jenisKeuntungan = $array_gadai['tagbaru'] == '1' ? 'onepercent' : 'asal';
|
||||||
|
|
||||||
|
$upahTawarruq = $CallableHttp
|
||||||
|
->get('/api/upahtawarruq/' . $array_gadai['kodcaw'] . '/' . $array_gadai['norujukan'], ['jeniskeuntungan' => $jenisKeuntungan])
|
||||||
|
->json();
|
||||||
|
|
||||||
|
if ($jenisKeuntungan == 'onepercent') {
|
||||||
|
$profit = $upahTawarruq['keuntungan'] + $upahTawarruq['ujrah'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($jenisKeuntungan == 'asal') {
|
||||||
|
$profit = $upahTawarruq;
|
||||||
|
}
|
||||||
|
|
||||||
|
$item = ($remain_loan - ($nm * 0.1) + $profit);
|
||||||
|
|
||||||
|
if ($payment > $item) {
|
||||||
|
return 'Baki Pembiayaan tidak boleh kurang 10% daripada Nilai Marhun!';
|
||||||
|
} else if ($payment < $profit && $profit !== 0.00) {
|
||||||
|
return 'Bayaran tidak boleh kurang daripada keuntungan semasa!';
|
||||||
|
}
|
||||||
|
else if ($payment == 0.00 && $profit == 0.00) {
|
||||||
|
return 'Bayaran tidak boleh dalam nilai 0.00';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,6 +151,16 @@
|
|||||||
</script>
|
</script>
|
||||||
@enderror
|
@enderror
|
||||||
|
|
||||||
|
@if (session('errorvalidate'))
|
||||||
|
<script>
|
||||||
|
Swal.fire(
|
||||||
|
"Pembayaran Gagal.",
|
||||||
|
"{{ session('errorvalidate') }}",
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
@endif
|
||||||
|
|
||||||
@if (\Session::has('error'))
|
@if (\Session::has('error'))
|
||||||
<script>
|
<script>
|
||||||
Swal.fire(
|
Swal.fire(
|
||||||
|
|||||||
@@ -68,6 +68,17 @@
|
|||||||
</script>
|
</script>
|
||||||
@enderror
|
@enderror
|
||||||
|
|
||||||
|
@if (session('errorvalidate'))
|
||||||
|
<script>
|
||||||
|
Swal.fire(
|
||||||
|
"Pembayaran Gagal.",
|
||||||
|
"{{ session('errorvalidate') }}",
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
|
||||||
@if (\Session::has('error'))
|
@if (\Session::has('error'))
|
||||||
<script>
|
<script>
|
||||||
Swal.fire(
|
Swal.fire(
|
||||||
|
|||||||
Reference in New Issue
Block a user