premios fixed
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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'
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PremioEntregado extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'premios_entregados';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'fecha',
|
||||
'entregado',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
Schema::create('premios_entregados', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
@@ -33,7 +33,14 @@
|
||||
</label>
|
||||
|
||||
@if (Auth::user()->rol->nombre == 'super' || Auth::user()->rol->nombre == 'administrador')
|
||||
<x-primary-button wire:click="entregarPremio" class="ml-4">Entregar premio de {{ Carbon\Carbon::now()->subMonth()->format('M') }}</x-primary-button>
|
||||
<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>
|
||||
@if ($consultaPremioEntregado)
|
||||
<span class="text-xs pt-1 text-gray-400 cursor-not-allowed">
|
||||
Los premios del mes de {{ Carbon\Carbon::now()->subMonth()->format('M') }} ya fueron entregados
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user