up
This commit is contained in:
@@ -104,7 +104,19 @@ class ConfeccionResource extends Resource
|
||||
->schema([
|
||||
Forms\Components\Placeholder::make('recepcion_summary')
|
||||
->label('Resumen')
|
||||
->content(fn ($get) => "Total recibido: " . ($get('cantidad_recibida') ?? 0) . " — Faltan: " . ($get('faltantes') ?? 0)),
|
||||
->content(function ($get) {
|
||||
$id = $get('id');
|
||||
if (! $id) return 'Sin recepciones registradas';
|
||||
|
||||
$total = \App\Models\Recepcion::where('referencia_type', \App\Models\Confeccion::class)
|
||||
->where('referencia_id', $id)
|
||||
->sum('cantidad');
|
||||
|
||||
$enviada = (int) ($get('cantidad_enviada') ?? 0);
|
||||
$faltan = max(0, $enviada - $total);
|
||||
|
||||
return "Total recibido: {$total} — Faltan: {$faltan}";
|
||||
}),
|
||||
|
||||
Forms\Components\Placeholder::make('instrucciones')
|
||||
->label('Acciones')
|
||||
|
||||
@@ -78,9 +78,15 @@ class Confeccion extends Model
|
||||
return $this->morphMany(\App\Models\Recepcion::class, 'referencia');
|
||||
}
|
||||
|
||||
// Cuantas faltan por recibir
|
||||
// Total recibido calculado desde recepciones (fuente de la verdad)
|
||||
public function getRecibidoTotalAttribute()
|
||||
{
|
||||
return (int) $this->recepciones()->sum('cantidad');
|
||||
}
|
||||
|
||||
// Cuantas faltan por recibir (usa la suma real de recepciones)
|
||||
public function getFaltantesAttribute()
|
||||
{
|
||||
return max(0, (int)($this->cantidad_enviada ?? 0) - (int)($this->cantidad_recibida ?? 0));
|
||||
return max(0, (int)($this->cantidad_enviada ?? 0) - $this->recibido_total);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,9 +69,15 @@ class Tintoreria extends Model
|
||||
return $this->morphMany(\App\Models\Recepcion::class, 'referencia');
|
||||
}
|
||||
|
||||
// Cuantas faltan por recibir
|
||||
// Total recibido calculado desde recepciones (fuente de la verdad)
|
||||
public function getRecibidoTotalAttribute()
|
||||
{
|
||||
return (int) $this->recepciones()->sum('cantidad');
|
||||
}
|
||||
|
||||
// Cuantas faltan por recibir (usa la suma real de recepciones)
|
||||
public function getFaltantesAttribute()
|
||||
{
|
||||
return max(0, (int)($this->cantidad_enviada ?? 0) - (int)($this->cantidad_recibida ?? 0));
|
||||
return max(0, (int)($this->cantidad_enviada ?? 0) - $this->recibido_total);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,7 @@ if ($op) {
|
||||
'tipo' => 'Confección',
|
||||
'id' => $c->id,
|
||||
'fecha' => $c->fecha_envio ?? $c->created_at,
|
||||
'detalle' => "Enviado: {$c->cantidad_enviada} - Recibido total: {$c->cantidad_recibida} - Defectos: {$c->prendas_defectuosas}",
|
||||
'link' => route('filament.admin.resources.confeccions.edit', ['record' => $c->id]),
|
||||
];
|
||||
|
||||
// Eventos por cada recepción
|
||||
$recepciones = $c->recepciones()->orderBy('fecha_recepcion')->get();
|
||||
foreach ($recepciones as $r) {
|
||||
'detalle' => "Enviado: {$c->cantidad_enviada} - Recibido total: {$c->recibido_total} - Defectos: {$c->prendas_defectuosas}",
|
||||
$events[] = [
|
||||
'tipo' => 'Recepción (Confección)',
|
||||
'id' => $r->id,
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use App\Models\Confeccion;
|
||||
use App\Models\Recepcion;
|
||||
use App\Models\Proveedor;
|
||||
use App\Models\OrdenProduccion;
|
||||
|
||||
class ConfeccionRecepcionesTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @test */
|
||||
public function recibido_total_and_faltantes_are_calculated_from_recepciones()
|
||||
{
|
||||
$proveedor = Proveedor::factory()->create(['categoria' => 'talleres']);
|
||||
$op = OrdenProduccion::factory()->create(['cantidad_total' => 100]);
|
||||
|
||||
$conf = Confeccion::create([
|
||||
'proveedor_id' => $proveedor->id,
|
||||
'orden_produccion_id' => $op->id,
|
||||
'cantidad_enviada' => 100,
|
||||
]);
|
||||
|
||||
// Crear recepciones 40 y 40
|
||||
Recepcion::create(['referencia_type' => Confeccion::class,'referencia_id' => $conf->id,'cantidad' => 40]);
|
||||
Recepcion::create(['referencia_type' => Confeccion::class,'referencia_id' => $conf->id,'cantidad' => 40]);
|
||||
|
||||
$conf->refresh();
|
||||
|
||||
$this->assertEquals(80, $conf->recibido_total);
|
||||
$this->assertEquals(20, $conf->faltantes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user