Add card order

This commit is contained in:
2023-12-11 20:21:52 +05:00
parent 9ea3e71456
commit 677cf6784a
10 changed files with 525 additions and 82 deletions

View File

@@ -2,7 +2,9 @@
namespace App\Models\Order\Card;
use App\Models\Branch\Branch;
use App\Models\User;
use App\Repos\Order\Card\CardOrderRepo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -90,4 +92,15 @@ class CardOrder extends Model
{
return $this->belongsTo(Branch::class, 'branch_id');
}
/**
* "boot" method for model
*/
protected static function boot()
{
parent::boot();
static::creating(CardOrderRepo::creating());
static::created(CardOrderRepo::created());
}
}

View File

@@ -4,20 +4,24 @@ namespace App\Nova\Resources\Order\Card;
use App\Models\Branch\Branch;
use App\Models\Order\Card\CardOrder as CardOrderModel;
use App\Nova\Filters\RegionFilter;
use App\Nova\Filters\StatusFilter;
use App\Nova\Resource;
use App\Nova\Resources\Order\Card\Concerns\CardOrderNovaRepo;
use App\Nova\User;
use App\Nova\Resources\Order\Card\Concerns\CardOrderFieldsForDetail;
use App\Nova\Resources\Order\Card\Concerns\CardOrderFieldsForIndex;
use App\Repos\Order\Card\CardStateRepo;
use App\Repos\Order\Card\CardTypeRepo;
use App\Repos\Order\OrderRepo;
use App\Repos\System\Location\CountryRepo;
use App\Repos\System\Nova\NovaRepo;
use App\Repos\System\Settings\Legal\PassportRepo;
use App\Repos\System\Settings\Location\RegionRepo;
use App\Rules\DowranAgaAllowed;
use App\Rules\OnlyLetters;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\BelongsTo;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\Hidden;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Image;
use Laravel\Nova\Fields\Number;
@@ -48,7 +52,7 @@ class CardOrder extends Resource
*
* @var array
*/
// public static $with = ['branch', 'loanType'];
public static $with = ['branch', 'cardState', 'cardType'];
/**
* The columns that should be searched.
@@ -117,29 +121,21 @@ class CardOrder extends Resource
return $query->where('user_id', $request->user()->id);
}
/**
* Register a callback to be called after the resource is created.
*/
// public static function afterCreate(NovaRequest $request, Model $model): void
// {
// CardOrderNovaRepo::afterCreate($request, $model);
// }
/**
* Get the fields for index.
*/
// public function fieldsForIndex(NovaRequest $request): array
// {
// return CardOrderFieldsForIndex::make($this);
// }
public function fieldsForIndex(NovaRequest $request): array
{
return CardOrderFieldsForIndex::make($this);
}
// /**
// * Get the fields for detail
// */
// public function fieldsForDetail(): array
// {
// return CardOrderFieldsForDetail::make($this);
// }
/**
* Get the fields for detail
*/
public function fieldsForDetail(): array
{
return CardOrderFieldsForDetail::make($this);
}
/**
* Get the fields displayed by the resource.
@@ -147,7 +143,11 @@ class CardOrder extends Resource
public function fields(NovaRequest $request): array
{
return [
ID::make()->sortable(),
ID::make(),
Hidden::make('user_id')
->default(auth()->id())
->hideWhenUpdating(),
Select::make(__('Status'), 'status')
->displayUsingLabels()
@@ -162,26 +162,22 @@ class CardOrder extends Resource
->fullWidth()
->canSeeWhen('systemUser', $this),
BelongsTo::make(__('Created by').': ', 'user', User::class)
->fullWidth()
->canSeeWhen('isMe', $this),
new Panel(__('Loan'), [
new Panel(__('Card'), [
Select::make(__('Reason for issuing the card'), 'card_state_id')
->displayUsingLabels()
->fullWidth()
->searchable()
->options(CardStateRepo::values())
->rules('required')
->sortable(),
->size('w-1/2')
->rules('required'),
Select::make(__('Reason for issuing the card'), 'card_type_id')
Select::make(__('Card type'), 'card_type_id')
->displayUsingLabels()
->fullWidth()
->searchable()
->options(CardTypeRepo::values())
->rules('required')
->sortable(),
->size('w-1/2')
->rules('required'),
]),
new Panel(__('Location'), [
@@ -191,16 +187,14 @@ class CardOrder extends Resource
->options(RegionRepo::values())
->default(RegionRepo::default())
->size('w-1/2')
->rules('required')
->sortable(),
->rules('required'),
Select::make(__('Branch'), 'branch_id')
->displayUsingLabels()
->searchable()
->dependsOn('region', NovaRepo::dependsOnRegion('region', Branch::class))
->size('w-1/2')
->rules('required')
->sortable(),
->rules('required'),
]),
new Panel(__('Personal data'), [
@@ -216,22 +210,34 @@ class CardOrder extends Resource
->size('w-1/3')
->rules('required', 'string', new OnlyLetters(), 'max:255'),
Text::make(__('Old surname (if changed)'), 'old_surname')
->size('w-1/2')
->rules('nullable', 'string', new OnlyLetters(), 'max:255'),
Date::make(__('Date of birth'), 'born_at')
->size('w-1/3')
->size('w-1/2')
->rules('required', 'before_or_equal:today'),
NovaInputmask::make(__('Phone'), 'phone')
->mask('+(\\9\\93)-99-99-99-99')
->storeRawValue()
->size('w-1/4')
->size('w-1/3')
->rules('required', 'integer', 'between:61000000, 71999999'),
NovaInputmask::make(__('Phone Additional'), 'phone_additional')
->mask('+(\\9\\93)-99-99-99-99')
->storeRawValue()
->size('w-1/4')
->size('w-1/3')
->rules('nullable', 'integer', 'between:61000000, 71999999'),
Select::make(__('Citizenship'), 'citizenship')
->displayUsingLabels()
->searchable()
->options(CountryRepo::values())
->default('TM')
->size('w-1/3')
->rules('required'),
Text::make(__('Residence (passport)'), 'passport_address')
->size('w-1/2')
->rules('required', 'string', new DowranAgaAllowed(), 'max:255'),
@@ -239,11 +245,11 @@ class CardOrder extends Resource
Text::make(__('Current Residence'), 'real_address')
->size('w-1/2')
->rules('required', 'string', new DowranAgaAllowed(), 'max:255'),
]),
// Text::make(__(), 'old_surname'),
// Text::make(__(), 'citizenship'),
// Text::make(__(), 'job_location'),
Text::make(__('Work location and your position'), 'job_location')
->size('w-full')
->rules('required', 'string', new DowranAgaAllowed(), 'max:255'),
]),
new Panel(__('Passport'), [
Select::make(__('Passport serie'), 'passport_serie')
@@ -251,8 +257,7 @@ class CardOrder extends Resource
->searchable()
->options(PassportRepo::values())
->size('w-1/3')
->rules('required')
->sortable(),
->rules('required'),
Number::make(__('Passport id'), 'passport_id')
->size('w-1/3')
@@ -316,7 +321,12 @@ class CardOrder extends Resource
*/
public function filters(NovaRequest $request): array
{
return [];
return [
RegionFilter::make()
->canSee(fn () => Gate::allows('isAdmin'), auth()->user()),
new StatusFilter(),
];
}
/**

View File

@@ -2,6 +2,101 @@
namespace App\Nova\Resources\Order\Card\Concerns;
use App\Nova\Resources\Branch\Branch;
use App\Nova\Resources\Order\Card\CardState;
use App\Nova\Resources\Order\Card\CardType;
use App\Nova\User;
use App\Repos\Order\OrderRepo;
use App\Repos\System\Location\CountryRepo;
use App\Repos\System\Settings\Location\RegionRepo;
use Laravel\Nova\Fields\Badge;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Image;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Panel;
use Nurmuhammet\NovaInputmask\NovaInputmask;
class CardOrderFieldsForDetail
{
/**
* Fields for index page
*/
public static function make($resource): array
{
return [
ID::make()->hide(),
Text::make(__('ID'), 'unique_id'),
Badge::make(__('Status'), 'status')
->map(OrderRepo::statusClasses())
->addTypes([
'primary' => 'dark:bg-gray-900 bg-gray-600 text-white',
])
->labels(OrderRepo::statusValues())
->withIcons()
->icons(OrderRepo::statusIcons()),
Text::make(__('Note'), 'notes'),
BelongsTo::make(__('Created by').': ', 'user', User::class),
new Panel(__('Card'), [
BelongsTo::make(__('Reason for issuing the card'), 'cardState', CardState::class),
BelongsTo::make(__('Card type'), 'cardType', CardType::class),
]),
new Panel(__('Location'), [
Select::make(__('Region'), 'region')
->displayUsingLabels()
->options(RegionRepo::values()),
BelongsTo::make(__('Branch'), 'branch', Branch::class),
]),
new Panel(__('Personal data'), [
Text::make(
__('Full Name'),
fn ($model) => sprintf(
'%s %s%s %s',
$model->customer_name,
$model->customer_surname,
$model->old_surname ? sprintf('(%s)', $model->old_surname) : '',
$model->customer_patronic_name
)
),
Date::make(__('Date of birth'), 'born_at')
->toTurkmenFormat(),
NovaInputmask::make(__('Phone'), 'phone')
->mask('+(\\9\\93)-99-99-99-99')
->storeRawValue(),
NovaInputmask::make(__('Phone additional'), 'phone_additional')
->mask('+(\\9\\93)-99-99-99-99')
->storeRawValue(),
Select::make(__('Citizenship'), 'citizenship')
->displayUsingLabels()
->searchable()
->options(CountryRepo::values()),
Text::make(__('Residence (passport)'), 'passport_address'),
Text::make(__('Current Residence'), 'real_address'),
Text::make(__('Work location and your position'), 'job_location'),
]),
new Panel(__('Passport files'), [
Image::make(__('Passport (page 1)'), 'passport_one'),
Image::make(__('Passport (page 2-3)'), 'passport_two'),
Image::make(__('Passport (page 8-9)'), 'passport_three'),
Image::make(__('Passport (page 32)'), 'passport_four'),
]),
];
}
}

