try
This commit is contained in:
@@ -16,7 +16,7 @@ class CardBalanceRepository
|
||||
*/
|
||||
public function showCardBalance(Card $record): View
|
||||
{
|
||||
/** @var \App\Modules\CardBalance\Type\CardBalanceResponse */
|
||||
/** @var \App\Modules\CardBalance\Types\CardBalanceResponse */
|
||||
$data = $this->fetchCardBalance(
|
||||
passport_serie: user()->getOption('passport_serie') ?? 'I',
|
||||
passport_id: user()->getOption('passport_id') ?? '909090',
|
||||
@@ -25,7 +25,7 @@ class CardBalanceRepository
|
||||
);
|
||||
|
||||
return $data->errCode != 0
|
||||
? view('module.card-balance::client-not-found', compact('data'))
|
||||
? view('module.card-balance::error-response', compact('data'))
|
||||
: view('module.card-balance::card-balance-modal', compact('data'));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\CardBalance\Type;
|
||||
namespace App\Modules\CardBalance\Types;
|
||||
|
||||
class CardBalanceResponse
|
||||
{
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Modules\CardTransaction;
|
||||
|
||||
use App\Modules\Core\ModulePackage;
|
||||
use App\Modules\Core\ModulePackageType;
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
@@ -51,7 +53,13 @@ class CardTransactionModule implements ModuleContract
|
||||
*/
|
||||
public function getComposerRequirements(): array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
new ModulePackage(
|
||||
type: ModulePackageType::PACKAGE,
|
||||
name: 'mpdf/mpdf',
|
||||
message: 'Required for pdf conversations'
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,11 @@ namespace App\Modules\CardTransaction\Repositories;
|
||||
use App\Modules\Card\Models\Card;
|
||||
use App\Modules\Makeable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use Mpdf\Mpdf;
|
||||
use Mpdf\Output\Destination;
|
||||
|
||||
class CardTransactionRepository
|
||||
{
|
||||
@@ -30,21 +34,18 @@ class CardTransactionRepository
|
||||
end_date: $end_date->format('d.m.Y'),
|
||||
);
|
||||
|
||||
info([
|
||||
'response' => $response,
|
||||
'type' => gettype($response),
|
||||
]);
|
||||
/** @var \App\Modules\CardTransaction\Types\CardTransactionResponse */
|
||||
$safeResponse = Str::isJson($response)
|
||||
? json_decode($response)
|
||||
: emptyClass(errCode: 1, message: 'Connection issue to VP');
|
||||
|
||||
// /** @var ResponseTypes\AzatApiClientInfoAllResponse */
|
||||
// $data = Str::isJson($response)
|
||||
// ? json_decode($response)
|
||||
// : emptyClass(errCode: 1, message: 'Connection issue to VP');
|
||||
if ($safeResponse->errCode != 0) {
|
||||
return view('module.card-transaction::error-response', ['data' => $safeResponse]);
|
||||
}
|
||||
|
||||
// if ($data->errCode != 0) {
|
||||
// return ActionResponse::danger($data->message);
|
||||
// }
|
||||
$url = $this->doFiles($record, $data);
|
||||
|
||||
// $url = $this->doFiles($model, $data);
|
||||
// return ActionResponse::openInNewTab($url);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,4 +85,74 @@ class CardTransactionRepository
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles all file stuff
|
||||
*/
|
||||
public function doFiles($model, $data): string
|
||||
{
|
||||
$unique_folder_name = Str::snake(str_replace(':', '-', $model->created_at->toDateTimeString()));
|
||||
$dir = public_path("files/{$unique_folder_name}");
|
||||
|
||||
File::makeDirectory($dir, 0777, true, true);
|
||||
|
||||
$fileDest = $dir."/{$model->id}.pdf";
|
||||
|
||||
$this->generateFile($data, $fileDest);
|
||||
|
||||
return url("files/{$unique_folder_name}/{$model->id}.pdf");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate file
|
||||
*
|
||||
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $data
|
||||
* @param string $fileDest
|
||||
*/
|
||||
public function generateFile($data, $fileDest): void
|
||||
{
|
||||
$mpdf = new Mpdf;
|
||||
|
||||
// Write HTML content...
|
||||
$html = Blade::render('orders.cards.card-transaction.download-card-transaction', [
|
||||
'data' => $data,
|
||||
'extra' => $this->getExtraVariables($data),
|
||||
]);
|
||||
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
// Save the PDF to a file...
|
||||
$mpdf->Output($fileDest, Destination::FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $data
|
||||
*/
|
||||
public function getExtraVariables($data): object
|
||||
{
|
||||
if (count($data->transactions) < 1) {
|
||||
return emptyClass(basdakyGalyndy: 0, ahyrkyGalyndy: 0, girdeji: 0, cykdajy: 0);
|
||||
}
|
||||
|
||||
$basdakyGalyndy = $data->transactions[0]->rest;
|
||||
$basdakyTransaksiya = $data->transactions[0]->currOperSum;
|
||||
$sonkyGalyndy = $data->transactions[count($data->transactions) - 1]->rest;
|
||||
|
||||
$positive = 0;
|
||||
$negative = 0;
|
||||
for ($i = 0; $i < count($data->transactions); $i++) {
|
||||
if ($data->transactions[$i]->sign == '-') {
|
||||
$negative += $data->transactions[$i]->currOperSum;
|
||||
} else {
|
||||
$positive += $data->transactions[$i]->currOperSum;
|
||||
}
|
||||
}
|
||||
|
||||
return emptyClass(
|
||||
basdakyGalyndy: $basdakyGalyndy - ($basdakyTransaksiya),
|
||||
ahyrkyGalyndy: $sonkyGalyndy,
|
||||
girdeji: $positive,
|
||||
cykdajy: $negative
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<h2>{{ $data->message }}</h2>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\CardTransaction\Types;
|
||||
|
||||
class CardTransactionResponse
|
||||
{
|
||||
public string $idSeria;
|
||||
|
||||
public string $idNo;
|
||||
|
||||
public string $cardMaskNumber;
|
||||
|
||||
public string $expDate;
|
||||
|
||||
public string $clientType;
|
||||
|
||||
public string $fromDate;
|
||||
|
||||
public string $toDate;
|
||||
|
||||
public string $clientName;
|
||||
|
||||
public string $depName;
|
||||
|
||||
public string $cardName;
|
||||
|
||||
public string $cardPan;
|
||||
|
||||
public string $cardAccountNumber;
|
||||
|
||||
public string $birthDate;
|
||||
|
||||
public string $mfo;
|
||||
|
||||
public string $inn;
|
||||
|
||||
public string $passOrg;
|
||||
|
||||
public string $passDate;
|
||||
|
||||
public string $address;
|
||||
|
||||
public string $phone;
|
||||
|
||||
public string $accountNumber;
|
||||
|
||||
public int $errCode;
|
||||
|
||||
public string $message;
|
||||
|
||||
public string $messageRu;
|
||||
|
||||
public string $messageEn;
|
||||
|
||||
/** @var array<int, object> */
|
||||
public array $transactions;
|
||||
}
|
||||
Reference in New Issue
Block a user