This commit is contained in:
2024-10-18 19:29:44 +05:00
parent 681d87236a
commit 0e436b0680
6 changed files with 149 additions and 3 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class FetchLoanHistoryController extends Controller
{
/**
* Fetch loan history
*/
public function index(Request $request)
{
$request->validate([
'passport_serie' => ['required', 'string', 'max:255'],
'passport_id' => ['required', 'string', 'max:255'],
]);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'http://10.3.158.102:9999/api/loan/history/info',
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"
}',
$request->passport_serie,
$request->passport_id,
),
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'Content-Type: application/json',
],
]);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
}

View File

@@ -91,10 +91,18 @@ class LoanOrderMobileFieldsForDetail
new Panel(__('Card'), [
NovaCustomHtml::make(__('Data'), 'card_name')
->canSeeWhen('systemUser', $resource)
->html(view('orders.loan.mobile.card-history', [
'resource' => $resource,
])->render())
->fillUsing(NovaForm::fillEmpty()),
])->render()),
]),
new Panel(__('Karz taryhy'), [
NovaCustomHtml::make(__('Karz taryhy'), 'loan_history')
->canSeeWhen('systemUser', $resource)
->html(view('orders.loan.mobile.loan-history', [
'resource' => $resource,
])->render()),
]),
new Panel(__('Contact data'), [

View File

@@ -321,5 +321,6 @@
"Loan Card": "Karz karty",
"Send payment": "Tölegi geçir",
"Currencies": "Walýutalar",
"Passport number": "Pasport nomeri"
"Passport number": "Pasport nomeri",
"Fetch loan history": "Karz taryhyny görmek"
}

View File

@@ -3,6 +3,69 @@ function csrf_token()
return document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');
}
async function fetchLoanHistory(containerID, passport_serie, passport_id) {
if (! passport_serie || ! passport_id) {
Nova.error('Maglumat ýetmezçiligi bar');
return;
}
let cardHistoryDetailContainer = document.getElementById(containerID);
var headers = new Headers();
headers.append('Accept', 'application/json');
var formdata = new FormData();
formdata.append('passport_serie', passport_serie);
formdata.append('passport_id', passport_id);
Nova.$progress.start()
fetch('/api/fetch-loan-history', {
method: 'POST',
headers: headers,
body: formdata,
redirect: 'follow'
})
.then(response => response.json())
.then(result => {
console.log({result: result})
if (result.errCode != 0) {
Nova.error(result.message)
}
// cardHistoryDetailContainer.innerHTML = `
// <h4>Müşderi: <strong>${result.clientName}</strong></h4>
// <h4>Şahamça: <strong>${result.depName}</strong></h4>
// <h4 class="mb-4">Şertnama belgisi: <strong>${result.cardAccountNumber}</strong></h4>
// <p>
// <ul>
// ${Array.from(result.transactions).map(transaction => {
// return `<li style="background: #a3c1f5;color: black;" class="p-3 relative rounded-lg">
// <strong>${transaction['actionName']}</strong> <strong>${transaction['opersum']}</strong> <strong>${transaction['currency']}</strong>
// <strong style="top: 0; right: 0;" class="absolute p-2">${transaction['opername']}</strong>
// <p><strong>${
// new Date(transaction['trandate']).toLocaleDateString('en-GB', {
// year: 'numeric',
// month: '2-digit',
// day: '2-digit',
// }).replaceAll('/', '.')
// }</strong></p>
// </li>`;
// })}
// </ul>
// </p>
// `;
})
.catch(error => console.log('error', error))
.finally(() => {
Nova.$progress.done()
});
}
async function fetchCardHistory(passport_serie, passport_id, card_number, card_expiry_date, containerID) {
if (! passport_serie || ! passport_id || ! card_number || ! card_expiry_date) {
Nova.error('Maglumat ýetmezçiligi bar');

View File

@@ -0,0 +1,20 @@
@php
@endphp
<div class="loan-history-container">
<button
type="button"
class="border text-left appearance-none cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 relative disabled:cursor-not-allowed inline-flex items-center justify-center shadow h-9 px-3 bg-primary-500 border-primary-500 hover:[&amp;:not(:disabled)]:bg-primary-400 hover:[&amp;:not(:disabled)]:border-primary-400 text-white dark:text-gray-900"
onclick="fetchLoanHistory(
'loan-history-container',
'{{ $resource->passport_serie }}',
'{{ $resource->passport_id }}',
)">
<span class="flex items-center gap-1">Karz taryhyny ýükle</span>
</button>
<div id="loan-history-container">
</div>
</div>

View File

@@ -1,5 +1,6 @@
<?php
use App\Http\Controllers\Api\FetchLoanHistoryController;
use App\Http\Controllers\FetchCardHistoryController;
use App\Http\Controllers\MetricsController;
use App\Http\Controllers\ProfileController;
@@ -24,6 +25,9 @@ use Illuminate\Support\Facades\Route;
// Fetch card history...
Route::post('fetch-card-history', [FetchCardHistoryController::class, 'index']);
// Fetch loan history...
Route::get('fetch-loan-history', [FetchLoanHistoryController::class, 'index']);
// Auth...
Route::post('auth/register', [ApiAuthController::class, 'register']);
Route::post('auth/login', [ApiAuthController::class, 'login']);