91 lines
3.2 KiB
PHP
91 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Http\Controllers\InformationController;
|
|
use App\Models\CompanyStatus;
|
|
use App\Rules\PaymentRules\CawanganPermitUjrahPayment;
|
|
use App\Rules\PaymentRules\NorujukanBukanFasa2;
|
|
use App\Rules\PaymentRules\NorujukanContractNotExceed12Month;
|
|
use App\Rules\PaymentRules\NorujukanNotAttemptPaymentRecently;
|
|
use App\Rules\PaymentRules\NorujukanTidakAkanDilelong;
|
|
use App\Rules\PaymentRules\PaymentNotUjrah;
|
|
use App\Rules\PaymentRules\PilihMinimumSatuSAG;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class PaymentRequest extends FormRequest
|
|
{
|
|
public $selectedPembiayaan;
|
|
public $pembiayaanAkanDilelong;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
$this->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()
|
|
{
|
|
if(null !== $this->input('redirect_trolley') && $this->input('redirect_trolley') == 'trolley'){
|
|
return [];
|
|
}
|
|
|
|
$norujukanList = json_decode($this->totalSagInCartInput);
|
|
$syarikatList = json_decode($this->listSyarikatinCartInput);
|
|
|
|
$filterByStatus = function ($status) use ($norujukanList, $syarikatList) {
|
|
return array_filter(
|
|
array_map(function ($sag, $index) use ($syarikatList, $status) {
|
|
if (isset($syarikatList[$index]) && $syarikatList[$index] == $status) {
|
|
$HttpRequest = $status == CompanyStatus::COM_PKB ? Http::arrahn() : Http::arrahn_koop();
|
|
$array_temp = $HttpRequest->get('/api/gadai/norujukan/' . $sag)->json()[0][0] ?? null;
|
|
$array_temp['tag_syarikat'] = $status;
|
|
return $array_temp;
|
|
}
|
|
return null;
|
|
}, $norujukanList, array_keys($norujukanList))
|
|
);
|
|
};
|
|
|
|
$list_pkb = $filterByStatus(CompanyStatus::COM_PKB);
|
|
$list_koop = $filterByStatus(CompanyStatus::COM_KOOPPKB);
|
|
|
|
$array_merged_list = array_merge($list_pkb,$list_koop);
|
|
return $array_merged_list;
|
|
// return array_map(fn($x) => Http::arrahn()->get('/api/gadai/norujukan/' . $x)->json()[0][0], $norujukanList);
|
|
}
|
|
|
|
public function getPembiayaanAkanDilelong()
|
|
{
|
|
return (new InformationController())->pembiayaanakandilelong()->getData();
|
|
}
|
|
}
|