This commit is contained in:
2024-10-14 14:05:37 +05:00
parent 5cd8123286
commit c2103fd810
3 changed files with 51 additions and 2 deletions

View File

@@ -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('');
}
})
];
}

View File

@@ -65,6 +65,7 @@ class CurrencyRate extends Resource
Text::make('Value', 'value')
->fullWidth()
->help('Bitin däl sanlary "." bilen ýazmaly')
->rules('required', 'numeric'),
];
}

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('currency_rates', function (Blueprint $table) {
$table->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');
});
}
};