update
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Confeccion extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'proveedor_id',
|
||||
'orden_produccion_id',
|
||||
'fecha_envio',
|
||||
'cantidad_enviada',
|
||||
'fecha_recepcion',
|
||||
'cantidad_recibida',
|
||||
'prendas_defectuosas',
|
||||
'valor_por_prenda',
|
||||
'total_pagar',
|
||||
'estado',
|
||||
];
|
||||
|
||||
/* Relaciones */
|
||||
public function proveedor()
|
||||
{
|
||||
return $this->belongsTo(Proveedor::class);
|
||||
}
|
||||
|
||||
public function ordenProduccion()
|
||||
{
|
||||
return $this->belongsTo(OrdenProduccion::class);
|
||||
}
|
||||
|
||||
/* Lógica de negocio */
|
||||
protected static function booted()
|
||||
{
|
||||
static::saving(function ($confeccion) {
|
||||
// Total a pagar
|
||||
if ($confeccion->cantidad_recibida !== null) {
|
||||
$confeccion->total_pagar =
|
||||
$confeccion->cantidad_recibida * $confeccion->valor_por_prenda;
|
||||
}
|
||||
|
||||
// Estado automático
|
||||
if (!$confeccion->cantidad_recibida) {
|
||||
$confeccion->estado = 'pendiente';
|
||||
} elseif ($confeccion->cantidad_recibida < $confeccion->cantidad_enviada) {
|
||||
$confeccion->estado = 'parcial';
|
||||
} else {
|
||||
$confeccion->estado = 'completo';
|
||||
}
|
||||
});
|
||||
|
||||
// Cuando se completa la confección → avanzar OP
|
||||
static::updated(function ($confeccion) {
|
||||
if ($confeccion->estado === 'completo') {
|
||||
$confeccion->ordenProduccion?->avanzarEstado();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class InventarioPrenda extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'orden_produccion_id',
|
||||
'cantidad_terminada',
|
||||
'cantidad_disponible',
|
||||
'fecha_ingreso',
|
||||
'estado',
|
||||
];
|
||||
|
||||
public function ordenProduccion()
|
||||
{
|
||||
return $this->belongsTo(OrdenProduccion::class);
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($inventario) {
|
||||
// Al ingresar al inventario, todo está disponible
|
||||
$inventario->cantidad_disponible = $inventario->cantidad_terminada;
|
||||
|
||||
// Estado automático inicial
|
||||
$inventario->estado = 'en_bodega';
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OrdenProduccion extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'numero_orden',
|
||||
'prenda_modelo',
|
||||
'referencia',
|
||||
'cantidad_total',
|
||||
'tela_id',
|
||||
'fecha_inicio',
|
||||
'fecha_entrega_estimada',
|
||||
'estado',
|
||||
];
|
||||
|
||||
public function tela()
|
||||
{
|
||||
return $this->belongsTo(Tela::class);
|
||||
}
|
||||
|
||||
public function avanzarEstado(): void
|
||||
{
|
||||
$flujo = [
|
||||
'en_corte',
|
||||
'en_confeccion',
|
||||
'en_tintoreria',
|
||||
'en_acabados',
|
||||
'finalizada',
|
||||
];
|
||||
|
||||
$actual = array_search($this->estado, $flujo, true);
|
||||
|
||||
if ($actual !== false && isset($flujo[$actual + 1])) {
|
||||
$this->update([
|
||||
'estado' => $flujo[$actual + 1],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($orden) {
|
||||
if (!$orden->numero_orden) {
|
||||
$ultimoId = self::max('id') + 1;
|
||||
|
||||
$orden->numero_orden = 'OP-' . str_pad($ultimoId, 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProcesoAcabado extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'orden_produccion_id',
|
||||
'tipo_proceso',
|
||||
'proveedor_id',
|
||||
'responsable_interno',
|
||||
'cantidad_enviada',
|
||||
'cantidad_recibida',
|
||||
'fecha_envio',
|
||||
'fecha_recepcion',
|
||||
'observaciones',
|
||||
];
|
||||
|
||||
/* Relaciones */
|
||||
public function ordenProduccion()
|
||||
{
|
||||
return $this->belongsTo(OrdenProduccion::class);
|
||||
}
|
||||
|
||||
public function proveedor()
|
||||
{
|
||||
return $this->belongsTo(Proveedor::class);
|
||||
}
|
||||
|
||||
/* Lógica de negocio */
|
||||
protected static function booted()
|
||||
{
|
||||
// Cuando se recibe el proceso
|
||||
static::updated(function ($acabado) {
|
||||
if (
|
||||
$acabado->fecha_recepcion &&
|
||||
$acabado->cantidad_recibida !== null
|
||||
) {
|
||||
// Validar si ya no quedan procesos pendientes
|
||||
$pendientes = self::where('orden_produccion_id', $acabado->orden_produccion_id)
|
||||
->whereNull('fecha_recepcion')
|
||||
->exists();
|
||||
|
||||
if (!$pendientes) {
|
||||
$acabado->ordenProduccion?->update([
|
||||
'estado' => 'finalizada',
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -9,24 +9,14 @@ class Proveedor extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'nombre',
|
||||
'contacto',
|
||||
'nit',
|
||||
'categoria',
|
||||
'telefono',
|
||||
'correo',
|
||||
'direccion',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
];
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Tela extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'codigo',
|
||||
'tipo',
|
||||
'foto',
|
||||
'color',
|
||||
'proveedor_id',
|
||||
'metros_comprados',
|
||||
'metros_disponibles',
|
||||
'fecha_compra',
|
||||
'valor_total',
|
||||
'costo_por_metro',
|
||||
'observaciones',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'foto' => 'string',
|
||||
];
|
||||
|
||||
public function proveedor()
|
||||
{
|
||||
return $this->belongsTo(Proveedor::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TintoreriaProceso extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'proveedor_id',
|
||||
'orden_produccion_id',
|
||||
'tipo_proceso',
|
||||
'fecha_envio',
|
||||
'cantidad_enviada',
|
||||
'fecha_recepcion',
|
||||
'cantidad_recibida',
|
||||
'perdidas',
|
||||
'observaciones',
|
||||
];
|
||||
|
||||
/* Relaciones */
|
||||
public function proveedor()
|
||||
{
|
||||
return $this->belongsTo(Proveedor::class);
|
||||
}
|
||||
|
||||
public function ordenProduccion()
|
||||
{
|
||||
return $this->belongsTo(OrdenProduccion::class);
|
||||
}
|
||||
|
||||
/* Lógica de negocio */
|
||||
protected static function booted()
|
||||
{
|
||||
static::saving(function ($tintoreria) {
|
||||
if ($tintoreria->cantidad_recibida !== null) {
|
||||
$tintoreria->perdidas =
|
||||
$tintoreria->cantidad_enviada - $tintoreria->cantidad_recibida;
|
||||
}
|
||||
});
|
||||
|
||||
// Cuando vuelve de tintorería → avanzar OP
|
||||
static::updated(function ($tintoreria) {
|
||||
if (
|
||||
$tintoreria->fecha_recepcion &&
|
||||
$tintoreria->cantidad_recibida !== null
|
||||
) {
|
||||
$tintoreria->ordenProduccion?->avanzarEstado();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user