211 lines
5.6 KiB
PHP
211 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Order\Loan;
|
|
|
|
use App\Models\Alert;
|
|
use App\Models\Branch\Branch;
|
|
use App\Models\System\Location\Province;
|
|
use App\Models\User;
|
|
use App\Modules\LoanOrder\Models\LoanOrderRequiredDocs;
|
|
use App\Repos\Order\Loan\LoanOrderRepo;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Laravel\Nova\Actions\Actionable;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $unique_id
|
|
* @property int $loan_type
|
|
* @property string $region
|
|
* @property int $branch_id
|
|
* @property string $customer_name
|
|
* @property string $customer_surname
|
|
* @property string $customer_patronic_name
|
|
* @property string $passport_address
|
|
* @property string $real_address
|
|
* @property string $passport_serie
|
|
* @property string $passport_id
|
|
* @property string $passport_given_at
|
|
* @property string $passport_given_by
|
|
* @property string $born_place
|
|
* @property string $born_at
|
|
* @property string $email
|
|
* @property string $phone
|
|
* @property string $phone_additional
|
|
* @property string $phone_home
|
|
* @property string $work_region
|
|
* @property int $work_province_id
|
|
* @property string $work_company
|
|
* @property string $work_company_accountant_number
|
|
* @property string $work_started_at
|
|
* @property string $work_salary
|
|
* @property string $work_position
|
|
* @property string $education
|
|
* @property string $marriage_status
|
|
* @property string $passport_one
|
|
* @property string $passport_two
|
|
* @property string $passport_three
|
|
* @property string $passport_four
|
|
* @property string $user_id
|
|
* @property string $status
|
|
* @property string $notes
|
|
* @property string $created_at
|
|
* @property string $updated_at
|
|
* @property string $deleted_at
|
|
* @property string $loan_amount
|
|
* @property string $card_number
|
|
* @property string $card_name
|
|
* @property string $card_month
|
|
* @property string $card_year
|
|
* @property string $guarantor_name
|
|
* @property string $guarantor_surname
|
|
* @property string $guarantor_patronic_name
|
|
* @property string $guarantor_card_number
|
|
* @property string $guarantor_card_name
|
|
* @property string $guarantor_card_month
|
|
* @property string $guarantor_card_year
|
|
* @property string $guarantor_2_name
|
|
* @property string $guarantor_2_surname
|
|
* @property string $guarantor_2_patronic_name
|
|
* @property string $guarantor_2_card_number
|
|
* @property string $guarantor_2_card_name
|
|
* @property string $guarantor_2_card_month
|
|
* @property string $guarantor_2_card_year
|
|
* @property string $source
|
|
* @property string $guarantor_note
|
|
* @property string $guarantor_2_note
|
|
* @property string $satisfiable
|
|
* @property string $guarantor_passport_serie
|
|
* @property string $guarantor_passport_id
|
|
* @property string $guarantor_2_passport_serie
|
|
* @property string $guarantor_2_passport_id
|
|
* @property string $loan_card_number
|
|
* @property string $loan_card_name
|
|
* @property string $loan_card_month
|
|
* @property string $loan_card_year
|
|
* @property ?int $loan_order_required_doc_id
|
|
*/
|
|
class LoanOrder extends Model
|
|
{
|
|
use Actionable;
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'unique_id',
|
|
'loan_type',
|
|
'region',
|
|
'branch_id',
|
|
'customer_name',
|
|
'customer_surname',
|
|
'customer_patronic_name',
|
|
'passport_address',
|
|
'real_address',
|
|
'passport_serie',
|
|
'passport_id',
|
|
'passport_given_at',
|
|
'passport_given_by',
|
|
'born_place',
|
|
'born_at',
|
|
'email',
|
|
'phone',
|
|
'phone_additional',
|
|
'phone_home',
|
|
'work_region',
|
|
'work_province_id',
|
|
'work_company',
|
|
'work_company_accountant_number',
|
|
'work_started_at',
|
|
'work_salary',
|
|
'work_position',
|
|
'education',
|
|
'marriage_status',
|
|
'passport_one',
|
|
'passport_two',
|
|
'passport_three',
|
|
'passport_four',
|
|
'user_id',
|
|
'status',
|
|
'status_reason',
|
|
'notes',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'born_at' => 'date',
|
|
'passport_given_at' => 'date',
|
|
'work_started_at' => 'date',
|
|
];
|
|
|
|
/**
|
|
* Loan type
|
|
*/
|
|
public function loanType(): BelongsTo
|
|
{
|
|
return $this->belongsTo(LoanType::class, 'loan_type');
|
|
}
|
|
|
|
/**
|
|
* Branch
|
|
*/
|
|
public function branch(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Branch::class);
|
|
}
|
|
|
|
/**
|
|
* Work province
|
|
*/
|
|
public function workProvince(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Province::class, 'work_province_id');
|
|
}
|
|
|
|
/**
|
|
* User (who created order)
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
/**
|
|
* Required docs
|
|
*/
|
|
public function requiredDocs(): BelongsTo
|
|
{
|
|
return $this->belongsTo(LoanOrderRequiredDocs::class, 'loan_order_required_doc_id');
|
|
}
|
|
|
|
/**
|
|
* "boot" method for model
|
|
*/
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(LoanOrderRepo::creating());
|
|
static::created(LoanOrderRepo::created());
|
|
static::updated(function (LoanOrder $model) {
|
|
if ($model->notes && $model->wasChanged('notes')) {
|
|
Alert::create([
|
|
'user_id' => auth()->id(),
|
|
'name' => 'Duýdyryş',
|
|
'value' => $model->notes,
|
|
]);
|
|
}
|
|
});
|
|
}
|
|
}
|