up
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user