*/ public static $model = \App\Modules\SberPaymentOrder\Models\SberPaymentOrder::class; /** * The single value that should be used to represent the resource when being displayed. * * @var string */ public static $title = 'unique_id'; /** * The columns that should be searched. * * @var array */ public static $search = [ 'unique_id', 'passport_name', 'passport_surname', 'phone', ]; /** * The relationships that should be eager loaded on index queries. * * @var array */ public static $with = ['branch']; /** * Indicates whether the resource should automatically poll for new resources. * * @var bool */ public static $polling = true; /** * The interval at which Nova should poll for new resources. * * @var int */ public static $pollingInterval = 120; /** * Indicates whether to show the polling toggle button inside Nova. * * @var bool */ public static $showPollingToggle = true; /** * Get the displayable label of the resource. */ public static function label(): string { return sprintf( '%s (%s)', __('Sber payments'), Str::lower(__('For students')) ); } /** * Get the displayable singular label of the resource. */ public static function singularLabel(): string { return sprintf( '%s (%s)', __('Sber payment'), Str::lower(__('For students')) ); } /** * Build an "index" query for the given resource. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public static function indexQuery(NovaRequest $request, mixed $query): Builder { $user = $request->user(); if ($user->isAdmin()) { return $query; } if ($user->isOperator()) { return $query->whereIn('branch_id', $user->branches()->pluck('branches.id')); } return $query->where('user_id', $request->user()->id); } /** * After resource created * * @param \Laravel\Nova\Http\Requests\NovaRequest $request * @param \Illuminate\Database\Eloquent\Model $model */ public static function afterCreate(NovaRequest $request, Model $model): void { $model->update(['unique_id' => CardOrderRepo::fillUniqueId($model)]); } /** * Get the fields for index. */ public function fieldsForIndex(): array { return SberPaymentOrderFieldsForIndex::make($this); } /** * Get the fields for detail */ public function fieldsForDetail(): array { return SberPaymentOrderFieldsForDetail::make($this); } /** * Get the fields displayed by the resource. * * @param \Laravel\Nova\Http\Requests\NovaRequest $request * @return array */ public function fields(NovaRequest $request): array { return [ new Panel(__('Status'), [ ID::make() ->hideFromDetail(), Hidden::make('user_id') ->default(auth()->id()) ->hideWhenUpdating(), Text::make(__('ID'), 'unique_id') ->exceptOnForms(), Select::make(__('Status'), 'status') ->displayUsingLabels() ->searchable() ->options(OrderRepo::statusValues()) ->default(OrderRepo::defaultStatus()) ->fullWidth() ->hideFromDetail() ->rules('required') ->canSeeWhen('systemUser', $this), 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()), Text::make(__('Note'), 'notes') ->fullWidth() ->canSeeWhen('systemUser', $this), ]), new Panel(__('Location'), [ Select::make(__('Region'), 'region') ->fullWidth() ->displayUsingLabels() ->searchable() ->options(RegionRepo::values()) ->default(RegionRepo::default()) ->rules('required') ->sortable(), Select::make(__('Branch'), 'branch_id') ->fullWidth() ->displayUsingLabels() ->searchable() ->dependsOn('region', NovaRepo::dependsOnRegion('region', Branch::class)) ->rules('required') ->sortable(), ]), new Panel(__('Personal data'), [ Text::make(__('Passport name'), 'passport_name') ->fullWidth() ->rules('required', 'string', 'max:255'), Text::make(__('Passport surname'), 'passport_surname') ->fullWidth() ->rules('required', 'string', 'max:255'), NovaInputmask::make(__('Phone'), 'phone') ->fullWidth() ->phonenumber('TM') ->rules('required', 'max:255') ->hideFromIndex(), Text::make(__('Email'), 'email') ->fullWidth() ->rules('nullable', 'max:255', 'email') ->hideFromIndex(), Text::make(__('Current Residence'), 'address') ->fullWidth() ->rules('required', 'string', 'max:255') ->hideFromIndex(), ]), new Panel(__('Payment'), [ SimpleRepeatable::make(__('Payment sender data'), 'sender_datas', [ Select::make(__('Passport serie'), 'passport_serie') ->displayUsingLabels() ->searchable() ->options(PassportRepo::values()) ->rules('required') ->sortable(), NovaInputmask::make(__('Passport number'), 'passport_number') ->mask('999999') ->rules('required', 'max:255'), Text::make( name: sprintf('%s %s %s', __('Name'), __('Surname'), __('Patronic name')), attribute: 'full_name' ) ->rules('required', 'max:255'), ])->minRows(1)->rules('required'), SimpleRepeatable::make(__('Payee information'), 'payment_reciever', [ Select::make(__('Passport serie'), 'passport_serie') ->displayUsingLabels() ->searchable() ->options(PassportRepo::values()) ->rules('required') ->sortable(), NovaInputmask::make(__('Passport number'), 'passport_number') ->mask('999999') ->rules('required', 'max:255'), Text::make( name: sprintf('%s %s %s', __('Name'), __('Surname'), __('Patronic name')), attribute: 'full_name' )->rules('required', 'max:255'), ])->maxRows(1)->minRows(1)->rules('required'), ]), new Panel(__('Reciver files'), SberPaymentOrderFileFields::reciverFiles()), new Panel(__('Sender files'), SberPaymentOrderFileFields::senderFiles()), ]; } }