56 lines
1.1 KiB
PHP
56 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use MongoDB\Laravel\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class SalesPlan extends Model
|
|
{
|
|
protected $fillable = [
|
|
'user_id',
|
|
'date',
|
|
'status',
|
|
'total_distance_km',
|
|
'optimized_at',
|
|
'optimized_route',
|
|
'notes',
|
|
'created_by',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'date' => 'date',
|
|
'total_distance_km' => 'decimal:2',
|
|
'optimized_at' => 'datetime',
|
|
'optimized_route' => 'array',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the user that owns the plan.
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Get the user that created the plan.
|
|
*/
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
/**
|
|
* Get the targets for the plan.
|
|
*/
|
|
public function targets(): HasMany
|
|
{
|
|
return $this->hasMany(PlanTarget::class, 'sales_plan_id')->orderBy('order');
|
|
}
|
|
}
|