94 خطوط
2.3 KiB
PHP
94 خطوط
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Deal extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'title', 'company_id', 'lead_id', 'contact_id', 'product_id', 'pipeline_id', 'deal_stage_id',
|
|
'estimated_value', 'final_amount', 'win_probability', 'sales_stage', 'expected_close_date',
|
|
'last_activity_at', 'closed_at', 'owner_id', 'status', 'won_lost_reason', 'competitor',
|
|
'forecast_category', 'version', 'notes', 'created_by',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'estimated_value' => 'decimal:2',
|
|
'final_amount' => 'decimal:2',
|
|
'win_probability' => 'integer',
|
|
'expected_close_date' => 'date',
|
|
'last_activity_at' => 'datetime',
|
|
'closed_at' => 'datetime',
|
|
'version' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function company(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Company::class);
|
|
}
|
|
|
|
public function lead(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Lead::class);
|
|
}
|
|
|
|
public function contact(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Contact::class);
|
|
}
|
|
|
|
public function product(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
public function owner(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'owner_id');
|
|
}
|
|
|
|
public function pipeline(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Pipeline::class);
|
|
}
|
|
|
|
public function stage(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DealStage::class, 'deal_stage_id');
|
|
}
|
|
|
|
public function stageHistory()
|
|
{
|
|
return $this->hasMany(DealStageHistory::class)->latest();
|
|
}
|
|
|
|
public function customFieldValues(): MorphMany
|
|
{
|
|
return $this->morphMany(CustomFieldValue::class, 'fieldable');
|
|
}
|
|
|
|
public function notes(): MorphMany
|
|
{
|
|
return $this->morphMany(Note::class, 'notable');
|
|
}
|
|
|
|
public function attachments(): MorphMany
|
|
{
|
|
return $this->morphMany(Attachment::class, 'attachable');
|
|
}
|
|
|
|
public function tasks(): MorphMany
|
|
{
|
|
return $this->morphMany(Task::class, 'taskable');
|
|
}
|
|
}
|