diff --git a/app/Http/Livewire/Bell.php b/app/Http/Livewire/Bell.php
index f44ecb1..02f28f7 100755
--- a/app/Http/Livewire/Bell.php
+++ b/app/Http/Livewire/Bell.php
@@ -3,6 +3,7 @@
namespace App\Http\Livewire;
use App\Models\Notificacion;
+use App\Models\PremioEntregado;
use App\Models\Saldo;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
@@ -28,7 +29,7 @@ class Bell extends Component
$this->numNoti = count($consulta);
return view('livewire.bell', [
- 'consulta' => $consulta
+ 'consulta' => $consulta,
]);
}
@@ -51,6 +52,17 @@ class Bell extends Component
$notificacion = Notificacion::find($id);
+ if (!$notificacion || $notificacion->estado == 0) {
+
+ $this->reclamandoPremio = false;
+
+ $this->alert('error', 'No se pudo reclamar el premio', [
+ 'position' => 'top'
+ ]);
+
+ return;
+ }
+
$consulta_saldo = Saldo::where('usuario_id', Auth::user()->id)->first();
if ($consulta_saldo) {
diff --git a/app/Http/Livewire/ShowTop.php b/app/Http/Livewire/ShowTop.php
index e4d106c..74a11a8 100755
--- a/app/Http/Livewire/ShowTop.php
+++ b/app/Http/Livewire/ShowTop.php
@@ -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'
+ ]);
+
}
}
diff --git a/app/Models/PremioEntregado.php b/app/Models/PremioEntregado.php
new file mode 100644
index 0000000..177faed
--- /dev/null
+++ b/app/Models/PremioEntregado.php
@@ -0,0 +1,24 @@
+belongsTo(User::class);
+ }
+}
diff --git a/database/migrations/2024_03_07_085523_create_premios_entregados_table.php b/database/migrations/2024_03_07_085523_create_premios_entregados_table.php
new file mode 100644
index 0000000..19b480f
--- /dev/null
+++ b/database/migrations/2024_03_07_085523_create_premios_entregados_table.php
@@ -0,0 +1,35 @@
+id();
+
+ $table->unsignedBigInteger('user_id')->nullable();
+
+
+ $table->string('fecha')->nullable();
+ $table->boolean('entregado')->default(true);
+
+ $table->foreign('user_id')
+ ->references('id')
+ ->on('users')
+ ->onDelete('cascade')
+ ->onUpdate('cascade');
+
+ $table->timestamps();
+ });
+ }
+
+ public function down()
+ {
+ Schema::dropIfExists('premios_entregados');
+ }
+};
diff --git a/resources/views/livewire/show-top.blade.php b/resources/views/livewire/show-top.blade.php
index 60568ae..8b8e1f6 100755
--- a/resources/views/livewire/show-top.blade.php
+++ b/resources/views/livewire/show-top.blade.php
@@ -33,7 +33,14 @@
@if (Auth::user()->rol->nombre == 'super' || Auth::user()->rol->nombre == 'administrador')
-