Files
alrahma_sunday_school_api/app/Models/InventoryMovement.php
T
2026-06-11 11:06:32 -04:00

99 lines
2.2 KiB
PHP

<?php
namespace App\Models;
use App\Models\BaseModel;
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',
// Audit/correction fields
'voided_at',
'voided_by',
'void_reason',
'corrects_movement_id',
'source_type',
'source_id',
];
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');
}
}