pdv.backend/app/Models/InventoryWarehouse.php

48 lines
1.1 KiB
PHP

<?php namespace App\Models;
use App\Observers\InventoryWarehouseObserver;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Model;
#[ObservedBy([InventoryWarehouseObserver::class])]
class InventoryWarehouse extends Model
{
protected $table = 'inventory_warehouse';
protected $fillable = [
'inventory_id',
'warehouse_id',
'stock',
'min_stock',
'max_stock',
];
protected $casts = [
'stock' => 'decimal:3',
'min_stock' => 'decimal:3',
'max_stock' => 'decimal:3',
];
// Relaciones
public function inventory() {
return $this->belongsTo(Inventory::class);
}
public function warehouse() {
return $this->belongsTo(Warehouse::class);
}
// Métodos útiles
public function isLowStock(): bool {
return $this->min_stock && $this->stock <= $this->min_stock;
}
public function isOverStock(): bool {
return $this->max_stock && $this->stock >= $this->max_stock;
}
public function hasAvailableStock(float $quantity): bool {
return $this->stock >= $quantity;
}
}