64 lines
2.7 KiB
PHP
64 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Tests\TestCase;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use App\Models\OrdenProduccion;
|
|
use App\Models\InventarioPrenda;
|
|
use App\Models\ProcesoAcabado;
|
|
|
|
class OrdenProduccionFaltantesTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_faltantes_and_realizado_calculation()
|
|
{
|
|
$op = OrdenProduccion::create(['numero_orden' => 'OP-900', 'prenda_modelo' => 'ModeloX', 'cantidad_total' => 50, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
|
|
|
// Initially nothing done
|
|
$this->assertEquals(0, $op->realizado);
|
|
$this->assertEquals(50, $op->faltantes);
|
|
|
|
// Create an inventario with 20 finished
|
|
InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 20, 'cantidad_disponible' => 20, 'fecha_ingreso' => now(), 'estado' => 'en_bodega']);
|
|
|
|
$op->refresh();
|
|
|
|
$this->assertEquals(20, $op->realizado);
|
|
$this->assertEquals(30, $op->faltantes);
|
|
}
|
|
|
|
public function test_do_not_set_finalizada_until_completed()
|
|
{
|
|
$op = OrdenProduccion::create(['numero_orden' => 'OP-901', 'prenda_modelo' => 'ModeloY', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
|
|
|
// Create process finished but no inventario yet
|
|
ProcesoAcabado::create(['orden_produccion_id' => $op->id, 'tipo_proceso' => 'PA', 'proveedor_id' => \App\Models\Proveedor::factory()->create(['categoria' => 'proveedor'])->id, 'cantidad_enviada' => 0, 'cantidad_recibida' => 8, 'fecha_envio' => now(), 'fecha_recepcion' => now()]);
|
|
|
|
$op->refresh();
|
|
|
|
// Since only 8 are received into processus, but no inventory recorded, still not finalizada
|
|
$this->assertNotEquals('finalizada', $op->estado);
|
|
|
|
// Create inventory for the 8 (not enough to finalize)
|
|
InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 8, 'cantidad_disponible' => 8, 'fecha_ingreso' => now(), 'estado' => 'en_bodega']);
|
|
|
|
$op->refresh();
|
|
$this->assertEquals(2, $op->faltantes);
|
|
|
|
// Now add remaining inventory
|
|
InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 2, 'cantidad_disponible' => 2, 'fecha_ingreso' => now(), 'estado' => 'en_bodega']);
|
|
|
|
$op->refresh();
|
|
$this->assertEquals(0, $op->faltantes);
|
|
|
|
// Simulate no pending procesosAcabado and trigger the check
|
|
ProcesoAcabado::where('orden_produccion_id', $op->id)->update(['fecha_recepcion' => now()]);
|
|
$op->refresh();
|
|
|
|
// Now the orden should be finalizada when all completed
|
|
$this->assertEquals('finalizada', $op->estado);
|
|
}
|
|
}
|