premios fixed
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Configuracione;
|
||||
use App\Models\Notificacion;
|
||||
use App\Models\PremioEntregado;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
@@ -18,9 +19,9 @@ class ShowTop extends Component
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
$this->configuracion = Configuracione::orderby('id', 'desc')->first();
|
||||
|
||||
$monthYear = date('m-Y', strtotime('last month'));
|
||||
$month = $this->showLastMonth ? date('m', strtotime('last month')) : date('m');
|
||||
|
||||
$consulta_ventas = User::with(['historiales_venta' => function ($query) use ($month) {
|
||||
@@ -33,17 +34,21 @@ class ShowTop extends Component
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
//dd($consulta_ventas);
|
||||
$consultaPremioEntregado = PremioEntregado::where('fecha', $monthYear)->first();
|
||||
|
||||
return view('livewire.show-top', [
|
||||
'usuarios' => $consulta_ventas,
|
||||
'consultaPremioEntregado' => $consultaPremioEntregado
|
||||
]);
|
||||
}
|
||||
|
||||
public function entregarPremio()
|
||||
{
|
||||
$monthYear = date('m-Y', strtotime('last month'));
|
||||
$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);
|
||||
}])
|
||||
@@ -57,6 +62,7 @@ class ShowTop extends Component
|
||||
|
||||
$notificacion = new Notificacion();
|
||||
$notificacion->remitente_id = Auth::user()->id;
|
||||
// $notificacion->destinatario_id = 410;
|
||||
$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'));
|
||||
@@ -65,5 +71,16 @@ class ShowTop extends Component
|
||||
$notificacion->premio = str_replace('.','',str_replace('$', '', $premio));
|
||||
$notificacion->save();
|
||||
}
|
||||
|
||||
PremioEntregado::create([
|
||||
'user_id' => Auth::user()->id,
|
||||
'fecha' => $monthYear,
|
||||
'entregado' => 1
|
||||
]);
|
||||
|
||||
$this->alert('success', 'Premios entregados correctamente', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user