This commit is contained in:
2025-10-28 21:24:50 +05:00
parent cd5570f431
commit 0d3dd8cca2
2 changed files with 82 additions and 15 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Modules\CardTransaction\Repositories; namespace App\Modules\CardTransaction\Repositories;
use App\Modules\CardTransaction\Types\CardTransactionResponse;
use App\Modules\Card\Models\Card; use App\Modules\Card\Models\Card;
use App\Modules\Makeable; use App\Modules\Makeable;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
@@ -25,7 +26,7 @@ class CardTransactionRepository
$start_date = Carbon::create($data['start_date']); $start_date = Carbon::create($data['start_date']);
$end_date = Carbon::create($data['end_date']); $end_date = Carbon::create($data['end_date']);
$response = $this->fetchApi( $apiResponse = $this->fetchApi(
passport_serie: user()->getOption('passport_serie') ?? 'I', passport_serie: user()->getOption('passport_serie') ?? 'I',
passport_id: user()->getOption('passport_id') ?? '909090', passport_id: user()->getOption('passport_id') ?? '909090',
card_number_masked: Str::mask($record->number, '*', 6, 6), card_number_masked: Str::mask($record->number, '*', 6, 6),
@@ -35,19 +36,17 @@ class CardTransactionRepository
); );
/** @var \App\Modules\CardTransaction\Types\CardTransactionResponse */ /** @var \App\Modules\CardTransaction\Types\CardTransactionResponse */
$safeResponse = Str::isJson($response) $response = Str::isJson($apiResponse)
? json_decode($response) ? json_decode($apiResponse)
: emptyClass(errCode: 1, message: 'Connection issue to VP'); : emptyClass(errCode: 1, message: 'Connection issue to VP');
if ($safeResponse->errCode != 0) { if ($response->errCode != 0) {
return view('module.card-transaction::error-response', ['data' => $safeResponse]); return view('module.card-transaction::error-response', ['data' => $response]);
} }
$url = $this->handleFiles($record, $safeResponse); $url = $this->handleFiles($record, $response);
info($url); return response()->download($url);
// return ActionResponse::openInNewTab($url);
} }
/** /**
@@ -90,8 +89,11 @@ class CardTransactionRepository
/** /**
* Handles all file stuff * 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())); $unique_folder_name = Str::snake(str_replace(':', '-', $model->created_at->toDateTimeString()));
$dir = public_path("files/{$unique_folder_name}"); $dir = public_path("files/{$unique_folder_name}");
@@ -100,7 +102,7 @@ class CardTransactionRepository
$fileDest = $dir."/{$model->id}.pdf"; $fileDest = $dir."/{$model->id}.pdf";
$this->generateFile($data, $fileDest); $this->generateFile($response, $fileDest);
return url("files/{$unique_folder_name}/{$model->id}.pdf"); return url("files/{$unique_folder_name}/{$model->id}.pdf");
} }
@@ -111,14 +113,14 @@ class CardTransactionRepository
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $data * @param \App\Modules\CardTransaction\Types\CardTransactionResponse $data
* @param string $fileDest * @param string $fileDest
*/ */
public function generateFile($data, $fileDest): void public function generateFile(object $response, string $fileDest): void
{ {
$mpdf = new Mpdf; $mpdf = new Mpdf;
// Write HTML content... // Write HTML content...
$html = Blade::render('orders.cards.card-transaction.download-card-transaction', [ $html = Blade::render('module.card-transaction::card-transaction-table', [
'data' => $data, 'data' => $response,
'extra' => $this->getExtraVariables($data), 'extra' => $this->getExtraVariables($response),
]); ]);
$mpdf->WriteHTML($html); $mpdf->WriteHTML($html);

View File

@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<style>
body {font-family: DejaVu Sans, sans-serif; font-size: 12px; color: #000; margin: 40px; } h1, h2, h3 {margin: 0; padding: 0; } p {margin: 4px 0; } .title {font-weight: bold; font-size: 16px; margin-top: 10px; } .section {margin-top: 20px; } table {width: 100%; border-collapse: collapse; margin-top: 10px; } th, td {border: 1px solid #999; padding: 6px; text-align: left; font-size: 11px; } th {background-color: #f0f0f0; } .summary {margin-top: 20px; } strong {font-weight: bold; } </style>
</head>
<body>
<p>{{ $data->depName }}</p>
<p>BAB: <strong>{{ $data->mfo }}</strong></p>
<div class="section">
<p>Sene: <strong>{{ now()->format('d.m.Y') }}</strong></p>
<p> {{ $data->accountNumber }} belgili kart hasaby boýunça GÖÇÜRME</p>
<p>Müşderiniň FAAa: <strong>{{ $data->clientName }}</strong></p>
<p>{{ $data->fromDate }} - {{ $data->toDate }} aralygy üçin</p>
<br>
<p>Başdaky galyndy: <strong> {{ $extra->basdakyGalyndy }} </strong></p>
<p>Ahyrky galyndy: <strong> {{ $extra->ahyrkyGalyndy }} </strong></p>
</div>
<table>
<thead>
<tr>
<th>Amalyň senesi</th>
<th>Tranzaksiýa senesi</th>
<th>Kart belgisi</th>
<th>Amalyň görnüşi</th>
<th>Tranz. geçirilen ýeri</th>
<th>Tranz. walýutasy</th>
<th>Tranz. wal-da möçberi</th>
<th>Hasabyň wal-da möçberi</th>
<th>Kart hasabynyň galyndysy</th>
</tr>
</thead>
<tbody>
@foreach($data->transactions as $transaction)
@php
$operdate = Carbon\Carbon::create($transaction->operdate);
$trandate = Carbon\Carbon::create($transaction->trandate);
@endphp
<tr>
<th>{{ $operdate->format('d.m.Y') }}</th>
<th>{{ $transaction->trantime }}, {{ $trandate->format('d.m.Y') }}</th>
<th>{{ $transaction->cardnum }}</th>
<th>{{ $transaction->binfo }}</th>
<th>{{ $transaction->terminalLocation }}</th>
<th>{{ $transaction->currCode }}</th>
<th>{{ $transaction->currOperSum }}</th>
<th>{{ $transaction->currOperSum }}({{ $transaction->sign }})</th>
<th>{{ $transaction->rest }}</th>
</tr>
@endforeach
</tbody>
</table>
<div class="summary">
<p>Aralyk boýunça hereket:</p>
<p>Girdeji: <strong>{{ $extra->girdeji }}</strong></p>
<p>Çykdajy: <strong>{{ $extra->cykdajy }}</strong></p>
</div>
</body>
</html>