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