This commit is contained in:
Lizandro Guarnizo
2026-01-18 13:14:59 -05:00
parent c358774862
commit e248b62a43
5 changed files with 160 additions and 5 deletions
+2 -4
View File
@@ -16,10 +16,8 @@ class GestionDashboard extends Page
protected function getHeaderWidgets(): array
{
return [
\App\Filament\Widgets\TelasStatsOverview::class,
// \App\Filament\Widgets\TelasStatsOverview::class,
// \App\Filament\Widgets\TelasEstadoOverview::class,
// \App\Filament\Widgets\TelasChart::class,
\App\Filament\Widgets\GestionKpisWidget::class,
\App\Filament\Widgets\AlertasStockBodegasWidget::class,
];
}
@@ -77,7 +77,8 @@ class OrdenProduccionResource extends Resource
->default(0),
DatePicker::make('fecha_inicio')
->required(),
->required()
->default(now()),
DatePicker::make('fecha_entrega_estimada')
->required(),
@@ -0,0 +1,64 @@
<?php
namespace App\Filament\Widgets;
use App\Models\OrdenProduccion;
use App\Models\Tela;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
class GestionKpisWidget extends BaseWidget
{
protected static bool $isLazy = false;
protected function getStats(): array
{
try {
$stats = [];
$total = OrdenProduccion::count();
$stats[] = Stat::make('Órdenes totales', $total)
->description('Total de órdenes de producción')
->descriptionIcon('heroicon-m-clipboard-list')
->color('primary');
$byState = OrdenProduccion::selectRaw('estado, count(*) as cnt')->groupBy('estado')->pluck('cnt', 'estado')->toArray();
$stats[] = Stat::make('En corte', $byState['en_corte'] ?? 0)
->color('warning');
$stats[] = Stat::make('En confección', $byState['en_confeccion'] ?? 0)
->color('info');
$stats[] = Stat::make('En tintorería', $byState['en_tintoreria'] ?? 0)
->color('primary');
$stats[] = Stat::make('En acabados', $byState['en_acabados'] ?? 0)
->color('secondary');
$stats[] = Stat::make('Finalizadas', $byState['finalizada'] ?? 0)
->color('success');
$metros = Tela::sum('metros_disponibles');
$stats[] = Stat::make('Metros disponibles', number_format($metros, 2) . ' m')
->description('Total metros disponibles en stock')
->descriptionIcon('heroicon-m-archive-box');
$atrasadas = OrdenProduccion::where('fecha_entrega_estimada', '<', now()->toDateString())
->where('estado', '!=', 'finalizada')
->count();
$stats[] = Stat::make('Órdenes atrasadas', $atrasadas)
->color($atrasadas > 0 ? 'danger' : 'success')
->description('OPs con fecha de entrega vencida');
return $stats;
} catch (\Exception $e) {
return [
Stat::make('KPIs', 'Error')
->description('Revisar logs')
->color('danger'),
];
}
}
protected function getColumns(): int
{
return 6;
}
}
+5
View File
@@ -125,6 +125,11 @@ class OrdenProduccion extends Model
$orden->numero_orden = 'OP-' . str_pad($ultimoId, 6, '0', STR_PAD_LEFT);
}
// Fecha de inicio por defecto hoy
if (! isset($orden->fecha_inicio) || ! $orden->fecha_inicio) {
$orden->fecha_inicio = now()->toDateString();
}
});
// Validar y reservar tela al cambiar de estado a 'en_corte'