up
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Producto;
|
||||
use App\Models\Bodega;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class AlertasStockBodegasWidget extends BaseWidget
|
||||
{
|
||||
protected static bool $isLazy = false;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
try {
|
||||
$stats = [];
|
||||
|
||||
// Productos con stock bajo general
|
||||
$productosStockBajo = Producto::where('estado', true)
|
||||
->get()
|
||||
->filter(function ($producto) {
|
||||
return $producto->getStockEfectivo() <= $producto->stock_minimo;
|
||||
})
|
||||
->count();
|
||||
|
||||
$stats[] = Stat::make('Stock Bajo Global', $productosStockBajo)
|
||||
->description('Productos bajo mínimo')
|
||||
->descriptionIcon('heroicon-m-exclamation-triangle')
|
||||
->color($productosStockBajo > 0 ? 'danger' : 'success');
|
||||
|
||||
// Productos con stock alto general
|
||||
$productosStockAlto = Producto::where('estado', true)
|
||||
->whereNotNull('stock_maximo')
|
||||
->get()
|
||||
->filter(function ($producto) {
|
||||
return $producto->getStockEfectivo() > $producto->stock_maximo;
|
||||
})
|
||||
->count();
|
||||
|
||||
$stats[] = Stat::make('Stock Excesivo', $productosStockAlto)
|
||||
->description('Productos sobre máximo')
|
||||
->descriptionIcon('heroicon-m-arrow-trending-up')
|
||||
->color($productosStockAlto > 0 ? 'warning' : 'success');
|
||||
|
||||
// Análisis por bodega crítica (si existe)
|
||||
$bodegaPrincipal = Bodega::where('nombre', 'Principal')->first();
|
||||
if ($bodegaPrincipal) {
|
||||
$productosConStockCero = $bodegaPrincipal->productos()
|
||||
->wherePivot('stock', 0)
|
||||
->count();
|
||||
|
||||
$stats[] = Stat::make('Sin Stock en Principal', $productosConStockCero)
|
||||
->description('Productos agotados')
|
||||
->descriptionIcon('heroicon-m-x-circle')
|
||||
->color($productosConStockCero > 0 ? 'danger' : 'success');
|
||||
}
|
||||
|
||||
return $stats;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// En caso de error, devolver estadísticas básicas
|
||||
return [
|
||||
Stat::make('Sistema de Alertas', 'Configurando...')
|
||||
->description('Ejecute las migraciones necesarias')
|
||||
->descriptionIcon('heroicon-m-cog-6-tooth')
|
||||
->color('warning')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
protected function getColumns(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\TransferenciaBodega;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class TransferenciasBodegaStatsWidget extends BaseWidget
|
||||
{
|
||||
protected function getStats(): array
|
||||
{
|
||||
$hoy = Carbon::today();
|
||||
$estaSemana = Carbon::now()->startOfWeek();
|
||||
$esteMes = Carbon::now()->startOfMonth();
|
||||
|
||||
$transferenciasHoy = TransferenciaBodega::whereDate('fecha_transferencia', $hoy)->count();
|
||||
$transferenciasEstaSemana = TransferenciaBodega::where('fecha_transferencia', '>=', $estaSemana)->count();
|
||||
$transferenciasEsteMes = TransferenciaBodega::where('fecha_transferencia', '>=', $esteMes)->count();
|
||||
|
||||
return [
|
||||
Stat::make('Transferencias Hoy', $transferenciasHoy)
|
||||
->description('Transferencias realizadas hoy')
|
||||
->descriptionIcon('heroicon-m-arrow-trending-up')
|
||||
->color('success'),
|
||||
|
||||
Stat::make('Esta Semana', $transferenciasEstaSemana)
|
||||
->description('Transferencias esta semana')
|
||||
->descriptionIcon('heroicon-m-calendar-days')
|
||||
->color('warning'),
|
||||
|
||||
Stat::make('Este Mes', $transferenciasEsteMes)
|
||||
->description('Transferencias este mes')
|
||||
->descriptionIcon('heroicon-m-chart-bar')
|
||||
->color('primary'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use App\Models\Venta;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class VentasChart extends ChartWidget
|
||||
{
|
||||
protected static ?string $heading = 'Reporte de Ventas';
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$ventas = Venta::whereBetween('created_at', [Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth()])
|
||||
->groupByRaw('DATE(created_at)')
|
||||
->selectRaw('DATE(created_at) as dia, SUM(total) as total')
|
||||
->pluck('total', 'dia');
|
||||
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Ventas del mes',
|
||||
'data' => array_values($ventas->toArray()),
|
||||
],
|
||||
],
|
||||
'labels' => array_keys($ventas->toArray()),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user