log general para entrega y reclamo de premios

This commit is contained in:
Felipe
2024-07-03 11:10:37 -05:00
parent c6193e4148
commit 58fef053d9
3 changed files with 56 additions and 39 deletions
+6
View File
@@ -2,6 +2,7 @@
namespace App\Http\Livewire; namespace App\Http\Livewire;
use App\Models\Log_general;
use App\Models\Notificacion; use App\Models\Notificacion;
use App\Models\PremioEntregado; use App\Models\PremioEntregado;
use App\Models\Saldo; use App\Models\Saldo;
@@ -74,6 +75,11 @@ class Bell extends Component
} }
} }
Log_general::create([
'user_id' => Auth::user()->id,
'detalle' => 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha reclamado el premio de $' . $notificacion->premio
]);
$this->reclamandoPremio = false; $this->reclamandoPremio = false;
$this->alert('success', 'Haz reclamado el premio correctamente', [ $this->alert('success', 'Haz reclamado el premio correctamente', [
+31 -27
View File
@@ -3,6 +3,7 @@
namespace App\Http\Livewire; namespace App\Http\Livewire;
use App\Models\Configuracione; use App\Models\Configuracione;
use App\Models\Log_general;
use App\Models\Notificacion; use App\Models\Notificacion;
use App\Models\PremioEntregado; use App\Models\PremioEntregado;
use App\Models\User; use App\Models\User;
@@ -18,35 +19,34 @@ class ShowTop extends Component
use LivewireAlert; use LivewireAlert;
public function render() public function render()
{ {
$this->configuracion = Configuracione::orderby('id', 'desc')->first(); $this->configuracion = Configuracione::orderby('id', 'desc')->first();
$currentYear = date('Y'); $currentYear = date('Y');
$monthYear = date('m-Y', strtotime('last month')); $monthYear = date('m-Y', strtotime('last month'));
$month = $this->showLastMonth ? date('m', strtotime('last month')) : date('m'); $month = $this->showLastMonth ? date('m', strtotime('last month')) : date('m');
$consulta_ventas = User::with(['historiales_venta' => function ($query) use ($month, $currentYear) { $consulta_ventas = User::with(['historiales_venta' => function ($query) use ($month, $currentYear) {
$query->whereMonth('fecha_inicio', $month) $query->whereMonth('fecha_inicio', $month)
->whereYear('fecha_inicio', $currentYear) ->whereYear('fecha_inicio', $currentYear)
->where('estado', 'activo'); ->where('estado', 'activo');
}]) }])
->withCount(['historiales_venta' => function ($query) use ($month, $currentYear) { ->withCount(['historiales_venta' => function ($query) use ($month, $currentYear) {
$query->whereMonth('fecha_inicio', $month) $query->whereMonth('fecha_inicio', $month)
->whereYear('fecha_inicio', $currentYear); ->whereYear('fecha_inicio', $currentYear);
}]) }])
->orderBy('historiales_venta_count', 'desc') ->orderBy('historiales_venta_count', 'desc')
->limit(10) ->limit(10)
->get(); ->get();
$consultaPremioEntregado = PremioEntregado::whereYear('fecha', $currentYear) $consultaPremioEntregado = PremioEntregado::where('fecha', $monthYear)
->where('fecha', $monthYear) ->first();
->first();
return view('livewire.show-top', [ return view('livewire.show-top', [
'usuarios' => $consulta_ventas, 'usuarios' => $consulta_ventas,
'consultaPremioEntregado' => $consultaPremioEntregado 'consultaPremioEntregado' => $consultaPremioEntregado
]); ]);
} }
public function entregarPremio() public function entregarPremio()
@@ -75,8 +75,13 @@ class ShowTop extends Component
$notificacion->descripcion = 'Quedaste ' . $rangos[$index] . ' en el #Top10MejoresDistribuidores del mes de ' . date('M', strtotime('last month')); $notificacion->descripcion = 'Quedaste ' . $rangos[$index] . ' en el #Top10MejoresDistribuidores del mes de ' . date('M', strtotime('last month'));
$notificacion->estado = 1; $notificacion->estado = 1;
$notificacion->todos = 0; $notificacion->todos = 0;
$notificacion->premio = str_replace('.','',str_replace('$', '', $premio)); $notificacion->premio = str_replace('.', '', str_replace('$', '', $premio));
$notificacion->save(); $notificacion->save();
Log_general::create([
'user_id' => Auth::user()->id,
'detalle' => 'El usuario ' . Auth::user()->name . ' ha entregado el premio ' . $premio . ' para el usuario: ' . $vendedor->name . ' - ' . $vendedor->email
]);
} }
PremioEntregado::create([ PremioEntregado::create([
@@ -88,6 +93,5 @@ class ShowTop extends Component
$this->alert('success', 'Premios entregados correctamente', [ $this->alert('success', 'Premios entregados correctamente', [
'position' => 'top' 'position' => 'top'
]); ]);
} }
} }
+19 -12
View File
@@ -3,17 +3,19 @@
<div class="flex justify-start my-2 items-center mb-4"> <div class="flex justify-start my-2 items-center mb-4">
<div class="flex text-sm"> <div class="flex text-sm">
<x-icon-arrow-right/> <x-icon-arrow-right />
Distribuidores Distribuidores
</div> </div>
</div> </div>
{{-- tabla --}} {{-- tabla --}}
<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 "> <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 ">
<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="" class="object-cover h-24 sm:h-48 w-full rounded-lg shadow my-3"> <img src="{{ asset($configuracion->img_top) }}" alt=""
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>
@@ -33,18 +35,23 @@
</label> </label>
@if (Auth::user()->rol->nombre == 'super') @if (Auth::user()->rol->nombre == 'super')
<div class="flex flex-col items-center justify-center"> <div class="flex flex-col items-center justify-center">
<x-primary-button wire:click="entregarPremio" class="ml-4 disabled:cursor-not-allowed" :disabled="$consultaPremioEntregado">Entregar premios de {{ Carbon\Carbon::now()->subMonth()->format('M') }}</x-primary-button> <x-primary-button wire:click="entregarPremio" class="ml-4 disabled:cursor-not-allowed"
@if ($consultaPremioEntregado) :disabled="$consultaPremioEntregado">Entregar premios de
<span class="text-xs pt-1 text-gray-400 cursor-not-allowed"> {{ Carbon\Carbon::now()->subMonth()->format('M') }}</x-primary-button>
Los premios del mes de {{ Carbon\Carbon::now()->subMonth()->format('M') }} ya fueron entregados @if ($consultaPremioEntregado)
</span> <span class="text-xs pt-1 text-gray-400 cursor-not-allowed">
@endif Los premios del mes de {{ Carbon\Carbon::now()->subMonth()->format('M') }} ya fueron
</div> entregados
</span>
@endif
</div>
@endif @endif
</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" wire:loading.class="opacity-50 cursor-wait"> <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">
<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>