Load pembiayaan detail modal whenever user clicks. not loaded it all at page startup
This commit is contained in:
@@ -8,23 +8,15 @@ use Illuminate\Support\Facades\Http;
|
||||
|
||||
class BayaranHistoryService
|
||||
{
|
||||
public $norujukanList;
|
||||
public $norujukan;
|
||||
|
||||
public function __construct($norujukanList) {
|
||||
$this->norujukanList = $norujukanList;
|
||||
public function __construct($norujukan) {
|
||||
$this->norujukan = $norujukan;
|
||||
}
|
||||
|
||||
public function getBayaranHistory()
|
||||
{
|
||||
$getBayaranHistory = function () {
|
||||
return Http::pool(function (Pool $pool){
|
||||
foreach ($this->norujukanList as $norujukan) {
|
||||
$pool->get(config('api.url') . '/api/transaction/' . $norujukan);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$bayaranHistoryResponse = array_map(fn($x) => $x->json(), $getBayaranHistory());
|
||||
$bayaranHistory = Http::arrahn()->get('/api/transaction/online/query', ['date' => $this->norujukan])->json();
|
||||
|
||||
$formatBayaranHistoryData = function ($x) {
|
||||
if (sizeof($x) === 0) {
|
||||
@@ -41,12 +33,12 @@ class BayaranHistoryService
|
||||
}, $x);
|
||||
};
|
||||
|
||||
return array_map($formatBayaranHistoryData, $bayaranHistoryResponse);
|
||||
return $formatBayaranHistoryData($bayaranHistory);
|
||||
}
|
||||
|
||||
public static function from($norujukanList)
|
||||
public static function from($norujukan)
|
||||
{
|
||||
return new static($norujukanList);
|
||||
return new static($norujukan);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ use Illuminate\Support\Facades\Http;
|
||||
|
||||
class MarhunService
|
||||
{
|
||||
public $norujukanList;
|
||||
public $norujukan;
|
||||
|
||||
public function __construct($norujukanList) {
|
||||
$this->norujukanList = $norujukanList;
|
||||
public function __construct($norujukan) {
|
||||
$this->norujukan = $norujukan;
|
||||
}
|
||||
|
||||
public function getMarhunDetails()
|
||||
@@ -30,18 +30,18 @@ class MarhunService
|
||||
};
|
||||
|
||||
$marhunDetailPipelines = [
|
||||
fn($x) => array_map($getMarhunDetails, $x),
|
||||
fn($x) => array_map(fn($y) => $x == null ? [] : $y, $x),
|
||||
fn($x) => $getMarhunDetails($x),
|
||||
fn($x) => $x == null ? [] : $x,
|
||||
fn($x) => array_map(fn($y) => array_merge([], ...$y), $x),
|
||||
fn($x) => array_map($formatMarhunDetailData, $x),
|
||||
fn($x) => $formatMarhunDetailData($x),
|
||||
];
|
||||
|
||||
return array_reduce($marhunDetailPipelines, fn($x, $y) => $y($x), $this->norujukanList);
|
||||
return array_reduce($marhunDetailPipelines, fn($x, $y) => $y($x), $this->norujukan);
|
||||
}
|
||||
|
||||
public static function from($norujukanList)
|
||||
public static function from($norujukan)
|
||||
{
|
||||
return new static($norujukanList);
|
||||
return new static($norujukan);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ class PembiayaanService
|
||||
$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;
|
||||
@@ -101,51 +100,28 @@ class PembiayaanService
|
||||
return $formatted;
|
||||
}
|
||||
|
||||
private function attachMarhunModalData($pembiayaan)
|
||||
public function getMarhunModalData($norujukan)
|
||||
{
|
||||
$marhunModalData = $this->getMarhunModalData($pembiayaan);
|
||||
|
||||
return array_map(
|
||||
function ($x, $y) {
|
||||
$x->marhunModalData = $y;
|
||||
$gadaianDetails = Http::arrahn()->get('/api/gadai/norujukan/' . $norujukan)->json()[0][0];
|
||||
|
||||
$attachCawanganName = function ($x) use ($gadaianDetails) {
|
||||
$x['cawangan_name'] = Http::arrahn()->get('/api/cawangan/detail/' . $gadaianDetails['kodcaw'])->json()[0]['cawangan'];
|
||||
return $x;
|
||||
},
|
||||
$pembiayaan,
|
||||
$marhunModalData,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
public function getMarhunModalData($pembiayaan)
|
||||
{
|
||||
$norujukanList = array_map(fn($x) => $x->norujukan, $pembiayaan);
|
||||
$gadaianDetails = $attachCawanganName($gadaianDetails);
|
||||
|
||||
$marhunDetails = MarhunService::from($norujukanList)->getMarhunDetails();
|
||||
$marhunDetails = MarhunService::from($norujukan)->getMarhunDetails();
|
||||
|
||||
$bayaranHistoryDetails = BayaranHistoryService::from($norujukanList)->getBayaranHistory();
|
||||
$bayaranHistoryDetails = BayaranHistoryService::from($norujukan)->getBayaranHistory();
|
||||
|
||||
return array_map(
|
||||
fn($x, $y, $z) => [
|
||||
'nilaimarhun' => $x->nilaimarhun,
|
||||
'berat' => $x->berat,
|
||||
'bakiupah' => $x->bakiupah,
|
||||
'pinjaman' => $x->pinjaman,
|
||||
'bakipjm' => $x->bakipjm,
|
||||
'taglel' => $x->taglel,
|
||||
'marhun' => $x->marhun,
|
||||
'pinjaman' => $x->pinjaman,
|
||||
'norujukan' => $x->norujukan,
|
||||
'hargajualan' => $x->hargajualan,
|
||||
'kodcaw' => $x->kodcaw,
|
||||
'tempoh' => $x->tempoh,
|
||||
'cawangan_name' => $x->cawangan_name,
|
||||
'marhun_details' => $y,
|
||||
'bayaran_history' => $z,
|
||||
],
|
||||
$pembiayaan,
|
||||
$marhunDetails,
|
||||
$bayaranHistoryDetails,
|
||||
);
|
||||
|
||||
return [
|
||||
'gadaianDetails' => $gadaianDetails,
|
||||
'marhunDetails' => $marhunDetails,
|
||||
'bayaranHistoryDetails' => $bayaranHistoryDetails,
|
||||
];
|
||||
}
|
||||
|
||||
private function getNorujukanRecentlyAttemptPayment($norujukanList)
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<a href="#" class="marhun-detail-link">
|
||||
<span class="text-sm text-info"
|
||||
data-marhun-modal="{{ json_encode($data->marhunModalData) }}">{{ $data->norujukan }}</span>
|
||||
<span class="text-sm text-info">{{ $data->norujukan }}</span>
|
||||
</a>
|
||||
</td>
|
||||
<td>{{ $data->t_lelong_formatted }}</td>
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<a href="#" class="marhun-detail-link">
|
||||
<span class="text-sm text-info"
|
||||
data-marhun-modal="{{ json_encode($data->marhunModalData) }}">{{ $data->norujukan }}</span>
|
||||
<span class="text-sm text-info">{{ $data->norujukan }}</span>
|
||||
</a>
|
||||
</td>
|
||||
<td class="hide-xs">{{ $data->tempoh }}</td>
|
||||
|
||||
@@ -169,38 +169,41 @@
|
||||
|
||||
@push('additional_js_scripts')
|
||||
<script>
|
||||
const showMarhunDetailModal = function(event) {
|
||||
const showMarhunDetailModal = async function(event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
const norujukan = event.target.innerHTML;
|
||||
|
||||
const data = await fetch('/api/pembiayaan-modal-data/' + norujukan).then(x => x.json());
|
||||
|
||||
const formatter = new Intl.NumberFormat('en-US', {
|
||||
minimumFractionDigits: 2
|
||||
});
|
||||
|
||||
let data = JSON.parse(event.target.dataset.marhunModal);
|
||||
|
||||
$('#pembiayaan').text('RM' + formatter.format(data.pinjaman));
|
||||
$('#bpembiayaan').text('RM' + formatter.format(data.bakipjm));
|
||||
$('#nm').text('RM' + formatter.format(data.nilaimarhun));
|
||||
$('#berat').text(data.berat + 'g');
|
||||
$('#koskeun').text('RM' + formatter.format(data.bakiupah));
|
||||
$('#norujukan').text(data.norujukan);
|
||||
$('#tempoh').text(data.tempoh);
|
||||
$('#namacaw').text(data.cawangan_name);
|
||||
$('#pemb').text('RM ' + data.pinjaman);
|
||||
$('#bpemb').text('RM ' + data.bakipjm);
|
||||
$('#statuslelong').text(data.taglel === 1 ? 'Akan Dilelong' : '-');
|
||||
$('#norujukan_modal').val(data.norujukan);
|
||||
$('#pinjaman_modal').val(data.pinjaman);
|
||||
$('#pembiayaan').text('RM' + formatter.format(data.gadaianDetails.pinjaman));
|
||||
$('#bpembiayaan').text('RM' + formatter.format(data.gadaianDetails.bakipjm));
|
||||
$('#nm').text('RM' + formatter.format(data.gadaianDetails.nilaimarhun));
|
||||
$('#berat').text(data.gadaianDetails.berat + 'g');
|
||||
$('#koskeun').text('RM' + formatter.format(data.gadaianDetails.bakiupah));
|
||||
$('#norujukan').text(data.gadaianDetails.norujukan);
|
||||
$('#tempoh').text(data.gadaianDetails.tempoh);
|
||||
$('#namacaw').text(data.gadaianDetails.cawangan_name);
|
||||
$('#pemb').text('RM ' + data.gadaianDetails.pinjaman);
|
||||
$('#bpemb').text('RM ' + data.gadaianDetails.bakipjm);
|
||||
$('#statuslelong').text(data.gadaianDetails.taglel === 1 ? 'Akan Dilelong' : '-');
|
||||
$('#norujukan_modal').val(data.gadaianDetails.norujukan);
|
||||
$('#pinjaman_modal').val(data.gadaianDetails.pinjaman);
|
||||
$('#marhunModal').modal('show');
|
||||
|
||||
|
||||
$('#tablehistorybayaran').DataTable().clear().destroy();
|
||||
let table_bayaran_history = $('#tablehistorybayaran').DataTable();
|
||||
|
||||
$('#biasa').DataTable().clear().destroy();
|
||||
let table_marhun = $('#biasa').DataTable();
|
||||
|
||||
data.bayaran_history.forEach((x, index) => {
|
||||
data.bayaranHistoryDetails.forEach((x, index) => {
|
||||
table_bayaran_history.row.add([
|
||||
index + 1,
|
||||
x.created_at,
|
||||
@@ -208,7 +211,7 @@
|
||||
]).draw(false)
|
||||
});
|
||||
|
||||
data.marhun_details.forEach((x, index) => {
|
||||
data.marhunDetails.forEach((x, index) => {
|
||||
table_marhun.row.add([
|
||||
index + 1,
|
||||
x.marhun,
|
||||
|
||||
@@ -4,6 +4,7 @@ use App\Http\Controllers\BillplzTransactionReviewController;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\BillplzController;
|
||||
use App\Services\PembiayaanService;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -23,3 +24,5 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
|
||||
Route::get('/billplz', BillplzController::class);
|
||||
Route::get('/billplz-transaction-review', [BillplzTransactionReviewController::class, 'index']);
|
||||
Route::get('/billplz-transaction-review/{bill_id}', [BillplzTransactionReviewController::class, 'show']);
|
||||
|
||||
Route::get('/pembiayaan-modal-data/{norujukan}', [PembiayaanService::class, 'getMarhunModalData']);
|
||||
|
||||
Reference in New Issue
Block a user