Compare commits
3 Commits
6bdc820589
...
72d2a4b1f5
| Author | SHA1 | Date | |
|---|---|---|---|
| 72d2a4b1f5 | |||
| 4a24ee61ff | |||
| 1e9bad12c5 |
@@ -7,6 +7,7 @@ use App\Filament\Clusters\Cards\CardsCluster;
|
||||
use App\Modules\AppHelpers\Repositories\DateHelper;
|
||||
use App\Modules\Card\Models\Card;
|
||||
use App\Modules\CardBalance\Repositories\CardBalanceRepository;
|
||||
use App\Modules\CardRequisite\Repositories\CardRequisiteRepository;
|
||||
use App\Modules\CardTransaction\Repositories\CardTransactionRepository;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
@@ -124,15 +125,15 @@ class CardResource extends Resource
|
||||
->recordActions([
|
||||
Action::make('card_balance')
|
||||
->label(__('Card balance'))
|
||||
->icon('heroicon-m-credit-card')
|
||||
->icon('heroicon-o-credit-card')
|
||||
->requiresConfirmation(false)
|
||||
->modal()
|
||||
->modalContent(fn (Card $record): View => CardBalanceRepository::make()->showCardBalance($record))
|
||||
->modalFooterActions([]),
|
||||
|
||||
Action::make('card_transaction')
|
||||
->label(__('Card transaction'))
|
||||
->icon('heroicon-m-arrows-right-left')
|
||||
Action::make('card_transactions')
|
||||
->label(__('Card transactions'))
|
||||
->icon('heroicon-o-arrows-right-left')
|
||||
->requiresConfirmation()
|
||||
->modalIcon('heroicon-m-arrows-right-left')
|
||||
->schema([
|
||||
@@ -148,11 +149,17 @@ class CardResource extends Resource
|
||||
->required()
|
||||
->beforeOrEqual('today'),
|
||||
])
|
||||
->openUrlInNewTab()
|
||||
->action(
|
||||
fn (array $data, Card $record, Component $livewire) => CardTransactionRepository::make()->downloadCardTransaction($data, $record, $livewire)
|
||||
),
|
||||
|
||||
Action::make('card_requisite')
|
||||
->label(__('Card requisite'))
|
||||
->icon('heroicon-o-document-text')
|
||||
->requiresConfirmation()
|
||||
->modalIcon('heroicon-o-document-text')
|
||||
->action(fn (Card $record, Component $livewire) => CardRequisiteRepository::make()->downloadCardRequisite($record, $livewire)),
|
||||
|
||||
EditAction::make()
|
||||
->label(''),
|
||||
DeleteAction::make()
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Modules\CardRequisite;
|
||||
|
||||
use App\Modules\Core\ModulePackage;
|
||||
use App\Modules\Core\ModulePackageType;
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
@@ -51,7 +53,19 @@ class CardRequisiteModule implements ModuleContract
|
||||
*/
|
||||
public function getComposerRequirements(): array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
new ModulePackage(
|
||||
type: ModulePackageType::MODULE,
|
||||
name: 'CardTransaction',
|
||||
message: 'Required for API',
|
||||
),
|
||||
new ModulePackage(
|
||||
type: ModulePackageType::PACKAGE,
|
||||
name: 'phpoffice/phpword',
|
||||
message: 'Required for docx file generation',
|
||||
version: '"dev-master"',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,9 +2,99 @@
|
||||
|
||||
namespace App\Modules\CardRequisite\Repositories;
|
||||
|
||||
use App\Modules\Card\Models\Card;
|
||||
use App\Modules\CardTransaction\Repositories\CardTransactionRepository;
|
||||
use App\Modules\Makeable;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component;
|
||||
|
||||
class CardRequisiteRepository
|
||||
{
|
||||
use Makeable;
|
||||
|
||||
public function downloadCardRequisite(Card $record, Component $livewire)
|
||||
{
|
||||
/** @var \App\Modules\CardTransaction\Types\CardTransactionResponse */
|
||||
$response = $this->fetchApi($record);
|
||||
|
||||
if ($response->errCode != 0) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title($response->message)
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$path = $this->generateFile($record, $response);
|
||||
|
||||
// return ActionResponse::download(
|
||||
// name: 'kart-rekwizit.docx',
|
||||
// url: url($path)
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch api
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function fetchApi(Card $record)
|
||||
{
|
||||
$date = today()->format('d.m.Y');
|
||||
|
||||
$response = CardTransactionRepository::make()->fetchApi(
|
||||
passport_serie: user()->passport_serie(),
|
||||
passport_id: user()->passport_id(),
|
||||
card_number_masked: Str::mask($record->number, '*', 6, 6),
|
||||
card_expire_date: $record->month.'/'.substr($record->year, 2),
|
||||
start_date: $date,
|
||||
end_date: $date,
|
||||
);
|
||||
|
||||
return Str::isJson($response)
|
||||
? json_decode($response)
|
||||
: emptyClass(errCode: 1, message: 'Connection issue to VP');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate file
|
||||
*
|
||||
* @param \App\Models\Order\Card\Requisite\CardRequisite $model
|
||||
* @param \App\Nova\Resources\Order\Card\CardTransaction\Actions\ResponseTypes\AzatApiClientInfoAllResponse $data
|
||||
* @return string
|
||||
*/
|
||||
public function generateFile($model, $data)
|
||||
{
|
||||
$doc_path = app_path('Nova/Resources/Order/Card/Requisite/Docs/card-requisite.docx');
|
||||
|
||||
$templateProcessor = new TemplateProcessor($doc_path);
|
||||
$templateProcessor->setValues([
|
||||
'year' => date('Y'),
|
||||
'name' => $data->clientName,
|
||||
'contract' => $data->cardAccountNumber,
|
||||
'bank' => $data->depName,
|
||||
'hasap' => $data->accountNumber,
|
||||
'sb' => $data->inn,
|
||||
'bab' => $data->mfo,
|
||||
'card_type' => $data->cardName,
|
||||
'card_number' => $data->cardPan,
|
||||
'phone' => $data->mobilPhone ?? '-',
|
||||
'contract_date' => '---YOK---',
|
||||
'card_order_date' => '---YOK---',
|
||||
'card_given_date' => '---YOK---',
|
||||
]);
|
||||
|
||||
$unique_folder_name = Str::snake(str_replace(':', '-', $model->created_at->toDateTimeString()));
|
||||
$dir = public_path("files/card-requisite/{$unique_folder_name}");
|
||||
|
||||
File::makeDirectory($dir, 0777, true, true);
|
||||
|
||||
$filePath = $dir."/{$model->id}.docx";
|
||||
|
||||
$templateProcessor->saveAs($filePath);
|
||||
|
||||
return "files/card-requisite/{$unique_folder_name}/{$model->id}.docx";
|
||||
}
|
||||
}
|
||||
|
||||
BIN
app/Modules/CardRequisite/Resources/Docs/card-requisite.docx
Normal file
BIN
app/Modules/CardRequisite/Resources/Docs/card-requisite.docx
Normal file
Binary file not shown.
@@ -126,4 +126,14 @@ class ModuleRepository
|
||||
{
|
||||
return $this->allModules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if module exists
|
||||
*
|
||||
* @param string $moduleName
|
||||
*/
|
||||
public function moduleExists(string $moduleName): bool
|
||||
{
|
||||
return $this->modules->contains(fn (BaseModule $module) => $module->name === $moduleName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace App\Modules;
|
||||
|
||||
use App\Modules\Core\ModulePackage;
|
||||
use App\Modules\Core\ModulePackageType;
|
||||
use Composer\Composer;
|
||||
use Composer\InstalledVersions;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -57,9 +61,21 @@ class ModuleServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function verifyModuleComposerRequirements(BaseModule $module): void
|
||||
{
|
||||
// foreach ($module->app->getComposerRequirements() as $requirement) {
|
||||
foreach ($module->app->getComposerRequirements() as $package) {
|
||||
$missingPackage = match ($package->type) {
|
||||
ModulePackageType::PACKAGE => InstalledVersions::isInstalled($package->name),
|
||||
ModulePackageType::MODULE => module_exists($package->name),
|
||||
default => true,
|
||||
};
|
||||
|
||||
// }
|
||||
if (! $missingPackage) {
|
||||
abort(
|
||||
500,
|
||||
"{$package->name} {$package->version} {$package->type->value} must be installed (module: {$module->name}) \n
|
||||
{$package->message}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,6 +46,14 @@ function emptyModule(): ModuleContract
|
||||
return modular()->emptyModule();
|
||||
}
|
||||
|
||||
/**
|
||||
* Module exists
|
||||
*/
|
||||
function module_exists(string $moduleName)
|
||||
{
|
||||
return modular()->moduleExists($moduleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an anonymous class that acts as a dynamic object.
|
||||
*
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"laravel/tinker": "^2.10.1",
|
||||
"laravel/ui": "^4.6",
|
||||
"mpdf/mpdf": "^8.2",
|
||||
"phpoffice/phpword": "dev-master",
|
||||
"spatie/laravel-translatable": "^6.11",
|
||||
"stevebauman/location": "^7.6"
|
||||
},
|
||||
|
||||
167
composer.lock
generated
167
composer.lock
generated
@@ -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": "769fb178b231c9a72b90a0bc385e946f",
|
||||
"content-hash": "b0a0696c3837569345f4ed8ecd9b2338",
|
||||
"packages": [
|
||||
{
|
||||
"name": "abdulmajeed-jamaan/filament-translatable-tabs",
|
||||
@@ -5209,6 +5209,167 @@
|
||||
},
|
||||
"time": "2020-10-15T08:29:30+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoffice/math",
|
||||
"version": "0.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHPOffice/Math.git",
|
||||
"reference": "fc31c8f57a7a81f962cbf389fd89f4d9d06fc99a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHPOffice/Math/zipball/fc31c8f57a7a81f962cbf389fd89f4d9d06fc99a",
|
||||
"reference": "fc31c8f57a7a81f962cbf389fd89f4d9d06fc99a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-dom": "*",
|
||||
"ext-xml": "*",
|
||||
"php": "^7.1|^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^0.12.88 || ^1.0.0",
|
||||
"phpunit/phpunit": "^7.0 || ^9.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpOffice\\Math\\": "src/Math/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Progi1984",
|
||||
"homepage": "https://lefevre.dev"
|
||||
}
|
||||
],
|
||||
"description": "Math - Manipulate Math Formula",
|
||||
"homepage": "https://phpoffice.github.io/Math/",
|
||||
"keywords": [
|
||||
"MathML",
|
||||
"officemathml",
|
||||
"php"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/PHPOffice/Math/issues",
|
||||
"source": "https://github.com/PHPOffice/Math/tree/0.3.0"
|
||||
},
|
||||
"time": "2025-05-29T08:31:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoffice/phpword",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHPOffice/PHPWord.git",
|
||||
"reference": "0ab0b4940bc52c7183e82ab2fd55324607037a73"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHPOffice/PHPWord/zipball/0ab0b4940bc52c7183e82ab2fd55324607037a73",
|
||||
"reference": "0ab0b4940bc52c7183e82ab2fd55324607037a73",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-dom": "*",
|
||||
"ext-gd": "*",
|
||||
"ext-json": "*",
|
||||
"ext-xml": "*",
|
||||
"ext-zip": "*",
|
||||
"php": "^7.1|^8.0",
|
||||
"phpoffice/math": "^0.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"dompdf/dompdf": "^2.0 || ^3.0",
|
||||
"ext-libxml": "*",
|
||||
"friendsofphp/php-cs-fixer": "^3.3",
|
||||
"mpdf/mpdf": "^7.0 || ^8.0",
|
||||
"phpmd/phpmd": "^2.13",
|
||||
"phpstan/phpstan": "^0.12.88 || ^1.0.0 || ^2.0.0",
|
||||
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
|
||||
"phpunit/phpunit": ">=7.0",
|
||||
"symfony/process": "^4.4 || ^5.0",
|
||||
"tecnickcom/tcpdf": "^6.5"
|
||||
},
|
||||
"suggest": {
|
||||
"dompdf/dompdf": "Allows writing PDF",
|
||||
"ext-xmlwriter": "Allows writing OOXML and ODF",
|
||||
"ext-xsl": "Allows applying XSL style sheet to headers, to main document part, and to footers of an OOXML template"
|
||||
},
|
||||
"default-branch": true,
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpOffice\\PhpWord\\": "src/PhpWord"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-3.0-only"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mark Baker"
|
||||
},
|
||||
{
|
||||
"name": "Gabriel Bull",
|
||||
"email": "me@gabrielbull.com",
|
||||
"homepage": "http://gabrielbull.com/"
|
||||
},
|
||||
{
|
||||
"name": "Franck Lefevre",
|
||||
"homepage": "https://rootslabs.net/blog/"
|
||||
},
|
||||
{
|
||||
"name": "Ivan Lanin",
|
||||
"homepage": "http://ivan.lanin.org"
|
||||
},
|
||||
{
|
||||
"name": "Roman Syroeshko",
|
||||
"homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
|
||||
},
|
||||
{
|
||||
"name": "Antoine de Troostembergh"
|
||||
}
|
||||
],
|
||||
"description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)",
|
||||
"homepage": "https://phpoffice.github.io/PHPWord/",
|
||||
"keywords": [
|
||||
"ISO IEC 29500",
|
||||
"OOXML",
|
||||
"Office Open XML",
|
||||
"OpenDocument",
|
||||
"OpenXML",
|
||||
"PhpOffice",
|
||||
"PhpWord",
|
||||
"Rich Text Format",
|
||||
"WordprocessingML",
|
||||
"doc",
|
||||
"docx",
|
||||
"html",
|
||||
"odf",
|
||||
"odt",
|
||||
"office",
|
||||
"pdf",
|
||||
"php",
|
||||
"reader",
|
||||
"rtf",
|
||||
"template",
|
||||
"template processor",
|
||||
"word",
|
||||
"writer"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/PHPOffice/PHPWord/issues",
|
||||
"source": "https://github.com/PHPOffice/PHPWord/tree/master"
|
||||
},
|
||||
"time": "2025-06-06T10:02:28+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoption/phpoption",
|
||||
"version": "1.9.4",
|
||||
@@ -12372,7 +12533,9 @@
|
||||
],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {},
|
||||
"stability-flags": {
|
||||
"phpoffice/phpword": 20
|
||||
},
|
||||
"prefer-stable": true,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
|
||||
Reference in New Issue
Block a user