cconsulta premios

This commit is contained in:
Felipe
2024-07-03 13:23:04 -05:00
parent 58fef053d9
commit 020bf656c3
+14 -6
View File
@@ -39,6 +39,7 @@ class ShowTop extends Component
->limit(10) ->limit(10)
->get(); ->get();
$consultaPremioEntregado = PremioEntregado::where('fecha', $monthYear) $consultaPremioEntregado = PremioEntregado::where('fecha', $monthYear)
->first(); ->first();
@@ -51,18 +52,25 @@ class ShowTop extends Component
public function entregarPremio() public function entregarPremio()
{ {
$currentYear = date('Y');
$monthYear = date('m-Y', strtotime('last month')); $monthYear = date('m-Y', strtotime('last month'));
$month = date('m', strtotime('last month')); $month = date('m', strtotime('last month'));
$rangos = ['primero', 'segundo', 'tercero', 'cuarto', 'quinto', 'sexto', 'séptimo', 'octavo', 'noveno', 'décimo']; $rangos = ['primero', 'segundo', 'tercero', 'cuarto', 'quinto', 'sexto', 'séptimo', 'octavo', 'noveno', 'décimo'];
$top_vendedores = User::with(['historiales_venta' => function ($query) use ($month) { $top_vendedores = User::with(['historiales_venta' => function ($query) use ($month, $currentYear) {
$query->whereMonth('fecha_inicio', $month); $query->whereMonth('fecha_inicio', $month)
->whereYear('fecha_inicio', $currentYear)
->where('estado', 'activo');
}]) }])
->withCount(['historiales_venta' => function ($query) use ($month) { ->withCount(['historiales_venta' => function ($query) use ($month, $currentYear) {
$query->whereMonth('fecha_inicio', $month); $query->whereMonth('fecha_inicio', $month)
}])->orderBy('historiales_venta_count', 'desc')->take(10)->get(); ->whereYear('fecha_inicio', $currentYear);
}])
->orderBy('historiales_venta_count', 'desc')
->limit(10)
->get();
foreach ($top_vendedores as $index => $vendedor) { foreach ($top_vendedores as $index => $vendedor) {
$premio = $this->configuracion->{'premio_' . ($index + 1)}; $premio = $this->configuracion->{'premio_' . ($index + 1)};