62 lines
1.3 KiB
PHP
62 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
/**
|
|
* @copyright (c) 2025 Notsoweb Software (https://notsoweb.com) - All Rights Reserved
|
|
*/
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Modelo para almacenes
|
|
*
|
|
* @author Moisés Cortés C. <moises.cortes@notsoweb.com>
|
|
*
|
|
* @version 1.0.0
|
|
*/
|
|
class Warehouse extends Model
|
|
{
|
|
protected $fillable = ['code', 'name', 'is_active', 'is_main'];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
'is_main' => 'boolean',
|
|
];
|
|
|
|
// Relaciones
|
|
public function inventories()
|
|
{
|
|
return $this->belongsToMany(Inventory::class, 'inventory_warehouse')
|
|
->withPivot('stock', 'min_stock', 'max_stock')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function inventorySerials()
|
|
{
|
|
return $this->hasMany(InventorySerial::class);
|
|
}
|
|
|
|
public function movementsFrom()
|
|
{
|
|
return $this->hasMany(InventoryMovement::class, 'warehouse_from_id');
|
|
}
|
|
|
|
public function movementsTo()
|
|
{
|
|
return $this->hasMany(InventoryMovement::class, 'warehouse_to_id');
|
|
}
|
|
|
|
// Scopes
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
|
|
public function scopeMain($query)
|
|
{
|
|
return $query->where('is_main', true);
|
|
}
|
|
}
|