Work on cards

This commit is contained in:
2023-12-08 23:54:21 +05:00
parent a4265e488c
commit 63e264805a
15 changed files with 299 additions and 98 deletions

View File

@@ -2,8 +2,10 @@
namespace App\Models\Order\Card;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class CardOrder extends Model
@@ -17,6 +19,75 @@ class CardOrder extends Model
* @var array<int, string>
*/
protected $fillable = [
'unique_id',
'card_state_id',
'card_type_id',
'region',
'branch_id',
'customer_name',
'customer_surname',
'customer_patronic_name',
'born_at',
'old_surname',
'citizenship',
'passport_serie',
'passport_id',
'passport_given_at',
'passport_given_by',
'born_place',
'job_location',
'passport_address',
'real_address',
'phone',
'phone_additional',
'status',
'passport_one',
'passport_two',
'passport_three',
'passport_four',
'notes',
'user_id',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'born_at' => 'date',
'passport_given_at' => 'date',
];
/**
* User
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* Card state
*/
public function cardState(): BelongsTo
{
return $this->belongsTo(CardState::class, 'card_state_id');
}
/**
* Card type
*/
public function cardType(): BelongsTo
{
return $this->belongsTo(CardType::class, 'card_type_id');
}
/**
* Branch
*/
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class, 'branch_id');
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Models\Order\Card;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class CardState extends Model
{
use HasFactory;
use HasTranslations;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'price',
];
/**
* Translatable fields
*
* @var array<string>
*/
public $translatable = ['name'];
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Models\Order\Card;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class CardType extends Model
{
use HasFactory;
use HasTranslations;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'price',
];
/**
* Translatable fields
*
* @var array<string>
*/
public $translatable = ['name'];
}

View File

@@ -13,9 +13,9 @@ use Laravel\Nova\Actions\Actionable;
class LoanOrder extends Model
{
use Actionable;
use HasFactory;
use SoftDeletes;
use Actionable;
/**
* The attributes that are mass assignable.
@@ -55,7 +55,6 @@ class LoanOrder extends Model
'passport_two',
'passport_three',
'passport_four',
'filled_by',
'user_id',
'status',
'status_reason',
@@ -104,12 +103,4 @@ class LoanOrder extends Model
{
return $this->belongsTo(User::class, 'user_id');
}
/**
* User who revieved order
*/
public function filledBy(): BelongsTo
{
return $this->belongsTo(User::class, 'filled_by');
}
}

View File

@@ -16,7 +16,6 @@ use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\Email;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Image;
use Laravel\Nova\Fields\MorphMany;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Panel;
@@ -45,7 +44,6 @@ class LoanOrderFieldsForDetail
Text::make(__('Note'), 'status_reason'),
BelongsTo::make(__('Created by').': ', 'user', User::class),
BelongsTo::make(__('Updated by').': ', 'filledBy', User::class),
new Panel(__('Loan'), [
BelongsTo::make(__('Loan type'), 'loanType', LoanType::class),
@@ -135,11 +133,11 @@ class LoanOrderFieldsForDetail
new Panel(__('Passport'), [
Text::make(__('Passport'), fn ($model) => sprintf(
'%s %s, %sý',
'<strong>%s %s, %sý<strong>',
$model->passport_serie,
$model->passport_id,
$model->passport_given_at?->format('d.m.Y')
)),
))->asHtml(),
Text::make(__('Passport given by'), 'passport_given_by')
->size('w-1/2'),
@@ -159,9 +157,6 @@ class LoanOrderFieldsForDetail
Image::make(__('Passport (page 32)'), 'passport_four')
->size('w-1/2'),
]),
// MorphMany::make(__('Actions'), 'actions', config('nova.actions.resource'))
// ->canSee(fn () => true)
];
}
}

View File

@@ -25,19 +25,8 @@ class LoanOrderNovaRepo
{
$model->update([
'unique_id' => static::fillUniqueId($request, $model),
'filled_by' => auth()->id(),
'user_id' => auth()->id(),
'status' => OrderRepo::defaultStatus(),
]);
}
/**
* After model has been updated
*/
public static function afterUpdate(NovaRequest $request, Model $model): void
{
$model->update([
'filled_by' => auth()->id(),
]);
}
}

View File

