diff --git a/app/Http/Controllers/FetchLoanRemainingController.php b/app/Http/Controllers/FetchLoanRemainingController.php new file mode 100644 index 0000000..74bff4c --- /dev/null +++ b/app/Http/Controllers/FetchLoanRemainingController.php @@ -0,0 +1,167 @@ +validate([ + 'passport_serie' => ['required', 'string', Rule::in(array_keys(PassportRepo::values()))], + 'passport_id' => ['required', 'numeric', 'digits:6'], + 'account_number' => ['required', 'string', 'max:255'], + ]); + + if (app()->isLocal()) { + return $this->sampleResponse(); + } + + $curl = curl_init(); + + curl_setopt_array($curl, [ + CURLOPT_URL => 'http://10.3.158.102:9999/api/loaninfo', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_POSTFIELDS => sprintf(' + { + "idSeria": "%s", + "idNo": "%s", + "accountCode": "%s" + } + ', + $request->passport_serie, + $request->passport_id, + $request->account_number, + ), + CURLOPT_HTTPHEADER => [ + 'Authorization: Basic dGJ1c2VyOlFBWndzeDEyMw==', + 'Content-Type: application/json', + ], + ]); + + $response = curl_exec($curl); + + curl_close($curl); + + return $response; + } + + public function sampleResponse() + { + return response()->json([ + 'idSeria' => 'I-AS', + 'idNo' => '298119', + 'cardMaskNumber' => '993403******6836', + 'expDate' => '01/34', + 'clientType' => 'recipient', + 'clientName' => 'Penjiýew Mahtymguly Meretgulowiç', + 'depName' => 'Türkmenistanyň "Türkmenbaşy" paýdarlar täjirçilik banky', + 'cardPan' => '993403******6836', + 'cardAccountNumber' => '1304602071667', + 'errCode' => 0, + 'message' => 'YETIRILDI', + 'messageRu' => 'SUCCESS', + 'messageEn' => 'SUCCESS', + 'transactions' => [ + [ + 'trandate' => '2024-05-15', + 'currency' => 'TMT', + 'opersum' => 2220, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + [ + 'trandate' => '2024-05-31', + 'currency' => 'TMT', + 'opersum' => 2689, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + [ + 'trandate' => '2024-06-14', + 'currency' => 'TMT', + 'opersum' => 2220, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + [ + 'trandate' => '2024-06-28', + 'currency' => 'TMT', + 'opersum' => 2689, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + [ + 'trandate' => '2024-07-15', + 'currency' => 'TMT', + 'opersum' => 2220, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + [ + 'trandate' => '2024-07-31', + 'currency' => 'TMT', + 'opersum' => 2689, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + [ + 'trandate' => '2024-08-15', + 'currency' => 'TMT', + 'opersum' => 2220, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + [ + 'trandate' => '2024-08-30', + 'currency' => 'TMT', + 'opersum' => 2689, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + [ + 'trandate' => '2024-09-16', + 'currency' => 'TMT', + 'opersum' => 2220, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + [ + 'trandate' => '2024-09-30', + 'currency' => 'TMT', + 'opersum' => 2689, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + [ + 'trandate' => '2024-10-15', + 'currency' => 'TMT', + 'opersum' => 2220, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + [ + 'trandate' => '2024-10-31', + 'currency' => 'TMT', + 'opersum' => 2689, + 'actionName' => 'Зачисление заработной платы организаций', + 'opername' => 'Дополнительный взнос', + ], + ], + ]); + } +} diff --git a/app/Nova/Resources/Order/Loan/Remaining/NovaLoanRemainingOrder.php b/app/Nova/Resources/Order/Loan/Remaining/NovaLoanRemainingOrder.php index 67d01ea..d9c395a 100644 --- a/app/Nova/Resources/Order/Loan/Remaining/NovaLoanRemainingOrder.php +++ b/app/Nova/Resources/Order/Loan/Remaining/NovaLoanRemainingOrder.php @@ -35,7 +35,7 @@ class NovaLoanRemainingOrder extends Resource * @var array */ public static $search = [ - 'account_number' + 'account_number', ]; /** @@ -74,7 +74,7 @@ class NovaLoanRemainingOrder extends Resource NovaCustomHtml::make(__('Karz taryhy'), 'loan_history') ->onlyOnDetail() ->canSeeWhen('systemUser', $this) - ->html(view('orders.loan.mobile.loan-history', [ + ->html(view('orders.loan.mobile.loan-remaining', [ 'resource' => $this, ])->render()), ]), diff --git a/resources/js/vendor/nova/js/additional.js b/resources/js/vendor/nova/js/additional.js index 0749c6f..fc3b356 100644 --- a/resources/js/vendor/nova/js/additional.js +++ b/resources/js/vendor/nova/js/additional.js @@ -3,6 +3,31 @@ function csrf_token() return document.querySelector('meta[name="csrf-token"]')?.getAttribute('content'); } +async function fetchLoanRemaining(containerID, passport_serie, passport_id) { + if (! passport_serie || ! passport_id || ! account_number) { + Nova.error('Maglumat ýetmezçiligi bar'); + return; + } + + let cardHistoryDetailContainer = document.getElementById(containerID); + + let formData = new FormData(); + formData.append('passport_serie', passport_serie); + formData.append('passport_id', passport_id); + formData.append('account_number', account_number); + + Nova.$progress.start() + + Nova.request().post('/api/fetch-loan-remaining', formData).then(response => { + let result = response.data; + console.log(result) + }) + .catch(error => console.log('error', error)) + .finally(() => { + Nova.$progress.done() + }); +} + async function fetchLoanHistory(containerID, passport_serie, passport_id) { if (! passport_serie || ! passport_id) { Nova.error('Maglumat ýetmezçiligi bar'); diff --git a/resources/views/orders/loan/mobile/loan-remaining.blade.php b/resources/views/orders/loan/mobile/loan-remaining.blade.php new file mode 100644 index 0000000..ae9c439 --- /dev/null +++ b/resources/views/orders/loan/mobile/loan-remaining.blade.php @@ -0,0 +1,40 @@ +@php + +@endphp + + + +
+
+ +
+ +
+ +
+
diff --git a/routes/api.php b/routes/api.php index 30a05b5..b7cf185 100644 --- a/routes/api.php +++ b/routes/api.php @@ -3,6 +3,7 @@ use App\Http\Controllers\AlertController; use App\Http\Controllers\Api\FetchLoanHistoryController; use App\Http\Controllers\FetchCardHistoryController; +use App\Http\Controllers\FetchLoanRemainingController; use App\Http\Controllers\MetricsController; use App\Http\Controllers\ProfileController; use App\Http\Middleware\OnlySystemUser; @@ -32,6 +33,9 @@ Route::middleware(['nova', Authenticate::class, Authorize::class, OnlySystemUser // Fetch loan history... Route::post('fetch-loan-history', [FetchLoanHistoryController::class, 'index']); + + // Fetch loan remaining... + Route::get('fetch-loan-remaining', [FetchLoanRemainingController::class, 'index']); }); // Auth...