278 lines
7.9 KiB
PHP
278 lines
7.9 KiB
PHP
<?php
|
|
|
|
namespace App\Nova\Resources\Order\Loan;
|
|
|
|
use App\Models\Branch\Branch;
|
|
use App\Models\Order\Loan\LoanPaidOffLetterOrder as LoanPaidOffLetterOrderModel;
|
|
use App\Nova\Filters\RegionFilter;
|
|
use App\Nova\Filters\StatusFilter;
|
|
use App\Nova\Resource;
|
|
use App\Repos\Order\Card\CardOrderRepo;
|
|
use App\Repos\Order\OrderRepo;
|
|
use App\Repos\System\Nova\NovaRepo;
|
|
use App\Repos\System\Settings\Legal\PassportRepo;
|
|
use App\Repos\System\Settings\Location\RegionRepo;
|
|
use App\Rules\OnlyLetters;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Laravel\Nova\Fields\Date;
|
|
use Laravel\Nova\Fields\Hidden;
|
|
use Laravel\Nova\Fields\ID;
|
|
use Laravel\Nova\Fields\Number;
|
|
use Laravel\Nova\Fields\Select;
|
|
use Laravel\Nova\Fields\Text;
|
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
|
use Laravel\Nova\Panel;
|
|
use Nurmuhammet\NovaInputmask\NovaInputmask;
|
|
|
|
class LoanPaidOffLetterOrder extends Resource
|
|
{
|
|
/**
|
|
* The model the resource corresponds to.
|
|
*/
|
|
public static $model = LoanPaidOffLetterOrderModel::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'];
|
|
|
|
/**
|
|
* 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 __('Karzyň ýapylandygy barada güwanama almak');
|
|
}
|
|
|
|
/**
|
|
* Get the displayable singular label of the resource.
|
|
*/
|
|
public static function singularLabel(): string
|
|
{
|
|
return __('Karzyň ýapylandygy barada güwanama almak');
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
/**
|
|
* 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 displayed by the resource.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function fields(NovaRequest $request)
|
|
{
|
|
return [
|
|
ID::make()->sortable(),
|
|
|
|
ID::make()->sortable(),
|
|
|
|
Hidden::make('user_id')
|
|
->default(auth()->id())
|
|
->hideWhenUpdating(),
|
|
|
|
Select::make(__('Status'), 'status')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(OrderRepo::statusValues())
|
|
->default(OrderRepo::defaultStatus())
|
|
->fullWidth()
|
|
->rules('required')
|
|
->canSeeWhen('systemUser', $this),
|
|
|
|
Text::make(__('Note'), 'notes')
|
|
->fullWidth()
|
|
->canSeeWhen('systemUser', $this),
|
|
|
|
new Panel(__('Location'), [
|
|
Select::make(__('Region'), 'region')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(RegionRepo::values())
|
|
->default(RegionRepo::default())
|
|
->size('w-1/2')
|
|
->rules('required'),
|
|
|
|
Select::make(__('Branch'), 'branch_id')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->dependsOn('region', NovaRepo::dependsOnRegion('region', Branch::class))
|
|
->size('w-1/2')
|
|
->rules('required'),
|
|
]),
|
|
|
|
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'),
|
|
|
|
Select::make(__('Passport serie'), 'passport_serie')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(PassportRepo::values())
|
|
->size('w-1/2')
|
|
->rules('required')
|
|
->sortable(),
|
|
|
|
Number::make(__('Passport id'), 'passport_id')
|
|
->size('w-1/2')
|
|
->rules('required', 'numeric', 'digits:6'),
|
|
|
|
Date::make(__('Date of birth'), 'born_at')
|
|
->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/2')
|
|
->rules('required', 'integer', 'between:61000000, 71999999'),
|
|
]),
|
|
|
|
new Panel(__('Karz barada maglumatlar'), [
|
|
Text::make(__('Karz şertnamanyň belgisi'), 'loan_contract_number')
|
|
->rules('required', 'string', 'max:255')
|
|
->fullWidth()
|
|
->size('w-1/2'),
|
|
|
|
Text::make(__('Karz şertnamanyň senesi'), 'loan_contract_date')
|
|
->rules('required', 'string', 'max:255')
|
|
->fullWidth()
|
|
->size('w-1/2'),
|
|
|
|
Text::make(__('Karzyň möçberi'), 'loan_amount')
|
|
->rules('required', 'string', 'max:255')
|
|
->fullWidth()
|
|
->size('w-1/2'),
|
|
|
|
Text::make(__('Karzyň maksady'), 'loan_reason')
|
|
->rules('required', 'string', 'max:255')
|
|
->fullWidth()
|
|
->size('w-1/2'),
|
|
]),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the cards available for the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function cards(NovaRequest $request)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* Get the filters available for the resource.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function filters(NovaRequest $request)
|
|
{
|
|
return [
|
|
RegionFilter::make()
|
|
->canSee(fn () => Gate::allows('isAdmin'), auth()->user()),
|
|
|
|
new StatusFilter(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the lenses available for the resource.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function lenses(NovaRequest $request)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* Get the actions available for the resource.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function actions(NovaRequest $request)
|
|
{
|
|
return [];
|
|
}
|
|
}
|