diff --git a/app/Modules/CardTransaction/Repositories/CardTransactionRepository.php b/app/Modules/CardTransaction/Repositories/CardTransactionRepository.php index 7de8cb0..4ecda13 100644 --- a/app/Modules/CardTransaction/Repositories/CardTransactionRepository.php +++ b/app/Modules/CardTransaction/Repositories/CardTransactionRepository.php @@ -2,6 +2,7 @@ namespace App\Modules\CardTransaction\Repositories; +use App\Modules\CardTransaction\Types\CardTransactionResponse; use App\Modules\Card\Models\Card; use App\Modules\Makeable; use Illuminate\Support\Carbon; @@ -25,7 +26,7 @@ class CardTransactionRepository $start_date = Carbon::create($data['start_date']); $end_date = Carbon::create($data['end_date']); - $response = $this->fetchApi( + $apiResponse = $this->fetchApi( passport_serie: user()->getOption('passport_serie') ?? 'I', passport_id: user()->getOption('passport_id') ?? '909090', card_number_masked: Str::mask($record->number, '*', 6, 6), @@ -35,19 +36,17 @@ class CardTransactionRepository ); /** @var \App\Modules\CardTransaction\Types\CardTransactionResponse */ - $safeResponse = Str::isJson($response) - ? json_decode($response) + $response = Str::isJson($apiResponse) + ? json_decode($apiResponse) : emptyClass(errCode: 1, message: 'Connection issue to VP'); - if ($safeResponse->errCode != 0) { - return view('module.card-transaction::error-response', ['data' => $safeResponse]); + if ($response->errCode != 0) { + return view('module.card-transaction::error-response', ['data' => $response]); } - $url = $this->handleFiles($record, $safeResponse); + $url = $this->handleFiles($record, $response); - info($url); - - // return ActionResponse::openInNewTab($url); + return response()->download($url); } /** @@ -90,8 +89,11 @@ class CardTransactionRepository /** * Handles all file stuff + * + * @param Card $model + * @param \App\Modules\CardTransaction\Types\CardTransactionResponse $response */ - public function handleFiles($model, $data): string + public function handleFiles(Card $model, object $response): string { $unique_folder_name = Str::snake(str_replace(':', '-', $model->created_at->toDateTimeString())); $dir = public_path("files/{$unique_folder_name}"); @@ -100,7 +102,7 @@ class CardTransactionRepository $fileDest = $dir."/{$model->id}.pdf"; - $this->generateFile($data, $fileDest); + $this->generateFile($response, $fileDest); return url("files/{$unique_folder_name}/{$model->id}.pdf"); } @@ -111,14 +113,14 @@ class CardTransactionRepository * @param \App\Modules\CardTransaction\Types\CardTransactionResponse $data * @param string $fileDest */ - public function generateFile($data, $fileDest): void + public function generateFile(object $response, string $fileDest): void { $mpdf = new Mpdf; // Write HTML content... - $html = Blade::render('orders.cards.card-transaction.download-card-transaction', [ - 'data' => $data, - 'extra' => $this->getExtraVariables($data), + $html = Blade::render('module.card-transaction::card-transaction-table', [ + 'data' => $response, + 'extra' => $this->getExtraVariables($response), ]); $mpdf->WriteHTML($html); diff --git a/app/Modules/CardTransaction/Resources/Views/card-transaction-table.blade.php b/app/Modules/CardTransaction/Resources/Views/card-transaction-table.blade.php new file mode 100644 index 0000000..5d13fa3 --- /dev/null +++ b/app/Modules/CardTransaction/Resources/Views/card-transaction-table.blade.php @@ -0,0 +1,65 @@ + + +
+ + + + +{{ $data->depName }}
+BAB: {{ $data->mfo }}
+ +Sene: {{ now()->format('d.m.Y') }}
+№ {{ $data->accountNumber }} belgili kart hasaby boýunça GÖÇÜRME
+Müşderiniň FAAa: {{ $data->clientName }}
+{{ $data->fromDate }} - {{ $data->toDate }} aralygy üçin
+ +Başdaky galyndy: {{ $extra->basdakyGalyndy }}
+Ahyrky galyndy: {{ $extra->ahyrkyGalyndy }}
+| Amalyň senesi | +Tranzaksiýa senesi | +Kart belgisi | +Amalyň görnüşi | +Tranz. geçirilen ýeri | +Tranz. walýutasy | +Tranz. wal-da möçberi | +Hasabyň wal-da möçberi | +Kart hasabynyň galyndysy | +
|---|---|---|---|---|---|---|---|---|
| {{ $operdate->format('d.m.Y') }} | +{{ $transaction->trantime }}, {{ $trandate->format('d.m.Y') }} | +{{ $transaction->cardnum }} | +{{ $transaction->binfo }} | +{{ $transaction->terminalLocation }} | +{{ $transaction->currCode }} | +{{ $transaction->currOperSum }} | +{{ $transaction->currOperSum }}({{ $transaction->sign }}) | +{{ $transaction->rest }} | +
Aralyk boýunça hereket:
+Girdeji: {{ $extra->girdeji }}
+Çykdajy: {{ $extra->cykdajy }}
+