65 lines
2.3 KiB
PHP
65 lines
2.3 KiB
PHP
<?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-o-clipboard-document-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-o-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;
|
|
}
|
|
}
|