62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Rules\PaymentRules;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class CawanganPermitUjrahPayment implements Rule
|
|
{
|
|
public $pembiayaan;
|
|
|
|
/**
|
|
* Create a new rule instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($pembiayaan)
|
|
{
|
|
$this->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!';
|
|
}
|
|
}
|