uo
This commit is contained in:
@@ -119,18 +119,31 @@ class TintoreriaResource extends Resource
|
|||||||
$id = $get('id');
|
$id = $get('id');
|
||||||
if (! $id) return 'Sin recepciones registradas';
|
if (! $id) return 'Sin recepciones registradas';
|
||||||
|
|
||||||
$total = \App\Models\Recepcion::where('referencia_type', \App\Models\Tintoreria::class)
|
$tintoreria = \App\Models\Tintoreria::find($id);
|
||||||
->where('referencia_id', $id)
|
if (!$tintoreria) return 'Sin datos';
|
||||||
->sum(\DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
|
|
||||||
|
|
||||||
$perdidas = \App\Models\Recepcion::where('referencia_type', \App\Models\Tintoreria::class)
|
$enviada = (int) ($tintoreria->cantidad_enviada ?? 0);
|
||||||
->where('referencia_id', $id)
|
$recepciones = (int) $tintoreria->recepciones()->sum(\DB::raw('cantidad - COALESCE(prendas_defectuosas, 0)'));
|
||||||
->sum('prendas_defectuosas');
|
$reprocesos = (int) $tintoreria->ajustes()->where('tipo', 'reproceso')->sum('cantidad');
|
||||||
|
$cobros = (int) $tintoreria->cobros()->sum('cantidad');
|
||||||
|
$cobrosValor = (float) $tintoreria->cobros()->sum('valor');
|
||||||
|
|
||||||
|
$recibidoNeto = $recepciones - $reprocesos;
|
||||||
|
$totalContabilizado = $recibidoNeto + $cobros;
|
||||||
|
$faltantes = max(0, $enviada - $totalContabilizado);
|
||||||
|
|
||||||
|
return "━━━ PRENDAS ━━━
|
||||||
|
📦 Enviadas: {$enviada}
|
||||||
|
|
||||||
$enviada = (int) ($get('cantidad_enviada') ?? 0);
|
✅ Recibidas: {$recepciones}
|
||||||
$faltan = max(0, $enviada - $total - $perdidas);
|
🔧 En reproceso: {$reprocesos}
|
||||||
|
📊 Neto recibido: {$recibidoNeto}
|
||||||
|
|
||||||
return "Total recibido: {$total} — Pérdidas: {$perdidas} — Faltan: {$faltan}";
|
💰 Cobradas: {$cobros} prendas
|
||||||
|
⚠️ Pendientes: {$faltantes}
|
||||||
|
|
||||||
|
━━━ COBROS ━━━
|
||||||
|
💸 Total cobros: $" . number_format($cobrosValor, 2);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
Forms\Components\Placeholder::make('instrucciones')
|
Forms\Components\Placeholder::make('instrucciones')
|
||||||
|
|||||||
@@ -67,74 +67,6 @@ class EditTintoreria extends EditRecord
|
|||||||
// Refrescar la página para ver cambios
|
// Refrescar la página para ver cambios
|
||||||
$this->redirect(route('filament.admin.resources.tintorerias.edit', ['record' => $record->id]));
|
$this->redirect(route('filament.admin.resources.tintorerias.edit', ['record' => $record->id]));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Reprocesos: registrar reproceso como ajuste (igual que arreglos en confecciones)
|
|
||||||
Actions\Action::make('reprocesos')
|
|
||||||
->label('Reprocesos')
|
|
||||||
->modalHeading('Registrar Reproceso')
|
|
||||||
->form([
|
|
||||||
Forms\Components\TextInput::make('cantidad')
|
|
||||||
->label('Cantidad a reprocesar')
|
|
||||||
->numeric()
|
|
||||||
->required()
|
|
||||||
->minValue(1)
|
|
||||||
->helperText('Prendas que llegaron defectuosas y necesitan reparación'),
|
|
||||||
Forms\Components\Textarea::make('notas'),
|
|
||||||
])
|
|
||||||
->action(function (array $data): void {
|
|
||||||
$record = $this->getRecord();
|
|
||||||
|
|
||||||
$cantidad = (int) ($data['cantidad'] ?? 0);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$record->registerReproceso($cantidad, $data['notas'] ?? null, auth()->id() ?? null);
|
|
||||||
|
|
||||||
\Filament\Notifications\Notification::make()->success()->title('Reproceso registrado')->body('Se registró el reproceso correctamente. Estas prendas podrán re-recibirse cuando regresen reparadas.')->send();
|
|
||||||
} catch (\Illuminate\Validation\ValidationException $e) {
|
|
||||||
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->validator->errors()->first() ?? 'Error al registrar reproceso.')->send();
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->redirect(route('filament.admin.resources.tintorerias.edit', ['record' => $record->id]));
|
|
||||||
}),
|
|
||||||
|
|
||||||
// Cobros: registrar prendas que no llegaron
|
|
||||||
Actions\Action::make('cobros')
|
|
||||||
->label('Cobros')
|
|
||||||
->modalHeading('Registrar Cobro')
|
|
||||||
->form([
|
|
||||||
Forms\Components\TextInput::make('cantidad')
|
|
||||||
->label('Cantidad')
|
|
||||||
->numeric()
|
|
||||||
->required()
|
|
||||||
->minValue(1)
|
|
||||||
->helperText('Prendas que NO llegaron y se cobran a la tintorería'),
|
|
||||||
Forms\Components\TextInput::make('valor')
|
|
||||||
->label('Valor a descontar')
|
|
||||||
->numeric()
|
|
||||||
->required()
|
|
||||||
->minValue(0),
|
|
||||||
Forms\Components\Textarea::make('notas'),
|
|
||||||
])
|
|
||||||
->action(function (array $data): void {
|
|
||||||
$record = $this->getRecord();
|
|
||||||
|
|
||||||
$cantidad = (int) ($data['cantidad'] ?? 0);
|
|
||||||
$valor = (float) ($data['valor'] ?? 0);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$record->registerCobro($cantidad, $valor, $data['notas'] ?? null, auth()->id() ?? null);
|
|
||||||
|
|
||||||
\Filament\Notifications\Notification::make()->success()->title('Cobro registrado')->body('Se registró el cobro correctamente.')->send();
|
|
||||||
} catch (\Illuminate\Validation\ValidationException $e) {
|
|
||||||
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->validator->errors()->first() ?? 'Error al registrar cobro.')->send();
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->redirect(route('filament.admin.resources.tintorerias.edit', ['record' => $record->id]));
|
|
||||||
}),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user