Car-Repairs-Shop/app/Models/PurchaseOrderItem.php
sackey e839d40a99
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
Initial commit
2025-07-30 17:15:50 +00:00

55 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PurchaseOrderItem extends Model
{
use HasFactory;
protected $fillable = [
'purchase_order_id',
'part_id',
'quantity_ordered',
'quantity_received',
'unit_cost',
'total_cost',
'notes',
];
protected $casts = [
'quantity_ordered' => 'integer',
'quantity_received' => 'integer',
'unit_cost' => 'decimal:2',
'total_cost' => 'decimal:2',
];
public function purchaseOrder(): BelongsTo
{
return $this->belongsTo(PurchaseOrder::class);
}
public function part(): BelongsTo
{
return $this->belongsTo(Part::class);
}
public function getQuantityPendingAttribute(): int
{
return $this->quantity_ordered - $this->quantity_received;
}
public function getIsCompleteAttribute(): bool
{
return $this->quantity_received >= $this->quantity_ordered;
}
public function getIsPartialAttribute(): bool
{
return $this->quantity_received > 0 && $this->quantity_received < $this->quantity_ordered;
}
}