85 lines
1.9 KiB
PHP
85 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Koneko\VuexyWarehouse\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
use Koneko\VuexyStoreManager\Models\Store;
|
|
use Koneko\VuexyAdmin\Models\User;
|
|
|
|
class InventoryMovement extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'inventory_movements';
|
|
protected $primaryKey = 'id';
|
|
public $incrementing = false;
|
|
protected $keyType = 'integer';
|
|
|
|
protected $fillable = [
|
|
'product_id',
|
|
'store_id',
|
|
'warehouse_id',
|
|
'movement_type',
|
|
'quantity',
|
|
'cost',
|
|
'cost_before',
|
|
'cost_after',
|
|
'cost_type',
|
|
'notes',
|
|
'transactionable_id',
|
|
'transactionable_type',
|
|
'created_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'quantity' => 'decimal:6',
|
|
'cost' => 'decimal:2',
|
|
'cost_before' => 'decimal:2',
|
|
'cost_after' => 'decimal:2',
|
|
'cost_type' => 'string',
|
|
];
|
|
|
|
/**
|
|
* Relación con el producto.
|
|
*/
|
|
public function product(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Product::class, 'product_id');
|
|
}
|
|
|
|
/**
|
|
* Relación con la sucursal.
|
|
*/
|
|
public function store(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Store::class, 'store_id');
|
|
}
|
|
|
|
/**
|
|
* Relación con el almacén.
|
|
*/
|
|
public function warehouse(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Warehouse::class, 'warehouse_id');
|
|
}
|
|
|
|
/**
|
|
* Relación con el usuario que creó el movimiento.
|
|
*/
|
|
public function createdBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
/**
|
|
* Relación polimórfica para vincular diferentes transacciones.
|
|
*/
|
|
public function transactionable(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
}
|