74 lines
1.8 KiB
PHP
74 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\CuttingStatus;
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
#[Guarded(['id'])]
|
|
class Cutting extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'status' => CuttingStatus::class,
|
|
'total_material_cost' => 'integer',
|
|
'sewing_cost' => 'integer',
|
|
'other_cost' => 'integer',
|
|
'cost_per_unit' => 'integer',
|
|
];
|
|
}
|
|
|
|
#[Scope]
|
|
protected function cancelled(Builder $query): void
|
|
{
|
|
$query->where('status', CuttingStatus::CANCELLED);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function completed(Builder $query): void
|
|
{
|
|
$query->where('status', CuttingStatus::COMPLETED);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function inProgress(Builder $query): void
|
|
{
|
|
$query->where('status', CuttingStatus::IN_PROGRESS);
|
|
}
|
|
|
|
public function createdBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by_id');
|
|
}
|
|
|
|
public function cuttingMaterialCombinations(): HasMany
|
|
{
|
|
return $this->hasMany(CuttingMaterialCombination::class);
|
|
}
|
|
|
|
public function cuttingMaterials(): HasMany
|
|
{
|
|
return $this->hasMany(CuttingMaterial::class);
|
|
}
|
|
|
|
public function cuttingResults(): HasMany
|
|
{
|
|
return $this->hasMany(CuttingResult::class);
|
|
}
|
|
|
|
public function submittedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'submitted_by_id');
|
|
}
|
|
}
|