175 lines
10 KiB
PHP
175 lines
10 KiB
PHP
@php
|
|
$opId = request()->route('record');
|
|
$op = \App\Models\OrdenProduccion::find($opId);
|
|
$events = [];
|
|
|
|
if ($op) {
|
|
$confecciones = $op->confeccions()->get();
|
|
foreach ($confecciones as $c) {
|
|
// Evento principal de la confección (creación/envío)
|
|
$events[] = [
|
|
'tipo' => 'Confección',
|
|
'id' => $c->id,
|
|
'fecha' => $c->fecha_envio ?? $c->created_at,
|
|
'detalle' => "Enviado: {$c->cantidad_enviada} - Recibido total: {$c->recibido_total} - Defectos: {$c->prendas_defectuosas}",
|
|
$events[] = [
|
|
'tipo' => 'Recepción (Confección)',
|
|
'id' => $r->id,
|
|
'fecha' => $r->fecha_recepcion ?? $r->created_at,
|
|
'detalle' => "Recibido: {$r->cantidad} - Notas: " . ($r->notas ?? '—'),
|
|
'link' => route('filament.admin.resources.confeccions.edit', ['record' => $c->id]),
|
|
];
|
|
}
|
|
}
|
|
|
|
$tints = $op->tintorerias()->get();
|
|
foreach ($tints as $t) {
|
|
$events[] = [
|
|
'tipo' => 'Tintorería',
|
|
'id' => $t->id,
|
|
'fecha' => $t->fecha_envio ?? $t->created_at,
|
|
'detalle' => "Enviado: {$t->cantidad_enviada} - Recibido total: {$t->cantidad_recibida} - Perdidas: {$t->perdidas}",
|
|
'link' => route('filament.admin.resources.tintorerias.edit', ['record' => $t->id]),
|
|
];
|
|
|
|
// Eventos por cada recepción
|
|
$recepciones = $t->recepciones()->orderBy('fecha_recepcion')->get();
|
|
foreach ($recepciones as $r) {
|
|
$events[] = [
|
|
'tipo' => 'Recepción (Tintorería)',
|
|
'id' => $r->id,
|
|
'fecha' => $r->fecha_recepcion ?? $r->created_at,
|
|
'detalle' => "Recibido: {$r->cantidad} - Notas: " . ($r->notas ?? '—'),
|
|
'link' => route('filament.admin.resources.tintorerias.edit', ['record' => $t->id]),
|
|
];
|
|
}
|
|
}
|
|
|
|
$acabados = $op->procesosAcabado()->orderBy('fecha_recepcion')->get();
|
|
foreach ($acabados as $p) {
|
|
$events[] = [
|
|
'tipo' => 'Acabado',
|
|
'id' => $p->id,
|
|
'fecha' => $p->fecha_recepcion ?? $p->created_at,
|
|
'detalle' => "Enviado: {$p->cantidad_enviada} - Recibido: {$p->cantidad_recibida}",
|
|
'link' => route('filament.admin.resources.proceso-acabados.edit', ['record' => $p->id]),
|
|
];
|
|
}
|
|
|
|
// Protege en entornos donde la migración aún no fue ejecutada
|
|
if (\Illuminate\Support\Facades\Schema::hasTable('traslados_prenda')) {
|
|
$traslados = $op->traslados()->orderBy('fecha_recepcion')->get();
|
|
} else {
|
|
$traslados = collect();
|
|
}
|
|
|
|
foreach ($traslados as $tr) {
|
|
$events[] = [
|
|
'tipo' => 'Traslado',
|
|
'id' => $tr->id,
|
|
'fecha' => $tr->fecha_recepcion ?? $tr->created_at,
|
|
'detalle' => "Origen: {$tr->origen} -> Destino: {$tr->destino} | Enviado: {$tr->cantidad_enviada} - Recibido: {$tr->cantidad_recibida} - Residual: {$tr->residual}",
|
|
'link' => route('filament.admin.resources.traslado-prendas.edit', ['record' => $tr->id]),
|
|
];
|
|
}
|
|
|
|
$inventarios = $op->inventarioPrenda()->orderBy('fecha_ingreso')->get();
|
|
foreach ($inventarios as $inv) {
|
|
$events[] = [
|
|
'tipo' => 'Inventario',
|
|
'id' => $inv->id,
|
|
'fecha' => $inv->fecha_ingreso ?? $inv->created_at,
|
|
'detalle' => "Terminadas: {$inv->cantidad_terminada} - Disponibles: {$inv->cantidad_disponible}",
|
|
'link' => route('filament.admin.resources.inventario-prendas.edit', ['record' => $inv->id]),
|
|
];
|
|
}
|
|
|
|
usort($events, function ($a, $b) {
|
|
return strtotime($a['fecha']) <=> strtotime($b['fecha']);
|
|
});
|
|
}
|
|
@endphp
|
|
|
|
<div class="filament-forms-component">
|
|
<div class="space-y-4">
|
|
@if (!$op)
|
|
<div>No se encontró la Orden de Producción.</div>
|
|
@elseif (count($events) === 0)
|
|
<div>No hay eventos registrados para esta orden.</div>
|
|
@else
|
|
<ol class="border-l border-gray-200 dark:border-gray-700">
|
|
@foreach ($events as $e)
|
|
<li class="mb-10 ml-6 relative" x-data="{ open: false }" @keydown.escape="open=false">
|
|
<span class="flex absolute -left-3 justify-center items-center w-6 h-6 bg-blue-200 rounded-full ring-8 ring-white dark:ring-gray-900 dark:bg-blue-900">
|
|
<svg aria-hidden="true" class="w-3 h-3 text-blue-600 dark:text-blue-300" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M6 2a1 1 0 00-1 1v1H4a1 1 0 00-1 1v1H2a1 1 0 00-1 1v1H0v2h1v1h1v1h1v1h1v1a1 1 0 001 1h2v-1h6v1h2a1 1 0 001-1v-1h1v-1h1v-1h1v-2h-1v-1h-1v-1h-1V8h-1V7h-1V6h-1V5h-1V4h-1V3a1 1 0-11-1-1H6z"></path></svg>
|
|
</span>
|
|
<h3 class="flex items-center mb-1 text-lg font-semibold text-gray-900 dark:text-white">{{ $e['tipo'] }} <a href="{{ $e['link'] }}" class="ml-3 text-sm text-blue-600">#{{ $e['id'] }}</a></h3>
|
|
<time class="block mb-2 text-sm font-normal leading-none text-gray-400">{{ \Carbon\Carbon::parse($e['fecha'])->format('Y-m-d H:i') }}</time>
|
|
<p class="mb-4 text-base font-normal text-gray-500 dark:text-gray-300">{{ $e['detalle'] }}</p>
|
|
|
|
{{-- Acciones rápidas --}}
|
|
@if(in_array($e['tipo'], ['Confección','Tintorería']))
|
|
<div class="flex gap-2">
|
|
<a href="{{ $e['link'] }}#recepciones" class="inline-flex items-center px-2 py-1 bg-blue-600 text-white rounded text-sm">Agregar recepción</a>
|
|
</div>
|
|
@endif
|
|
@if($e['tipo'] === 'Traslado')
|
|
@php $tr = \App\Models\TrasladoPrenda::find($e['id']); @endphp
|
|
<div class="flex gap-2">
|
|
<button x-on:click="open = true" class="inline-flex items-center px-2 py-1 bg-white border rounded text-sm">Detalles</button>
|
|
|
|
@if($tr && $tr->estado !== 'recibido')
|
|
<form method="POST" action="{{ route('filament.traslados.mark-received', ['traslado' => $tr->id]) }}" onsubmit="return confirm('Marcar traslado #'+{{ $tr->id }}+' como recibido?');">
|
|
@csrf
|
|
<button type="submit" class="inline-flex items-center px-2 py-1 bg-green-600 text-white rounded text-sm">Marcar recibido</button>
|
|
</form>
|
|
@endif
|
|
</div>
|
|
|
|
{{-- Modal --}}
|
|
<div x-show="open" x-cloak class="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
|
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg w-2/3 p-6">
|
|
<h3 class="text-lg font-semibold mb-2">Traslado #{{ $e['id'] }} - Detalles</h3>
|
|
@if($tr)
|
|
<p class="text-sm mb-2">Origen: <strong>{{ $tr->origen }}</strong> → Destino: <strong>{{ $tr->destino }}</strong></p>
|
|
<p class="text-sm mb-2">Enviado: {{ $tr->cantidad_enviada }} — Recibido: {{ $tr->cantidad_recibida ?? '—' }} — Residual: {{ $tr->residual ?? '—' }}</p>
|
|
|
|
<form method="POST" action="{{ route('filament.traslados.mark-received', ['traslado' => $tr->id]) }}">
|
|
@csrf
|
|
<div class="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<label class="block text-sm">Cantidad recibida</label>
|
|
<input type="number" name="cantidad_recibida" value="{{ $tr->cantidad_recibida ?? '' }}" class="mt-1 block w-full rounded border-gray-300" />
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm">Prendas defectuosas</label>
|
|
<input type="number" name="prendas_defectuosas" value="{{ $tr->prendas_defectuosas ?? 0 }}" class="mt-1 block w-full rounded border-gray-300" />
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm">Reparaciones</label>
|
|
<input type="number" name="reparaciones" value="{{ $tr->reparaciones ?? 0 }}" class="mt-1 block w-full rounded border-gray-300" />
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm">Saldos</label>
|
|
<input type="number" name="saldos" value="{{ $tr->saldos ?? 0 }}" class="mt-1 block w-full rounded border-gray-300" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-4 flex justify-end gap-2">
|
|
<button type="button" x-on:click="open=false" class="px-3 py-1 bg-gray-200 rounded">Cerrar</button>
|
|
<button type="submit" class="px-3 py-1 bg-blue-600 text-white rounded">Guardar y marcar recibido</button>
|
|
</div>
|
|
</form>
|
|
@else
|
|
<p>No se encontró el traslado.</p>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
@endif
|
|
|
|
</li>
|
|
@endforeach
|
|
</ol>
|
|
@endif
|
|
</div>
|
|
</div> |