Modificación registro de asistencias por codigo qr, separar a un corporativo de un colaborador de campus
This commit is contained in:
+42
-111
@@ -4,7 +4,6 @@ namespace App\Livewire;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Code;
|
||||
use App\Models\User;
|
||||
use Livewire\Component;
|
||||
use Livewire\Attributes\On;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -24,19 +23,13 @@ class CodeScanner extends Component
|
||||
->where('name', $texto)
|
||||
->first();
|
||||
|
||||
$corporativo = DB::table('area_code')
|
||||
->where('name','like', '%COR%')
|
||||
->first();
|
||||
if($codigo){
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
if($user->code == $corporativo->id){
|
||||
|
||||
if($codigo){
|
||||
|
||||
$planteles = $user->plantelUsuarios;
|
||||
|
||||
$match=0;
|
||||
$match=true;
|
||||
|
||||
foreach($planteles as $plantel){
|
||||
|
||||
@@ -46,26 +39,58 @@ class CodeScanner extends Component
|
||||
|
||||
$distancia = $this->calcularDistancia($lat,$lng,$latCentro,$lngCentro);
|
||||
|
||||
if($distancia > $radioPermitido){
|
||||
$match=1;
|
||||
}else{
|
||||
$match = 0;
|
||||
if($distancia <= $radioPermitido){
|
||||
$match = false;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($match == 1){
|
||||
|
||||
if($match){
|
||||
$this->dispatch('swal',
|
||||
icon: 'error',
|
||||
title: 'Error!',
|
||||
text: 'Fuera del area permitida',
|
||||
confirm: false,
|
||||
closeModal: true
|
||||
closeModal: true,
|
||||
reload: true,
|
||||
timer: 5000
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$corps = DB::table('area_code')
|
||||
->where('name', 'LIKE','%COR%')
|
||||
->get();
|
||||
|
||||
$cor=false;
|
||||
foreach($corps as $corp){
|
||||
|
||||
if($corp->id == $user->code){
|
||||
$cor = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($cor){
|
||||
dd("Ec un corpo el que esta checando");
|
||||
}else{
|
||||
if($user->code != $codigo->id){
|
||||
|
||||
$this->dispatch('swal',
|
||||
icon: 'error',
|
||||
title: 'Error!',
|
||||
text: 'Este código no corresponde a tu area de trabajo',
|
||||
confirm: false,
|
||||
closeModal: true,
|
||||
reload: true,
|
||||
timer: 5000
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$hoy = Carbon::today();
|
||||
|
||||
@@ -118,7 +143,8 @@ class CodeScanner extends Component
|
||||
text: 'asistencia registrada',
|
||||
confirm: false,
|
||||
closeModal: true,
|
||||
reload:true
|
||||
reload: true,
|
||||
timer: 3000
|
||||
);
|
||||
return;
|
||||
|
||||
@@ -133,101 +159,6 @@ class CodeScanner extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
if($codigo->id != $user->code){
|
||||
$this->dispatch('swal',
|
||||
icon: 'error',
|
||||
title: 'Error!',
|
||||
text: 'Este codigo no corresponde a tu area',
|
||||
confirm: false,
|
||||
closeModal: true
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$planteles = $user->plantelUsuarios;
|
||||
|
||||
$match=0;
|
||||
|
||||
foreach($planteles as $plantel){
|
||||
|
||||
$latCentro = $plantel->latitud;
|
||||
$lngCentro = $plantel->longitud;
|
||||
$radioPermitido = 100; // metros
|
||||
|
||||
$distancia = $this->calcularDistancia($lat,$lng,$latCentro,$lngCentro);
|
||||
|
||||
if($distancia > $radioPermitido){
|
||||
$match=1;
|
||||
}else{
|
||||
$match = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($match == 1){
|
||||
$this->dispatch('swal',
|
||||
icon: 'error',
|
||||
title: 'Error!',
|
||||
text: 'Fuera del area permitida',
|
||||
confirm: false,
|
||||
closeModal: true
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$hoy = Carbon::today();
|
||||
|
||||
$asistenciasHoy = Code::where('user_id',$user->id)
|
||||
->whereDate('registro',$hoy)
|
||||
->orderBy('registro','desc')
|
||||
->get();
|
||||
|
||||
if($asistenciasHoy->count() >= 4){
|
||||
$this->dispatch('swal',
|
||||
icon: 'warning',
|
||||
title: 'Chequeos completos!',
|
||||
text: 'Límite de registros alcanzados',
|
||||
confirm: false,
|
||||
closeModal: true,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if($asistenciasHoy->count() > 0){
|
||||
$ultima = $asistenciasHoy->first();
|
||||
|
||||
if($ultima->registro->diffInMinutes(now()) < 40){
|
||||
$this->dispatch('swal',
|
||||
icon:'info',
|
||||
title:'Aún no pasan 40 minutos'
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Code::create([
|
||||
'user_id' => $user->id,
|
||||
'codigo' => $texto,
|
||||
'registro' => Carbon::now('America/Mexico_City')->format('d-m-Y H:i:s'),
|
||||
'latitud' => $lat,
|
||||
'longitud' => $lng,
|
||||
]);
|
||||
|
||||
$this->dispatch('swal',
|
||||
icon: 'success',
|
||||
title: 'Excelente!',
|
||||
text: 'asistencia registrada',
|
||||
confirm: false,
|
||||
closeModal: true,
|
||||
reload:true
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function calcularDistancia($lat1,$lon1,$lat2,$lon2)
|
||||
|
||||
Reference in New Issue
Block a user