Files
online.tbbank.gov.tm-larave…/app/Modules/VisaMasterPaymentOrder/Nova/Resources/Concerns/VisaMasterPaymentOrderFieldsForIndex.php
2025-03-15 23:58:38 +05:00

101 lines
3.1 KiB
PHP

<?php
namespace App\Modules\VisaMasterPaymentOrder\Nova\Resources\Concerns;
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder;
use App\Modules\VisaMasterPaymentOrder\Nova\Resources\NovaVisaMasterPaymentOrder;
use App\Nova\Resources\Branch\Branch;
use App\Repos\Order\OrderRepo;
use App\Repos\System\Settings\Location\RegionRepo;
use Laravel\Nova\Fields\Badge;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
class VisaMasterPaymentOrderFieldsForIndex
{
/**
* Loan Order fields for "create"
*
* @return array<int, \Laravel\Nova\Fields\Field>
*/
public static function make(NovaVisaMasterPaymentOrder $resource): array
{
return [
ID::make()->hide(),
Text::make(__('ID'), 'unique_id')->sortable(),
Select::make(__('Ýüztutmanyň görnüşi'), 'type')
->fullWidth()
->searchable()
->rules('required')
->displayUsingLabels()
->options(VisaMasterPaymentOrder::applicationTypes()),
DateTime::make(__('Created at'), 'created_at')
->turkmenDateTime(),
Select::make(__('Region'), 'region')
->displayUsingLabels()
->options(RegionRepo::values())
->canSeeWhen('isAdmin', $resource)
->sortable(),
BelongsTo::make(__('Branch'), 'branch', Branch::class)
->canSeeWhen('isAdmin', $resource)
->filterable()
->sortable(),
Text::make(__('Name'), 'passport_name'),
Text::make(__('Surname'), 'passport_surname'),
Text::make(__('Phone'), 'phone'),
Badge::make(__('Status'), 'status')
->map(OrderRepo::statusClasses())
->addTypes([
'primary' => 'dark:bg-gray-900 bg-gray-600 text-white',
])
->labels(OrderRepo::statusValues())
->withIcons()
->icons(OrderRepo::statusIcons())
->sortable(),
Text::make(sprintf('%s (%s)', __('Paid'), __('This month')), function () use ($resource) {
return static::paidField(
$resource,
$resource->offsetExists('filter_month') ? $resource->offsetGet('filter_month') : null
);
}),
];
}
/**
* Paid field
*/
public static function paidField(NovaVisaMasterPaymentOrder $resource, ?string $date = null): string
{
/** @var \App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder */
$model = $resource->model();
$items = $model->paymentItems;
$month = $date ?: date('m');
$paid = false;
foreach ($items as $item) {
if (boolval($item->paid)) {
if ($item->created_at->format('m') == $month) {
$paid = true;
}
}
}
return $paid ? 'Tölenen' : 'Tölenmedik';
}
}