e13df69885
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 4m53s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 59s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
class InventoryItem extends BaseModel
|
|
{
|
|
protected $table = 'inventory_items';
|
|
|
|
// ✅ legacy: useTimestamps = true
|
|
public $timestamps = true;
|
|
|
|
protected $fillable = ['type', 'category_id', 'name', 'description', 'quantity', 'good_qty', 'needs_repair_qty', 'need_replace_qty', 'cannot_find_qty', 'unit', 'condition', 'isbn', 'edition', 'sku', 'notes', 'semester', 'school_year', 'updated_by', 'created_at', 'updated_at'];
|
|
|
|
protected $casts = [
|
|
'category_id' => 'integer',
|
|
'quantity' => 'integer',
|
|
'updated_by' => 'integer',
|
|
|
|
'good_qty' => 'integer',
|
|
'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 */
|
|
public function category()
|
|
{
|
|
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);
|
|
}
|
|
}
|