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);
}
}
+37
View File
@@ -23,6 +23,13 @@ class InventoryMovement extends BaseModel
'teacher_id',
'student_id',
'class_section_id',
// Audit/correction fields
'voided_at',
'voided_by',
'void_reason',
'corrects_movement_id',
'source_type',
'source_id',
];
protected $casts = [
@@ -32,8 +39,23 @@ class InventoryMovement extends BaseModel
'teacher_id' => 'integer',
'student_id' => 'integer',
'class_section_id'=> 'integer',
'voided_by' => 'integer',
'corrects_movement_id' => 'integer',
'source_id' => 'integer',
'voided_at' => 'datetime',
];
/* Scopes */
public function scopeNotVoided($query)
{
return $query->whereNull('voided_at');
}
public function scopeVoided($query)
{
return $query->whereNotNull('voided_at');
}
/* Optional relationships */
public function item()
{
@@ -59,4 +81,19 @@ class InventoryMovement extends BaseModel
{
return $this->belongsTo(ClassSection::class, 'class_section_id');
}
public function voidedBy()
{
return $this->belongsTo(User::class, 'voided_by');
}
public function correctsMovement()
{
return $this->belongsTo(self::class, 'corrects_movement_id');
}
public function corrections()
{
return $this->hasMany(self::class, 'corrects_movement_id');
}
}
+1
View File
@@ -12,6 +12,7 @@ class PurchaseOrderItem extends BaseModel
protected $fillable = [
'purchase_order_id',
'supply_id',
'inventory_item_id',
'description',
'quantity',
'received_qty',