wip on loanorders
This commit is contained in:
@@ -57,6 +57,17 @@ class LoanOrder extends Model
|
|||||||
'notes',
|
'notes',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $casts = [
|
||||||
|
'born_at' => 'date',
|
||||||
|
'passport_given_at' => 'date',
|
||||||
|
'work_started_at' => 'date',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loan type
|
* Loan type
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ use Laravel\Nova\Resource as NovaResource;
|
|||||||
|
|
||||||
abstract class Resource extends NovaResource
|
abstract class Resource extends NovaResource
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Indicates whether Nova should check for modifications between viewing and updating a resource.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public static $trafficCop = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build an "index" query for the given resource.
|
* Build an "index" query for the given resource.
|
||||||
*
|
*
|
||||||
|
|||||||
21
app/Nova/Resources/Order/Loan/Concerns/LoanOrderEvents.php
Normal file
21
app/Nova/Resources/Order/Loan/Concerns/LoanOrderEvents.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Nova\Resources\Order\Loan\Concerns;
|
||||||
|
|
||||||
|
use App\Nova\Resources\Order\Loan\Concerns\LoanOrderNovaRepo;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||||
|
|
||||||
|
trait LoanOrderEvents
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register a callback to be called after the resource is created.
|
||||||
|
*
|
||||||
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
*/
|
||||||
|
public static function afterCreate(NovaRequest $request, Model $model): void
|
||||||
|
{
|
||||||
|
LoanOrderNovaRepo::afterCreate($request, $model);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,18 +3,32 @@
|
|||||||
namespace App\Nova\Resources\Order\Loan\Concerns;
|
namespace App\Nova\Resources\Order\Loan\Concerns;
|
||||||
|
|
||||||
use App\Models\Branch\Branch;
|
use App\Models\Branch\Branch;
|
||||||
|
use App\Repos\Order\OrderRepo;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||||
|
|
||||||
class LoanOrderNovaRepo
|
class LoanOrderNovaRepo
|
||||||
{
|
{
|
||||||
public function fillUniqueId(): Closure
|
public static function fillUniqueId($request, $model): string
|
||||||
{
|
{
|
||||||
return function ($request, $model, $attribute, $requestAttribute) {
|
return mb_strtoupper(sprintf(
|
||||||
$model->{$attribute} = mb_strtoupper(sprintf(
|
'%s-%s',
|
||||||
'%s-%s',
|
Branch::find($request->branch_id)->unique_code ?? 'TB',
|
||||||
Branch::find($request->branch_id)->unique_code,
|
$model->id
|
||||||
$request->id
|
)) ?? uniqid();
|
||||||
)) ?? uniqid();
|
}
|
||||||
};
|
|
||||||
|
/**
|
||||||
|
* After model has been created
|
||||||
|
*/
|
||||||
|
public static function afterCreate(NovaRequest $request, Model $model): void
|
||||||
|
{
|
||||||
|
$model->update([
|
||||||
|
'unique_id' => static::fillUniqueId($request, $model),
|
||||||
|
'filled_by' => auth()->id(),
|
||||||
|
'user_id' => auth()->id(),
|
||||||
|
'status' => OrderRepo::defaultStatus(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Nova\Resources\Order\Loan;
|
|||||||
use App\Models\Order\Loan\LoanOrder as LoanOrderModel;
|
use App\Models\Order\Loan\LoanOrder as LoanOrderModel;
|
||||||
use App\Nova\Resource;
|
use App\Nova\Resource;
|
||||||
use App\Nova\Resources\Branch\Concerns\BranchNovaRepo;
|
use App\Nova\Resources\Branch\Concerns\BranchNovaRepo;
|
||||||
|
use App\Nova\Resources\Order\Loan\Concerns\LoanOrderEvents;
|
||||||
use App\Nova\Resources\Order\Loan\Concerns\LoanOrderNovaRepo;
|
use App\Nova\Resources\Order\Loan\Concerns\LoanOrderNovaRepo;
|
||||||
use App\Repos\Order\Loan\BranchRepo;
|
use App\Repos\Order\Loan\BranchRepo;
|
||||||
use App\Repos\Order\Loan\LoanTypeRepo;
|
use App\Repos\Order\Loan\LoanTypeRepo;
|
||||||
@@ -17,7 +18,9 @@ use Konsulting\NovaTarget\NovaTarget;
|
|||||||
use Laravel\Nova\Fields\Date;
|
use Laravel\Nova\Fields\Date;
|
||||||
use Laravel\Nova\Fields\Email;
|
use Laravel\Nova\Fields\Email;
|
||||||
use Laravel\Nova\Fields\File;
|
use Laravel\Nova\Fields\File;
|
||||||
|
use Laravel\Nova\Fields\Hidden;
|
||||||
use Laravel\Nova\Fields\ID;
|
use Laravel\Nova\Fields\ID;
|
||||||
|
use Laravel\Nova\Fields\Image;
|
||||||
use Laravel\Nova\Fields\Number;
|
use Laravel\Nova\Fields\Number;
|
||||||
use Laravel\Nova\Fields\Select;
|
use Laravel\Nova\Fields\Select;
|
||||||
use Laravel\Nova\Fields\Slug;
|
use Laravel\Nova\Fields\Slug;
|
||||||
@@ -28,6 +31,8 @@ use Nurmuhammet\NovaInputmask\NovaInputmask;
|
|||||||
|
|
||||||
class LoanOrder extends Resource
|
class LoanOrder extends Resource
|
||||||
{
|
{
|
||||||
|
use LoanOrderEvents;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The model the resource corresponds to.
|
* The model the resource corresponds to.
|
||||||
*
|
*
|
||||||
@@ -48,9 +53,30 @@ class LoanOrder extends Resource
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $search = [
|
public static $search = [
|
||||||
'unique_id',
|
'unique_id', 'customer_name', 'customer_surname'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Get the displayable label of the resource.
|
||||||
*/
|
*/
|
||||||
@@ -68,12 +94,37 @@ class LoanOrder extends Resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the fields for create.
|
* Get the fields for index.
|
||||||
*/
|
*/
|
||||||
// public function fieldsForCreate(NovaRequest $request): array
|
public function fieldsForIndex(NovaRequest $request): array
|
||||||
// {
|
{
|
||||||
|
return [
|
||||||
|
ID::make()->hide(),
|
||||||
|
|
||||||
// }
|
Text::make(__('Unique id'), 'unique_id')->sortable(),
|
||||||
|
|
||||||
|
Select::make(__('Loan type'), 'loan_type')
|
||||||
|
->displayUsingLabels()
|
||||||
|
->options(LoanTypeRepo::values())
|
||||||
|
->sortable(),
|
||||||
|
|
||||||
|
Select::make(__('Region'), 'region')
|
||||||
|
->displayUsingLabels()
|
||||||
|
->options(RegionRepo::values())
|
||||||
|
->sortable(),
|
||||||
|
|
||||||
|
Select::make(__('Branch'), 'branch_id')
|
||||||
|
->displayUsingLabels()
|
||||||
|
->options(BranchRepo::values())
|
||||||
|
->sortable(),
|
||||||
|
|
||||||
|
Text::make(__('Customer name'), 'customer_name'),
|
||||||
|
|
||||||
|
Text::make(__('Customer surname'), 'customer_surname'),
|
||||||
|
|
||||||
|
Text::make(__('Phone'), 'phone')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the fields displayed by the resource.
|
* Get the fields displayed by the resource.
|
||||||
@@ -81,7 +132,7 @@ class LoanOrder extends Resource
|
|||||||
public function fields(NovaRequest $request): array
|
public function fields(NovaRequest $request): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
ID::hidden()->sortable(),
|
ID::make()->sortable(),
|
||||||
|
|
||||||
new Panel(__('Loan'), [
|
new Panel(__('Loan'), [
|
||||||
Select::make(__('Loan type'), 'loan_type')
|
Select::make(__('Loan type'), 'loan_type')
|
||||||
@@ -196,7 +247,7 @@ class LoanOrder extends Resource
|
|||||||
NovaInputmask::make(__('Phone Additional'), 'phone_additional')
|
NovaInputmask::make(__('Phone Additional'), 'phone_additional')
|
||||||
->phonenumber('TM')
|
->phonenumber('TM')
|
||||||
->size('w-1/4')
|
->size('w-1/4')
|
||||||
->rules('required'),
|
->rules('nullable'),
|
||||||
|
|
||||||
NovaInputmask::make(__('Home phone'), 'phone_home')
|
NovaInputmask::make(__('Home phone'), 'phone_home')
|
||||||
->size('w-1/4')
|
->size('w-1/4')
|
||||||
@@ -225,8 +276,8 @@ class LoanOrder extends Resource
|
|||||||
->displayUsingLabels()
|
->displayUsingLabels()
|
||||||
->searchable()
|
->searchable()
|
||||||
->dependsOn('region', BranchNovaRepo::dependsOnRegion('work_region'))
|
->dependsOn('region', BranchNovaRepo::dependsOnRegion('work_region'))
|
||||||
->size('w-1/2')
|
->size('w-1/2'),
|
||||||
->rules('required'),
|
// ->rules('required'),
|
||||||
|
|
||||||
Text::make(__('Position'), 'work_position')
|
Text::make(__('Position'), 'work_position')
|
||||||
->size('w-1/2')
|
->size('w-1/2')
|
||||||
@@ -242,10 +293,21 @@ class LoanOrder extends Resource
|
|||||||
]),
|
]),
|
||||||
|
|
||||||
new Panel(__('Passport'), [
|
new Panel(__('Passport'), [
|
||||||
File::make(__('Passport (page 1)'), 'passport_one'),
|
Image::make(__('Passport (page 1)'), 'passport_one')
|
||||||
File::make(__('Passport (page 2-3)'), 'passport_two'),
|
->size('w-1/2')
|
||||||
File::make(__('Passport (page 8-9)'), 'passport_three'),
|
->rules('required', 'max:2048'),
|
||||||
File::make(__('Passport (page 32)'), 'passport_four'),
|
|
||||||
|
Image::make(__('Passport (page 2-3)'), 'passport_two')
|
||||||
|
->size('w-1/2')
|
||||||
|
->rules('required', 'max:2048'),
|
||||||
|
|
||||||
|
Image::make(__('Passport (page 8-9)'), 'passport_three')
|
||||||
|
->size('w-1/2')
|
||||||
|
->rules('required', 'max:2048'),
|
||||||
|
|
||||||
|
Image::make(__('Passport (page 32)'), 'passport_four')
|
||||||
|
->size('w-1/2')
|
||||||
|
->rules('required', 'max:2048'),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
// $table->foreignId('filled_by')->constrained('users')->restrictOnDelete();
|
// $table->foreignId('filled_by')->constrained('users')->restrictOnDelete();
|
||||||
|
|||||||
89
app/Repos/Order/OrderRepo.php
Normal file
89
app/Repos/Order/OrderRepo.php
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repos\Order;
|
||||||
|
|
||||||
|
class OrderRepo
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Pending orders are brand new orders that have not been processed yet.
|
||||||
|
*/
|
||||||
|
public const PENDING = 'pending';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Orders that has been registered..
|
||||||
|
*/
|
||||||
|
public const REGISTER = 'register';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Orders that has been registered..
|
||||||
|
*/
|
||||||
|
public const PROCESSING = 'processing';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Orders fulfilled completely.
|
||||||
|
*/
|
||||||
|
public const COMPLETED = 'completed';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order that has been cancelled.
|
||||||
|
*/
|
||||||
|
public const CANCELLED = 'cancelled';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default status value
|
||||||
|
*/
|
||||||
|
public static function defaultStatus(): string
|
||||||
|
{
|
||||||
|
return static::PENDING;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status Values
|
||||||
|
*/
|
||||||
|
public static function statusValues(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::PENDING => __('Pending'),
|
||||||
|
self::REGISTER => __('Registered'),
|
||||||
|
self::PROCESSING => __('Processing'),
|
||||||
|
self::COMPLETED => __('Completed'),
|
||||||
|
self::CANCELLED => __('Cancelled'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tailwind
|
||||||
|
*/
|
||||||
|
public static function statusClasses(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::PENDING => 'warning',
|
||||||
|
self::REGISTER => 'info',
|
||||||
|
self::PROCESSING => 'primary',
|
||||||
|
self::COMPLETED => 'success',
|
||||||
|
self::CANCELLED => 'danger',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HEX Colors
|
||||||
|
*/
|
||||||
|
public static function statusColors(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::PENDING => '#F5573B',
|
||||||
|
self::REGISTER => '#F2CB22',
|
||||||
|
self::PROCESSING => '#098F56',
|
||||||
|
self::COMPLETED => '#8FC15D',
|
||||||
|
self::CANCELLED => '#d70206',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formatted status for given "status"
|
||||||
|
*/
|
||||||
|
public static function statusFormatted(string $status = 'pending'): string
|
||||||
|
{
|
||||||
|
return static::values()[$status] ?? __('None');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Repos\Order\OrderRepo;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@@ -56,11 +57,11 @@ return new class extends Migration
|
|||||||
$table->text('passport_three');
|
$table->text('passport_three');
|
||||||
$table->text('passport_four');
|
$table->text('passport_four');
|
||||||
|
|
||||||
$table->foreignId('filled_by')->constrained('users')->restrictOnDelete();
|
$table->foreignId('filled_by')->nullable()->constrained('users')->restrictOnDelete();
|
||||||
$table->foreignId('user_id')->constrained('users')->restrictOnDelete();
|
$table->foreignId('user_id')->nullable()->constrained('users')->restrictOnDelete();
|
||||||
|
|
||||||
$table->string('status')->index();
|
$table->string('status')->nullable()->default(OrderRepo::defaultStatus())->index();
|
||||||
$table->string('status_reason')->nullable();
|
$table->string('status_reason')->nullable()->default('');
|
||||||
|
|
||||||
$table->string('notes')->nullable();
|
$table->string('notes')->nullable();
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,11 @@ class DatabaseSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$this->call([BranchTableSeeder::class]);
|
$this->call([
|
||||||
$this->call([UsersTableSeeder::class]);
|
UsersTableSeeder::class,
|
||||||
$this->call([LoanTypeSeeder::class]);
|
ProvinceTableSeeder::class,
|
||||||
|
BranchTableSeeder::class,
|
||||||
|
LoanTypeSeeder::class,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
64
database/seeders/ProvinceTableSeeder.php
Normal file
64
database/seeders/ProvinceTableSeeder.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\System\Location\Province;
|
||||||
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class ProvinceTableSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
$datas = [
|
||||||
|
[
|
||||||
|
'region' => 'ag',
|
||||||
|
'name' => 'Arçabil',
|
||||||
|
'active' => true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'region' => 'ag',
|
||||||
|
'name' => 'Bagtyýarlyk',
|
||||||
|
'active' => true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'region' => 'ag',
|
||||||
|
'name' => 'Berkararlyk',
|
||||||
|
'active' => true,
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'region' => 'ag',
|
||||||
|
'name' => 'Çandybil',
|
||||||
|
'active' => true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'region' => 'ag',
|
||||||
|
'name' => 'Köpetdag',
|
||||||
|
'active' => true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'region' => 'ah',
|
||||||
|
'name' => 'Altyn-Asyr',
|
||||||
|
'active' => true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'region' => 'ah',
|
||||||
|
'name' => 'Ak-Bugdaý',
|
||||||
|
'active' => true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'region' => 'mr',
|
||||||
|
'name' => 'Mary',
|
||||||
|
'active' => true,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($datas as $data) {
|
||||||
|
Province::create($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user