From c2103fd810a38920edf9d739d1f20792db176298 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Mon, 14 Oct 2024 14:05:37 +0500 Subject: [PATCH] wip --- .../Actions/MakePaymentNovaVisaMaster.php | 24 ++++++++++++++-- app/Nova/Resources/CurrencyRate.php | 1 + ...4_132424_add_index_to_currencies_table.php | 28 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2024_10_14_132424_add_index_to_currencies_table.php diff --git a/app/Nova/Actions/MakePaymentNovaVisaMaster.php b/app/Nova/Actions/MakePaymentNovaVisaMaster.php index 3ae2a1b..9f9ad62 100644 --- a/app/Nova/Actions/MakePaymentNovaVisaMaster.php +++ b/app/Nova/Actions/MakePaymentNovaVisaMaster.php @@ -2,6 +2,7 @@ namespace App\Nova\Actions; +use App\Models\CurrencyRate; use App\Models\Payment\OnlinePaymentHistory; use App\Repos\Payment\OnlinePaymentRepo; use Illuminate\Bus\Queueable; @@ -12,6 +13,7 @@ use Illuminate\Support\Facades\Log; use Laravel\Nova\Actions\Action; use Laravel\Nova\Actions\ActionResponse; use Laravel\Nova\Fields\ActionFields; +use Laravel\Nova\Fields\Heading; use Laravel\Nova\Fields\Text; use Laravel\Nova\Http\Requests\NovaRequest; @@ -57,11 +59,29 @@ class MakePaymentNovaVisaMaster extends Action */ public function fields(NovaRequest $request): array { + $usd_to_tmt = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value'); + + $max_value = number_format($usd_to_tmt->value * 250, 2); + return [ - Text::make(__('Töleg möçberi'), 'payment_amount') + Heading::make('1 USD = ' . $usd_to_tmt->value . ' TMT'), + + Text::make(sprintf('%s (%s)', __('Töleg möçberi'), __('TMT')), 'payment_amount') ->fullWidth() ->required() - ->rules('required', 'rules:250'), + ->rules('required', 'max:' . $max_value) + ->help("Iň ýokary möçberi: {$max_value} TMT"), + + Text::make(__('USD ekwalendi'), 'usd_rate') + ->fullWidth() + ->readonly() + ->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_tmt) { + if ($formData->payment_amount) { + $field->setValue(number_format($formData->payment_amount / $usd_to_tmt->value, 2)); + } else { + $field->setValue(''); + } + }) ]; } diff --git a/app/Nova/Resources/CurrencyRate.php b/app/Nova/Resources/CurrencyRate.php index 139dafc..8ea5c6d 100644 --- a/app/Nova/Resources/CurrencyRate.php +++ b/app/Nova/Resources/CurrencyRate.php @@ -65,6 +65,7 @@ class CurrencyRate extends Resource Text::make('Value', 'value') ->fullWidth() + ->help('Bitin däl sanlary "." bilen ýazmaly') ->rules('required', 'numeric'), ]; } diff --git a/database/migrations/2024_10_14_132424_add_index_to_currencies_table.php b/database/migrations/2024_10_14_132424_add_index_to_currencies_table.php new file mode 100644 index 0000000..b3896d5 --- /dev/null +++ b/database/migrations/2024_10_14_132424_add_index_to_currencies_table.php @@ -0,0 +1,28 @@ +index(['currency_from', 'currency_to']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('currency_rates', function (Blueprint $table) { + $table->dropIndex('currency_rates_currency_from_currency_to_index'); + }); + } +};