This commit is contained in:
2023-11-28 12:40:49 +05:00
parent b45cec0200
commit dab7cc0069
16 changed files with 215 additions and 58 deletions

View File

@@ -31,6 +31,7 @@ class Branch extends Model
'billing_username',
'billing_password',
'address',
'phone_numbers',
'active',
];

13
app/Models/Test.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Test extends Model
{
use HasFactory;
protected $guarded = [];
}

View File

@@ -3,7 +3,7 @@
namespace App\Nova\Resources\Branch;
use App\Models\Branch\Branch as BranchModel;
use App\Nova\Resources\Branch\Concerns\BranchNovaRepo;
use App\Repos\System\Nova\NovaRepo;
use App\Repos\System\Settings\Location\RegionRepo;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
@@ -78,7 +78,7 @@ class Branch extends Resource
Select::make(__('Province'), 'province_id')
->displayUsingLabels()
->searchable()
->dependsOn('region', BranchNovaRepo::dependsOnRegion()),
->dependsOn('region', NovaRepo::dependsOnRegion('region')),
Text::make(__('Unique code'), 'unique_code')
->rules('required', 'string', 'max:255'),

View File

@@ -1,23 +0,0 @@
<?php
namespace App\Nova\Resources\Branch\Concerns;
use App\Models\System\Location\Province;
use Closure;
class BranchNovaRepo
{
/**
* Depends on region
*/
public static function dependsOnRegion(string $attribute = 'region'): Closure
{
return function ($field, $request, $formData) use ($attribute) {
$field->options(
$formData->{$attribute}
? Province::where('region', $formData->{$attribute})->pluck('name', 'id')
: []
);
};
}
}

View File

@@ -2,7 +2,7 @@
namespace App\Nova\Resources\Order\Loan\Concerns;
use App\Repos\Order\Loan\BranchRepo;
use App\Repos\Branch\BranchRepo;
use App\Repos\Order\Loan\LoanTypeRepo;
use App\Repos\Order\OrderRepo;
use App\Repos\System\Settings\Location\RegionRepo;

View File

