fix inventory
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user