88 lines
3.0 KiB
PHP
88 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Nova\Actions;
|
|
|
|
use App\Models\CurrencyRate;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Laravel\Nova\Actions\Action;
|
|
use Laravel\Nova\Fields\ActionFields;
|
|
use Laravel\Nova\Fields\Heading;
|
|
use Laravel\Nova\Fields\Text;
|
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
|
|
|
class MakeSberPaymentAction extends Action
|
|
{
|
|
use InteractsWithQueue, Queueable;
|
|
|
|
/**
|
|
* Perform the action on the given models.
|
|
*
|
|
* @param \Laravel\Nova\Fields\ActionFields $fields
|
|
* @param \Illuminate\Support\Collection $models
|
|
* @return mixed
|
|
*/
|
|
public function handle(ActionFields $fields, Collection $models)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Get the fields available on the action.
|
|
*
|
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
|
* @return array
|
|
*/
|
|
public function fields(NovaRequest $request)
|
|
{
|
|
$usd_to_tmt = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value');
|
|
|
|
if (! $usd_to_tmt) {
|
|
return [];
|
|
}
|
|
|
|
$max_value = number_format($usd_to_tmt->value * 250, 2);
|
|
|
|
return [
|
|
Heading::make(Blade::render(<<<HTML
|
|
<h3 class="uppercase tracking-wide font-bold text-xs" dusk="heading">1 USD = $usd_to_tmt->value TMT</h3>
|
|
<h3 class="uppercase tracking-wide font-bold text-xs" dusk="heading">TVEB USD tutumy: 18 USD</h3>
|
|
<h3 class="uppercase tracking-wide font-bold text-xs" dusk="heading">GBÜS tutumy: 3 TMT</h3>
|
|
HTML))->asHtml(),
|
|
|
|
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 ($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('');
|
|
}
|
|
}),
|
|
|
|
Text::make(__('Jemi (TMT)'), 'total_amount')
|
|
->fullWidth()
|
|
->readonly()
|
|
->dependsOn('payment_amount', function ($field, $request, $formData) {
|
|
if (is_numeric($formData->payment_amount)) {
|
|
$field->setValue(
|
|
floatval(number_format($formData->payment_amount, 2, '.', '')) + 23
|
|
);
|
|
} else {
|
|
$field->setValue('');
|
|
}
|
|
}),
|
|
];
|
|
}
|
|
}
|