635 lines
24 KiB
PHP
635 lines
24 KiB
PHP
<?php
|
|
|
|
namespace App\Nova\Resources\Order\Loan;
|
|
|
|
use App\Models\Branch\Branch;
|
|
use App\Models\Order\Loan\LoanOrder as LoanOrderModel;
|
|
use App\Models\System\Location\Province;
|
|
use App\Modules\DateHelper\Repositories\DateHelperRepository;
|
|
use App\Modules\LoanOrder\Repositories\LoanOrderRequiredDocsRepository;
|
|
use App\Nova\Filters\RegionFilter;
|
|
use App\Nova\Filters\StatusFilter;
|
|
use App\Nova\Resource;
|
|
use App\Nova\Resources\Order\Loan\Concerns\LoanOrderFieldsForIndex;
|
|
use App\Repos\Order\Loan\LoanOrderRepo;
|
|
use App\Repos\Order\Loan\LoanTypeRepo;
|
|
use App\Repos\Order\OrderRepo;
|
|
use App\Repos\System\Nova\NovaRepo;
|
|
use App\Repos\System\Settings\Legal\EducationRepo;
|
|
use App\Repos\System\Settings\Legal\MarriageRepo;
|
|
use App\Repos\System\Settings\Legal\PassportRepo;
|
|
use App\Repos\System\Settings\Location\RegionRepo;
|
|
use App\Rules\DowranAgaAllowed;
|
|
use App\Rules\OnlyLetters;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Laravel\Nova\Fields\Date;
|
|
use Laravel\Nova\Fields\Email;
|
|
use Laravel\Nova\Fields\FormData;
|
|
use Laravel\Nova\Fields\Hidden;
|
|
use Laravel\Nova\Fields\ID;
|
|
use Laravel\Nova\Fields\Image;
|
|
use Laravel\Nova\Fields\Number;
|
|
use Laravel\Nova\Fields\Select;
|
|
use Laravel\Nova\Fields\Text;
|
|
use Laravel\Nova\Fields\Trix;
|
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
|
use Laravel\Nova\Panel;
|
|
use Nurmuhammet\NovaInputmask\NovaInputmask;
|
|
|
|
class LoanOrderMobile extends Resource
|
|
{
|
|
/**
|
|
* The model the resource corresponds to.
|
|
*
|
|
* @var class-string<LoanOrderModel>
|
|
*/
|
|
public static $model = LoanOrderModel::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 __('Loan orders');
|
|
}
|
|
|
|
/**
|
|
* Get the displayable singular label of the resource.
|
|
*/
|
|
public static function singularLabel(): string
|
|
{
|
|
return __('Loan 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, mixed $query): Builder
|
|
{
|
|
$user = $request->user();
|
|
|
|
$query->where('source', 'mobile');
|
|
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* Get the fields for index.
|
|
*/
|
|
public function fieldsForIndex(NovaRequest $request): array
|
|
{
|
|
return LoanOrderFieldsForIndex::make($this);
|
|
}
|
|
|
|
/**
|
|
* Get the fields for detail
|
|
*/
|
|
public function fieldsForDetail(): array
|
|
{
|
|
return LoanOrderMobileFieldsForDetail::make($this);
|
|
}
|
|
|
|
/**
|
|
* Get the fields displayed by the resource.
|
|
*/
|
|
public function fields(NovaRequest $request): array
|
|
{
|
|
return [
|
|
ID::make(),
|
|
|
|
Hidden::make('user_id')
|
|
->default(auth()->id())
|
|
->hideWhenUpdating(),
|
|
|
|
Hidden::make('source')
|
|
->default('mobile'),
|
|
|
|
new Panel(__('New :resource', ['resource' => $this->singularLabel()]), [
|
|
Select::make(__('Status'), 'status')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(OrderRepo::statusValues())
|
|
->default(OrderRepo::defaultStatus())
|
|
->fullWidth()
|
|
->rules('required')
|
|
->canSeeWhen('systemUser', $this),
|
|
|
|
Select::make(__('Required docs'), 'loan_order_required_doc_id')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(LoanOrderRequiredDocsRepository::values())
|
|
->fullWidth()
|
|
->canSeeWhen('systemUser', $this),
|
|
|
|
Trix::make(__('Note'), 'notes')
|
|
->fullWidth()
|
|
->dependsOn('loan_order_required_doc_id', function (Trix $field, NovaRequest $request, FormData $formData) {
|
|
$requiredDoc = $formData->get('loan_order_required_doc_id');
|
|
|
|
if ($requiredDoc) {
|
|
$field->setValue(LoanOrderRequiredDocsRepository::find($requiredDoc)->value);
|
|
}
|
|
}),
|
|
]),
|
|
|
|
new Panel(__('Loan'), [
|
|
Select::make(__('Loan type'), 'loan_type')
|
|
->displayUsingLabels()
|
|
->fullWidth()
|
|
->searchable()
|
|
->options(LoanTypeRepo::onlyGuarantor())
|
|
->rules('required')
|
|
->default(LoanTypeRepo::loanTypeGuarantorId()),
|
|
|
|
Number::make(__('Amount of loan'), 'loan_amount')
|
|
->fullWidth()
|
|
->rules('required', 'integer', 'max:40000'),
|
|
]),
|
|
|
|
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('nullable', 'string', new OnlyLetters, 'max:255'),
|
|
|
|
Select::make(__('Education'), 'education')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(EducationRepo::values())
|
|
->default(EducationRepo::default())
|
|
->size('w-1/3')
|
|
->rules('required'),
|
|
|
|
Select::make(__('Marriage status'), 'marriage_status')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(MarriageRepo::values())
|
|
->default(MarriageRepo::default())
|
|
->size('w-1/3')
|
|
->rules('required'),
|
|
|
|
Date::make(__('Date of birth'), 'born_at')
|
|
->size('w-1/3')
|
|
->rules('required', 'before_or_equal:today'),
|
|
|
|
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'),
|
|
|
|
Select::make(__('Karz taryhy'), 'satisfiable')
|
|
->searchable()
|
|
->displayUsingLabels()
|
|
->options(LoanOrderRepo::satisfiableValues())
|
|
->size('w-full')
|
|
->canSeeWhen('systemUser', $this),
|
|
]),
|
|
|
|
new Panel(sprintf('%s (%s)', __('Card'), __('Salary')), [
|
|
Number::make(__('Card number'), 'card_number')
|
|
->size('w-1/4')
|
|
->rules('required', 'digits:16'),
|
|
|
|
Text::make(__('Name on card'), 'card_name')
|
|
->size('w-1/4')
|
|
->rules('required'),
|
|
|
|
Select::make(__('Card').' '.__('Expiration month'), 'card_month')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(DateHelperRepository::monthsAsNumber())
|
|
->size('w-1/4')
|
|
->rules('required'),
|
|
|
|
Select::make(__('Card').' '.__('Expiration year'), 'card_year')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(DateHelperRepository::yearsUntil())
|
|
->size('w-1/4')
|
|
->rules('required'),
|
|
]),
|
|
|
|
new Panel(sprintf('%s (%s)', __('Loan Card'), __('Eger bar bolsa')), [
|
|
Number::make(__('Card number'), 'loan_card_number')
|
|
->size('w-1/4')
|
|
->rules('nullable', 'digits:16'),
|
|
|
|
Text::make(__('Name on card'), 'loan_card_name')
|
|
->size('w-1/4')
|
|
->rules('nullable'),
|
|
|
|
Select::make(__('Card').' '.__('Expiration month'), 'loan_card_month')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(DateHelperRepository::monthsAsNumber())
|
|
->size('w-1/4')
|
|
->rules('nullable'),
|
|
|
|
Select::make(__('Card').' '.__('Expiration year'), 'loan_card_year')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(DateHelperRepository::yearsUntil())
|
|
->size('w-1/4')
|
|
->rules('nullable'),
|
|
]),
|
|
|
|
new Panel(__('Passport'), [
|
|
Select::make(__('Passport serie'), 'passport_serie')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(PassportRepo::values())
|
|
->size('w-1/3')
|
|
->rules('required'),
|
|
|
|
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(__('Contact data'), [
|
|
Email::make(__('Email'), 'email')
|
|
->size('w-1/4')
|
|
->rules('nullable', 'email', 'max:255'),
|
|
|
|
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(__('Home phone'), 'phone_home')
|
|
->size('w-1/4')
|
|
->rules('required'),
|
|
]),
|
|
|
|
new Panel(__('Job'), [
|
|
Text::make(__('Work company name'), 'work_company')
|
|
->rules('required', 'string', new DowranAgaAllowed, 'max:255')
|
|
->size('w-1/2'),
|
|
|
|
NovaInputmask::make(__('HR department work number'), 'work_company_accountant_number')
|
|
->mask('+(\\9\\93)-9{8}')
|
|
->size('w-1/2')
|
|
->rules('required'),
|
|
|
|
Select::make(__('Work region'), 'work_region')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(RegionRepo::values())
|
|
->default(RegionRepo::default())
|
|
->size('w-1/2')
|
|
->rules('required'),
|
|
|
|
Select::make(__('Work province'), 'work_province_id')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->dependsOn('work_region', NovaRepo::dependsOnRegion('work_region', Province::class))
|
|
->size('w-1/2')
|
|
->rules('required'),
|
|
|
|
Text::make(__('Position'), 'work_position')
|
|
->size('w-1/2')
|
|
->rules('required', 'string', new DowranAgaAllowed, 'max:255'),
|
|
|
|
Text::make(__('Salary'), 'work_salary')
|
|
->size('w-1/4')
|
|
->rules('required', 'max_digits:8'),
|
|
|
|
Date::make(__('Work started at'), 'work_started_at')
|
|
->size('w-1/4')
|
|
->rules('required', 'before_or_equal:today'),
|
|
]),
|
|
|
|
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'),
|
|
]),
|
|
|
|
new Panel('1. '.__('Guarantor'), [
|
|
Text::make(__('Guarantor name'), 'guarantor_name')
|
|
->fullWidth()
|
|
->size('w-1/3')
|
|
->rules('required', 'string', 'max:255'),
|
|
|
|
Text::make(__('Guarantor Surname'), 'guarantor_surname')
|
|
->fullWidth()
|
|
->size('w-1/3')
|
|
->rules('required', 'string', 'max:255'),
|
|
|
|
Text::make(__('Guarantor Patronic name'), 'guarantor_patronic_name')
|
|
->fullWidth()
|
|
->size('w-1/3')
|
|
->rules('nullable', 'string', 'max:255'),
|
|
|
|
Select::make(__('Passport serie'), 'guarantor_passport_serie')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(PassportRepo::values())
|
|
->size('w-1/2')
|
|
->rules('required'),
|
|
|
|
Number::make(__('Passport id'), 'guarantor_passport_id')
|
|
->size('w-1/2')
|
|
->rules('required', 'numeric', 'digits:6'),
|
|
|
|
Number::make(__('Card number'), 'guarantor_card_number')
|
|
->size('w-1/4')
|
|
->rules('required', 'integer', 'digits:16'),
|
|
|
|
Text::make(__('Name on card'), 'guarantor_card_name')
|
|
->size('w-1/4')
|
|
->rules('required', 'string', 'max:255'),
|
|
|
|
Select::make(__('Expiration month'), 'guarantor_card_month')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(DateHelperRepository::monthsAsNumber())
|
|
->size('w-1/4')
|
|
->rules('required'),
|
|
|
|
Select::make(__('Expiration year'), 'guarantor_card_year')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(DateHelperRepository::yearsUntil())
|
|
->size('w-1/4')
|
|
->rules('required'),
|
|
|
|
Text::make(__('Ortaça zähmet haky'), 'guarantor_note')
|
|
->size('w-full')
|
|
->canSeeWhen('systemUser', $this),
|
|
]),
|
|
|
|
new Panel('2. '.__('Guarantor'), [
|
|
Text::make(__('Guarantor name'), 'guarantor_2_name')
|
|
->fullWidth()
|
|
->size('w-1/3')
|
|
->hide()
|
|
->dependsOn('loan_amount', function ($field, $request, $formData) {
|
|
if ($formData->loan_amount && floatval($formData->loan_amount) > 20000) {
|
|
$field->show()->rules('required', 'string', 'max:255');
|
|
}
|
|
}),
|
|
|
|
Text::make(__('Guarantor Surname'), 'guarantor_2_surname')
|
|
->fullWidth()
|
|
->size('w-1/3')
|
|
->hide()
|
|
->dependsOn('loan_amount', function ($field, $request, $formData) {
|
|
if ($formData->loan_amount && floatval($formData->loan_amount) > 20000) {
|
|
$field->show()->rules('required', 'string', 'max:255');
|
|
}
|
|
}),
|
|
|
|
Text::make(__('Guarantor Patronic name'), 'guarantor_2_patronic_name')
|
|
->fullWidth()
|
|
->size('w-1/3')
|
|
->hide()
|
|
->dependsOn('loan_amount', function ($field, $request, $formData) {
|
|
if ($formData->loan_amount && floatval($formData->loan_amount) > 20000) {
|
|
$field->show()->rules('nullable', 'string', 'max:255');
|
|
}
|
|
}),
|
|
|
|
Select::make(__('Passport serie'), 'guarantor_2_passport_serie')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(PassportRepo::values())
|
|
->size('w-1/2')
|
|
->hide()
|
|
->dependsOn('loan_amount', function ($field, $request, $formData) {
|
|
if ($formData->loan_amount && floatval($formData->loan_amount) > 20000) {
|
|
$field->show()->rules('required', 'string', 'max:255');
|
|
}
|
|
}),
|
|
|
|
Number::make(__('Passport id'), 'guarantor_2_passport_id')
|
|
->size('w-1/2')
|
|
->hide()
|
|
->dependsOn('loan_amount', function ($field, $request, $formData) {
|
|
if ($formData->loan_amount && floatval($formData->loan_amount) > 20000) {
|
|
$field->show()->rules('required', 'numeric', 'digits:6');
|
|
}
|
|
}),
|
|
|
|
Number::make(__('Card number'), 'guarantor_2_card_number')
|
|
->size('w-1/2')
|
|
->hide()
|
|
->dependsOn('loan_amount', function ($field, $request, $formData) {
|
|
if ($formData->loan_amount && floatval($formData->loan_amount) > 20000) {
|
|
$field->show()->rules('required', 'string', 'max:255');
|
|
}
|
|
}),
|
|
|
|
Text::make(__('Name on card'), 'guarantor_2_card_name')
|
|
->size('w-1/2')
|
|
->hide()
|
|
->dependsOn('loan_amount', function ($field, $request, $formData) {
|
|
if ($formData->loan_amount && floatval($formData->loan_amount) > 20000) {
|
|
$field->show()->rules('required', 'string', 'max:255');
|
|
}
|
|
}),
|
|
|
|
Select::make(__('Card').' '.__('Expiration month'), 'guarantor_2_card_month')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(DateHelperRepository::monthsAsNumber())
|
|
->size('w-1/2')
|
|
->hide()
|
|
->dependsOn('loan_amount', function ($field, $request, $formData) {
|
|
if ($formData->loan_amount && floatval($formData->loan_amount) > 20000) {
|
|
$field->show()->rules('required');
|
|
}
|
|
}),
|
|
|
|
Select::make(__('Card').' '.__('Expiration year'), 'guarantor_2_card_year')
|
|
->displayUsingLabels()
|
|
->searchable()
|
|
->options(DateHelperRepository::yearsUntil())
|
|
->size('w-1/2')
|
|
->hide()
|
|
->dependsOn('loan_amount', function ($field, $request, $formData) {
|
|
if ($formData->loan_amount && floatval($formData->loan_amount) > 20000) {
|
|
$field->show()->rules('required');
|
|
}
|
|
}),
|
|
|
|
Text::make(__('Ortaça zähmek haky'), 'guarantor_2_note')
|
|
->size('w-full')
|
|
->hide()
|
|
->canSeeWhen('systemUser', $this)
|
|
->dependsOn('loan_amount', function ($field, $request, $formData) {
|
|
if ($formData->loan_amount && floatval($formData->loan_amount) > 20000) {
|
|
$field->show()->rules('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 [
|
|
RegionFilter::make()
|
|
->canSee(fn () => Gate::allows('isAdmin', auth()->user())),
|
|
|
|
new StatusFilter,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 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 [];
|
|
}
|
|
}
|