View File

@@ -2,6 +2,61 @@
namespace App\Nova\Resources\Order\Card\Concerns;
use App\Nova\Resources\Branch\Branch;
use App\Nova\Resources\Order\Card\CardState;
use App\Nova\Resources\Order\Card\CardType;
use App\Repos\Order\OrderRepo;
use App\Repos\System\Settings\Location\RegionRepo;
use Laravel\Nova\Fields\Badge;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
class CardOrderFieldsForIndex
{
/**
* Fields for index page
*/
public static function make($resource): array
{
return [
ID::make()->hide(),
Text::make(__('ID'), 'unique_id')->sortable(),
BelongsTo::make(__('Reason'), 'cardState', CardState::class)
->sortable(),
BelongsTo::make(__('Type'), 'cardType', CardType::class)
->sortable(),
Select::make(__('Region'), 'region')
->displayUsingLabels()
->options(RegionRepo::values())
->canSeeWhen('isAdmin', $resource)
->sortable(),
BelongsTo::make(__('Branch'), 'branch', Branch::class)
->canSeeWhen('isAdmin', $resource)
->filterable()
->sortable(),
Text::make(__('Name'), 'customer_name'),
Text::make(__('Surname'), 'customer_surname'),
Text::make(__('Phone'), 'phone'),
Badge::make(__('Status'), 'status')
->map(OrderRepo::statusClasses())
->addTypes([
'primary' => 'dark:bg-gray-900 bg-gray-600 text-white',
])
->labels(OrderRepo::statusValues())
->withIcons()
->icons(OrderRepo::statusIcons())
->sortable(),
];
}
}

