Files
tbbank-new/app/Modules/VisaMasterPaymentOrder/Filament/Actions/PayVisaMasterPaymentAction.php

99 lines
4.2 KiB
PHP

<?php
namespace App\Modules\VisaMasterPaymentOrder\Filament\Actions;
use App\Modules\CurrencyRate\Models\CurrencyRate;
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder;
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterSettings;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Infolists\Components\TextEntry;
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(sprintf('%s %s', __('Make payment for:'), today()->translatedFormat('F')))
->icon('heroicon-o-credit-card')
->modal()
->schema(function () {
$usd_to_tmt = floatval(CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value')?->value);
$payment_warning_text = VisaMasterSettings::where('name', 'payment_warning_text')->first();
if (! $usd_to_tmt || ! $payment_warning_text) {
return [];
}
$bank_fee = 20;
$gbus_fee = 3;
$max_value = number_format($usd_to_tmt * 250, 2);
return [
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('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')),
]),
];
})
->action(function (array $data, VisaMasterPaymentOrder $record): void {
// $record->author()->associate($data['authorId']);
// $record->save();
});
}
}