diff --git a/app/Nova/Resource.php b/app/Nova/Resource.php index 2cfd39e..0c9f083 100644 --- a/app/Nova/Resource.php +++ b/app/Nova/Resource.php @@ -15,6 +15,13 @@ abstract class Resource extends NovaResource */ public static $trafficCop = false; + /** + * Indicates if the resource should be globally searchable. + * + * @var bool + */ + public static $globallySearchable = false; + /** * Determine if the current user can replicate the given resource. */ diff --git a/app/Nova/Resources/Order/Card/CardOrder.php b/app/Nova/Resources/Order/Card/CardOrder.php new file mode 100644 index 0000000..496cde4 --- /dev/null +++ b/app/Nova/Resources/Order/Card/CardOrder.php @@ -0,0 +1,333 @@ + + */ + public static $model = CardOrderModel::class; + + /** + * The single value that should be used to represent the resource when being displayed. + * + * @var string + */ + public static $title = 'unique_id'; + + /** + * The relationships that should be eager loaded on index queries. + * + * @var array + */ + // public static $with = ['branch', 'loanType']; + + /** + * The columns that should be searched. + * + * @var array + */ + public static $search = [ + 'unique_id', 'customer_name', 'customer_surname', 'phone', + ]; + + /** + * 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 __('Card orders'); + } + + /** + * Get the displayable singular label of the resource. + */ + public static function singularLabel(): string + { + return __('Card order'); + } + + /** + * 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, $query) + { + $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); + } + + /** + * Register a callback to be called after the resource is created. + */ + // public static function afterCreate(NovaRequest $request, Model $model): void + // { + // CardOrderNovaRepo::afterCreate($request, $model); + // } + + /** + * Get the fields for index. + */ + // public function fieldsForIndex(NovaRequest $request): array + // { + // return CardOrderFieldsForIndex::make($this); + // } + + // /** + // * Get the fields for detail + // */ + // public function fieldsForDetail(): array + // { + // return CardOrderFieldsForDetail::make($this); + // } + + /** + * Get the fields displayed by the resource. + */ + public function fields(NovaRequest $request): array + { + return [ + ID::make()->sortable(), + + Select::make(__('Status'), 'status') + ->displayUsingLabels() + ->searchable() + ->options(OrderRepo::statusValues()) + ->default(OrderRepo::defaultStatus()) + ->fullWidth() + ->rules('required') + ->canSeeWhen('systemUser', $this), + + Text::make(__('Note'), 'status') + ->fullWidth() + ->canSeeWhen('systemUser', $this), + + BelongsTo::make(__('Created by').': ', 'user', User::class) + ->fullWidth() + ->canSeeWhen('isMe', $this), + + new Panel(__('Loan'), [ + Select::make(__('Reason for issuing the card'), 'card_state_id') + ->displayUsingLabels() + ->fullWidth() + ->searchable() + ->options(CardStateRepo::values()) + ->rules('required') + ->sortable(), + + Select::make(__('Reason for issuing the card'), 'card_type_id') + ->displayUsingLabels() + ->fullWidth() + ->searchable() + ->options(CardTypeRepo::values()) + ->rules('required') + ->sortable(), + ]), + + new Panel(__('Location'), [ + Select::make(__('Region'), 'region') + ->displayUsingLabels() + ->searchable() + ->options(RegionRepo::values()) + ->default(RegionRepo::default()) + ->size('w-1/2') + ->rules('required') + ->sortable(), + + Select::make(__('Branch'), 'branch_id') + ->displayUsingLabels() + ->searchable() + ->dependsOn('region', NovaRepo::dependsOnRegion('region', Branch::class)) + ->size('w-1/2') + ->rules('required') + ->sortable(), + ]), + + new Panel(__('Personal data'), [ + Text::make(__('Name'), 'customer_name') + ->size('w-1/3') + ->rules('required', 'string', new OnlyLetters(), 'max:255'), + + Text::make(__('Surname'), 'customer_surname') + ->size('w-1/3') + ->rules('required', 'string', new OnlyLetters(), 'max:255'), + + Text::make(__('Patronic name'), 'customer_patronic_name') + ->size('w-1/3') + ->rules('required', 'string', new OnlyLetters(), 'max:255'), + + Date::make(__('Date of birth'), 'born_at') + ->size('w-1/3') + ->rules('required', 'before_or_equal:today'), + + NovaInputmask::make(__('Phone'), 'phone') + ->mask('+(\\9\\93)-99-99-99-99') + ->storeRawValue() + ->size('w-1/4') + ->rules('required', 'integer', 'between:61000000, 71999999'), + + NovaInputmask::make(__('Phone Additional'), 'phone_additional') + ->mask('+(\\9\\93)-99-99-99-99') + ->storeRawValue() + ->size('w-1/4') + ->rules('nullable', 'integer', 'between:61000000, 71999999'), + + Text::make(__('Residence (passport)'), 'passport_address') + ->size('w-1/2') + ->rules('required', 'string', new DowranAgaAllowed(), 'max:255'), + + Text::make(__('Current Residence'), 'real_address') + ->size('w-1/2') + ->rules('required', 'string', new DowranAgaAllowed(), 'max:255'), + ]), + + // Text::make(__(), 'old_surname'), + // Text::make(__(), 'citizenship'), + // Text::make(__(), 'job_location'), + + new Panel(__('Passport'), [ + Select::make(__('Passport serie'), 'passport_serie') + ->displayUsingLabels() + ->searchable() + ->options(PassportRepo::values()) + ->size('w-1/3') + ->rules('required') + ->sortable(), + + Number::make(__('Passport id'), 'passport_id') + ->size('w-1/3') + ->rules('required', 'numeric', 'digits:6'), + + Date::make(__('Passport date of issue'), 'passport_given_at') + ->size('w-1/3') + ->rules('required', 'before_or_equal:today'), + + Text::make(__('Passport given by'), 'passport_given_by') + ->size('w-1/2') + ->rules('required', 'string', new DowranAgaAllowed(), 'max:255'), + + Text::make(__('Born place (passport)'), 'born_place') + ->size('w-1/2') + ->rules('required', 'string', new DowranAgaAllowed(), 'max:255'), + ]), + + new Panel(__('Passport files'), [ + Image::make(__('Passport (page 1)'), 'passport_one') + ->size('w-1/2') + ->deletable(false) + ->rules('max:2048', 'mimes:jpg,png,jpeg') + ->creationRules('required') + ->updateRules('nullable'), + + Image::make(__('Passport (page 2-3)'), 'passport_two') + ->size('w-1/2') + ->deletable(false) + ->rules('max:2048', 'mimes:jpg,png,jpeg') + ->creationRules('required') + ->updateRules('nullable'), + + Image::make(__('Passport (page 8-9)'), 'passport_three') + ->size('w-1/2') + ->deletable(false) + ->rules('max:2048', 'mimes:jpg,png,jpeg') + ->creationRules('required') + ->updateRules('nullable'), + + Image::make(__('Passport (page 32)'), 'passport_four') + ->size('w-1/2') + ->deletable(false) + ->rules('max:2048', 'mimes:jpg,png,jpeg') + ->creationRules('required') + ->updateRules('nullable'), + ]), + ]; + } + + /** + * Get the cards available for the request. + */ + public function cards(NovaRequest $request): array + { + return []; + } + + /** + * Get the filters available for the resource. + */ + public function filters(NovaRequest $request): array + { + return []; + } + + /** + * Get the lenses available for the resource. + */ + public function lenses(NovaRequest $request): array + { + return []; + } + + /** + * Get the actions available for the resource. + */ + public function actions(NovaRequest $request): array + { + return []; + } +} diff --git a/app/Nova/Resources/Order/Card/CardState.php b/app/Nova/Resources/Order/Card/CardState.php new file mode 100644 index 0000000..b8fda2c --- /dev/null +++ b/app/Nova/Resources/Order/Card/CardState.php @@ -0,0 +1,101 @@ + + */ + public static $model = CardStateModel::class; + + /** + * The single value that should be used to represent the resource when being displayed. + * + * @var string + */ + public static $title = 'name'; + + /** + * The columns that should be searched. + * + * @var array + */ + public static $search = [ + 'name', + ]; + + /** + * Get the displayable label of the resource. + */ + public static function label(): string + { + return __('Card states'); + } + + /** + * Get the displayable singular label of the resource. + */ + public static function singularLabel(): string + { + return __('Card state'); + } + + /** + * Get the fields displayed by the resource. + */ + public function fields(NovaRequest $request): array + { + return [ + ID::make()->sortable(), + + Text::make(__('Name'), 'name') + ->rules('required', 'string', 'max:255') + ->translatable(), + + Text::make(__('Price'), 'price') + ->rules('required', 'string', 'max:255'), + ]; + } + + /** + * Get the cards available for the request. + */ + public function cards(NovaRequest $request): array + { + return []; + } + + /** + * Get the filters available for the resource. + */ + public function filters(NovaRequest $request): array + { + return []; + } + + /** + * Get the lenses available for the resource. + */ + public function lenses(NovaRequest $request): array + { + return []; + } + + /** + * Get the actions available for the resource. + */ + public function actions(NovaRequest $request): array + { + return []; + } +} diff --git a/app/Nova/Resources/Order/Card/CardType.php b/app/Nova/Resources/Order/Card/CardType.php new file mode 100644 index 0000000..0fd0479 --- /dev/null +++ b/app/Nova/Resources/Order/Card/CardType.php @@ -0,0 +1,91 @@ + + */ + public static $model = CardTypeModel::class; + + /** + * The single value that should be used to represent the resource when being displayed. + * + * @var string + */ + public static $title = 'name'; + + /** + * The columns that should be searched. + * + * @var array + */ + public static $search = [ + 'name', + ]; + + /** + * Get the fields displayed by the resource. + */ + public function fields(NovaRequest $request): array + { + return [ + ID::make()->sortable(), + + Text::make(__('Name'), 'name') + ->rules('required', 'string', 'max:255') + ->translatable(), + + Text::make(__('Price'), 'price') + ->rules('nullable', 'numeric'), + + Text::make(__('Notes'), 'notes') + ->rules('required', 'string', 'max:255'), + + NovaSwitcher::make(__('Active'), 'active') + ->default(true), + ]; + } + + /** + * Get the cards available for the request. + */ + public function cards(NovaRequest $request): array + { + return []; + } + + /** + * Get the filters available for the resource. + */ + public function filters(NovaRequest $request): array + { + return []; + } + + /** + * Get the lenses available for the resource. + */ + public function lenses(NovaRequest $request): array + { + return []; + } + + /** + * Get the actions available for the resource. + */ + public function actions(NovaRequest $request): array + { + return []; + } +} diff --git a/app/Nova/Resources/Order/Card/Concerns/CardOrderFieldsForDetail.php b/app/Nova/Resources/Order/Card/Concerns/CardOrderFieldsForDetail.php new file mode 100644 index 0000000..8849ff6 --- /dev/null +++ b/app/Nova/Resources/Order/Card/Concerns/CardOrderFieldsForDetail.php @@ -0,0 +1,7 @@ +branch_id)->unique_code ?? 'TB', + $model->id + )) ?? uniqid(); + } + + /** + * After model has been created + */ + public static function afterCreate(NovaRequest $request, Model $model): void + { + $model->update([ + 'unique_id' => static::fillUniqueId($request, $model), + 'user_id' => auth()->id(), + 'status' => OrderRepo::defaultStatus(), + ]); + } +} diff --git a/app/Nova/Resources/Order/Loan/LoanOrder.php b/app/Nova/Resources/Order/Loan/LoanOrder.php index 20bec71..9871f44 100644 --- a/app/Nova/Resources/Order/Loan/LoanOrder.php +++ b/app/Nova/Resources/Order/Loan/LoanOrder.php @@ -29,7 +29,6 @@ use Laravel\Nova\Fields\Date; use Laravel\Nova\Fields\Email; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Image; -use Laravel\Nova\Fields\MorphMany; use Laravel\Nova\Fields\Number; use Laravel\Nova\Fields\Select; use Laravel\Nova\Fields\Text; @@ -66,7 +65,7 @@ class LoanOrder extends Resource * @var array */ public static $search = [ - 'unique_id', 'customer_name', 'customer_surname', + 'unique_id', 'customer_name', 'customer_surname', 'phone', ]; /** @@ -367,9 +366,6 @@ class LoanOrder extends Resource ->creationRules('required') ->updateRules('nullable'), ]), - - MorphMany::make(__('Actions'), 'actions', config('nova.actions.resource')) - ->canSee(fn ($request) => false), ]; } diff --git a/app/Providers/NovaServiceProvider.php b/app/Providers/NovaServiceProvider.php index d284d64..4c66ec5 100644 --- a/app/Providers/NovaServiceProvider.php +++ b/app/Providers/NovaServiceProvider.php @@ -4,6 +4,7 @@ namespace App\Providers; use App\Nova\Dashboards\Main; use App\Nova\Resources\Branch\Branch; +use App\Nova\Resources\Order\Card\CardState; use App\Nova\Resources\Order\Loan\LoanOrder; use App\Nova\Resources\Order\Loan\LoanType; use App\Nova\Resources\System\Location\Province; @@ -127,10 +128,14 @@ class NovaServiceProvider extends NovaApplicationServiceProvider MenuItem::resource(Permission::class), ])->collapsable(), - MenuGroup::make(__('Loan'), [ + MenuGroup::make(__('Loan orders'), [ MenuItem::resource(LoanType::class), ])->collapsable(), + MenuGroup::make(__('Card orders'), [ + MenuItem::resource(CardState::class), + ]), + MenuGroup::make(__('Location'), [ MenuItem::resource(Province::class), MenuItem::resource(Branch::class), diff --git a/app/Repos/Order/Card/CardStateRepo.php b/app/Repos/Order/Card/CardStateRepo.php new file mode 100644 index 0000000..993b62f --- /dev/null +++ b/app/Repos/Order/Card/CardStateRepo.php @@ -0,0 +1,17 @@ +pluck('name', 'id'); + } +} diff --git a/app/Repos/Order/Card/CardTypeRepo.php b/app/Repos/Order/Card/CardTypeRepo.php new file mode 100644 index 0000000..7ed1043 --- /dev/null +++ b/app/Repos/Order/Card/CardTypeRepo.php @@ -0,0 +1,17 @@ +pluck('name', 'id'); + } +} diff --git a/database/migrations/2023_12_08_173710_create_card_states_table.php b/database/migrations/2023_12_08_173710_create_card_states_table.php index a780430..e56444d 100644 --- a/database/migrations/2023_12_08_173710_create_card_states_table.php +++ b/database/migrations/2023_12_08_173710_create_card_states_table.php @@ -15,6 +15,8 @@ return new class extends Migration $table->id(); $table->jsonb('name'); $table->string('price')->nullable(); + $table->string('notes')->nullable(); + $table->boolean('active')->default(true); $table->timestamps(); }); } diff --git a/database/migrations/2023_12_08_173710_create_card_types_table.php b/database/migrations/2023_12_08_173710_create_card_types_table.php index 37163fe..52f232b 100644 --- a/database/migrations/2023_12_08_173710_create_card_types_table.php +++ b/database/migrations/2023_12_08_173710_create_card_types_table.php @@ -15,6 +15,8 @@ return new class extends Migration $table->id(); $table->jsonb('name'); $table->string('price')->nullable(); + $table->string('notes')->nullable(); + $table->boolean('active')->default(true); $table->timestamps(); }); } diff --git a/lang/tk.json b/lang/tk.json index cc24078..005e98d 100644 --- a/lang/tk.json +++ b/lang/tk.json @@ -231,5 +231,10 @@ "all": "ählisi", "Created by": "Sargyt eden", "Updated by": "Üýtgeden", - "Passport files": "Pasport faýýlar" + "Passport files": "Pasport faýýlar", + "Card order": "Kart sargyt", + "Card orders": "Kart sargytlary", + "Reason for issuing the card": "Kartyň çykarylmagynyň sebäbi", + "Card state": "Kartyň çykarylmagynyň sebäbi", + "Card states": "Kartyň çykarylmagynyň sebäpleri" }