134 lines
4.9 KiB
PHP
134 lines
4.9 KiB
PHP
<?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
|
|
}
|
|
}
|