This commit is contained in:
2025-10-27 21:53:27 +05:00
parent 6157902274
commit e24ad8deb0
9 changed files with 510 additions and 77 deletions

View File

@@ -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'));
}

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Modules\CardBalance\Type;
namespace App\Modules\CardBalance\Types;
class CardBalanceResponse
{

View File

@@ -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'
),
];
}
/**

View File

@@ -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
);
}
}

View File

@@ -0,0 +1 @@
<h2>{{ $data->message }}</h2>

View File

@@ -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;
}

View File

@@ -15,6 +15,7 @@
"laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1",
"laravel/ui": "^4.6",
"mpdf/mpdf": "^8.2",
"spatie/laravel-translatable": "^6.11",
"stevebauman/location": "^7.6"
},

417
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "96cc4e2251c414d8a2321f952f8efc6c",
"content-hash": "769fb178b231c9a72b90a0bc385e946f",
"packages": [
{
"name": "abdulmajeed-jamaan/filament-translatable-tabs",
@@ -4291,6 +4291,239 @@
],
"time": "2025-03-24T10:02:05+00:00"
},
{
"name": "mpdf/mpdf",
"version": "v8.2.6",
"source": {
"type": "git",
"url": "https://github.com/mpdf/mpdf.git",
"reference": "dd30e3b01061cf8dfe65e7041ab4cc46d8ebdd44"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mpdf/mpdf/zipball/dd30e3b01061cf8dfe65e7041ab4cc46d8ebdd44",
"reference": "dd30e3b01061cf8dfe65e7041ab4cc46d8ebdd44",
"shasum": ""
},
"require": {
"ext-gd": "*",
"ext-mbstring": "*",
"mpdf/psr-http-message-shim": "^1.0 || ^2.0",
"mpdf/psr-log-aware-trait": "^2.0 || ^3.0",
"myclabs/deep-copy": "^1.7",
"paragonie/random_compat": "^1.4|^2.0|^9.99.99",
"php": "^5.6 || ^7.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
"psr/http-message": "^1.0 || ^2.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"setasign/fpdi": "^2.1"
},
"require-dev": {
"mockery/mockery": "^1.3.0",
"mpdf/qrcode": "^1.1.0",
"squizlabs/php_codesniffer": "^3.5.0",
"tracy/tracy": "~2.5",
"yoast/phpunit-polyfills": "^1.0"
},
"suggest": {
"ext-bcmath": "Needed for generation of some types of barcodes",
"ext-xml": "Needed mainly for SVG manipulation",
"ext-zlib": "Needed for compression of embedded resources, such as fonts"
},
"type": "library",
"autoload": {
"files": [
"src/functions.php"
],
"psr-4": {
"Mpdf\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-only"
],
"authors": [
{
"name": "Matěj Humpál",
"role": "Developer, maintainer"
},
{
"name": "Ian Back",
"role": "Developer (retired)"
}
],
"description": "PHP library generating PDF files from UTF-8 encoded HTML",
"homepage": "https://mpdf.github.io",
"keywords": [
"pdf",
"php",
"utf-8"
],
"support": {
"docs": "https://mpdf.github.io",
"issues": "https://github.com/mpdf/mpdf/issues",
"source": "https://github.com/mpdf/mpdf"
},
"funding": [
{
"url": "https://www.paypal.me/mpdf",
"type": "custom"
}
],
"time": "2025-08-18T08:51:51+00:00"
},
{
"name": "mpdf/psr-http-message-shim",
"version": "v2.0.1",
"source": {
"type": "git",
"url": "https://github.com/mpdf/psr-http-message-shim.git",
"reference": "f25a0153d645e234f9db42e5433b16d9b113920f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mpdf/psr-http-message-shim/zipball/f25a0153d645e234f9db42e5433b16d9b113920f",
"reference": "f25a0153d645e234f9db42e5433b16d9b113920f",
"shasum": ""
},
"require": {
"psr/http-message": "^2.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Mpdf\\PsrHttpMessageShim\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Dorison",
"email": "mark@chromatichq.com"
},
{
"name": "Kristofer Widholm",
"email": "kristofer@chromatichq.com"
},
{
"name": "Nigel Cunningham",
"email": "nigel.cunningham@technocrat.com.au"
}
],
"description": "Shim to allow support of different psr/message versions.",
"support": {
"issues": "https://github.com/mpdf/psr-http-message-shim/issues",
"source": "https://github.com/mpdf/psr-http-message-shim/tree/v2.0.1"
},
"time": "2023-10-02T14:34:03+00:00"
},
{
"name": "mpdf/psr-log-aware-trait",
"version": "v3.0.0",
"source": {
"type": "git",
"url": "https://github.com/mpdf/psr-log-aware-trait.git",
"reference": "a633da6065e946cc491e1c962850344bb0bf3e78"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mpdf/psr-log-aware-trait/zipball/a633da6065e946cc491e1c962850344bb0bf3e78",
"reference": "a633da6065e946cc491e1c962850344bb0bf3e78",
"shasum": ""
},
"require": {
"psr/log": "^3.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Mpdf\\PsrLogAwareTrait\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Dorison",
"email": "mark@chromatichq.com"
},
{
"name": "Kristofer Widholm",
"email": "kristofer@chromatichq.com"
}
],
"description": "Trait to allow support of different psr/log versions.",
"support": {
"issues": "https://github.com/mpdf/psr-log-aware-trait/issues",
"source": "https://github.com/mpdf/psr-log-aware-trait/tree/v3.0.0"
},
"time": "2023-05-03T06:19:36+00:00"
},
{
"name": "myclabs/deep-copy",
"version": "1.13.4",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"conflict": {
"doctrine/collections": "<1.6.8",
"doctrine/common": "<2.13.3 || >=3 <3.2.2"
},
"require-dev": {
"doctrine/collections": "^1.6.8",
"doctrine/common": "^2.13.3 || ^3.2.2",
"phpspec/prophecy": "^1.10",
"phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
},
"type": "library",
"autoload": {
"files": [
"src/DeepCopy/deep_copy.php"
],
"psr-4": {
"DeepCopy\\": "src/DeepCopy/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Create deep copies (clones) of your objects",
"keywords": [
"clone",
"copy",
"duplicate",
"object",
"object graph"
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
"source": "https://github.com/myclabs/DeepCopy/tree/1.13.4"
},
"funding": [
{
"url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy",
"type": "tidelift"
}
],
"time": "2025-08-01T08:46:24+00:00"
},
{
"name": "nesbot/carbon",
"version": "3.10.3",
@@ -4926,6 +5159,56 @@
},
"time": "2025-09-24T15:06:41+00:00"
},
{
"name": "paragonie/random_compat",
"version": "v9.99.100",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a",
"reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a",
"shasum": ""
},
"require": {
"php": ">= 7"
},
"require-dev": {
"phpunit/phpunit": "4.*|5.*",
"vimeo/psalm": "^1"
},
"suggest": {
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
"keywords": [
"csprng",
"polyfill",
"pseudorandom",
"random"
],
"support": {
"email": "info@paragonie.com",
"issues": "https://github.com/paragonie/random_compat/issues",
"source": "https://github.com/paragonie/random_compat"
},
"time": "2020-10-15T08:29:30+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.9.4",
@@ -5964,6 +6247,78 @@
],
"time": "2022-12-17T21:53:22+00:00"
},
{
"name": "setasign/fpdi",
"version": "v2.6.4",
"source": {
"type": "git",
"url": "https://github.com/Setasign/FPDI.git",
"reference": "4b53852fde2734ec6a07e458a085db627c60eada"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Setasign/FPDI/zipball/4b53852fde2734ec6a07e458a085db627c60eada",
"reference": "4b53852fde2734ec6a07e458a085db627c60eada",
"shasum": ""
},
"require": {
"ext-zlib": "*",
"php": "^7.1 || ^8.0"
},
"conflict": {
"setasign/tfpdf": "<1.31"
},
"require-dev": {
"phpunit/phpunit": "^7",
"setasign/fpdf": "~1.8.6",
"setasign/tfpdf": "~1.33",
"squizlabs/php_codesniffer": "^3.5",
"tecnickcom/tcpdf": "^6.8"
},
"suggest": {
"setasign/fpdf": "FPDI will extend this class but as it is also possible to use TCPDF or tFPDF as an alternative. There's no fixed dependency configured."
},
"type": "library",
"autoload": {
"psr-4": {
"setasign\\Fpdi\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jan Slabon",
"email": "jan.slabon@setasign.com",
"homepage": "https://www.setasign.com"
},
{
"name": "Maximilian Kresse",
"email": "maximilian.kresse@setasign.com",
"homepage": "https://www.setasign.com"
}
],
"description": "FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF. Because it is also possible to use FPDI with TCPDF, there are no fixed dependencies defined. Please see suggestions for packages which evaluates the dependencies automatically.",
"homepage": "https://www.setasign.com/fpdi",
"keywords": [
"fpdf",
"fpdi",
"pdf"
],
"support": {
"issues": "https://github.com/Setasign/FPDI/issues",
"source": "https://github.com/Setasign/FPDI/tree/v2.6.4"
},
"funding": [
{
"url": "https://tidelift.com/funding/github/packagist/setasign/fpdi",
"type": "tidelift"
}
],
"time": "2025-08-05T09:57:14+00:00"
},
{
"name": "spatie/invade",
"version": "2.1.0",
@@ -10136,66 +10491,6 @@
},
"time": "2024-05-16T03:13:13+00:00"
},
{
"name": "myclabs/deep-copy",
"version": "1.13.4",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"conflict": {
"doctrine/collections": "<1.6.8",
"doctrine/common": "<2.13.3 || >=3 <3.2.2"
},
"require-dev": {
"doctrine/collections": "^1.6.8",
"doctrine/common": "^2.13.3 || ^3.2.2",
"phpspec/prophecy": "^1.10",
"phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
},
"type": "library",
"autoload": {
"files": [
"src/DeepCopy/deep_copy.php"
],
"psr-4": {
"DeepCopy\\": "src/DeepCopy/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Create deep copies (clones) of your objects",
"keywords": [
"clone",
"copy",
"duplicate",
"object",
"object graph"
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
"source": "https://github.com/myclabs/DeepCopy/tree/1.13.4"
},
"funding": [
{
"url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy",
"type": "tidelift"
}
],
"time": "2025-08-01T08:46:24+00:00"
},
{
"name": "nunomaduro/collision",
"version": "v8.8.2",