cambio real
This commit is contained in:
@@ -178,21 +178,31 @@ class ShowServicios extends Component
|
||||
$cantidad_restante = $servicio_tarifa->pantallas - $cantidad_solicitada;
|
||||
|
||||
//Traer todas las cuentas por pantalla 'activo' de los ultimos 15 dias. solo disponibles
|
||||
$cuentas_pantallas = Cuentas::whereDate('inicio', '>=', $this->fecha)
|
||||
/* $cuentas_pantallas = Cuentas::whereDate('inicio', '>=', $this->fecha)
|
||||
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
||||
->where('servicio_id', $servicio_tarifa->id)
|
||||
->where('estado', 'activo')
|
||||
->withCount('historiales')
|
||||
->where('estado', 'activo')
|
||||
->having('historiales_count', '<=', $cantidad_restante)
|
||||
->get();
|
||||
*/
|
||||
|
||||
|
||||
$cuentas = Cuentas::whereDate('inicio', '>=', $this->fecha)
|
||||
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
||||
->where('servicio_id', $servicio_tarifa->id)
|
||||
->where('estado', 'activo')
|
||||
//->with('perfil')
|
||||
//->whereDoesntHave('perfil', function ($query) use ($cantidad_restante) {
|
||||
// $query->select('cuenta_id')
|
||||
// ->groupBy('cuenta_id')
|
||||
// ->havingRaw("COUNT(*) >= $cantidad_restante");
|
||||
//})
|
||||
->withCount('historiales')
|
||||
->where('estado', 'activo')
|
||||
->having('historiales_count', '<=', $cantidad_restante)
|
||||
->get();
|
||||
|
||||
$cuentas_filtradas = $cuentas->filter(function ($cuenta) use ($cantidad_restante) {
|
||||
$historiales_count = $cuenta->historiales()->count();
|
||||
return $historiales_count <= $cantidad_restante;
|
||||
});
|
||||
|
||||
$cuentas_pantallas = $cuentas_filtradas->values();
|
||||
//dd($cuentas_pantallas); // con count da un numero entero
|
||||
|
||||
$cuentas_pantallas_tomadas = Historial_cuenta::whereIn('cuenta_id', $cuentas_pantallas
|
||||
@@ -308,40 +318,50 @@ class ShowServicios extends Component
|
||||
if ((int) $pantalla_servicio >= (int) $cantidad_solicitada && (int) $pantalla_servicio_completa != (int) $this->pantallas_tarjetaPlan) {
|
||||
$suma = $pantalla_servicio - $cantidad_solicitada;
|
||||
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
||||
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)
|
||||
$cuentas = Cuentas::where('servicio_id', $this->servicio_id)
|
||||
->whereDate('inicio', '>=', $this->fecha)
|
||||
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
||||
// ->whereDate('vencimiento','>=', $this->fechaFinal)
|
||||
->Orderby('inicio', 'ASC')
|
||||
->withCount('historiales')
|
||||
->where('estado', 'activo')
|
||||
->having('historiales_count', '<=', $suma)
|
||||
//->with('perfil')
|
||||
//->whereDoesntHave('perfil', function ($query) use ($suma) {
|
||||
// $query->select('cuenta_id')
|
||||
// ->groupBy('cuenta_id')
|
||||
// ->havingRaw("COUNT(*) >= $suma");
|
||||
//})
|
||||
->orderBy('inicio', 'ASC')
|
||||
->get();
|
||||
$cuentas_filtradas = $cuentas->filter(function ($cuenta) use ($suma) {
|
||||
$historiales_count = $cuenta->historiales()->count();
|
||||
return $historiales_count <= $suma;
|
||||
});
|
||||
|
||||
$cuenta = $cuentas_filtradas->values();
|
||||
|
||||
|
||||
if ($cuenta->isEmpty()) {
|
||||
$suma3 = $pantalla_servicio - $pantallas;
|
||||
$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('vencimiento', '>=', $this->fecha_final_1)
|
||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
||||
->Orderby('inicio', 'ASC')
|
||||
->withCount('historiales')
|
||||
->where('estado', 'activo')
|
||||
->having('historiales_count', '<=', $suma3)
|
||||
->get(); */
|
||||
|
||||
$consulta_cuentas = Cuentas::where('servicio_id', $this->servicio_id)
|
||||
->whereDate('inicio', '>=', $this->fecha)
|
||||
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
||||
->Orderby('inicio', 'ASC')
|
||||
->withCount('historiales')
|
||||
->where('estado', 'activo')
|
||||
->having('historiales_count', '<=', $suma3)
|
||||
//->with('perfil')
|
||||
//->whereDoesntHave('perfil', function ($query) use ($suma2) {
|
||||
//$query->select('cuenta_id')
|
||||
// ->groupBy('cuenta_id')
|
||||
// ->havingRaw("COUNT(*) >= $suma2");
|
||||
//})
|
||||
->orderBy('inicio', 'ASC')
|
||||
->get();
|
||||
|
||||
$cuentas_filtradas = $consulta_cuentas->filter(function ($cuenta) use ($suma3) {
|
||||
$historiales_count = $cuenta->historiales()->count();
|
||||
return $historiales_count <= $suma3;
|
||||
});
|
||||
|
||||
$cuenta = $cuentas_filtradas->values();
|
||||
|
||||
|
||||
}
|
||||
// dd($cuenta);
|
||||
} elseif ((int) $pantalla_servicio_completa == (int) $this->pantallas_tarjetaPlan) {
|
||||
@@ -360,21 +380,32 @@ class ShowServicios extends Component
|
||||
} elseif ((int) $pantalla_servicio < (int) $cantidad_solicitada) {
|
||||
$suma2 = $pantalla_servicio - $pantallas;
|
||||
$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('vencimiento', '>=', $this->fecha_final_1)
|
||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
||||
->Orderby('inicio', 'ASC')
|
||||
->withCount('historiales')
|
||||
->where('estado', 'activo')
|
||||
->having('historiales_count', '<=', $suma2)
|
||||
->get(); */
|
||||
|
||||
$consulta_cuentas = Cuentas::where('servicio_id', $this->servicio_id)
|
||||
->whereDate('inicio', '>=', $this->fecha)
|
||||
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
||||
->Orderby('inicio', 'ASC')
|
||||
->withCount('historiales')
|
||||
->where('estado', 'activo')
|
||||
->having('historiales_count', '<=', $suma2)
|
||||
//->with('perfil')
|
||||
//->whereDoesntHave('perfil', function ($query) use ($suma2) {
|
||||
//$query->select('cuenta_id')
|
||||
// ->groupBy('cuenta_id')
|
||||
// ->havingRaw("COUNT(*) >= $suma2");
|
||||
//})
|
||||
->orderBy('inicio', 'ASC')
|
||||
->get();
|
||||
|
||||
$cuentas_filtradas = $consulta_cuentas->filter(function ($cuenta) use ($suma2) {
|
||||
$historiales_count = $cuenta->historiales()->count();
|
||||
return $historiales_count <= $suma2;
|
||||
});
|
||||
|
||||
$cuentas = $cuentas_filtradas->values();
|
||||
|
||||
|
||||
} else {
|
||||
$cuenta = null;
|
||||
$cantidad_necesaria = null;
|
||||
@@ -471,15 +502,17 @@ class ShowServicios extends Component
|
||||
$this->tarjetaPlan = false;
|
||||
$this->cantidad_tarjetaPlan = 1;
|
||||
} catch (Exception $e) {
|
||||
|
||||
// Hacer rollback de cualquier cambio realizado en la base de datos
|
||||
DB::rollBack();
|
||||
|
||||
// Establecer variables a su estado inicial o a un valor que indique error
|
||||
$this->credenciales = false;
|
||||
$this->cuentas =[];
|
||||
|
||||
$this->alert('warning', 'Error al comprar: Esta cuenta ha sido tomada por otro usuario al mismo tiempo, intenta nuevamente' , [
|
||||
$this->cuentas = [];
|
||||
|
||||
// Mostrar un mensaje de alerta al usuario
|
||||
$this->alert('warning', 'Error al comprar: Esta cuenta ha sido tomada por otro usuario al mismo tiempo, intenta nuevamente. Error: ' . $e->getMessage(), [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user