entrega de premios desde boton
This commit is contained in:
@@ -3,7 +3,9 @@
|
|||||||
namespace App\Http\Livewire;
|
namespace App\Http\Livewire;
|
||||||
|
|
||||||
use App\Models\Configuracione;
|
use App\Models\Configuracione;
|
||||||
|
use App\Models\Notificacion;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||||
|
|
||||||
@@ -16,6 +18,7 @@ class ShowTop extends Component
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->configuracion = Configuracione::orderby('id', 'desc')->first();
|
$this->configuracion = Configuracione::orderby('id', 'desc')->first();
|
||||||
|
|
||||||
$month = $this->showLastMonth ? date('m', strtotime('last month')) : date('m');
|
$month = $this->showLastMonth ? date('m', strtotime('last month')) : date('m');
|
||||||
@@ -35,4 +38,32 @@ class ShowTop extends Component
|
|||||||
'usuarios' => $consulta_ventas,
|
'usuarios' => $consulta_ventas,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function entregarPremio()
|
||||||
|
{
|
||||||
|
$month = date('m', strtotime('last month'));
|
||||||
|
$rangos = ['primero', 'segundo', 'tercero', 'cuarto', 'quinto', 'sexto', 'séptimo', 'octavo', 'noveno', 'décimo'];
|
||||||
|
|
||||||
|
$top_vendedores = User::with(['historiales_venta' => function ($query) use ($month) {
|
||||||
|
$query->whereMonth('fecha_inicio', $month);
|
||||||
|
}])
|
||||||
|
->withCount(['historiales_venta' => function ($query) use ($month) {
|
||||||
|
$query->whereMonth('fecha_inicio', $month);
|
||||||
|
}])->orderBy('historiales_venta_count', 'desc')->take(10)->get();
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($top_vendedores as $index => $vendedor) {
|
||||||
|
$premio = $this->configuracion->{'premio_' . ($index + 1)};
|
||||||
|
|
||||||
|
$notificacion = new Notificacion();
|
||||||
|
$notificacion->remitente_id = Auth::user()->id;
|
||||||
|
$notificacion->destinatario_id = $vendedor->id;
|
||||||
|
$notificacion->titulo = 'Felicidades ' . $vendedor->name ?? '' . ' 🎊';
|
||||||
|
$notificacion->descripcion = 'Quedaste ' . $rangos[$index] . ' en el #Top10MejoresDistribuidores del mes de ' . date('M', strtotime('last month'));
|
||||||
|
$notificacion->estado = 1;
|
||||||
|
$notificacion->todos = 0;
|
||||||
|
$notificacion->premio = str_replace('.','',str_replace('$', '', $premio));
|
||||||
|
$notificacion->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,17 +9,15 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{-- tabla --}}
|
{{-- tabla --}}
|
||||||
<div
|
<div class="mx-auto bg-white grid grid-cols-1 lg:grid-cols-1text-center rounded-xl py-4 px-2 ms:px-8 shadow-md xl:mx-10 mb-8 ">
|
||||||
class="mx-auto bg-white grid grid-cols-1 lg:grid-cols-1text-center rounded-xl py-4 px-2 ms:px-8 shadow-md xl:mx-10 mb-8 ">
|
|
||||||
<p class="text-center font-semibold text-base sm:text-2xl">Mejores distribuidores del mes</p>
|
<p class="text-center font-semibold text-base sm:text-2xl">Mejores distribuidores del mes</p>
|
||||||
|
|
||||||
<div class="text-center w-full">
|
<div class="text-center w-full">
|
||||||
<img src="{{ asset($configuracion->img_top) }}" alt=""
|
<img src="{{ asset($configuracion->img_top) }}" alt="" class="object-cover h-24 sm:h-48 w-full rounded-lg shadow my-3">
|
||||||
class="object-cover h-24 sm:h-48 w-full rounded-lg shadow my-3">
|
|
||||||
<p class=" text-sm sm:text-base my-2 ">{{ $configuracion->mensaje_top }}</p>
|
<p class=" text-sm sm:text-base my-2 ">{{ $configuracion->mensaje_top }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center">
|
<div class="flex items-center justify-between mx-8 my-4">
|
||||||
<label class="inline-flex items-center cursor-pointer">
|
<label class="inline-flex items-center cursor-pointer">
|
||||||
<input type="checkbox" wire:model="showLastMonth" class="hidden" />
|
<input type="checkbox" wire:model="showLastMonth" class="hidden" />
|
||||||
@if ($showLastMonth)
|
@if ($showLastMonth)
|
||||||
@@ -33,10 +31,11 @@
|
|||||||
@endif
|
@endif
|
||||||
<div class="ml-2 font-medium text-gray-700">Mostrar resultados del mes pasado</div>
|
<div class="ml-2 font-medium text-gray-700">Mostrar resultados del mes pasado</div>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<x-primary-button wire:click="entregarPremio" class="ml-4">Entregar premio de {{ Carbon\Carbon::now()->subMonth()->format('M') }}</x-primary-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<table class="sm:text-base text-sm text-center rounded-lg shadow-lg m-auto sm:mt-4 mb-4 border-separate border-spacing-y-2"
|
<table class="sm:text-base text-sm text-center rounded-lg shadow-lg m-auto sm:mt-4 mb-4 border-separate border-spacing-y-2" wire:loading.class="opacity-50 cursor-wait">
|
||||||
wire:loading.class="opacity-50 cursor-wait">
|
|
||||||
<thead class="font-normal bg-[#000029] text-white h-9">
|
<thead class="font-normal bg-[#000029] text-white h-9">
|
||||||
<tr class="text-left">
|
<tr class="text-left">
|
||||||
<th class="rounded-l-lg font-normal pl-[1rem] sm:pl-[2rem]"></th>
|
<th class="rounded-l-lg font-normal pl-[1rem] sm:pl-[2rem]"></th>
|
||||||
|
|||||||
Reference in New Issue
Block a user