@@ -24,7 +24,6 @@ use App\Rules\OnlyLetters;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\Email;
@@ -136,14 +135,6 @@ class LoanOrder extends Resource
LoanOrderNovaRepo::afterCreate($request, $model);
}
/**
* Register a callback to be called after the resource is updated.
*/
public static function afterUpdate(NovaRequest $request, Model $model): void
{
LoanOrderNovaRepo::afterUpdate($request, $model);
}
/**
* Get the fields for index.
*/
@@ -185,10 +176,6 @@ class LoanOrder extends Resource
->fullWidth()
->canSeeWhen('isMe', $this),
BelongsTo::make(__('Updated by').': ', 'filledBy', User::class)
->fullWidth()
->canSeeWhen('isMe', $this),
new Panel(__('Loan'), [
Select::make(__('Loan type'), 'loan_type')
->displayUsingLabels()
@@ -351,7 +338,7 @@ class LoanOrder extends Resource
->rules('required', 'before_or_equal:today'),
]),
new Panel(__('Passport'), [
new Panel(__('Passport files'), [
Image::make(__('Passport (page 1)'), 'passport_one')
->size('w-1/2')
->deletable(false)
@@ -382,7 +369,7 @@ class LoanOrder extends Resource
]),
MorphMany::make(__('Actions'), 'actions', config('nova.actions.resource'))
->canSee(fn ($request) => false)
->canSee(fn ($request) => false),
];
}

View File

@@ -2,9 +2,8 @@
namespace App\Policies\System\Logs;
use Laravel\Nova\Actions\ActionEvent;
use App\Models\User;
use Illuminate\Auth\Access\Response;
use Laravel\Nova\Actions\ActionEvent;
class ActionEventPolicy
{

View File

@@ -1,49 +0,0 @@
<?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('card_orders', function (Blueprint $table) {
$table->id();
// $table->foreignId('user_id')->constrained('users')->restrictOnDelete();
// $table->string('cart_inception');
// $table->string('cart_type');
// $table->string('region');
// $table->foreignId('branch_id')->constrained('branches')->restrictOnDelete();
// $table->string('name');
// $table->string('surname');
// $table->string('patronic_name')->nullable();
// $table->date('born_at')->nullable();
// $table->string('old_surname')->nullable();
// $table->string('citizenship');
// $table->string('passport_serie');
// $table->integer('passport_number');
// $table->date('passport_given_at');
// $table->string('passport_given_by')->nullable();
// $table->string('born_location');
// $table->string('job_location')->nullable();
// $table->string('passport_address')->nullable();
// $table->string('home_address')->nullable();
// $table->string('phone')->nullable();
// $table->string('status')->nullable();
// $table->text('notes')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('card_orders');
}
};

View File

@@ -0,0 +1,29 @@
<?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('card_states', function (Blueprint $table) {
$table->id();
$table->jsonb('name');
$table->string('price')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('card_states');
}
};

View File

@@ -0,0 +1,29 @@
<?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('card_types', function (Blueprint $table) {
$table->id();
$table->jsonb('name');
$table->string('price')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('card_types');
}
};

View File

@@ -0,0 +1,32 @@
<?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::table('loan_orders', function (Blueprint $table) {
$table->dropColumn('status_reason');
$table->dropColumn('filled_by');
$table->text('notes')->nullable()->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('loan_orders', function (Blueprint $table) {
$table->string('status_reason')->nullable()->default('');
$table->foreignId('filled_by')->nullable()->constrained('users')->restrictOnDelete();
$table->string('notes')->nullable()->change();
});
}
};

View File

@@ -0,0 +1,67 @@
<?php
use App\Repos\Order\OrderRepo;
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('card_orders', function (Blueprint $table) {
$table->id();
$table->string('unique_id')->nullable()->unique();
$table->foreignId('card_state_id')->constrained()->restrictOnDelete();
$table->foreignId('card_type_id')->constrained()->restrictOnDelete();
$table->string('region', 2)->index();
$table->foreignId('branch_id')->constrained('branches')->restrictOnDelete();
$table->string('customer_name')->index();
$table->string('customer_surname')->index();
$table->string('customer_patronic_name')->nullable();
$table->date('born_at')->nullable();
$table->string('old_surname')->nullable();
$table->string('citizenship');
$table->string('passport_serie')->index();
$table->string('passport_id')->index();
$table->date('passport_given_at');
$table->string('passport_given_by');
$table->string('born_place');
$table->string('job_location')->nullable();
$table->string('passport_address')->nullable();
$table->string('real_address')->nullable();
$table->string('phone')->nullable()->index();
$table->string('phone_additional')->nullable()->index();
$table->string('status')->nullable()->default(OrderRepo::defaultStatus())->index();
$table->text('passport_one');
$table->text('passport_two');
$table->text('passport_three');
$table->text('passport_four');
$table->text('notes')->nullable();
$table->foreignId('user_id')->constrained('users')->restrictOnDelete();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('card_orders');
}
};

View File

@@ -230,5 +230,6 @@
"Backups": "Bekaplar",
"all": "ählisi",
"Created by": "Sargyt eden",
"Updated by": "Üýtgeden"
"Updated by": "Üýtgeden",
"Passport files": "Pasport faýýlar"
}