From 8637c22ed7cd3149d6af65bbb1d60df246fe7bd3 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Fri, 14 Nov 2025 18:29:14 +0500 Subject: [PATCH] Refactor CurrencyRateForm and PayVisaMasterPaymentAction: streamline component definitions, enhance layout with fieldsets, and update Turkish translations for payment-related terms. --- .../Schemas/CurrencyRateForm.php | 38 ++--- .../Schemas/VisaMasterSettingsForm.php | 1 - .../CurrencyRate/Models/CurrencyRate.php | 9 +- .../Actions/PayVisaMasterPaymentAction.php | 131 ++++++++---------- .../Models/VisaMasterSettings.php | 2 +- lang/tk.json | 5 +- 6 files changed, 85 insertions(+), 101 deletions(-) diff --git a/app/Filament/Clusters/Settings/Resources/CurrencyRates/Schemas/CurrencyRateForm.php b/app/Filament/Clusters/Settings/Resources/CurrencyRates/Schemas/CurrencyRateForm.php index 257dee3..3c35d77 100644 --- a/app/Filament/Clusters/Settings/Resources/CurrencyRates/Schemas/CurrencyRateForm.php +++ b/app/Filament/Clusters/Settings/Resources/CurrencyRates/Schemas/CurrencyRateForm.php @@ -13,27 +13,27 @@ class CurrencyRateForm { return $schema ->components([ - Select::make('currency_from') - ->label(__('Currency from')) - ->native(false) - ->searchable() - ->options(CurrencyRate::currencies()) - ->rules('required') - ->belowLabel('1 möçberi'), + Select::make('currency_from') + ->label(__('Currency from')) + ->native(false) + ->searchable() + ->options(CurrencyRate::currencies()) + ->rules('required') + ->belowLabel('1 möçberi'), - Select::make('currency_to') - ->label(__('Currency to')) - ->native(false) - ->searchable() - ->options(CurrencyRate::currencies()) - ->rules('required') - ->belowLabel('1 möçberi'), + Select::make('currency_to') + ->label(__('Currency to')) + ->native(false) + ->searchable() + ->options(CurrencyRate::currencies()) + ->rules('required') + ->belowLabel('1 möçberi'), - TextInput::make('value') - ->label(__('Currency value')) - ->required() - ->numeric() - ->belowLabel('Bitin däl sanlary "." bilen ýazmaly'), + TextInput::make('value') + ->label(__('Currency value')) + ->required() + ->numeric() + ->belowLabel('Bitin däl sanlary "." bilen ýazmaly'), ]); } } diff --git a/app/Filament/Clusters/Settings/Resources/VisaMasterSettings/Schemas/VisaMasterSettingsForm.php b/app/Filament/Clusters/Settings/Resources/VisaMasterSettings/Schemas/VisaMasterSettingsForm.php index 56c2e6f..7dfbd91 100644 --- a/app/Filament/Clusters/Settings/Resources/VisaMasterSettings/Schemas/VisaMasterSettingsForm.php +++ b/app/Filament/Clusters/Settings/Resources/VisaMasterSettings/Schemas/VisaMasterSettingsForm.php @@ -6,7 +6,6 @@ use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterSettings; use Filament\Forms\Components\RichEditor; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; -use Filament\Forms\Components\Textarea; use Filament\Schemas\Schema; class VisaMasterSettingsForm diff --git a/app/Modules/CurrencyRate/Models/CurrencyRate.php b/app/Modules/CurrencyRate/Models/CurrencyRate.php index 49d0521..0716ed9 100644 --- a/app/Modules/CurrencyRate/Models/CurrencyRate.php +++ b/app/Modules/CurrencyRate/Models/CurrencyRate.php @@ -2,8 +2,8 @@ namespace App\Modules\CurrencyRate\Models; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Casts\Attribute; +use Illuminate\Database\Eloquent\Model; /** * @property int $id @@ -13,22 +13,23 @@ use Illuminate\Database\Eloquent\Casts\Attribute; * @property \Illuminate\Support\Carbon $created_at * @property \Illuminate\Support\Carbon $updated_at */ -class CurrencyRate extends Model +class CurrencyRate extends Model { /** * The table associated with the model. */ protected $table = 'currency_rates'; - /** + /** * Get the user's first name. */ protected function name(): Attribute { return Attribute::make( - get: fn () => $this->currency_from . '-' . $this->currency_to, + get: fn () => $this->currency_from.'-'.$this->currency_to, ); } + /** * Currencies * diff --git a/app/Modules/VisaMasterPaymentOrder/Filament/Actions/PayVisaMasterPaymentAction.php b/app/Modules/VisaMasterPaymentOrder/Filament/Actions/PayVisaMasterPaymentAction.php index 7433ddf..3d90b4a 100644 --- a/app/Modules/VisaMasterPaymentOrder/Filament/Actions/PayVisaMasterPaymentAction.php +++ b/app/Modules/VisaMasterPaymentOrder/Filament/Actions/PayVisaMasterPaymentAction.php @@ -8,14 +8,15 @@ use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterSettings; use Filament\Actions\Action; use Filament\Forms\Components\TextInput; use Filament\Infolists\Components\TextEntry; -use Filament\Schemas\Components\Section; +use Filament\Schemas\Components\Fieldset; +use Filament\Schemas\Components\Utilities\Set; class PayVisaMasterPaymentAction { public static function make(): Action { return Action::make('pay_visa_master_payment') - ->label(__('Make payment')) + ->label(sprintf('%s %s', __('Make payment for:'), today()->translatedFormat('F'))) ->icon('heroicon-o-credit-card') ->modal() ->schema(function () { @@ -32,86 +33,66 @@ class PayVisaMasterPaymentAction $max_value = number_format($usd_to_tmt * 250, 2); return [ - Section::make('Customer Information') - ->schema([ - TextEntry::make('usd_to_tmt') - ->extraAttributes(['class' => 'uppercase tracking-wide font-bold text-xs']) - ->label(sprintf('1 USD = %s TMT', $usd_to_tmt)), + Fieldset::make(__('Tax')) + ->columns([ + 'default' => 1, + 'md' => 2, + 'xl' => 3, + ]) + ->schema([ + TextEntry::make('usd_to_tmt') + ->extraAttributes(['class' => 'uppercase tracking-wide font-bold text-xs']) + ->label(sprintf('1 USD = %s TMT', $usd_to_tmt)), - TextEntry::make('bank_fee') - ->extraAttributes(['class' => 'uppercase tracking-wide font-bold text-xs']) - ->label(sprintf('Bankyň tutumy: %s TMT', $bank_fee)), + TextEntry::make('bank_fee') + ->extraAttributes(['class' => 'uppercase tracking-wide font-bold text-xs']) + ->label(sprintf('Bankyň tutumy: %s TMT', $bank_fee)), - TextEntry::make('gbus_fee') - ->extraAttributes(['class' => 'uppercase tracking-wide font-bold text-xs']) - ->label(sprintf('GBÜS tutumy: %s TMT', $gbus_fee)), - ]), + TextEntry::make('gbus_fee') + ->extraAttributes(['class' => 'uppercase tracking-wide font-bold text-xs']) + ->label(sprintf('GBÜS tutumy: %s TMT', $gbus_fee)), + ]), + + Fieldset::make() + ->columns([ + 'default' => 1, + 'md' => 2, + 'xl' => 3, + ]) + ->schema([ + TextInput::make('payment_amount') + ->label(sprintf('%s (%s)', __('Payment amount'), __('TMT'))) + ->required() + ->numeric() + ->maxValue($max_value) + ->helperText(sprintf('Iň ýokary möçberi: %s TMT', $max_value)) + ->live() + ->afterStateUpdated(function (Set $set, ?string $state) use ($usd_to_tmt) { + if (! $state || $state === 0 || $state === '') { + $set('usd_rate', ''); + + return; + } + + $usd_rate = number_format($state / $usd_to_tmt, 2, '.', ''); + $total_amount = floatval(number_format($state, 2, '.', '')) + 23; + + $set('usd_rate', $usd_rate.' USD'); + $set('total_amount', $total_amount.' TMT'); + }), + + TextEntry::make('usd_rate') + ->label(__('USD ekwalendi')), + + TextEntry::make('total_amount') + ->label(__('Total amount')), + ]), - TextInput::make(__('Töleg aý'), 'month') - ->fullWidth() - ->readonly() - ->default(today()->translatedFormat('F')), ]; - - // Text::make(sprintf('%s (%s)', __('Töleg möçberi'), __('TMT')), 'payment_amount') - // ->fullWidth() - // ->required() - // ->rules('required', 'numeric', 'max:'.$max_value) - // ->help("Iň ýokary möçberi: {$max_value} TMT"), - - // Text::make(__('USD ekwalendi'), 'usd_rate') - // ->fullWidth() - // ->readonly() - // ->dependsOn('payment_amount', function (Text $field, NovaRequest $request, FormData $formData) use ($usd_to_tmt) { - // $payment_amount = $formData->get('payment_amount'); - - // if ($payment_amount) { - // $field->setValue(number_format($payment_amount / $usd_to_tmt, 2, '.', '')); - // } else { - // $field->setValue(''); - // } - // }), - - // Hidden::make('usd_payment') - // ->dependsOn('payment_amount', function (Hidden $field, NovaRequest $request, FormData $formData) use ($usd_to_tmt) { - // $payment_amount = $formData->get('payment_amount'); - - // if ($payment_amount) { - // $field->setValue(number_format($payment_amount / $usd_to_tmt, 2, '.', '')); - // } else { - // $field->setValue(''); - // } - // }), - - // Text::make(__('Jemi (TMT)'), 'total_amount') - // ->fullWidth() - // ->readonly() - // ->dependsOn('payment_amount', function ($field, $request, $formData) { - // $payment_amount = $formData->get('payment_amount'); - - // if ($payment_amount) { - // $field->setValue( - // floatval(number_format($payment_amount, 2, '.', '')) + 23 - // ); - // } else { - // $field->setValue(''); - // } - // }), - - // Heading::make(Blade::render(<< - // - // - // - // $payment_warning_text->value - // - // HTML))->asHtml(), - // ]; }) ->action(function (array $data, VisaMasterPaymentOrder $record): void { // $record->author()->associate($data['authorId']); // $record->save(); - }) - ->modalFooterActions([]); + }); } } diff --git a/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterSettings.php b/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterSettings.php index 6900d71..0d55912 100644 --- a/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterSettings.php +++ b/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterSettings.php @@ -4,7 +4,7 @@ namespace App\Modules\VisaMasterPaymentOrder\Models; use Illuminate\Database\Eloquent\Model; -/** +/** * @property int $id * @property string $name * @property string $display_name diff --git a/lang/tk.json b/lang/tk.json index 7f5c371..f136ab5 100644 --- a/lang/tk.json +++ b/lang/tk.json @@ -711,5 +711,8 @@ "Currency value": "Kursy", "Currency rates": "Walýuta kurslary", "Warning text": "Duýduruş teksti", - "Content": "Mazmuny" + "Content": "Mazmuny", + "Payment month": "Töleg aýy", + "Make payment for:": "Töleg üçin:", + "Payment amount": "Töleg möçberi" }