View File

@@ -2,34 +2,6 @@
namespace App\Nova\Resources\Order\Card\Concerns;
use App\Models\Branch\Branch;
use App\Repos\Order\OrderRepo;
use Illuminate\Database\Eloquent\Model;
use Laravel\Nova\Http\Requests\NovaRequest;
class CardOrderNovaRepo
{
/**
* Fill unique
*/
public static function fillUniqueId($request, $model): string
{
return mb_strtoupper(sprintf(
'TB%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),
'user_id' => auth()->id(),
'status' => OrderRepo::defaultStatus(),
]);
}
}

View File

@@ -120,9 +120,9 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
// MenuItem::resource(Test::class),
MenuSection::make(__('Orders'), [
MenuItem::resource(LoanOrder::class),
MenuItem::resource(CardOrder::class),
])->icon('collection')->collapsable(),
MenuItem::resource(LoanOrder::class)->name(__('Loan department')),
MenuItem::resource(CardOrder::class)->name(__('Card department')),
])->icon('ticket')->collapsable(),
MenuSection::make(__('System'), [
MenuGroup::make(__('Users'), [

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Repos\Order\Card;
use App\Models\Branch\Branch;
use App\Repos\Order\OrderRepo;
use Closure;
class CardOrderRepo
{
/**
* When model is being created
*/
public static function creating(): Closure
{
return function ($model) {
$model->status = $model->status ?: OrderRepo::defaultStatus();
};
}
/**
* When model is created
*/
public static function created(): Closure
{
return function ($model) {
$model->update(['unique_id' => static::fillUniqueId($model)]);
};
}
/**
* Fill unique id
*/
public static function fillUniqueId($model): string
{
return sprintf('TB%s-%s', Branch::find($model->branch_id)->unique_code, $model->id) ?? uniqid();
}
}

View File

@@ -29,8 +29,6 @@ class LoanOrderRepo
/**
* Fill unique id
*
* @param App\Models\Order\Loan\LoanOrder $model
*/
public static function fillUniqueId($model): string
{

View File

@@ -0,0 +1,254 @@
<?php
namespace App\Repos\System\Location;
class CountryRepo
{
/**
* List of countries
*/
public static function values(): array
{
return [
'AF' => 'Afghanistan',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
'AO' => 'Angola',
'AI' => 'Anguilla',
'AQ' => 'Antarctica',
'AG' => 'Antigua and Barbuda',
'AR' => 'Argentina',
'AM' => 'Armenia',
'AW' => 'Aruba',
'AU' => 'Australia',
'AT' => 'Austria',
'AZ' => 'Azerbaijan',
'BS' => 'Bahamas',
'BH' => 'Bahrain',
'BD' => 'Bangladesh',
'BB' => 'Barbados',
'BY' => 'Belarus',
'BE' => 'Belgium',
'BZ' => 'Belize',
'BJ' => 'Benin',
'BM' => 'Bermuda',
'BT' => 'Bhutan',
'BO' => 'Bolivia',
'BA' => 'Bosnia and Herzegovina',
'BW' => 'Botswana',
'BV' => 'Bouvet Island',
'BR' => 'Brazil',
'IO' => 'British Indian Ocean Territory',
'BN' => 'Brunei Darussalam',
'BG' => 'Bulgaria',
'BF' => 'Burkina Faso',
'BI' => 'Burundi',
'KH' => 'Cambodia',
'CM' => 'Cameroon',
'CA' => 'Canada',
'CV' => 'Cape Verde',
'KY' => 'Cayman Islands',
'CF' => 'Central African Republic',
'TD' => 'Chad',
'CL' => 'Chile',
'CN' => 'China',
'CX' => 'Christmas Island',
'CC' => 'Cocos (Keeling) Islands',
'CO' => 'Colombia',
'KM' => 'Comoros',
'CG' => 'Congo',
'CD' => 'Congo, the Democratic Republic of the',
'CK' => 'Cook Islands',
'CR' => 'Costa Rica',
'CI' => "Cote D'Ivoire",
'HR' => 'Croatia',
'CU' => 'Cuba',
'CY' => 'Cyprus',
'CZ' => 'Czech Republic',
'DK' => 'Denmark',
'DJ' => 'Djibouti',
'DM' => 'Dominica',
'DO' => 'Dominican Republic',
'EC' => 'Ecuador',
'EG' => 'Egypt',
'SV' => 'El Salvador',
'GQ' => 'Equatorial Guinea',
'ER' => 'Eritrea',
'EE' => 'Estonia',
'ET' => 'Ethiopia',
'FK' => 'Falkland Islands (Malvinas)',
'FO' => 'Faroe Islands',
'FJ' => 'Fiji',
'FI' => 'Finland',
'FR' => 'France',
'GF' => 'French Guiana',
'PF' => 'French Polynesia',
'TF' => 'French Southern Territories',
'GA' => 'Gabon',
'GM' => 'Gambia',
'GE' => 'Georgia',
'DE' => 'Germany',
'GH' => 'Ghana',
'GI' => 'Gibraltar',
'GR' => 'Greece',
'GL' => 'Greenland',
'GD' => 'Grenada',
'GP' => 'Guadeloupe',
'GU' => 'Guam',
'GT' => 'Guatemala',
'GN' => 'Guinea',
'GW' => 'Guinea-Bissau',
'GY' => 'Guyana',
'HT' => 'Haiti',
'HM' => 'Heard Island and Mcdonald Islands',
'VA' => 'Holy See (Vatican City State)',
'HN' => 'Honduras',
'HK' => 'Hong Kong',
'HU' => 'Hungary',
'IS' => 'Iceland',
'IN' => 'India',
'ID' => 'Indonesia',
'IR' => 'Iran, Islamic Republic of',
'IQ' => 'Iraq',
'IE' => 'Ireland',
'IL' => 'Israel',
'IT' => 'Italy',
'JM' => 'Jamaica',
'JP' => 'Japan',
'JO' => 'Jordan',
'KZ' => 'Kazakhstan',
'KE' => 'Kenya',
'KI' => 'Kiribati',
'KP' => "Korea, Democratic People's Republic of",
'KR' => 'Korea, Republic of',
'KW' => 'Kuwait',
'KG' => 'Kyrgyzstan',
'LA' => "Lao People's Democratic Republic",
'LV' => 'Latvia',
'LB' => 'Lebanon',
'LS' => 'Lesotho',
'LR' => 'Liberia',
'LY' => 'Libyan Arab Jamahiriya',
'LI' => 'Liechtenstein',
'LT' => 'Lithuania',
'LU' => 'Luxembourg',
'MO' => 'Macao',
'MK' => 'Macedonia, the Former Yugoslav Republic of',
'MG' => 'Madagascar',
'MW' => 'Malawi',
'MY' => 'Malaysia',
'MV' => 'Maldives',
'ML' => 'Mali',
'MT' => 'Malta',
'MH' => 'Marshall Islands',
'MQ' => 'Martinique',
'MR' => 'Mauritania',
'MU' => 'Mauritius',
'YT' => 'Mayotte',
'MX' => 'Mexico',
'FM' => 'Micronesia, Federated States of',
'MD' => 'Moldova, Republic of',
'MC' => 'Monaco',
'MN' => 'Mongolia',
'MS' => 'Montserrat',
'MA' => 'Morocco',
'MZ' => 'Mozambique',
'MM' => 'Myanmar',
'NA' => 'Namibia',
'NR' => 'Nauru',
'NP' => 'Nepal',
'NL' => 'Netherlands',
'AN' => 'Netherlands Antilles',
'NC' => 'New Caledonia',
'NZ' => 'New Zealand',
'NI' => 'Nicaragua',
'NE' => 'Niger',
'NG' => 'Nigeria',
'NU' => 'Niue',
'NF' => 'Norfolk Island',
'MP' => 'Northern Mariana Islands',
'NO' => 'Norway',
'OM' => 'Oman',
'PK' => 'Pakistan',
'PW' => 'Palau',
'PS' => 'Palestinian Territory, Occupied',
'PA' => 'Panama',
'PG' => 'Papua New Guinea',
'PY' => 'Paraguay',
'PE' => 'Peru',
'PH' => 'Philippines',
'PN' => 'Pitcairn',
'PL' => 'Poland',
'PT' => 'Portugal',
'PR' => 'Puerto Rico',
'QA' => 'Qatar',
'RE' => 'Reunion',
'RO' => 'Romania',
'RU' => 'Russian Federation',
'RW' => 'Rwanda',
'SH' => 'Saint Helena',
'KN' => 'Saint Kitts and Nevis',
'LC' => 'Saint Lucia',
'PM' => 'Saint Pierre and Miquelon',
'VC' => 'Saint Vincent and the Grenadines',
'WS' => 'Samoa',
'SM' => 'San Marino',
'ST' => 'Sao Tome and Principe',
'SA' => 'Saudi Arabia',
'SN' => 'Senegal',
'CS' => 'Serbia and Montenegro',
'SC' => 'Seychelles',
'SL' => 'Sierra Leone',
'SG' => 'Singapore',
'SK' => 'Slovakia',
'SI' => 'Slovenia',
'SB' => 'Solomon Islands',
'SO' => 'Somalia',
'ZA' => 'South Africa',
'GS' => 'South Georgia and the South Sandwich Islands',
'ES' => 'Spain',
'LK' => 'Sri Lanka',
'SD' => 'Sudan',
'SR' => 'Suriname',
'SJ' => 'Svalbard and Jan Mayen',
'SZ' => 'Swaziland',
'SE' => 'Sweden',
'CH' => 'Switzerland',
'SY' => 'Syrian Arab Republic',
'TW' => 'Taiwan, Province of China',
'TJ' => 'Tajikistan',
'TZ' => 'Tanzania, United Republic of',
'TH' => 'Thailand',
'TL' => 'Timor-Leste',
'TG' => 'Togo',
'TK' => 'Tokelau',
'TO' => 'Tonga',
'TT' => 'Trinidad and Tobago',
'TN' => 'Tunisia',
'TR' => 'Turkey',
'TM' => 'Turkmenistan',
'TC' => 'Turks and Caicos Islands',
'TV' => 'Tuvalu',
'UG' => 'Uganda',
'UA' => 'Ukraine',
'AE' => 'United Arab Emirates',
'GB' => 'United Kingdom',
'US' => 'United States',
'UM' => 'United States Minor Outlying Islands',
'UY' => 'Uruguay',
'UZ' => 'Uzbekistan',
'VU' => 'Vanuatu',
'VE' => 'Venezuela',
'VN' => 'Viet Nam',
'VG' => 'Virgin Islands, British',
'VI' => 'Virgin Islands, U.s.',
'WF' => 'Wallis and Futuna',
'EH' => 'Western Sahara',
'YE' => 'Yemen',
'ZM' => 'Zambia',
'ZW' => 'Zimbabwe',
];
}
}

View File

@@ -131,6 +131,7 @@
"PHD": "PHD",
"Phone": "Telefon",
"Phone Additional": "Telefon goşmaça",
"Phone additional": "Telefon goşmaça",
"Please click the button below to verify your email address.": "E-poçta salgyňyzy barlamak üçin aşakdaky düwmä basyň.",
"Please confirm your password before continuing.": "Dowam etmezden ozal açar sözüni tassyklaň.",
"Position": "Wezipe",
@@ -239,5 +240,12 @@
"Card states": "Kartyň çykarylmagynyň sebäpleri",
"Card": "Kart",
"Card type": "Kart görnüşi",
"Card types": "Kart görnüşleri"
"Card types": "Kart görnüşleri",
"Old surname (if changed)": "Köne familiýaňyz (eger üýtgän bolsa)",
"Work location and your position": "Işleýän ýeriňiz we wezipäňiz",
"Reason": "Sebäp",
"Loan department": "Karz bölümi",
"Card department": "Kart bölümi",
"Price": "Baha",
"Citizenship": "Raýatlyk"
}