@@ -2,13 +2,15 @@
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\Nova\Resource;
use App\Nova\Resources\Branch\Concerns\BranchNovaRepo;
use App\Nova\Resources\Order\Loan\Concerns\LoanOrderEvents;
use App\Nova\Resources\Order\Loan\Concerns\LoanOrderFieldsForIndex;
use App\Repos\Order\Loan\BranchRepo;
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;
@@ -105,6 +107,15 @@ class LoanOrder extends Resource
return [
ID::make()->sortable(),
Select::make(__('Status'), 'status')
->displayUsingLabels()
->searchable()
->options(OrderRepo::statusValues())
->default(OrderRepo::defaultStatus())
->fullWidth()
->rules('required')
->sortable(),
new Panel(__('Loan'), [
Select::make(__('Loan type'), 'loan_type')
->displayUsingLabels()
@@ -128,7 +139,7 @@ class LoanOrder extends Resource
Select::make(__('Branch'), 'branch_id')
->displayUsingLabels()
->searchable()
->dependsOn('region', BranchNovaRepo::dependsOnRegion())
->dependsOn('region', NovaRepo::dependsOnRegion('region', Branch::class))
->size('w-1/2')
->rules('required')
->sortable(),
@@ -210,12 +221,14 @@ class LoanOrder extends Resource
->rules('nullable', 'email'),
NovaInputmask::make(__('Phone'), 'phone')
->phonenumber('TM')
->mask('+(\\9\\93)-99-99-99-99')
->storeRawValue()
->size('w-1/4')
->rules('required'),
NovaInputmask::make(__('Phone Additional'), 'phone_additional')
->phonenumber('TM')
->mask('+(\\9\\93)-99-99-99-99')
->storeRawValue()
->size('w-1/4')
->rules('nullable'),
@@ -245,7 +258,7 @@ class LoanOrder extends Resource
Select::make(__('Work province'), 'work_province')
->displayUsingLabels()
->searchable()
->dependsOn('region', BranchNovaRepo::dependsOnRegion('work_region'))
->dependsOn('work_region', NovaRepo::dependsOnRegion('work_region', Province::class))
->size('w-1/2')
->rules('required'),
@@ -265,26 +278,23 @@ class LoanOrder extends Resource
new Panel(__('Passport'), [
Image::make(__('Passport (page 1)'), 'passport_one')
->size('w-1/2')
->rules('required', 'max:2048'),
->rules('nullable', 'max:2048'),
Image::make(__('Passport (page 2-3)'), 'passport_two')
->size('w-1/2')
->rules('required', 'max:2048'),
->rules('nullable', 'max:2048'),
Image::make(__('Passport (page 8-9)'), 'passport_three')
->size('w-1/2')
->rules('required', 'max:2048'),
->rules('nullable', 'max:2048'),
Image::make(__('Passport (page 32)'), 'passport_four')
->size('w-1/2')
->rules('required', 'max:2048'),
->rules('nullable', 'max:2048'),
]),
// $table->foreignId('filled_by')->constrained('users')->restrictOnDelete();
// $table->foreignId('user_id')->constrained('users')->restrictOnDelete();
// $table->string('status')->index();
// $table->string('status_reason')->nullable();
// $table->string('notes')->nullable();
];
}

View File

@@ -70,6 +70,7 @@ class Province extends Resource
->sortable(),
Text::make(__('Name'), 'name')
->translatable()
->rules('required', 'string', 'max:255'),
NovaSwitcher::make(__('Active'), 'active')

View File

@@ -0,0 +1,97 @@
<?php
namespace App\Nova\Resources;
use App\Nova\Resource;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Http\Requests\NovaRequest;
use Nurmuhammet\NovaInputmask\NovaInputmask;
class Test extends Resource
{
/**
* The model the resource corresponds to.
*
* @var class-string<\App\Models\Test>
*/
public static $model = \App\Models\Test::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'id';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'phone',
];
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
{
return [
ID::make()->sortable(),
// NovaInputmask::make('Phone', 'phone')
// ->mask('+(\\9\\93)-69-99-99-99')
// ->storeRawValue(),
];
}
/**
* Get the cards available for the request.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function cards(NovaRequest $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function filters(NovaRequest $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function lenses(NovaRequest $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function actions(NovaRequest $request)
{
return [];
}
}

View File

@@ -8,6 +8,7 @@ use App\Nova\Resources\Order\Loan\LoanType;
use App\Nova\Resources\System\Location\Province;
use App\Nova\Resources\System\Roles\Permission;
use App\Nova\Resources\System\Roles\Role;
use App\Nova\Resources\Test;
use App\Nova\User;
use App\Repos\System\Nova\NovaRepo;
use Eolica\NovaLocaleSwitcher\LocaleSwitcher;
@@ -103,6 +104,7 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
Nova::mainMenu(function (Request $request) {
return [
MenuSection::dashboard(Main::class)->icon('chart-bar'),
MenuItem::resource(Test::class),
MenuSection::make(__('Orders'), [
MenuItem::resource(LoanOrder::class),

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Repos\Order\Loan;
namespace App\Repos\Branch;
use App\Models\Branch\Branch;
use Illuminate\Support\Collection;
@@ -9,6 +9,7 @@ class BranchRepo
{
/**
* Model
*
* @var App\Models\Branch\Branch
*/
protected $model;
@@ -16,7 +17,7 @@ class BranchRepo
/**
* New Branch Repo
*/
public function __construct()
public function __construct()
{
$this->model = Branch::class;
$this->query = $this->model::query();
@@ -54,6 +55,6 @@ class BranchRepo
*/
public static function values(): Collection|array
{
return static::make()->pluck('name', 'id');
return static::make()->query()->pluck('name', 'id');
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace App\Repos\System\Location;
class ProvinceRepo
{
}

View File

@@ -2,6 +2,7 @@
namespace App\Repos\System\Nova;
use App\Models\System\Location\Province;
use Closure;
use Illuminate\Http\Request;
use Laravel\Nova\Events\ServingNova;
@@ -41,4 +42,19 @@ class NovaRepo
}
};
}
/**
* Depends on region
*/
public static function dependsOnRegion(string $attribute = 'region', string $model = Province::class): Closure
{
return function ($field, $request, $formData) use ($attribute, $model) {
info($formData->{$attribute});
$field->options(
$formData->{$attribute}
? $model::where('region', $formData->{$attribute})->pluck('name', 'id')
: []
);
};
}
}