Update ShowServicios.php

This commit is contained in:
Lizandro Guarnizo
2024-10-11 15:40:15 -05:00
parent 6b85c9a88a
commit 7454087a9c
+42 -36
View File
@@ -90,7 +90,7 @@ class ShowServicios extends Component
//dd($this->tarifa_id); //dd($this->tarifa_id);
$this->cargartarjetaPlan($this->tarifa_id); $this->cargartarjetaPlan($this->tarifa_id);
} }
$this->msj = Configuracione::orderby('id', 'desc')->select('msj_compra', 'msj_wp', 'clave_1', 'clave_2', 'clave_3', 'clave_4', 'clave_5', 'clave_6', 'iptv')->first(); $this->msj = Configuracione::orderby('id', 'desc')->select('msj_compra', 'msj_wp', 'clave_1', 'clave_2', 'clave_3', 'clave_4', 'clave_5', 'clave_6', 'iptv')->first();
@@ -123,7 +123,7 @@ class ShowServicios extends Component
//Traer el servicio relacionado con esa tarifa //Traer el servicio relacionado con esa tarifa
$servicio_tarifa = $tarifa_seleccionada->servicio; $servicio_tarifa = $tarifa_seleccionada->servicio;
//INFORMACIÓN DEL SERVICIO //INFORMACIÓN DEL SERVICIO
$this->servicio_id = $servicio_tarifa->id; //Id $this->servicio_id = $servicio_tarifa->id; //Id
$this->servicio_tarjetaPlan = $servicio_tarifa->nombre; //Nombre $this->servicio_tarjetaPlan = $servicio_tarifa->nombre; //Nombre
@@ -146,7 +146,7 @@ class ShowServicios extends Component
->where('tarifa_id', $id) ->where('tarifa_id', $id)
->first(); ->first();
//Si tiene tarifa personalizada toma el precio, si no tiene da el valor de la tarifa. //Si tiene tarifa personalizada toma el precio, si no tiene da el valor de la tarifa.
$this->valor_tarjetaPlan = ($usuario_tarifa) ? $usuario_tarifa->precio : $tarifa_seleccionada->valor; $this->valor_tarjetaPlan = ($usuario_tarifa) ? $usuario_tarifa->precio : $tarifa_seleccionada->valor;
//Si tiene tarifa personalizada toma la utilidad, si no tiene toma la utilidad de la tarifa. //Si tiene tarifa personalizada toma la utilidad, si no tiene toma la utilidad de la tarifa.
@@ -163,7 +163,12 @@ class ShowServicios extends Component
->whereDate('vencimiento', '<=', $this->fecha_final_2) ->whereDate('vencimiento', '<=', $this->fecha_final_2)
->where('servicio_id', $servicio_tarifa->id) ->where('servicio_id', $servicio_tarifa->id)
->where('estado', 'pendiente') ->where('estado', 'pendiente')
->doesntHave('perfil') ->where(function ($query) {
$query->doesntHave('perfil')
->orWhereHas('perfil', function ($query) {
$query->whereNull('historial_id');
});
})
->count(); ->count();
} else { } else {
@@ -186,12 +191,12 @@ class ShowServicios extends Component
->where('estado', 'activo') ->where('estado', 'activo')
->having('historiales_count', '<=', $cantidad_restante) ->having('historiales_count', '<=', $cantidad_restante)
->get(); ->get();
//dd($cuentas_pantallas); // con count da un numero entero //dd($cuentas_pantallas); // con count da un numero entero
$cuentas_pantallas_tomadas = Historial_cuenta::whereIn('cuenta_id', $cuentas_pantallas $cuentas_pantallas_tomadas = Historial_cuenta::whereIn('cuenta_id', $cuentas_pantallas
->pluck('id'))->whereNotNull('historial_id') ->pluck('id'))->whereNotNull('historial_id')
->count(); ->count();
//dd($cuentas_pantallas_tomadas); //dd($cuentas_pantallas_tomadas);
//Validar si el numero pantallas del servicio es igual o mayor que lo solicitado //Validar si el numero pantallas del servicio es igual o mayor que lo solicitado
if ($servicio_tarifa->pantallas >= $cantidad_solicitada) { if ($servicio_tarifa->pantallas >= $cantidad_solicitada) {
//dd($servicio_tarifa->pantallas * $cuentas_pantallas->count()); //dd($servicio_tarifa->pantallas * $cuentas_pantallas->count());
@@ -203,15 +208,16 @@ class ShowServicios extends Component
} }
} }
//dd($this->tarjetaPlan); //dd($this->tarjetaPlan);
$this->tarjetaPlan = true; $this->tarjetaPlan = true;
} }
public function cerrartarjetaPlan(){ public function cerrartarjetaPlan()
{
$this->cantidad_tarjetaPlan = 1; $this->cantidad_tarjetaPlan = 1;
$this->tarjetaPlan = false; $this->tarjetaPlan = false;
$this->tarifa_id = ''; $this->tarifa_id = '';
} }
@@ -313,25 +319,25 @@ class ShowServicios extends Component
// ->havingRaw("COUNT(*) >= $suma"); // ->havingRaw("COUNT(*) >= $suma");
//}) //})
->get(); ->get();
if ($cuenta->isEmpty()) { if ($cuenta->isEmpty()) {
$suma3 = $pantalla_servicio - $pantallas; $suma3 = $pantalla_servicio - $pantallas;
$cantidad_necesaria = $this->cantidad_tarjetaPlan; $cantidad_necesaria = $this->cantidad_tarjetaPlan;
$cuenta = Cuentas::where('servicio_id', $this->servicio_id) $cuenta = Cuentas::where('servicio_id', $this->servicio_id)
->whereDate('inicio', '>=', $this->fecha) ->whereDate('inicio', '>=', $this->fecha)
->whereDate('vencimiento', '>=', $this->fecha_final_1) ->whereDate('vencimiento', '>=', $this->fecha_final_1)
->whereDate('vencimiento', '<=', $this->fecha_final_2) ->whereDate('vencimiento', '<=', $this->fecha_final_2)
->Orderby('inicio', 'ASC') ->Orderby('inicio', 'ASC')
->withCount('historiales') ->withCount('historiales')
->where('estado', 'activo') ->where('estado', 'activo')
->having('historiales_count', '<=', $suma3) ->having('historiales_count', '<=', $suma3)
//->with('perfil') //->with('perfil')
//->whereDoesntHave('perfil', function ($query) use ($suma2) { //->whereDoesntHave('perfil', function ($query) use ($suma2) {
//$query->select('cuenta_id') //$query->select('cuenta_id')
// ->groupBy('cuenta_id') // ->groupBy('cuenta_id')
// ->havingRaw("COUNT(*) >= $suma2"); // ->havingRaw("COUNT(*) >= $suma2");
//}) //})
->get(); ->get();
} }
// dd($cuenta); // dd($cuenta);
} elseif ((int) $pantalla_servicio_completa == (int) $this->pantallas_tarjetaPlan) { } elseif ((int) $pantalla_servicio_completa == (int) $this->pantallas_tarjetaPlan) {
//Cuentas completas //Cuentas completas
@@ -358,9 +364,9 @@ class ShowServicios extends Component
->having('historiales_count', '<=', $suma2) ->having('historiales_count', '<=', $suma2)
//->with('perfil') //->with('perfil')
//->whereDoesntHave('perfil', function ($query) use ($suma2) { //->whereDoesntHave('perfil', function ($query) use ($suma2) {
//$query->select('cuenta_id') //$query->select('cuenta_id')
// ->groupBy('cuenta_id') // ->groupBy('cuenta_id')
// ->havingRaw("COUNT(*) >= $suma2"); // ->havingRaw("COUNT(*) >= $suma2");
//}) //})
->get(); ->get();
} else { } else {
@@ -393,7 +399,7 @@ class ShowServicios extends Component
$eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete(); $eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete();
$logsGeneral = new Log_general(); $logsGeneral = new Log_general();
$logsGeneral->user_id = Auth::user()->id; $logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor.' Se desligaron todas las cuentas.'; $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ' Se desligaron todas las cuentas.';
$logsGeneral->save(); $logsGeneral->save();
$this->alert('warning', 'No hay cuentas disponibles!', [ $this->alert('warning', 'No hay cuentas disponibles!', [
'position' => 'top' 'position' => 'top'
@@ -413,9 +419,9 @@ class ShowServicios extends Component
$logsGeneral = new Log_general(); $logsGeneral = new Log_general();
$logsGeneral->user_id = Auth::user()->id; $logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor .', Saldo anterior: $'.$saldo_anterior.', Nuevo saldo disponible: $'.$nuevo_saldo; $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ', Saldo anterior: $' . $saldo_anterior . ', Nuevo saldo disponible: $' . $nuevo_saldo;
$logsGeneral->save(); $logsGeneral->save();
$this->credenciales($historial); $this->credenciales($historial);
@@ -436,7 +442,7 @@ class ShowServicios extends Component
$eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete(); $eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete();
$logsGeneral = new Log_general(); $logsGeneral = new Log_general();
$logsGeneral->user_id = Auth::user()->id; $logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor.' No se desconto el saldo, ni se asignaron cuentas.'; $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ' No se desconto el saldo, ni se asignaron cuentas.';
$logsGeneral->save(); $logsGeneral->save();
$this->alert('warning', 'No hay cuentas disponibles!', [ $this->alert('warning', 'No hay cuentas disponibles!', [
'position' => 'top' 'position' => 'top'