add visa/master module

This commit is contained in:
2024-09-04 19:50:40 +05:00
parent be39810f62
commit 837d2a4704
17 changed files with 476 additions and 17 deletions

View File

@@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('visa_master_payment_orders', function (Blueprint $table) {
$table->id();
$table->string('unique_id')->nullable()->unique();
$table->string('type')->nullable();
$table->string('passport_name')->nullable();
$table->string('passport_surname')->nullable();
$table->string('phone')->nullable();
$table->string('email')->nullable();
$table->string('region')->nullable();
$table->foreignId('branch_id')->nullable()->constrained('branches')->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained('users')->cascadeOnDelete();
$table->string('address')->nullable();
$table->json('sender_datas')->nullable();
$table->json('payment_reciever')->nullable();
$table->json('documents')->nullable();
$table->string('status')->nullable();
$table->string('notes')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('visa_master_payment_orders');
}
};

View File

@@ -0,0 +1,76 @@
<?php
namespace App\Modules\VisaMasterPaymentOrder\Models;
use App\Models\Branch\Branch;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
class VisaMasterPaymentOrder extends Model implements HasMedia
{
use InteractsWithMedia;
/**
* Table
*
* @var string
*/
protected $table = 'visa_master_payment_orders';
/**
* Guarded attributes
*/
protected $guarded = [];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'sender_datas' => 'array',
'payment_reciever' => 'array',
];
/**
* Media conversions
*
* @param Media|null $media
*/
public function registerMediaConversions(?Media $media = null): void
{
$this->addMediaConversion('thumb')
->width(200)
->height(200);
}
/**
* Media collections
*/
public function registerMediaCollections(): void
{
$this->addMediaCollection('main');
}
/**
* Branch
*/
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class);
}
/**
* Get applications types
*/
public static function applicationTypes(): array
{
return [
'visa' => __('Visa'),
'master' => __('Master'),
];
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Modules\VisaMasterPaymentOrder\Nova\Resources\Concerns;
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder;
use App\Nova\Resources\Branch\Branch;
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\DateTime;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
class VisaMasterPaymentOrderFieldsForIndex
{
/**
* Loan Order fields for "create"
*/
public static function make($resource): array
{
return [
ID::make()->hide(),
Text::make(__('ID'), 'unique_id')->sortable(),
Select::make(__('Ýüztutmanyň görnüşi'), 'type')
->fullWidth()
->searchable()
->rules('required')
->displayUsingLabels()
->options(VisaMasterPaymentOrder::applicationTypes()),
DateTime::make(__('Created at'), 'created_at')
->turkmenDateTime(),
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'), 'passport_name'),
Text::make(__('Surname'), 'passport_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

@@ -0,0 +1,241 @@
<?php
namespace App\Modules\VisaMasterPaymentOrder\Nova\Resources;
use App\Models\Branch\Branch;
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder;
use App\Modules\VisaMasterPaymentOrder\Nova\Resources\Concerns\VisaMasterPaymentOrderFieldsForIndex;
use App\Nova\Resource;
use App\Repos\Order\Card\CardOrderRepo;
use App\Repos\Order\OrderRepo;
use App\Repos\System\Nova\NovaRepo;
use App\Repos\System\Settings\Legal\PassportRepo;
use App\Repos\System\Settings\Location\RegionRepo;
use Ebess\AdvancedNovaMediaLibrary\Fields\Files;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Laravel\Nova\Fields\Badge;
use Laravel\Nova\Fields\Hidden;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Panel;
use Nurmuhammet\NovaInputmask\NovaInputmask;
use Outl1ne\NovaSimpleRepeatable\SimpleRepeatable;
/**
* @template TModel of \App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder
*/
class NovaVisaMasterPaymentOrder extends Resource
{
/**
* The model the resource corresponds to.
*
* @var class-string<\App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder>
*/
public static $model = \App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'unique_id';
/**
* The columns that should be searched.
*
* @var array<int, string>
*/
public static $search = [
'unique_id', 'passport_name', 'passport_surname', 'phone',
];
/**
* Get the displayable label of the resource.
*/
public static function label(): string
{
return sprintf(
'%s (%s)',
__('Visa/Master payments'),
Str::lower(__('For students'))
);
}
/**
* Get the displayable singular label of the resource.
*/
public static function singularLabel(): string
{
return sprintf(
'%s (%s)',
__('Visa/Master payment'),
Str::lower(__('For students'))
);
}
/**
* After resource created
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @param \Illuminate\Database\Eloquent\Model $model
*/
public static function afterCreate(NovaRequest $request, Model $model): void
{
$model->update(['unique_id' => CardOrderRepo::fillUniqueId($model)]);
}
/**
* Get the fields for index.
*/
public function fieldsForIndex(): array
{
return VisaMasterPaymentOrderFieldsForIndex::make($this);
}
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array<int, \Laravel\Nova\Fields\FieldElement|\Laravel\Nova\Panel>
*/
public function fields(NovaRequest $request): array
{
return [
ID::hidden(),
Hidden::make('user_id')
->default(auth()->id())
->hideWhenUpdating(),
new Panel(__('New :resource', ['resource' => $this->singularLabel()]), [
Text::make(__('ID'), 'unique_id')
->exceptOnForms(),
Select::make(__('Status'), 'status')
->displayUsingLabels()
->searchable()
->options(OrderRepo::statusValues())
->default(OrderRepo::defaultStatus())
->fullWidth()
->hideFromDetail()
->rules('required')
->canSeeWhen('systemUser', $this),
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')
->fullWidth()
->canSeeWhen('systemUser', $this),
]),
new Panel(__('Application type'), [
Select::make(__('Application type'), 'type')
->fullWidth()
->searchable()
->rules('required')
->displayUsingLabels()
->options(VisaMasterPaymentOrder::applicationTypes()),
]),
new Panel(__('Location'), [
Select::make(__('Region'), 'region')
->fullWidth()
->displayUsingLabels()
->searchable()
->options(RegionRepo::values())
->default(RegionRepo::default())
->rules('required')
->sortable(),
Select::make(__('Branch'), 'branch_id')
->fullWidth()
->displayUsingLabels()
->searchable()
->dependsOn('region', NovaRepo::dependsOnRegion('region', Branch::class))
->rules('required')
->sortable(),
]),
new Panel(__('Personal data'), [
Text::make(__('Passport name'), 'passport_name')
->fullWidth()
->rules('required', 'string', 'max:255'),
Text::make(__('Passport surname'), 'passport_surname')
->fullWidth()
->rules('required', 'string', 'max:255'),
NovaInputmask::make(__('Phone'), 'phone')
->fullWidth()
->phonenumber('TM')
->rules('required', 'max:255')
->hideFromIndex(),
Text::make(__('Email'), 'email')
->fullWidth()
->rules('nullable', 'max:255', 'email')
->hideFromIndex(),
Text::make(__('Current Residence'), 'address')
->fullWidth()
->rules('required', 'string', 'max:255')
->hideFromIndex(),
]),
new Panel(__('Payment'), [
SimpleRepeatable::make(__('Payment sender data'), 'sender_datas', [
Select::make(__('Passport serie'), 'passport_serie')
->displayUsingLabels()
->searchable()
->options(PassportRepo::values())
->rules('required')
->sortable(),
NovaInputmask::make(__('Passport number'), 'passport_number')
->mask('999999')
->rules('required', 'max:255'),
Text::make(
name: sprintf('%s %s %s', __('Name'), __('Surname'), __('Patronic name')),
attribute: 'full_name'
)
->rules('required', 'max:255'),
])->minRows(1)->rules('required'),
SimpleRepeatable::make('Tölegi kabul edijiniň maglumatlary', 'payment_reciever', [
Select::make(__('Passport serie'), 'passport_serie')
->displayUsingLabels()
->searchable()
->options(PassportRepo::values())
->rules('required')
->sortable(),
NovaInputmask::make(__('Passport number'), 'passport_number')
->mask('999999')
->rules('required', 'max:255'),
Text::make(
name: sprintf('%s %s %s', __('Name'), __('Surname'), __('Patronic name')),
attribute: 'full_name'
),
])->maxRows(1)->minRows(1)->rules('required'),
Files::make('Talap edilýän resminamalar', 'main')
->conversionOnIndexView('thumb')
->rules('required')
->required()
->hideFromIndex(),
]),
];
}
}