84 lines
2.3 KiB
PHP
84 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\SberPaymentOrder\Nova\Resources\Concerns;
|
|
|
|
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 SberPaymentOrderFieldsForIndex
|
|
{
|
|
/**
|
|
* Loan Order fields for "create"
|
|
*/
|
|
public static function make($resource): array
|
|
{
|
|
return [
|
|
ID::make()->hide(),
|
|
|
|
Text::make(__('ID'), 'unique_id')->sortable(),
|
|
|
|
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->filter_month);
|
|
}),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Paid field
|
|
*/
|
|
public static function paidField($resource, $date = null)
|
|
{
|
|
$paid = false;
|
|
$items = $resource->paymentItems;
|
|
|
|
$month = $date ?: date('m');
|
|
|
|
foreach ($items as $item) {
|
|
if (boolval($item->paid)) {
|
|
if ($item->created_at->format('m') == $month) {
|
|
$paid = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $paid ? 'Tölenen' : 'Tölenmedik';
|
|
}
|
|
}
|