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
79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
class InventoryMovement extends BaseModel
|
|
{
|
|
protected $table = 'inventory_movements';
|
|
|
|
// ✅ legacy: useTimestamps = true (created_at/updated_at)
|
|
public $timestamps = true;
|
|
|
|
protected $fillable = ['item_id', 'qty_change', 'movement_type', 'reason', 'note', 'semester', 'school_year', 'performed_by', 'teacher_id', 'student_id', 'class_section_id', 'created_at', 'updated_at'];
|
|
|
|
protected $casts = [
|
|
'item_id' => 'integer',
|
|
'qty_change' => 'integer',
|
|
'performed_by' => 'integer',
|
|
'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()
|
|
{
|
|
return $this->belongsTo(InventoryItem::class, 'item_id');
|
|
}
|
|
|
|
public function performer()
|
|
{
|
|
return $this->belongsTo(User::class, 'performed_by');
|
|
}
|
|
|
|
public function teacher()
|
|
{
|
|
return $this->belongsTo(User::class, 'teacher_id');
|
|
}
|
|
|
|
public function student()
|
|
{
|
|
return $this->belongsTo(Student::class, 'student_id');
|
|
}
|
|
|
|
public function classSection()
|
|
{
|
|
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');
|
|
}
|
|
}
|