Upgrade filament from 3 to 4

This commit is contained in:
2025-09-22 13:04:31 +05:00
parent 564b609afa
commit 48593b234e
25 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
<?php
namespace App\Filament\Resources\PaymentOrder\PaymentOrderResource\Actions;
use App\Modules\Makeable;
use App\Modules\PaymentOrder\Models\PaymentOrder;
use Carbon\Carbon;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use PhpOffice\PhpWord\TemplateProcessor;
use Symfony\Component\HttpFoundation\StreamedResponse;
class ExportToWord
{
use Makeable;
/**
* Export to ms-word
*/
public function __construct(protected PaymentOrder $record, protected string $filepath = '')
{
// ...
}
/**
* Export to ms-word
*/
public function handle(): self
{
Carbon::setLocale('tk');
$date_written_turkmen = sprintf(
'%s -nji(y) ýylyň %s aýynyň %s',
$this->record->created_at->year,
Str::lower($this->record->created_at->translatedFormat('F')),
$this->record->created_at->format('d')
);
$templateProcessor = new TemplateProcessor(modules_path('PaymentOrder/Resources/Docs/orders.docx'));
$templateProcessor->setValues([
'n' => $this->record->number,
// Dates...
'date_written_turkmen' => $date_written_turkmen,
'p_date' => $this->record->created_at->format('Y-m-d'),
// Money...
'money_amount' => number_format(floatval($this->record->money_amount), 2, '-', ''),
'money_in_letter' => ucfirst(moneyFormatInTurkmenLetter($this->record->money_amount)),
// Bank topary...
'b_nm' => $this->record->bank_code,
// Sebäbi...
'p_reason_n' => $this->record->payment_reason_number,
'p_reason' => $this->record->payment_reason_description,
// Töleýji...
't_name' => $this->record->t_name,
't_ssb' => $this->record->t_ssb,
't_bab' => $this->record->t_bab,
't_bank' => $this->record->t_bank,
't_hb_1' => $this->record->t_hb_1,
't_hb_2' => $this->record->t_hb_2,
// Alyjy...
'a_name' => $this->record->a_name,
'a_ssb' => $this->record->a_ssb,
'a_bab' => $this->record->a_bab,
'a_bank' => $this->record->a_bank,
'a_hb_1' => $this->record->a_hb_1,
'a_hb_2' => $this->record->a_hb_2,
]);
$this->filepath = storage_path('app/private/payment-order.docx');
$templateProcessor->saveAs($this->filepath);
return $this;
}
/**
* Return the file path
*/
public function filePath(): string
{
return $this->filepath;
}
/**
* Force browser to download file
*/
public function download(): StreamedResponse
{
/** @var Storage $storage */
$storage = Storage::disk('private');
return $storage->download('payment-order.docx');
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\PaymentOrder\PaymentOrderResource\Pages;
use App\Filament\Resources\PaymentOrder\PaymentOrderResource;
use Filament\Resources\Pages\CreateRecord;
class CreatePaymentOrder extends CreateRecord
{
protected static string $resource = PaymentOrderResource::class;
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Filament\Resources\PaymentOrder\PaymentOrderResource\Pages;
use App\Filament\Resources\PaymentOrder\PaymentOrderResource;
use App\Filament\Resources\PaymentOrder\PaymentOrderResource\Actions\ExportToWord;
use Filament\Actions;
use Filament\Actions\Action;
use Filament\Pages\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
class EditPaymentOrder extends EditRecord
{
protected static string $resource = PaymentOrderResource::class;
protected function getActions(): array
{
return [
Action::make('Go back')
->url($this->getResource()::getUrl('index'))
->icon('heroicon-m-arrow-uturn-left')
->button()
->outlined()
->color('primary'),
Action::make('Save')
->action('save')
->keyBindings(['mod+s'])
->icon('heroicon-m-cloud-arrow-up'),
Action::make('ExportToWord')
->icon('heroicon-m-document-arrow-down')
->color('gray')
->action(fn () => ExportToWord::make($this->getRecord())->handle()->download()),
DeleteAction::make()
->icon('heroicon-m-trash'),
];
}
protected function getFormActions(): array
{
return []; // necessary to remove the bottom actions
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\PaymentOrder\PaymentOrderResource\Pages;
use App\Filament\Resources\PaymentOrder\PaymentOrderResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListPaymentOrders extends ListRecords
{
protected static string $resource = PaymentOrderResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,128 @@
<?php
namespace App\Filament\Resources\PaymentOrder;
use App\Filament\Resources\PaymentOrder\PaymentOrderResource\Pages;
use App\Modules\PaymentOrder\Models\PaymentOrder;
use Filament\Forms\Components\Fieldset;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class PaymentOrderResource extends Resource
{
protected static ?string $model = PaymentOrder::class;
protected static ?string $navigationIcon = 'heroicon-o-receipt-percent';
public static function form(Form $form): Form
{
return $form
->schema([
Fieldset::make(__('Töleg'))
->schema([
TextInput::make('number')
->integer()
->required(),
TextInput::make('money_amount')
->required()
->label('Pul mocberi'),
TextInput::make('bank_code')
->required()
->label('Bank topary'),
TextInput::make('payment_reason_number')
->integer()
->required()
->label('Toleg maksady nomeri'),
Textarea::make('payment_reason_description')
->label('Toleg maksady')
->autosize(),
]),
Fieldset::make('Toleyji')
->schema([
TextInput::make('t_name')
->label('ady familyasy'),
TextInput::make('t_ssb')
->label('ŞSB'),
TextInput::make('t_bab')
->label('BAB'),
TextInput::make('t_bank')
->label('Banky'),
TextInput::make('t_hb_1')
->label('H/b 1'),
TextInput::make('t_hb_2')
->label('H/b 2'),
]),
Fieldset::make('Alyjy')
->schema([
TextInput::make('a_name')
->label('ady familyasy'),
TextInput::make('a_ssb')
->label('ŞSB'),
TextInput::make('a_bab')
->label('BAB'),
TextInput::make('a_bank')
->label('Banky'),
TextInput::make('a_hb_1')
->label('H/b 1'),
TextInput::make('a_hb_2')
->label('H/b 2'),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('number'),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListPaymentOrders::route('/'),
'create' => Pages\CreatePaymentOrder::route('/create'),
'edit' => Pages\EditPaymentOrder::route('/{record}/edit'),
];
}
}