fix inventory

This commit is contained in:
root
2026-06-11 11:06:32 -04:00
parent 9483750161
commit c91fa2ce4d
53 changed files with 2936 additions and 12666 deletions
+39
View File
@@ -30,6 +30,17 @@ class InventoryItem extends BaseModel
'needs_repair_qty',
'need_replace_qty',
'cannot_find_qty',
// Supplier/reorder fields
'preferred_supplier_id',
'last_purchase_price',
'average_unit_cost',
'reorder_point',
'reorder_quantity',
'lead_time_days',
// Barcode/QR fields
'barcode',
'qr_code',
'asset_tag',
];
protected $casts = [
@@ -41,6 +52,13 @@ class InventoryItem extends BaseModel
'needs_repair_qty' => 'integer',
'need_replace_qty' => 'integer',
'cannot_find_qty' => 'integer',
'preferred_supplier_id' => 'integer',
'last_purchase_price' => 'decimal:2',
'average_unit_cost' => 'decimal:2',
'reorder_point' => 'integer',
'reorder_quantity' => 'integer',
'lead_time_days' => 'integer',
];
/* Optional relationships */
@@ -48,4 +66,25 @@ class InventoryItem extends BaseModel
{
return $this->belongsTo(InventoryCategory::class, 'category_id');
}
public function preferredSupplier()
{
return $this->belongsTo(Supplier::class, 'preferred_supplier_id');
}
public function movements()
{
return $this->hasMany(InventoryMovement::class, 'item_id');
}
public function scopeLowStock($query)
{
return $query->whereNotNull('reorder_point')
->whereColumn('quantity', '<=', 'reorder_point');
}
public function scopeOutOfStock($query)
{
return $query->where('quantity', '<=', 0);
}
}