Add card order
This commit is contained in:
@@ -4,20 +4,24 @@ namespace App\Nova\Resources\Order\Card;
|
||||
|
||||
use App\Models\Branch\Branch;
|
||||
use App\Models\Order\Card\CardOrder as CardOrderModel;
|
||||
use App\Nova\Filters\RegionFilter;
|
||||
use App\Nova\Filters\StatusFilter;
|
||||
use App\Nova\Resource;
|
||||
use App\Nova\Resources\Order\Card\Concerns\CardOrderNovaRepo;
|
||||
use App\Nova\User;
|
||||
use App\Nova\Resources\Order\Card\Concerns\CardOrderFieldsForDetail;
|
||||
use App\Nova\Resources\Order\Card\Concerns\CardOrderFieldsForIndex;
|
||||
use App\Repos\Order\Card\CardStateRepo;
|
||||
use App\Repos\Order\Card\CardTypeRepo;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
use App\Repos\System\Location\CountryRepo;
|
||||
use App\Repos\System\Nova\NovaRepo;
|
||||
use App\Repos\System\Settings\Legal\PassportRepo;
|
||||
use App\Repos\System\Settings\Location\RegionRepo;
|
||||
use App\Rules\DowranAgaAllowed;
|
||||
use App\Rules\OnlyLetters;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Nova\Fields\BelongsTo;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Nova\Fields\Date;
|
||||
use Laravel\Nova\Fields\Hidden;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Image;
|
||||
use Laravel\Nova\Fields\Number;
|
||||
@@ -48,7 +52,7 @@ class CardOrder extends Resource
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
// public static $with = ['branch', 'loanType'];
|
||||
public static $with = ['branch', 'cardState', 'cardType'];
|
||||
|
||||
/**
|
||||
* The columns that should be searched.
|
||||
@@ -117,29 +121,21 @@ class CardOrder extends Resource
|
||||
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);
|
||||
// }
|
||||
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 for detail
|
||||
*/
|
||||
public function fieldsForDetail(): array
|
||||
{
|
||||
return CardOrderFieldsForDetail::make($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fields displayed by the resource.
|
||||
@@ -147,7 +143,11 @@ class CardOrder extends Resource
|
||||
public function fields(NovaRequest $request): array
|
||||
{
|
||||
return [
|
||||
ID::make()->sortable(),
|
||||
ID::make(),
|
||||
|
||||
Hidden::make('user_id')
|
||||
->default(auth()->id())
|
||||
->hideWhenUpdating(),
|
||||
|
||||
Select::make(__('Status'), 'status')
|
||||
->displayUsingLabels()
|
||||
@@ -162,26 +162,22 @@ class CardOrder extends Resource
|
||||
->fullWidth()
|
||||
->canSeeWhen('systemUser', $this),
|
||||
|
||||
BelongsTo::make(__('Created by').': ', 'user', User::class)
|
||||
->fullWidth()
|
||||
->canSeeWhen('isMe', $this),
|
||||
|
||||
new Panel(__('Loan'), [
|
||||
new Panel(__('Card'), [
|
||||
Select::make(__('Reason for issuing the card'), 'card_state_id')
|
||||
->displayUsingLabels()
|
||||
->fullWidth()
|
||||
->searchable()
|
||||
->options(CardStateRepo::values())
|
||||
->rules('required')
|
||||
->sortable(),
|
||||
->size('w-1/2')
|
||||
->rules('required'),
|
||||
|
||||
Select::make(__('Reason for issuing the card'), 'card_type_id')
|
||||
Select::make(__('Card type'), 'card_type_id')
|
||||
->displayUsingLabels()
|
||||
->fullWidth()
|
||||
->searchable()
|
||||
->options(CardTypeRepo::values())
|
||||
->rules('required')
|
||||
->sortable(),
|
||||
->size('w-1/2')
|
||||
->rules('required'),
|
||||
]),
|
||||
|
||||
new Panel(__('Location'), [
|
||||
@@ -191,16 +187,14 @@ class CardOrder extends Resource
|
||||
->options(RegionRepo::values())
|
||||
->default(RegionRepo::default())
|
||||
->size('w-1/2')
|
||||
->rules('required')
|
||||
->sortable(),
|
||||
->rules('required'),
|
||||
|
||||
Select::make(__('Branch'), 'branch_id')
|
||||
->displayUsingLabels()
|
||||
->searchable()
|
||||
->dependsOn('region', NovaRepo::dependsOnRegion('region', Branch::class))
|
||||
->size('w-1/2')
|
||||
->rules('required')
|
||||
->sortable(),
|
||||
->rules('required'),
|
||||
]),
|
||||
|
||||
new Panel(__('Personal data'), [
|
||||
@@ -216,22 +210,34 @@ class CardOrder extends Resource
|
||||
->size('w-1/3')
|
||||
->rules('required', 'string', new OnlyLetters(), 'max:255'),
|
||||
|
||||
Text::make(__('Old surname (if changed)'), 'old_surname')
|
||||
->size('w-1/2')
|
||||
->rules('nullable', 'string', new OnlyLetters(), 'max:255'),
|
||||
|
||||
Date::make(__('Date of birth'), 'born_at')
|
||||
->size('w-1/3')
|
||||
->size('w-1/2')
|
||||
->rules('required', 'before_or_equal:today'),
|
||||
|
||||
NovaInputmask::make(__('Phone'), 'phone')
|
||||
->mask('+(\\9\\93)-99-99-99-99')
|
||||
->storeRawValue()
|
||||
->size('w-1/4')
|
||||
->size('w-1/3')
|
||||
->rules('required', 'integer', 'between:61000000, 71999999'),
|
||||
|
||||
NovaInputmask::make(__('Phone Additional'), 'phone_additional')
|
||||
->mask('+(\\9\\93)-99-99-99-99')
|
||||
->storeRawValue()
|
||||
->size('w-1/4')
|
||||
->size('w-1/3')
|
||||
->rules('nullable', 'integer', 'between:61000000, 71999999'),
|
||||
|
||||
Select::make(__('Citizenship'), 'citizenship')
|
||||
->displayUsingLabels()
|
||||
->searchable()
|
||||
->options(CountryRepo::values())
|
||||
->default('TM')
|
||||
->size('w-1/3')
|
||||
->rules('required'),
|
||||
|
||||
Text::make(__('Residence (passport)'), 'passport_address')
|
||||
->size('w-1/2')
|
||||
->rules('required', 'string', new DowranAgaAllowed(), 'max:255'),
|
||||
@@ -239,11 +245,11 @@ class CardOrder extends Resource
|
||||
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'),
|
||||
Text::make(__('Work location and your position'), 'job_location')
|
||||
->size('w-full')
|
||||
->rules('required', 'string', new DowranAgaAllowed(), 'max:255'),
|
||||
]),
|
||||
|
||||
new Panel(__('Passport'), [
|
||||
Select::make(__('Passport serie'), 'passport_serie')
|
||||
@@ -251,8 +257,7 @@ class CardOrder extends Resource
|
||||
->searchable()
|
||||
->options(PassportRepo::values())
|
||||
->size('w-1/3')
|
||||
->rules('required')
|
||||
->sortable(),
|
||||
->rules('required'),
|
||||
|
||||
Number::make(__('Passport id'), 'passport_id')
|
||||
->size('w-1/3')
|
||||
@@ -316,7 +321,12 @@ class CardOrder extends Resource
|
||||
*/
|
||||
public function filters(NovaRequest $request): array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
RegionFilter::make()
|
||||
->canSee(fn () => Gate::allows('isAdmin'), auth()->user()),
|
||||
|
||||
new StatusFilter(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,101 @@
|
||||
|
||||
namespace App\Nova\Resources\Order\Card\Concerns;
|
||||
|
||||
use App\Nova\Resources\Branch\Branch;
|
||||
use App\Nova\Resources\Order\Card\CardState;
|
||||
use App\Nova\Resources\Order\Card\CardType;
|
||||
use App\Nova\User;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
use App\Repos\System\Location\CountryRepo;
|
||||
use App\Repos\System\Settings\Location\RegionRepo;
|
||||
use Laravel\Nova\Fields\Badge;
|
||||
use Laravel\Nova\Fields\BelongsTo;
|
||||
use Laravel\Nova\Fields\Date;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Image;
|
||||
use Laravel\Nova\Fields\Select;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Panel;
|
||||
use Nurmuhammet\NovaInputmask\NovaInputmask;
|
||||
|
||||
class CardOrderFieldsForDetail
|
||||
{
|
||||
/**
|
||||
* Fields for index page
|
||||
*/
|
||||
public static function make($resource): array
|
||||
{
|
||||
return [
|
||||
ID::make()->hide(),
|
||||
Text::make(__('ID'), 'unique_id'),
|
||||
|
||||
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'),
|
||||
|
||||
BelongsTo::make(__('Created by').': ', 'user', User::class),
|
||||
|
||||
new Panel(__('Card'), [
|
||||
BelongsTo::make(__('Reason for issuing the card'), 'cardState', CardState::class),
|
||||
BelongsTo::make(__('Card type'), 'cardType', CardType::class),
|
||||
]),
|
||||
|
||||
new Panel(__('Location'), [
|
||||
Select::make(__('Region'), 'region')
|
||||
->displayUsingLabels()
|
||||
->options(RegionRepo::values()),
|
||||
|
||||
BelongsTo::make(__('Branch'), 'branch', Branch::class),
|
||||
]),
|
||||
|
||||
new Panel(__('Personal data'), [
|
||||
Text::make(
|
||||
__('Full Name'),
|
||||
fn ($model) => sprintf(
|
||||
'%s %s%s %s',
|
||||
$model->customer_name,
|
||||
$model->customer_surname,
|
||||
$model->old_surname ? sprintf('(%s)', $model->old_surname) : '',
|
||||
$model->customer_patronic_name
|
||||
)
|
||||
),
|
||||
|
||||
Date::make(__('Date of birth'), 'born_at')
|
||||
->toTurkmenFormat(),
|
||||
|
||||
NovaInputmask::make(__('Phone'), 'phone')
|
||||
->mask('+(\\9\\93)-99-99-99-99')
|
||||
->storeRawValue(),
|
||||
|
||||
NovaInputmask::make(__('Phone additional'), 'phone_additional')
|
||||
->mask('+(\\9\\93)-99-99-99-99')
|
||||
->storeRawValue(),
|
||||
|
||||
Select::make(__('Citizenship'), 'citizenship')
|
||||
->displayUsingLabels()
|
||||
->searchable()
|
||||
->options(CountryRepo::values()),
|
||||
|
||||
Text::make(__('Residence (passport)'), 'passport_address'),
|
||||
|
||||
Text::make(__('Current Residence'), 'real_address'),
|
||||
|
||||
Text::make(__('Work location and your position'), 'job_location'),
|
||||
]),
|
||||
|
||||
new Panel(__('Passport files'), [
|
||||
Image::make(__('Passport (page 1)'), 'passport_one'),
|
||||
Image::make(__('Passport (page 2-3)'), 'passport_two'),
|
||||
Image::make(__('Passport (page 8-9)'), 'passport_three'),
|
||||
Image::make(__('Passport (page 32)'), 'passport_four'),
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,61 @@
|
||||
|
||||
namespace App\Nova\Resources\Order\Card\Concerns;
|
||||
|
||||
use App\Nova\Resources\Branch\Branch;
|
||||
use App\Nova\Resources\Order\Card\CardState;
|
||||
use App\Nova\Resources\Order\Card\CardType;
|
||||
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\ID;
|
||||
use Laravel\Nova\Fields\Select;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
|
||||
class CardOrderFieldsForIndex
|
||||
{
|
||||
/**
|
||||
* Fields for index page
|
||||
*/
|
||||
public static function make($resource): array
|
||||
{
|
||||
return [
|
||||
ID::make()->hide(),
|
||||
|
||||
Text::make(__('ID'), 'unique_id')->sortable(),
|
||||
|
||||
BelongsTo::make(__('Reason'), 'cardState', CardState::class)
|
||||
->sortable(),
|
||||
|
||||
BelongsTo::make(__('Type'), 'cardType', CardType::class)
|
||||
->sortable(),
|
||||
|
||||
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'), 'customer_name'),
|
||||
|
||||
Text::make(__('Surname'), 'customer_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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,34 +2,6 @@
|
||||
|
||||
namespace App\Nova\Resources\Order\Card\Concerns;
|
||||
|
||||
use App\Models\Branch\Branch;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
|
||||
class CardOrderNovaRepo
|
||||
{
|
||||
/**
|
||||
* Fill unique
|
||||
*/
|
||||
public static function fillUniqueId($request, $model): string
|
||||
{
|
||||
return mb_strtoupper(sprintf(
|
||||
'TB%s-%s',
|
||||
Branch::find($request->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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user