45 lines
1004 B
PHP
45 lines
1004 B
PHP
<?php namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class InventoryWarehouse extends Model
|
|
{
|
|
protected $table = 'inventory_warehouse';
|
|
|
|
protected $fillable = [
|
|
'inventory_id',
|
|
'warehouse_id',
|
|
'stock',
|
|
'min_stock',
|
|
'max_stock',
|
|
];
|
|
|
|
protected $casts = [
|
|
'stock' => 'integer',
|
|
'min_stock' => 'integer',
|
|
'max_stock' => 'integer',
|
|
];
|
|
|
|
// 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(int $quantity): bool {
|
|
return $this->stock >= $quantity;
|
|
}
|
|
}
|