diff --git a/app/Filament/Clusters/Loans/Loans/Tables/LoansTable.php b/app/Filament/Clusters/Loans/Loans/Tables/LoansTable.php index b818ad4..5d77f49 100644 --- a/app/Filament/Clusters/Loans/Loans/Tables/LoansTable.php +++ b/app/Filament/Clusters/Loans/Loans/Tables/LoansTable.php @@ -2,6 +2,7 @@ namespace App\Filament\Clusters\Loans\Loans\Tables; +use App\Modules\Loan\Filaments\Actions\ShowLoanRemainingAction; use Filament\Actions\BulkActionGroup; use Filament\Actions\DeleteBulkAction; use Filament\Actions\EditAction; @@ -31,6 +32,7 @@ class LoansTable // ]) ->recordActions([ + ShowLoanRemainingAction::make(), EditAction::make(), ]) ->toolbarActions([ diff --git a/app/Modules/Loan/Filaments/Actions/ShowLoanRemainingAction.php b/app/Modules/Loan/Filaments/Actions/ShowLoanRemainingAction.php new file mode 100644 index 0000000..cf87d50 --- /dev/null +++ b/app/Modules/Loan/Filaments/Actions/ShowLoanRemainingAction.php @@ -0,0 +1,22 @@ +label(__('Show remaining loan')) + ->icon('heroicon-o-banknotes') + ->requiresConfirmation(false) + ->modal() + ->modalContent(fn (Loan $record): View => LoanRepository::make()->showRemainingLoan($record)) + ->modalFooterActions([]); + } +} diff --git a/app/Modules/Loan/Repositories/LoanRepository.php b/app/Modules/Loan/Repositories/LoanRepository.php index 38c1035..33f0f59 100644 --- a/app/Modules/Loan/Repositories/LoanRepository.php +++ b/app/Modules/Loan/Repositories/LoanRepository.php @@ -2,4 +2,71 @@ namespace App\Modules\Loan\Repositories; -class LoanRepository {} +use App\Modules\Loan\Models\Loan; +use App\Modules\Makeable; +use Illuminate\Support\Str; + +class LoanRepository +{ + use Makeable; + + public function showRemainingLoan(Loan $record) + { + $data = $this->fetchCardBalance( + passport_serie: user()->passport_serie(), + passport_id: user()->passport_id(), + account_number: $record->account_number, + ); + + info([$data]); + + // return $data->errCode != 0 + // ? view('module.card-balance::error-response', compact('data')) + // : view('module.card-balance::card-balance-modal', compact('data')); + + return view('welcome'); + } + + public function fetchCardBalance(string $passport_serie, int|string $passport_id, int|string $account_number): object + { + $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" + } + ', + $passport_serie, + $passport_id, + $account_number, + ), + CURLOPT_HTTPHEADER => [ + 'Authorization: Basic dGJ1c2VyOlFBWndzeDEyMw==', + 'Content-Type: application/json', + 'Accept: application/json', + ], + ]); + + $response = curl_exec($curl); + + curl_close($curl); + + /** @var object */ + $safeResponse = Str::isJson($response) + ? json_decode($response) + : emptyClass(errCode: 1, message: 'Connection issue to VP'); + + return $safeResponse; + } +} diff --git a/lang/tk.json b/lang/tk.json index 506d687..9cc287e 100644 --- a/lang/tk.json +++ b/lang/tk.json @@ -669,5 +669,6 @@ "Loans": "Karzlar", "Loan": "Karz", "Please update your profile": "Profiliňizi doldurmagyňyzy haýyş edýäris", - "Pay": "Töle" + "Pay": "Töle", + "Show remaining loan": "Karz galyndysyny gör" }