update
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Cuentas;
|
|||||||
use App\Models\Historiale;
|
use App\Models\Historiale;
|
||||||
use App\Models\Historial_cuenta;
|
use App\Models\Historial_cuenta;
|
||||||
use App\Models\Log_general;
|
use App\Models\Log_general;
|
||||||
|
use App\Models\Pendientes;
|
||||||
use App\Models\Role;
|
use App\Models\Role;
|
||||||
use App\Models\Servicio;
|
use App\Models\Servicio;
|
||||||
use App\Models\Tarifas;
|
use App\Models\Tarifas;
|
||||||
@@ -81,14 +82,14 @@ class ShowPlanes extends Component
|
|||||||
public $photo;
|
public $photo;
|
||||||
public $photo_inicio;
|
public $photo_inicio;
|
||||||
|
|
||||||
public $estado='activo';
|
public $estado = 'activo';
|
||||||
public $completa;
|
public $completa;
|
||||||
public $pantallas;
|
public $pantallas;
|
||||||
public $venceHoy;
|
public $venceHoy;
|
||||||
public $activoHoy;
|
public $activoHoy;
|
||||||
public $libres = null;
|
public $libres = null;
|
||||||
|
|
||||||
public $delete_1=['1'];
|
public $delete_1 = ['1'];
|
||||||
public $tarifas;
|
public $tarifas;
|
||||||
public $addUser;
|
public $addUser;
|
||||||
public $usuarios;
|
public $usuarios;
|
||||||
@@ -110,44 +111,43 @@ class ShowPlanes extends Component
|
|||||||
|
|
||||||
$consulta_tarifas = Tarifas::take(1);
|
$consulta_tarifas = Tarifas::take(1);
|
||||||
|
|
||||||
if(empty($this->fecha_inicial)){
|
if (empty($this->fecha_inicial)) {
|
||||||
$this->fecha_inicial=Carbon::now()->format('Y-m-d');
|
$this->fecha_inicial = Carbon::now()->format('Y-m-d');
|
||||||
$this->fecha_final=Carbon::now()->addDay(30)->format('Y-m-d');
|
$this->fecha_final = Carbon::now()->addDay(30)->format('Y-m-d');
|
||||||
}
|
}
|
||||||
if ($this->servicio_modTarifas) {
|
if ($this->servicio_modTarifas) {
|
||||||
$this->tarifas = Tarifas::with('rol')
|
$this->tarifas = Tarifas::with('rol')
|
||||||
->where('servicio_id', $this->servicio_modTarifas)
|
->where('servicio_id', $this->servicio_modTarifas)
|
||||||
->where('estado', 'activo')
|
->where('estado', 'activo')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empezamos definiendo la consulta básica
|
// Empezamos definiendo la consulta básica
|
||||||
$consulta_cuentas = Cuentas::where('correo', 'LIKE', '%'.$this->buscar.'%')
|
$consulta_cuentas = Cuentas::where('correo', 'LIKE', '%' . $this->buscar . '%')
|
||||||
->withCount('historiales')
|
->withCount('historiales')
|
||||||
->with('historiales')
|
->with('historiales')
|
||||||
->orderBy('id','DESC');
|
->orderBy('id', 'DESC');
|
||||||
|
|
||||||
$consulta_cuentas = $consulta_cuentas->when(!empty($this->servicios_id), function ($query) {
|
$consulta_cuentas = $consulta_cuentas->when(!empty($this->servicios_id), function ($query) {
|
||||||
return $query->where('servicio_id', $this->servicios_id);
|
return $query->where('servicio_id', $this->servicios_id);
|
||||||
})
|
})
|
||||||
->when(!empty($this->completa), function ($query) {
|
->when(!empty($this->completa), function ($query) {
|
||||||
return $query->where('estado', 'pendiente');
|
return $query->where('estado', 'pendiente');
|
||||||
})
|
})
|
||||||
->when(!empty($this->pantallas), function ($query) {
|
->when(!empty($this->pantallas), function ($query) {
|
||||||
return $query->where('estado', 'activo');
|
return $query->where('estado', 'activo');
|
||||||
})
|
})
|
||||||
->when(!empty($this->activoHoy), function ($query) {
|
->when(!empty($this->activoHoy), function ($query) {
|
||||||
$fechaHoy = Carbon::now()->subDay(1);
|
$fechaHoy = Carbon::now()->subDay(1);
|
||||||
return $query->whereDate('vencimiento', '>', $fechaHoy);
|
return $query->whereDate('vencimiento', '>', $fechaHoy);
|
||||||
})
|
})
|
||||||
->when($this->venceHoy, function ($query) {
|
->when($this->venceHoy, function ($query) {
|
||||||
$fechaHoy = Carbon::now()->addDay(1);
|
$fechaHoy = Carbon::now()->addDay(1);
|
||||||
return $query->whereDate('vencimiento', '<', $fechaHoy);
|
return $query->whereDate('vencimiento', '<', $fechaHoy);
|
||||||
})
|
})
|
||||||
->when($this->libres, function ($query) {
|
->when($this->libres, function ($query) {
|
||||||
return $query->whereDoesntHave('historiales');
|
return $query->whereDoesntHave('historiales');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!empty($this->repetidas)) {
|
if (!empty($this->repetidas)) {
|
||||||
$consulta_cuentas = $consulta_cuentas->whereIn('correo', function ($subquery) {
|
$consulta_cuentas = $consulta_cuentas->whereIn('correo', function ($subquery) {
|
||||||
@@ -161,19 +161,19 @@ class ShowPlanes extends Component
|
|||||||
|
|
||||||
$consulta_cuentas = $consulta_cuentas->paginate($this->entradas);
|
$consulta_cuentas = $consulta_cuentas->paginate($this->entradas);
|
||||||
|
|
||||||
if ( $this->searchTerm) {
|
if ($this->searchTerm) {
|
||||||
$this->usuarios = User::where('email', 'LIKE', '%' . $this->searchTerm . '%')->get();
|
$this->usuarios = User::where('email', 'LIKE', '%' . $this->searchTerm . '%')->get();
|
||||||
if ($this->selectedOption) {
|
if ($this->selectedOption) {
|
||||||
$this->searchTerm = $this->selectedOption;
|
$this->searchTerm = $this->selectedOption;
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$this->selectedOption = null;
|
$this->selectedOption = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return view('livewire.show-planes', [
|
return view('livewire.show-planes', [
|
||||||
'cuentas' => $consulta_cuentas,
|
'cuentas' => $consulta_cuentas,
|
||||||
'servicios' => Servicio::where('estado','activo')->get(),
|
'servicios' => Servicio::where('estado', 'activo')->get(),
|
||||||
'roles' => Role::get()
|
'roles' => Role::get()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ class ShowPlanes extends Component
|
|||||||
public function ver($id, $nom)
|
public function ver($id, $nom)
|
||||||
{
|
{
|
||||||
$this->id_cuentaVer = $id;
|
$this->id_cuentaVer = $id;
|
||||||
$this->consulta_verUsuarios = Cuentas::with('historiales','servicio')->where('id', $id)->first();
|
$this->consulta_verUsuarios = Cuentas::with('historiales', 'servicio')->where('id', $id)->first();
|
||||||
//dd($this->consulta_verUsuarios);
|
//dd($this->consulta_verUsuarios);
|
||||||
$this->nombre_servicios = $nom;
|
$this->nombre_servicios = $nom;
|
||||||
}
|
}
|
||||||
@@ -222,21 +222,22 @@ class ShowPlanes extends Component
|
|||||||
/* ------------- CREAR ------------- */
|
/* ------------- CREAR ------------- */
|
||||||
public function createNewCuenta()
|
public function createNewCuenta()
|
||||||
{
|
{
|
||||||
$this->validate([
|
// $this->validate([
|
||||||
'servicio_newCuenta' => 'required',
|
// 'servicio_newCuenta' => 'required',
|
||||||
'usuario_newCuenta' => 'required',
|
// 'usuario_newCuenta' => 'required',
|
||||||
'password_newCuenta' => 'required',
|
// 'password_newCuenta' => 'required',
|
||||||
'fecha_inicial' => 'required',
|
// 'fecha_inicial' => 'required',
|
||||||
'fecha_final' => 'required',
|
// 'fecha_final' => 'required',
|
||||||
'estado' => 'required',
|
// 'estado' => 'required',
|
||||||
]);
|
// ]);
|
||||||
|
|
||||||
|
|
||||||
if($consulta_cuenta = Cuentas::where('correo',$this->usuario_newCuenta)->exists()){
|
|
||||||
|
if ($consulta_cuenta = Cuentas::where('correo', $this->usuario_newCuenta)->exists()) {
|
||||||
$this->alert('warning', 'La cuenta ya existe', [
|
$this->alert('warning', 'La cuenta ya existe', [
|
||||||
'position' => 'top'
|
'position' => 'top'
|
||||||
]);
|
]);
|
||||||
}else{
|
} else {
|
||||||
$cuenta = new Cuentas;
|
$cuenta = new Cuentas;
|
||||||
$cuenta->servicio_id = $this->servicio_newCuenta;
|
$cuenta->servicio_id = $this->servicio_newCuenta;
|
||||||
$cuenta->correo = $this->usuario_newCuenta;
|
$cuenta->correo = $this->usuario_newCuenta;
|
||||||
@@ -246,6 +247,21 @@ class ShowPlanes extends Component
|
|||||||
$cuenta->estado = $this->estado;
|
$cuenta->estado = $this->estado;
|
||||||
$cuenta->save();
|
$cuenta->save();
|
||||||
|
|
||||||
|
if ($this->estado === 'activo') {
|
||||||
|
$servicioPantallas = Servicio::find($this->servicio_newCuenta)->pantallas;
|
||||||
|
|
||||||
|
$cuentasPendientes = Pendientes::where('estado', 'pendiente')->where('servicio_id', $this->servicio_newCuenta)->take($servicioPantallas)->get();
|
||||||
|
|
||||||
|
foreach ($cuentasPendientes as $i => $cuentaPendiente) {
|
||||||
|
$historial_cuenta = new Historial_cuenta();
|
||||||
|
$historial_cuenta->historial_id = $cuentaPendiente->historial_id;
|
||||||
|
$historial_cuenta->cuenta_id = $cuenta->id;
|
||||||
|
$historial_cuenta->perfil = $i + 1;
|
||||||
|
$historial_cuenta->save();
|
||||||
|
$cuentaPendiente->update(['estado' => 'cerrado']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->alert('success', 'Cuenta creada correctamente!', [
|
$this->alert('success', 'Cuenta creada correctamente!', [
|
||||||
'position' => 'top'
|
'position' => 'top'
|
||||||
]);
|
]);
|
||||||
@@ -254,8 +270,6 @@ class ShowPlanes extends Component
|
|||||||
|
|
||||||
$this->newCuenta = false;
|
$this->newCuenta = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public function createServicio()
|
public function createServicio()
|
||||||
{
|
{
|
||||||
@@ -354,10 +368,10 @@ class ShowPlanes extends Component
|
|||||||
public function updateTarifas()
|
public function updateTarifas()
|
||||||
{
|
{
|
||||||
$consulta_existe = Tarifas::where('pantallas', $this->pantallas_modTarifas)
|
$consulta_existe = Tarifas::where('pantallas', $this->pantallas_modTarifas)
|
||||||
->where('servicio_id', $this->servicio_modTarifas)
|
->where('servicio_id', $this->servicio_modTarifas)
|
||||||
->where('rol_id', $this->roles_modTarifas)
|
->where('rol_id', $this->roles_modTarifas)
|
||||||
->where('dias', $this->diasTarifa)
|
->where('dias', $this->diasTarifa)
|
||||||
->exists();
|
->exists();
|
||||||
|
|
||||||
if ($consulta_existe) {
|
if ($consulta_existe) {
|
||||||
$this->alert('warning', '¡Esta tarifa ya existe!', [
|
$this->alert('warning', '¡Esta tarifa ya existe!', [
|
||||||
@@ -390,8 +404,6 @@ class ShowPlanes extends Component
|
|||||||
'position' => 'top'
|
'position' => 'top'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -399,7 +411,7 @@ class ShowPlanes extends Component
|
|||||||
|
|
||||||
public function eliminarModTarifa($id)
|
public function eliminarModTarifa($id)
|
||||||
{
|
{
|
||||||
Tarifas::where('id',$id)->delete();
|
Tarifas::where('id', $id)->delete();
|
||||||
|
|
||||||
$this->alert('success', 'Tarifas eliminada correctamente!', [
|
$this->alert('success', 'Tarifas eliminada correctamente!', [
|
||||||
'position' => 'top'
|
'position' => 'top'
|
||||||
@@ -434,19 +446,19 @@ class ShowPlanes extends Component
|
|||||||
$this->color_servicio = null;
|
$this->color_servicio = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function eliminarCuentas(){
|
public function eliminarCuentas()
|
||||||
|
{
|
||||||
$consulta_cuentas = Cuentas::whereIn('id',$this->delete_1)->delete();
|
|
||||||
|
|
||||||
|
$consulta_cuentas = Cuentas::whereIn('id', $this->delete_1)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function openAdd(){
|
public function openAdd()
|
||||||
|
{
|
||||||
|
|
||||||
$this->addUser = true;
|
$this->addUser = true;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public function saveUser(){
|
public function saveUser()
|
||||||
|
{
|
||||||
|
|
||||||
$this->validate([
|
$this->validate([
|
||||||
'tarifa' => 'required',
|
'tarifa' => 'required',
|
||||||
@@ -460,7 +472,7 @@ class ShowPlanes extends Component
|
|||||||
$usuario_id = $usuario_existe;
|
$usuario_id = $usuario_existe;
|
||||||
|
|
||||||
if (is_null($usuario_existe)) {
|
if (is_null($usuario_existe)) {
|
||||||
$rol_id=Role::where('nombre','cliente')->value('id');
|
$rol_id = Role::where('nombre', 'cliente')->value('id');
|
||||||
$usuario = new User;
|
$usuario = new User;
|
||||||
$usuario->name = 'AssignedUser';
|
$usuario->name = 'AssignedUser';
|
||||||
$usuario->email = $this->searchTerm;
|
$usuario->email = $this->searchTerm;
|
||||||
@@ -485,7 +497,7 @@ class ShowPlanes extends Component
|
|||||||
$historial->cantidad = $tarifa['pantallas'];
|
$historial->cantidad = $tarifa['pantallas'];
|
||||||
$historial->save();
|
$historial->save();
|
||||||
|
|
||||||
$consultaHC = Historial_cuenta::where('cuenta_id',$this->consulta_verUsuarios->id)->where('perfil',$this->perfil)->exists();
|
$consultaHC = Historial_cuenta::where('cuenta_id', $this->consulta_verUsuarios->id)->where('perfil', $this->perfil)->exists();
|
||||||
|
|
||||||
if (!$consultaHC) {
|
if (!$consultaHC) {
|
||||||
$historial_cuenta = new Historial_cuenta;
|
$historial_cuenta = new Historial_cuenta;
|
||||||
@@ -499,20 +511,19 @@ class ShowPlanes extends Component
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->addUser = false;
|
$this->addUser = false;
|
||||||
$this->consulta_verUsuarios = Cuentas::with('historiales','servicio')->where('id', $this->id_cuentaVer)->first();
|
$this->consulta_verUsuarios = Cuentas::with('historiales', 'servicio')->where('id', $this->id_cuentaVer)->first();
|
||||||
|
} else {
|
||||||
}else{
|
|
||||||
$historial->delete();
|
$historial->delete();
|
||||||
$this->alert('warning', 'El perfil ya se encuentra en uso!', [
|
$this->alert('warning', 'El perfil ya se encuentra en uso!', [
|
||||||
'position' => 'top'
|
'position' => 'top'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function editar($tarifa){
|
public function editar($tarifa)
|
||||||
//dd($tarifa);
|
{
|
||||||
$this->editarTarifaRol=true;
|
//dd($tarifa);
|
||||||
|
$this->editarTarifaRol = true;
|
||||||
$this->informacionTarifaRol = $tarifa;
|
$this->informacionTarifaRol = $tarifa;
|
||||||
|
|
||||||
$this->roles_modTarifas = $tarifa['rol_id'];
|
$this->roles_modTarifas = $tarifa['rol_id'];
|
||||||
@@ -524,22 +535,23 @@ class ShowPlanes extends Component
|
|||||||
$this->servicio_modTarifas = $tarifa['servicio_id'];
|
$this->servicio_modTarifas = $tarifa['servicio_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actualizarTarifaRol($id){
|
public function actualizarTarifaRol($id)
|
||||||
|
{
|
||||||
//dd($id);
|
//dd($id);
|
||||||
$validateData = $this->validate([
|
$validateData = $this->validate([
|
||||||
'roles_modTarifas'=> 'required',
|
'roles_modTarifas' => 'required',
|
||||||
'pantallas_modTarifas' => 'required',
|
'pantallas_modTarifas' => 'required',
|
||||||
'precio_modTarifas'=> 'required',
|
'precio_modTarifas' => 'required',
|
||||||
'utilidad'=> 'required',
|
'utilidad' => 'required',
|
||||||
'diasTarifa' => 'required',
|
'diasTarifa' => 'required',
|
||||||
'estadoTarifa'=> 'required'
|
'estadoTarifa' => 'required'
|
||||||
]);
|
]);
|
||||||
$consulta = Tarifas::find($id)->update([
|
$consulta = Tarifas::find($id)->update([
|
||||||
'pantallas' => $this->pantallas_modTarifas,
|
'pantallas' => $this->pantallas_modTarifas,
|
||||||
'dias' => $this->diasTarifa,
|
'dias' => $this->diasTarifa,
|
||||||
'valor'=> $this->precio_modTarifas,
|
'valor' => $this->precio_modTarifas,
|
||||||
'utilidad'=> $this->utilidad,
|
'utilidad' => $this->utilidad,
|
||||||
'estado'=> $this->estadoTarifa,
|
'estado' => $this->estadoTarifa,
|
||||||
'rol_id' => $this->roles_modTarifas,
|
'rol_id' => $this->roles_modTarifas,
|
||||||
'servicio_id' => $this->servicio_modTarifas
|
'servicio_id' => $this->servicio_modTarifas
|
||||||
|
|
||||||
@@ -549,6 +561,5 @@ class ShowPlanes extends Component
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->editarTarifaRol = false;
|
$this->editarTarifaRol = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user