diff --git a/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForDetail.php b/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForDetail.php index dcd20a8..15f2b5d 100644 --- a/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForDetail.php +++ b/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForDetail.php @@ -98,12 +98,12 @@ class LoanOrderFieldsForDetail Text::make(__('Name on card'), 'card_name'), - Select::make(__('Expiration month'), 'card_month') + Select::make(__('Card'). ' ' . __('Expiration month'), 'card_month') ->displayUsingLabels() ->searchable() ->options(DateHelperRepository::monthsAsNumber()), - Select::make(__('Expiration year'), 'card_year') + Select::make(__('Card'). ' ' . __('Expiration year'), 'card_year') ->displayUsingLabels() ->searchable() ->options(DateHelperRepository::yearsUntil()), @@ -182,7 +182,7 @@ class LoanOrderFieldsForDetail ->size('w-1/2'), ]), - new Panel(__('1. Guarantor'), [ + new Panel('1. ' . __('Guarantor'), [ Text::make(__('Guarantor name'), 'guarantor_name'), Text::make(__('Guarantor Surname'), 'guarantor_surname'), @@ -204,7 +204,7 @@ class LoanOrderFieldsForDetail ->options(DateHelperRepository::yearsUntil()), ]), - new Panel(__('2. Guarantor'), [ + new Panel('2. ' . __('Guarantor'), [ Text::make(__('Guarantor name'), 'guarantor_2_name'), Text::make(__('Guarantor Surname'), 'guarantor_2_surname'), Text::make(__('Guarantor Patronic name'), 'guarantor_2_patronic_name'), diff --git a/app/Nova/Resources/Order/Loan/LoanOrder.php b/app/Nova/Resources/Order/Loan/LoanOrder.php index 82d1207..61988cb 100644 --- a/app/Nova/Resources/Order/Loan/LoanOrder.php +++ b/app/Nova/Resources/Order/Loan/LoanOrder.php @@ -115,6 +115,8 @@ class LoanOrder extends Resource { $user = $request->user(); + $query->whereNot('source', 'mobile'); + if ($user->isAdmin()) { return $query; } diff --git a/app/Nova/Resources/Order/Loan/LoanOrderMobile.php b/app/Nova/Resources/Order/Loan/LoanOrderMobile.php new file mode 100644 index 0000000..a513b4d --- /dev/null +++ b/app/Nova/Resources/Order/Loan/LoanOrderMobile.php @@ -0,0 +1,551 @@ + + */ + 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 LoanOrderFieldsForDetail::make($this); + } + + /** + * Get the fields displayed by the resource. + */ + public function fields(NovaRequest $request): array + { + return [ + ID::make()->sortable(), + + 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), + + Text::make(__('Note'), 'notes') + ->fullWidth() + ->canSeeWhen('systemUser', $this), + ]), + + 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') + ->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('nullable', 'string', new OnlyLetters, 'max:255'), + + Select::make(__('Education'), 'education') + ->displayUsingLabels() + ->searchable() + ->options(EducationRepo::values()) + ->default(EducationRepo::default()) + ->size('w-1/3') + ->rules('required') + ->sortable(), + + Select::make(__('Marriage status'), 'marriage_status') + ->displayUsingLabels() + ->searchable() + ->options(MarriageRepo::values()) + ->default(MarriageRepo::default()) + ->size('w-1/3') + ->rules('required') + ->sortable(), + + 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'), + ]), + + new Panel(__('Card'), [ + 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(__('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(__('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'), + + NovaInputmask::make(__('Home phone'), 'phone_home') + ->mask('+(\\9\\93)-9{8}') + ->storeRawValue() + ->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') + ->sortable(), + + 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'), + + Number::make(__('Card number'), 'guarantor_card_number') + ->size('w-1/2') + ->rules('required', 'integer', 'digits:16'), + + Text::make(__('Name on card'), 'guarantor_card_name') + ->size('w-1/2') + ->rules('required', 'string', 'max:255'), + + Select::make(__('Expiration month'), 'guarantor_card_month') + ->displayUsingLabels() + ->searchable() + ->options(DateHelperRepository::monthsAsNumber()) + ->size('w-1/2') + ->rules('required'), + + Select::make(__('Expiration year'), 'guarantor_card_year') + ->displayUsingLabels() + ->searchable() + ->options(DateHelperRepository::yearsUntil()) + ->size('w-1/2') + ->rules('required'), + ]), + + 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(); + } + }), + + 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'); + } + }), + + 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('nullable', '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') + ->sortable() + ->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') + ->sortable() + ->hide() + ->dependsOn('loan_amount', function ($field, $request, $formData) { + if ($formData->loan_amount && floatval($formData->loan_amount) > 20000) { + $field->show()->rules('required'); + } + }), + ]), + + ]; + } + + /** + * 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 []; + } +} diff --git a/app/Repos/Order/Loan/LoanTypeRepo.php b/app/Repos/Order/Loan/LoanTypeRepo.php index 3752670..df45a0f 100644 --- a/app/Repos/Order/Loan/LoanTypeRepo.php +++ b/app/Repos/Order/Loan/LoanTypeRepo.php @@ -17,6 +17,11 @@ class LoanTypeRepo return LoanType::where('active', true)->pluck('name', 'id'); } + public static function onlyGuarantor(): Collection|array + { + return LoanType::where('active', true)->where('id', static::loanTypeGuarantorId())->pluck('name', 'id'); + } + /** * Loan type guarantor id */ diff --git a/app/Repos/System/Nova/NovaMenuRepo.php b/app/Repos/System/Nova/NovaMenuRepo.php index ff4f5a1..b06c049 100644 --- a/app/Repos/System/Nova/NovaMenuRepo.php +++ b/app/Repos/System/Nova/NovaMenuRepo.php @@ -13,6 +13,7 @@ use App\Nova\Resources\Order\Card\CardType; use App\Nova\Resources\Order\Card\Pin\CardPin; use App\Nova\Resources\Order\Card\Requisite\CardRequisite; use App\Nova\Resources\Order\Loan\LoanOrder; +use App\Nova\Resources\Order\Loan\LoanOrderMobile; use App\Nova\Resources\Order\Loan\LoanPaidOffLetterOrder; use App\Nova\Resources\Order\Loan\LoanType; use App\Nova\Resources\System\Locale\LocaleManagerResource; @@ -42,6 +43,8 @@ class NovaMenuRepo MenuSection::make(__('Orders'), [ MenuGroup::make(__('Loan department'), [ MenuItem::resource(LoanOrder::class), + MenuItem::resource(LoanOrderMobile::class) + ->name(__('Loan order') . ' (Mobile)'), MenuItem::resource(LoanPaidOffLetterOrder::class), ])->collapsedByDefault(), diff --git a/database/migrations/2024_09_24_124726_add_source_to_loan_orders_table.php b/database/migrations/2024_09_24_124726_add_source_to_loan_orders_table.php new file mode 100644 index 0000000..06cfe7b --- /dev/null +++ b/database/migrations/2024_09_24_124726_add_source_to_loan_orders_table.php @@ -0,0 +1,30 @@ +string('source') + ->nullable() + ->default('web'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('loan_orders', function (Blueprint $table) { + $table->dropColumn('source'); + }); + } +}; diff --git a/lang/tk.json b/lang/tk.json index d9d4126..d7714ab 100644 --- a/lang/tk.json +++ b/lang/tk.json @@ -306,5 +306,9 @@ "Amount of loan": "Karz mukdary", "Name on card": "Kartdaky ady", "Expiration month": "Möhleti (aý)", - "Expiration year": "Möhleti (ýyl)" + "Expiration year": "Möhleti (ýyl)", + "Guarantor": "Zamun", + "Guarantor name": "Zamunyň ady", + "Guarantor Surname": "Zamunyň familiýasy", + "Guarantor Patronic name": "Zamunyň atasynyň ady" }