185 lines
4.1 KiB
PHP
185 lines
4.1 KiB
PHP
<?php
|
|
|
|
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;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property null|string $unique_id
|
|
* @property int $card_state_id
|
|
* @property int $card_type_id
|
|
* @property string $region
|
|
* @property int $branch_id
|
|
* @property string $customer_name
|
|
* @property string $customer_surname
|
|
* @property null|string $customer_patronic_name
|
|
* @property null|string $born_at
|
|
* @property null|string $old_surname
|
|
* @property string $citizenship
|
|
* @property string $passport_serie
|
|
* @property string $passport_id
|
|
* @property string $passport_given_at
|
|
* @property string $passport_given_by
|
|
* @property string $born_place
|
|
* @property null|string $job_location
|
|
* @property null|string $passport_address
|
|
* @property null|string $real_address
|
|
* @property null|string $phone
|
|
* @property null|string $phone_additional
|
|
* @property null|string $status
|
|
* @property string $passport_one
|
|
* @property string $passport_two
|
|
* @property string $passport_three
|
|
* @property string $passport_four
|
|
* @property null|string $notes
|
|
* @property int $user_id
|
|
* @property null|\Illuminate\Support\Carbon $created_at
|
|
* @property null|\Illuminate\Support\Carbon $updated_at
|
|
* @property null|\Illuminate\Support\Carbon $deleted_at
|
|
* @property bool $paid
|
|
*/
|
|
class CardOrder extends Model
|
|
{
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @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',
|
|
'paid',
|
|
'notes',
|
|
'user_id',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'born_at' => 'date',
|
|
'passport_given_at' => 'date',
|
|
];
|
|
|
|
/**
|
|
* User
|
|
*
|
|
* @return BelongsTo<User, CardOrder>
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Card state
|
|
*
|
|
* @return BelongsTo<CardState, CardOrder>
|
|
*/
|
|
public function cardState(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CardState::class, 'card_state_id');
|
|
}
|
|
|
|
/**
|
|
* Card type
|
|
*
|
|
* @return BelongsTo<CardType, CardOrder>
|
|
*/
|
|
public function cardType(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CardType::class, 'card_type_id');
|
|
}
|
|
|
|
/**
|
|
* Branch
|
|
*
|
|
* @return BelongsTo<Branch, CardOrder>
|
|
*/
|
|
public function branch(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Branch::class, 'branch_id');
|
|
}
|
|
|
|
/**
|
|
* "boot" method for model
|
|
*/
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(CardOrderRepo::creating());
|
|
}
|
|
|
|
/**
|
|
* Check if order is paid
|
|
*/
|
|
public function isPaid(): bool
|
|
{
|
|
return $this->paid;
|
|
}
|
|
|
|
/**
|
|
* Price for order
|
|
*/
|
|
public function priceAmount(): float
|
|
{
|
|
return $this->cardState->price ?? 32;
|
|
}
|
|
|
|
/**
|
|
* Return ID ))
|
|
*/
|
|
public function really(): int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* Panel url
|
|
*/
|
|
public function panelUrl(string $type = 'index'): string
|
|
{
|
|
return match ($type) {
|
|
'index' => sprintf('%s/resources/card-orders', config('nova.path')),
|
|
default => config('nova.path'),
|
|
};
|
|
}
|
|
}
|