wip on loanorders

This commit is contained in:
2023-11-26 21:15:42 +05:00
parent 11ad96e5d8
commit 307f197d27
9 changed files with 300 additions and 28 deletions

View File

@@ -57,6 +57,17 @@ class LoanOrder extends Model
'notes',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'born_at' => 'date',
'passport_given_at' => 'date',
'work_started_at' => 'date',
];
/**
* Loan type
*/

View File

@@ -7,6 +7,13 @@ use Laravel\Nova\Resource as 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.
*

View 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);
}
}

View File

@@ -3,18 +3,32 @@
namespace App\Nova\Resources\Order\Loan\Concerns;
use App\Models\Branch\Branch;
use App\Repos\Order\OrderRepo;
use Closure;
use Illuminate\Database\Eloquent\Model;
use Laravel\Nova\Http\Requests\NovaRequest;
class LoanOrderNovaRepo
{
public function fillUniqueId(): Closure
public static function fillUniqueId($request, $model): string
{
return function ($request, $model, $attribute, $requestAttribute) {
$model->{$attribute} = mb_strtoupper(sprintf(
'%s-%s',
Branch::find($request->branch_id)->unique_code,
$request->id
)) ?? uniqid();
};
return mb_strtoupper(sprintf(
'%s-%s',
Branch::find($request->branch_id)->unique_code ?? 'TB',
$model->id
)) ?? 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(),
]);
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Nova\Resources\Order\Loan;
use App\Models\Order\Loan\LoanOrder as LoanOrderModel;
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\LoanOrderNovaRepo;
use App\Repos\Order\Loan\BranchRepo;
use App\Repos\Order\Loan\LoanTypeRepo;
@@ -17,7 +18,9 @@ use Konsulting\NovaTarget\NovaTarget;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\Email;
use Laravel\Nova\Fields\File;
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\Slug;
@@ -28,6 +31,8 @@ use Nurmuhammet\NovaInputmask\NovaInputmask;
class LoanOrder extends Resource
{
use LoanOrderEvents;
/**
* The model the resource corresponds to.
*
@@ -48,9 +53,30 @@ class LoanOrder extends Resource
* @var array
*/
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.
*/
@@ -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.
@@ -81,7 +132,7 @@ class LoanOrder extends Resource
public function fields(NovaRequest $request): array
{
return [
ID::hidden()->sortable(),
ID::make()->sortable(),
new Panel(__('Loan'), [
Select::make(__('Loan type'), 'loan_type')
@@ -196,7 +247,7 @@ class LoanOrder extends Resource
NovaInputmask::make(__('Phone Additional'), 'phone_additional')
->phonenumber('TM')
->size('w-1/4')
->rules('required'),
->rules('nullable'),
NovaInputmask::make(__('Home phone'), 'phone_home')
->size('w-1/4')
@@ -225,8 +276,8 @@ class LoanOrder extends Resource
->displayUsingLabels()
->searchable()
->dependsOn('region', BranchNovaRepo::dependsOnRegion('work_region'))
->size('w-1/2')
->rules('required'),
->size('w-1/2'),
// ->rules('required'),
Text::make(__('Position'), 'work_position')
->size('w-1/2')
@@ -242,10 +293,21 @@ class LoanOrder extends Resource
]),
new Panel(__('Passport'), [
File::make(__('Passport (page 1)'), 'passport_one'),
File::make(__('Passport (page 2-3)'), 'passport_two'),
File::make(__('Passport (page 8-9)'), 'passport_three'),
File::make(__('Passport (page 32)'), 'passport_four'),
Image::make(__('Passport (page 1)'), 'passport_one')
->size('w-1/2')
->rules('required', 'max:2048'),
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();

View 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');
}
}

View File

@@ -1,5 +1,6 @@
<?php
use App\Repos\Order\OrderRepo;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -56,11 +57,11 @@ return new class extends Migration
$table->text('passport_three');
$table->text('passport_four');
$table->foreignId('filled_by')->constrained('users')->restrictOnDelete();
$table->foreignId('user_id')->constrained('users')->restrictOnDelete();
$table->foreignId('filled_by')->nullable()->constrained('users')->restrictOnDelete();
$table->foreignId('user_id')->nullable()->constrained('users')->restrictOnDelete();
$table->string('status')->index();
$table->string('status_reason')->nullable();
$table->string('status')->nullable()->default(OrderRepo::defaultStatus())->index();
$table->string('status_reason')->nullable()->default('');
$table->string('notes')->nullable();

View File

@@ -12,8 +12,11 @@ class DatabaseSeeder extends Seeder
*/
public function run(): void
{
$this->call([BranchTableSeeder::class]);
$this->call([UsersTableSeeder::class]);
$this->call([LoanTypeSeeder::class]);
$this->call([
UsersTableSeeder::class,
ProvinceTableSeeder::class,
BranchTableSeeder::class,
LoanTypeSeeder::class,
]);
}
}

View 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);
}
}
}