up
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use App\Models\Confeccion;
|
||||
use App\Models\Proveedor;
|
||||
use App\Models\OrdenProduccion;
|
||||
use App\Models\Recepcion;
|
||||
use App\Models\TrasladoPrenda;
|
||||
use App\Models\InventarioPrenda;
|
||||
use App\Models\Producto;
|
||||
use App\Models\Cobro;
|
||||
use App\Models\Ajuste;
|
||||
|
||||
class ConfeccionActionsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_register_arreglo_creates_ajuste_and_traslado_and_affects_recibido()
|
||||
{
|
||||
$proveedor = Proveedor::create(['nombre' => 'Prov Test', 'nit' => '000', 'categoria' => 'talleres']);
|
||||
$op = OrdenProduccion::create(['prenda_modelo' => 'Test', 'cantidad_total' => 100, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
$conf = Confeccion::create([
|
||||
'proveedor_id' => $proveedor->id,
|
||||
'orden_produccion_id' => $op->id,
|
||||
'cantidad_enviada' => 100,
|
||||
'valor_por_prenda' => 0,
|
||||
]);
|
||||
|
||||
// Registrar recepciones para tener recibido
|
||||
Recepcion::create(['referencia_type' => Confeccion::class, 'referencia_id' => $conf->id, 'cantidad' => 50]);
|
||||
Recepcion::create(['referencia_type' => Confeccion::class, 'referencia_id' => $conf->id, 'cantidad' => 30]);
|
||||
|
||||
$conf->refresh();
|
||||
$this->assertEquals(80, $conf->recibido_total);
|
||||
|
||||
// Registrar arreglo 10
|
||||
$conf->registerArreglo(10, 'Arreglo prueba');
|
||||
|
||||
$this->assertDatabaseHas('ajustes', [
|
||||
'referencia_type' => Confeccion::class,
|
||||
'referencia_id' => $conf->id,
|
||||
'tipo' => 'arreglo',
|
||||
'cantidad' => 10,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('traslados_prenda', [
|
||||
'referencia_type' => Confeccion::class,
|
||||
'referencia_id' => $conf->id,
|
||||
'origen' => 'confeccion',
|
||||
'destino' => 'reparaciones',
|
||||
'reparaciones' => 10,
|
||||
]);
|
||||
|
||||
$conf->refresh();
|
||||
$this->assertEquals(70, $conf->recibido_total);
|
||||
$this->assertEquals(30, $conf->faltantes);
|
||||
}
|
||||
|
||||
public function test_register_cobro_creates_cobro_and_adjusts_inventory_and_total_pagar()
|
||||
{
|
||||
$proveedor = Proveedor::create(['nombre' => 'Prov Test', 'nit' => '000', 'categoria' => 'talleres']);
|
||||
$op = OrdenProduccion::create(['prenda_modelo' => 'Test', 'cantidad_total' => 100, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
$conf = Confeccion::create([
|
||||
'proveedor_id' => $proveedor->id,
|
||||
'orden_produccion_id' => $op->id,
|
||||
'cantidad_enviada' => 50,
|
||||
'cantidad_recibida' => 50,
|
||||
'valor_por_prenda' => 100,
|
||||
]);
|
||||
|
||||
// Crear proceso de acabado que aporta cantidad recibida para permitir inventario
|
||||
\App\Models\ProcesoAcabado::create([
|
||||
'orden_produccion_id' => $op->id,
|
||||
'tipo_proceso' => 'Acabado',
|
||||
'proveedor_id' => $proveedor->id,
|
||||
'cantidad_enviada' => 20,
|
||||
'fecha_envio' => now(),
|
||||
'fecha_recepcion' => now(),
|
||||
'cantidad_recibida' => 20,
|
||||
]);
|
||||
|
||||
// Crear producto y proceso de acabado que aporta cantidad recibida para permitir inventario
|
||||
$categoria = \App\Models\Categoria::create(['nombre' => 'Ropa']);
|
||||
$producto = Producto::create(['nombre' => 'Prod', 'descripcion' => 'x', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => 'X', 'categoria_id' => $categoria->id, 'imagen' => '']);
|
||||
|
||||
\App\Models\ProcesoAcabado::create([
|
||||
'orden_produccion_id' => $op->id,
|
||||
'tipo_proceso' => 'Acabado',
|
||||
'proveedor_id' => $proveedor->id,
|
||||
'cantidad_enviada' => 20,
|
||||
'fecha_envio' => now(),
|
||||
'fecha_recepcion' => now(),
|
||||
'cantidad_recibida' => 20,
|
||||
]);
|
||||
|
||||
// Crear inventario con cantidad disponible y asociar producto
|
||||
$inv = InventarioPrenda::create([
|
||||
'orden_produccion_id' => $op->id,
|
||||
'cantidad_terminada' => 20,
|
||||
'cantidad_disponible' => 20,
|
||||
'fecha_ingreso' => now(),
|
||||
'estado' => 'en_bodega',
|
||||
'producto_id' => $producto->id,
|
||||
]);
|
||||
|
||||
$conf->refresh();
|
||||
$this->assertEquals(5000, $conf->total_pagar); // 50 * 100
|
||||
|
||||
// Registrar cobro: cantidad 5, valor 200
|
||||
$conf->registerCobro(5, 200, 'Cobro prueba');
|
||||
|
||||
$this->assertDatabaseHas('cobros', [
|
||||
'referencia_type' => Confeccion::class,
|
||||
'referencia_id' => $conf->id,
|
||||
'cantidad' => 5,
|
||||
'valor' => 200,
|
||||
]);
|
||||
|
||||
$inv->refresh();
|
||||
$this->assertEquals(15, $inv->cantidad_disponible);
|
||||
|
||||
$producto->refresh();
|
||||
$this->assertEquals(15, $producto->stock);
|
||||
|
||||
$conf->refresh();
|
||||
$this->assertEquals(4800, $conf->total_pagar); // 5000 - 200
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ class InventarioDistribucionTest extends TestCase
|
||||
$producto = Producto::create(['nombre' => 'Camiseta', 'descripcion' => '', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => '', 'categoria_id' => $categoria->id, 'imagen' => '']);
|
||||
$op = OrdenProduccion::create(['numero_orden' => 'OP-0001', 'prenda_modelo' => 'Camiseta', 'referencia' => 'C-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
|
||||
|
||||
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => $producto->id]);
|
||||
|
||||
// Crear distribución
|
||||
@@ -61,6 +63,8 @@ class InventarioDistribucionTest extends TestCase
|
||||
|
||||
$op = OrdenProduccion::create(['numero_orden' => 'OP-0100', 'prenda_modelo' => 'PrendaX', 'referencia' => 'PX-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
|
||||
|
||||
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => null]);
|
||||
|
||||
// Crear distribución sin producto previo
|
||||
@@ -93,6 +97,8 @@ class InventarioDistribucionTest extends TestCase
|
||||
$op = OrdenProduccion::create(['numero_orden' => 'OP-0200', 'prenda_modelo' => 'Doblez', 'referencia' => 'D-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
// Crear inventario: esto incrementa el stock global del producto en +5
|
||||
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
|
||||
|
||||
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => $producto->id]);
|
||||
|
||||
$producto->refresh();
|
||||
@@ -122,6 +128,8 @@ class InventarioDistribucionTest extends TestCase
|
||||
|
||||
$op = OrdenProduccion::create(['numero_orden' => 'OP-0002', 'prenda_modelo' => 'Polo', 'referencia' => 'P-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
|
||||
|
||||
$data = [
|
||||
'orden_produccion_id' => $op->id,
|
||||
'cantidad_terminada' => 5,
|
||||
@@ -151,6 +159,8 @@ class InventarioDistribucionTest extends TestCase
|
||||
|
||||
$op = OrdenProduccion::create(['numero_orden' => 'OP-0003', 'prenda_modelo' => 'Camisa', 'referencia' => 'C-02', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
|
||||
|
||||
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => $producto->id]);
|
||||
|
||||
// Crear primera distribución 2
|
||||
@@ -177,6 +187,8 @@ class InventarioDistribucionTest extends TestCase
|
||||
|
||||
$op = OrdenProduccion::create(['numero_orden' => 'OP-0004', 'prenda_modelo' => 'Saco', 'referencia' => 'S-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
|
||||
|
||||
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => $producto->id]);
|
||||
|
||||
// Crear dos distribuciones 2 y 2
|
||||
@@ -198,5 +210,72 @@ class InventarioDistribucionTest extends TestCase
|
||||
$d1->cantidad = 4;
|
||||
$d1->save();
|
||||
}
|
||||
|
||||
public function test_distribution_to_providers_decreases_disponible_and_does_not_create_bodega_stock()
|
||||
{
|
||||
$categoria = \App\Models\Categoria::create(['nombre' => 'Ropa']);
|
||||
$producto = Producto::create(['nombre' => 'Equipo', 'descripcion' => '', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => '', 'categoria_id' => $categoria->id, 'imagen' => '']);
|
||||
|
||||
$op = OrdenProduccion::create(['numero_orden' => 'OP-1000', 'prenda_modelo' => 'Equipo', 'referencia' => 'E-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 10, 'fecha_recepcion' => now()]);
|
||||
|
||||
// La creación del ProcesoAcabado puede crear automáticamente el inventario al finalizar la OP.
|
||||
$inv = \App\Models\InventarioPrenda::where('orden_produccion_id', $op->id)->first();
|
||||
$this->assertNotNull($inv);
|
||||
|
||||
$p1 = \App\Models\Proveedor::create(['nombre' => 'Proveedor 1']);
|
||||
$p2 = \App\Models\Proveedor::create(['nombre' => 'Proveedor 2']);
|
||||
|
||||
// Crear distribuciones a proveedores
|
||||
InventarioPrendaDistribucion::create([
|
||||
'inventario_prenda_id' => $inv->id,
|
||||
'proveedor_id' => $p1->id,
|
||||
'cantidad' => 4,
|
||||
]);
|
||||
|
||||
InventarioPrendaDistribucion::create([
|
||||
'inventario_prenda_id' => $inv->id,
|
||||
'proveedor_id' => $p2->id,
|
||||
'cantidad' => 5,
|
||||
]);
|
||||
|
||||
// No deben crearse filas en producto_bodega / variante_bodega
|
||||
$this->assertEquals(0, \DB::table('producto_bodega')->count());
|
||||
$this->assertEquals(0, \DB::table('variante_bodega')->count());
|
||||
|
||||
$inv->refresh();
|
||||
$this->assertEquals(1, $inv->cantidad_disponible);
|
||||
}
|
||||
|
||||
public function test_provider_distributions_exceeding_throws_validation_exception()
|
||||
{
|
||||
$categoria = \App\Models\Categoria::create(['nombre' => 'Ropa']);
|
||||
$producto = Producto::create(['nombre' => 'Surtido', 'descripcion' => '', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => '', 'categoria_id' => $categoria->id, 'imagen' => '']);
|
||||
|
||||
$op = OrdenProduccion::create(['numero_orden' => 'OP-2000', 'prenda_modelo' => 'Surtido', 'referencia' => 'S-02', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
\App\Models\ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'Acabado', 'cantidad_enviada' => 0, 'cantidad_recibida' => 5, 'fecha_recepcion' => now()]);
|
||||
|
||||
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => $producto->id]);
|
||||
|
||||
$p = \App\Models\Proveedor::create(['nombre' => 'Proveedor X']);
|
||||
|
||||
// Primera distribución 3
|
||||
InventarioPrendaDistribucion::create([
|
||||
'inventario_prenda_id' => $inv->id,
|
||||
'proveedor_id' => $p->id,
|
||||
'cantidad' => 3,
|
||||
]);
|
||||
|
||||
$this->expectException(\Illuminate\Validation\ValidationException::class);
|
||||
|
||||
// Intentar crear 3 nuevamente => 3 + 3 = 6 > 5
|
||||
InventarioPrendaDistribucion::create([
|
||||
'inventario_prenda_id' => $inv->id,
|
||||
'proveedor_id' => $p->id,
|
||||
'cantidad' => 3,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use App\Models\Proveedor;
|
||||
use App\Models\OrdenProduccion;
|
||||
use App\Models\Confeccion;
|
||||
use App\Models\Prensilla;
|
||||
use App\Models\Ojal;
|
||||
use App\Models\Recepcion;
|
||||
|
||||
class PrensillaOjalTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_cannot_assign_more_than_available_from_confecciones()
|
||||
{
|
||||
$prov = Proveedor::create(['nombre' => 'P', 'nit' => '00', 'categoria' => 'prensilla']);
|
||||
$prov2 = Proveedor::create(['nombre' => 'O', 'nit' => '01', 'categoria' => 'ojal']);
|
||||
$op = OrdenProduccion::create(['prenda_modelo' => 'X', 'cantidad_total' => 100, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
// Crear confecciones y recepciones para generar 50 unidades
|
||||
$conf = Confeccion::create(['proveedor_id' => $prov->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 50, 'valor_por_prenda' => 0]);
|
||||
Recepcion::create(['referencia_type' => Confeccion::class, 'referencia_id' => $conf->id, 'cantidad' => 50]);
|
||||
|
||||
$this->assertEquals(50, $conf->recibido_total);
|
||||
|
||||
// Asignar 30 a prensilla y 20 a ojal => OK
|
||||
Prensilla::create(['proveedor_id' => $prov->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 30]);
|
||||
Ojal::create(['proveedor_id' => $prov2->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 20]);
|
||||
|
||||
$this->assertDatabaseHas('prensillas', ['orden_produccion_id' => $op->id, 'cantidad_enviada' => 30]);
|
||||
$this->assertDatabaseHas('ojales', ['orden_produccion_id' => $op->id, 'cantidad_enviada' => 20]);
|
||||
|
||||
// Ahora intentar asignar 1 adicional en prensilla debe fallar (excede 50)
|
||||
$this->expectException(\Illuminate\Validation\ValidationException::class);
|
||||
Prensilla::create(['proveedor_id' => $prov->id, 'orden_produccion_id' => $op->id, 'cantidad_enviada' => 1]);
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class RecepcionFlowTest extends TestCase
|
||||
|
||||
$this->assertEquals(2, $count);
|
||||
|
||||
// Crear recepción con defectos y comprobar traslado creado
|
||||
// Crear recepción con faltantes y comprobar traslado creado
|
||||
Recepcion::create([
|
||||
'referencia_type' => Confeccion::class,
|
||||
'referencia_id' => $conf->id,
|
||||
|
||||
@@ -38,7 +38,7 @@ class RecepcionTintoreriaFlowTest extends TestCase
|
||||
$this->assertEquals(30, $tint->recibido_total);
|
||||
$this->assertEquals(20, $tint->faltantes);
|
||||
|
||||
// Recepción con perdidas 25 y 5 defectuosas
|
||||
// Recepción con perdidas 25 y 5 faltantes
|
||||
Recepcion::create([
|
||||
'referencia_type' => Tintoreria::class,
|
||||
'referencia_id' => $tint->id,
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use App\Models\Tintoreria;
|
||||
use App\Models\Proveedor;
|
||||
use App\Models\OrdenProduccion;
|
||||
use App\Models\Recepcion;
|
||||
use App\Models\TrasladoPrenda;
|
||||
use App\Models\InventarioPrenda;
|
||||
use App\Models\Producto;
|
||||
use App\Models\Cobro;
|
||||
use App\Models\Ajuste;
|
||||
|
||||
class TintoreriaActionsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_register_reproceso_creates_ajuste_and_traslado_and_affects_recibido()
|
||||
{
|
||||
$proveedor = Proveedor::create(['nombre' => 'Prov T', 'nit' => '000', 'categoria' => 'tintoreria']);
|
||||
$op = OrdenProduccion::create(['prenda_modelo' => 'X', 'cantidad_total' => 100, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
$tint = Tintoreria::create([
|
||||
'proveedor_id' => $proveedor->id,
|
||||
'orden_produccion_id' => $op->id,
|
||||
'tipo_proceso' => 'Tinte',
|
||||
'cantidad_enviada' => 50,
|
||||
]);
|
||||
|
||||
// Registrar recepciones para tener recibido
|
||||
Recepcion::create(['referencia_type' => Tintoreria::class, 'referencia_id' => $tint->id, 'cantidad' => 40]);
|
||||
Recepcion::create(['referencia_type' => Tintoreria::class, 'referencia_id' => $tint->id, 'cantidad' => 5]);
|
||||
|
||||
$tint->refresh();
|
||||
$this->assertEquals(45, $tint->recibido_total);
|
||||
|
||||
// Registrar reproceso 10
|
||||
$tint->registerReproceso(10, 'Reproceso prueba');
|
||||
|
||||
$this->assertDatabaseHas('ajustes', [
|
||||
'referencia_type' => Tintoreria::class,
|
||||
'referencia_id' => $tint->id,
|
||||
'tipo' => 'reproceso',
|
||||
'cantidad' => 10,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('traslados_prenda', [
|
||||
'referencia_type' => Tintoreria::class,
|
||||
'referencia_id' => $tint->id,
|
||||
'origen' => 'tintoreria',
|
||||
'destino' => 'reprocesos',
|
||||
'cantidad_enviada' => 10,
|
||||
]);
|
||||
|
||||
$tint->refresh();
|
||||
$this->assertEquals(35, $tint->recibido_total);
|
||||
}
|
||||
|
||||
public function test_register_cobro_creates_cobro_and_adjusts_inventory()
|
||||
{
|
||||
$proveedor = Proveedor::create(['nombre' => 'Prov T', 'nit' => '000', 'categoria' => 'tintoreria']);
|
||||
$op = OrdenProduccion::create(['prenda_modelo' => 'X', 'cantidad_total' => 100, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
$tint = Tintoreria::create([
|
||||
'proveedor_id' => $proveedor->id,
|
||||
'orden_produccion_id' => $op->id,
|
||||
'tipo_proceso' => 'Tinte',
|
||||
'cantidad_enviada' => 20,
|
||||
'cantidad_recibida' => 20,
|
||||
]);
|
||||
|
||||
// Crear producto y proceso de acabado que aporta cantidad recibida para permitir inventario
|
||||
$categoria = \App\Models\Categoria::create(['nombre' => 'Ropa']);
|
||||
$producto = Producto::create(['nombre' => 'Prod', 'descripcion' => 'x', 'stock' => 0, 'estado' => true, 'precio_compra' => 0, 'precio_venta' => 0, 'unidad_medida' => 'unidad', 'codigo_barras' => 'X', 'categoria_id' => $categoria->id, 'imagen' => '']);
|
||||
|
||||
\App\Models\ProcesoAcabado::create([
|
||||
'orden_produccion_id' => $op->id,
|
||||
'tipo_proceso' => 'Acabado',
|
||||
'proveedor_id' => $proveedor->id,
|
||||
'cantidad_enviada' => 10,
|
||||
'fecha_envio' => now(),
|
||||
'fecha_recepcion' => now(),
|
||||
'cantidad_recibida' => 10,
|
||||
]);
|
||||
|
||||
// Crear inventario con cantidad disponible y asociar producto
|
||||
$inv = InventarioPrenda::create([
|
||||
'orden_produccion_id' => $op->id,
|
||||
'cantidad_terminada' => 10,
|
||||
'cantidad_disponible' => 10,
|
||||
'fecha_ingreso' => now(),
|
||||
'estado' => 'en_bodega',
|
||||
'producto_id' => $producto->id,
|
||||
]);
|
||||
|
||||
// Registrar cobro: cantidad 5, valor 100
|
||||
$tint->registerCobro(5, 100, 'Cobro tintoreria');
|
||||
|
||||
$this->assertDatabaseHas('cobros', [
|
||||
'referencia_type' => Tintoreria::class,
|
||||
'referencia_id' => $tint->id,
|
||||
'cantidad' => 5,
|
||||
'valor' => 100,
|
||||
]);
|
||||
|
||||
$inv->refresh();
|
||||
$this->assertEquals(5, $inv->cantidad_disponible);
|
||||
|
||||
$producto->refresh();
|
||||
$this->assertEquals(5, $producto->stock);
|
||||
|
||||
$tint->refresh();
|
||||
$this->assertEquals(100, $tint->descuentos_cobros); // 100 applied
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class TrasladoFlowTest extends TestCase
|
||||
'categoria' => 'talleres',
|
||||
]);
|
||||
|
||||
// Paso 1: Confección - envía 100, llegan 95, 2 defectuosas
|
||||
// Paso 1: Confección - envía 100, llegan 95, 2 faltantes
|
||||
$conf = Confeccion::create([
|
||||
'proveedor_id' => $proveedor->id,
|
||||
'orden_produccion_id' => $op->id,
|
||||
|
||||
@@ -25,7 +25,7 @@ class ConfeccionRecepcionesTest extends TestCase
|
||||
'cantidad_enviada' => 100,
|
||||
]);
|
||||
|
||||
// Crear recepciones 40 y 40 con defectos en la segunda (10)
|
||||
// Crear recepciones 40 y 40 con faltantes en la segunda (10)
|
||||
Recepcion::create(['referencia_type' => Confeccion::class,'referencia_id' => $conf->id,'cantidad' => 40]);
|
||||
Recepcion::create(['referencia_type' => Confeccion::class,'referencia_id' => $conf->id,'cantidad' => 40, 'prendas_defectuosas' => 10]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user