66 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use App\Models\Stock\ProductPackaging;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class StockMove extends Model
{
use HasFactory;
protected $fillable = [
'product_id',
'from_warehouse_id',
'to_warehouse_id',
'packaging_id',
'packages_qty',
'units_qty',
'qty_base',
'move_type',
'ref_type',
'ref_id',
'moved_at',
];
protected $casts = [
'packages_qty' => 'decimal:3',
'units_qty' => 'decimal:3',
'qty_base' => 'decimal:3',
'moved_at' => 'datetime',
];
/**
* Get the product being moved.
*/
public function product(): BelongsTo
{
return $this->belongsTo(Product::class);
}
/**
* Get the source warehouse.
*/
public function fromWarehouse(): BelongsTo
{
return $this->belongsTo(Warehouse::class, 'from_warehouse_id');
}
/**
* Get the destination warehouse.
*/
public function toWarehouse(): BelongsTo
{
return $this->belongsTo(Warehouse::class, 'to_warehouse_id');
}
/**
* Get the packaging used for this move.
*/
public function packaging(): BelongsTo
{
return $this->belongsTo(ProductPackaging::class, 'packaging_id');
}
}