Files
backend/app/Models/Accident.php
2025-09-27 14:30:41 +03:30

144 lines
3.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Traits\ReceiptReportAble;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Support\Facades\Storage;
class Accident extends Model
{
use ReceiptReportAble, HasFactory;
protected $guarded = [];
protected $appends = ['link'];
public static function boot()
{
parent::boot();
self::creating(function ($model) {
});
self::created(function ($model) {
// auth()->user()->addActivityComplete(1118);
});
self::updating(function ($model) {
});
self::updated(function ($model) {
});
self::deleting(function ($model) {
// auth()->user()->addActivityComplete(1120,$model);
});
self::deleted(function ($model) {
});
}
public function damages()
{
return $this->belongsToMany('App\Models\Damage')->withPivot('unit', 'amount', 'value');
}
public function withoutAction()
{
if ($this->status == 0) {
$this->status_fa = "بدون اقدام";
}
}
public function sendToInsurance()
{
if ($this->status == 0) {
$this->status_fa = "صدور نامه بیمه و کارشناسی داغی";
$this->status = 1;
}
}
public function receiveInsuranceAndDaqiBill()
{
if ($this->status == 1) {
$this->status_fa = "فیش ها ثبت شده است.";
$this->status = 2;
}
}
public function invoiceBill()
{
if ($this->status == 2) {
$this->status_fa = "فاکتور صادر شده است.";
$this->status = 3;
}
}
public function payBill()
{
if ($this->status == 3) {
$this->status_fa = "فاکتور پرداخت شده است";
$this->status = 4;
}
}
public function documentRelease()
{
if ($this->status == 4) {
$this->status_fa = "نامه پلیس راه صادر شده است (اتمام فرایند)";
$this->status = 5;
}
}
public function files(): MorphMany
{
return $this->morphMany(File::class, 'fileable');
}
protected function damagePicture1(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null : Storage::disk('public')->url($value)
);
}
protected function damagePicture2(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null : Storage::disk('public')->url($value)
);
}
protected function policeFile(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null : Storage::disk('public')->url($value)
);
}
protected function link(): Attribute
{
return Attribute::make(
get: fn ($value) => env("PAYMENT_LINK")."/#/pay/".explode("/", $this->bill_code)[0]."/{$this->final_amount}",
);
}
protected function depositInsuranceImage(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null : Storage::disk('public')->url($value)
);
}
protected function depositDaghiImage(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null : Storage::disk('public')->url($value)
);
}
}