update
This commit is contained in:
@@ -278,62 +278,37 @@ class ShowPromociones extends Component
|
|||||||
$this->fecha_final_1 = $today = Carbon::now()->addDays($tarifa->dias - 20);
|
$this->fecha_final_1 = $today = Carbon::now()->addDays($tarifa->dias - 20);
|
||||||
$this->fecha_final_2 = $today = Carbon::now()->addDays($tarifa->dias + 20);
|
$this->fecha_final_2 = $today = Carbon::now()->addDays($tarifa->dias + 20);
|
||||||
|
|
||||||
/* $cuenta = Cuentas::where('servicio_id', $servicio_id)
|
$baseQuery = Cuentas::select('*')->where('servicio_id', $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')->with('historiales')
|
->Orderby('inicio', 'ASC')->with('historiales')
|
||||||
->withCount('historiales')
|
->withCount('historiales')
|
||||||
->where('estado', 'pendiente')
|
->where('estado', 'pendiente');
|
||||||
->having('historiales_count', '==', 0)
|
|
||||||
->first(); */
|
|
||||||
|
|
||||||
$cuenta = Cuentas::where('servicio_id', $servicio_id)
|
$cuenta = Cuentas::fromSub($baseQuery, 'alias')
|
||||||
->whereDate('inicio', '>=', $this->fecha)
|
->where('historiales_count', '==', 0)
|
||||||
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
|
||||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
|
||||||
->where('estado', 'pendiente')
|
|
||||||
->orderBy('inicio', 'ASC')
|
->orderBy('inicio', 'ASC')
|
||||||
->with('historiales') // Relación de historiales
|
|
||||||
->withCount('historiales') // Contar historiales
|
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($cuenta) {
|
|
||||||
// Filtrar la cuenta si tiene 0 historiales
|
|
||||||
if ($cuenta->historiales_count != 0) {
|
|
||||||
$cuenta = null; // Si
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* $cuenta = Cuentas::where('servicio_id', $servicio_id)
|
$baseQuery = Cuentas::select('*')->where('servicio_id', $servicio_id)
|
||||||
->whereDate('inicio', '>=', $this->fecha)
|
|
||||||
->Orderby('inicio', 'ASC')
|
|
||||||
->with('historiales')
|
|
||||||
->withCount('historiales')
|
|
||||||
->where('estado', 'activo')
|
|
||||||
->having('historiales_count', '<=', (int) $faltante)
|
|
||||||
->first(); */
|
|
||||||
|
|
||||||
$cuenta = Cuentas::where('servicio_id', $servicio_id)
|
|
||||||
->whereDate('inicio', '>=', $this->fecha)
|
->whereDate('inicio', '>=', $this->fecha)
|
||||||
->where('estado', 'activo')
|
->Orderby('inicio', 'ASC')
|
||||||
|
->with('historiales')
|
||||||
|
->withCount('historiales')
|
||||||
|
->where('estado', 'activo');
|
||||||
|
|
||||||
|
$cuenta = Cuentas::fromSub($baseQuery, 'alias')
|
||||||
|
->where('historiales_count', '<=', (int) $faltante)
|
||||||
->orderBy('inicio', 'ASC')
|
->orderBy('inicio', 'ASC')
|
||||||
->with('historiales') // Relación de historiales
|
|
||||||
->withCount('historiales') // Contar historiales
|
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($cuenta && $cuenta->historiales_count <= (int) $faltante) {
|
|
||||||
// La cuenta cumple con el filtro, puedes usarla.
|
|
||||||
} else {
|
|
||||||
// La cuenta no cumple con el filtro, la descartas o manejas según sea necesario.
|
|
||||||
$cuenta = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!is_null($cuenta)) {
|
if (!is_null($cuenta)) {
|
||||||
$perfil = $cuenta->historiales_count;
|
$perfil = $cuenta->historiales_count;
|
||||||
for ($y = 0; $y < (int) $pantallas_tarifa; $y++) {
|
for ($y = 0; $y < (int) $pantallas_tarifa; $y++) {
|
||||||
|
|||||||
@@ -178,31 +178,21 @@ class ShowServicios extends Component
|
|||||||
$cantidad_restante = $servicio_tarifa->pantallas - $cantidad_solicitada;
|
$cantidad_restante = $servicio_tarifa->pantallas - $cantidad_solicitada;
|
||||||
|
|
||||||
//Traer todas las cuentas por pantalla 'activo' de los ultimos 15 dias. solo disponibles
|
//Traer todas las cuentas por pantalla 'activo' de los ultimos 15 dias. solo disponibles
|
||||||
/* $cuentas_pantallas = Cuentas::whereDate('inicio', '>=', $this->fecha)
|
$baseQuery = Cuentas::select('*')->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)
|
||||||
->where('servicio_id', $servicio_tarifa->id)
|
->where('servicio_id', $servicio_tarifa->id)
|
||||||
->where('estado', 'activo')
|
->where('estado', 'activo')
|
||||||
->withCount('historiales')
|
->withCount('historiales')
|
||||||
->where('estado', 'activo')
|
->where('estado', 'activo');
|
||||||
->having('historiales_count', '<=', $cantidad_restante)
|
|
||||||
->get();
|
$cuentas_pantallas = Cuentas::fromSub($baseQuery, 'alias')
|
||||||
*/
|
->where('historiales_count', '<=', $cantidad_restante)
|
||||||
|
->orderBy('inicio', 'ASC')
|
||||||
|
->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')
|
|
||||||
->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
|
//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
|
||||||
@@ -278,31 +268,30 @@ class ShowServicios extends Component
|
|||||||
$usuario_existe = User::firstWhere('email', $this->email_tarjetaPlan)->id ?? null;
|
$usuario_existe = User::firstWhere('email', $this->email_tarjetaPlan)->id ?? null;
|
||||||
$usuario_id = $usuario_existe;
|
$usuario_id = $usuario_existe;
|
||||||
|
|
||||||
if (is_null($usuario_existe)) {
|
if (is_null($usuario_existe)) {
|
||||||
$usuario = new User;
|
$usuario = new User;
|
||||||
$usuario->name = $this->nombre_tarjetaPlan;
|
$usuario->name = $this->nombre_tarjetaPlan;
|
||||||
$usuario->email = $this->email_tarjetaPlan;
|
$usuario->email = $this->email_tarjetaPlan;
|
||||||
$usuario->password = '123';
|
$usuario->password = '123';
|
||||||
$usuario->celular = '+57' . $this->celular_tarjetaPlan;
|
$usuario->celular = '+57' . $this->celular_tarjetaPlan;
|
||||||
$usuario->save();
|
$usuario->save();
|
||||||
|
|
||||||
$usuario_id = $usuario->id;
|
$usuario_id = $usuario->id;
|
||||||
}
|
}
|
||||||
|
//dd($this->fechaFinal);
|
||||||
//dd($this->fechaFinal);
|
$historial = new Historiale;
|
||||||
$historial = new Historiale;
|
$historial->fecha_inicio = Carbon::now();
|
||||||
$historial->fecha_inicio = Carbon::now();
|
$historial->fecha_final = $this->fechaFinal;
|
||||||
$historial->fecha_final = $this->fechaFinal;
|
$historial->valor = $total_valor;
|
||||||
$historial->valor = $total_valor;
|
$historial->tipo_pago = 'manual';
|
||||||
$historial->tipo_pago = 'manual';
|
$historial->estado = 'pendiente';
|
||||||
$historial->estado = 'pendiente';
|
$historial->vendedor_id = Auth()->user()->id;
|
||||||
$historial->vendedor_id = Auth()->user()->id;
|
$historial->tarifa_id = $this->tarifa_id;
|
||||||
$historial->tarifa_id = $this->tarifa_id;
|
$historial->cliente_id = $usuario_id;
|
||||||
$historial->cliente_id = $usuario_id;
|
$historial->cantidad = $this->cantidad_tarjetaPlan;
|
||||||
$historial->cantidad = $this->cantidad_tarjetaPlan;
|
$historial->nombre_cliente = $this->nombre_tarjetaPlan;
|
||||||
$historial->nombre_cliente = $this->nombre_tarjetaPlan;
|
$historial->utilidad = $utilidad_total;
|
||||||
$historial->utilidad = $utilidad_total;
|
$historial->save();
|
||||||
$historial->save();
|
|
||||||
|
|
||||||
$pantallas = Tarifas::where('id', $this->tarifa_id)->with('servicio')->first();
|
$pantallas = Tarifas::where('id', $this->tarifa_id)->with('servicio')->first();
|
||||||
|
|
||||||
@@ -316,60 +305,49 @@ class ShowServicios extends Component
|
|||||||
|
|
||||||
|
|
||||||
if ((int) $pantalla_servicio >= (int) $cantidad_solicitada && (int) $pantalla_servicio_completa != (int) $this->pantallas_tarjetaPlan) {
|
if ((int) $pantalla_servicio >= (int) $cantidad_solicitada && (int) $pantalla_servicio_completa != (int) $this->pantallas_tarjetaPlan) {
|
||||||
|
//dd('soy este');
|
||||||
$suma = $pantalla_servicio - $cantidad_solicitada;
|
$suma = $pantalla_servicio - $cantidad_solicitada;
|
||||||
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
||||||
$cuentas = Cuentas::where('servicio_id', $this->servicio_id)
|
|
||||||
|
$baseQuery = Cuentas::select('*')
|
||||||
|
->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)
|
||||||
->where('estado', 'activo')
|
->where('estado', 'activo')
|
||||||
|
->withCount('historiales')
|
||||||
|
->orderBy('inicio', 'ASC');
|
||||||
|
|
||||||
|
$cuenta = Cuentas::fromSub($baseQuery, 'alias')
|
||||||
|
->where('historiales_count', '<=', $suma)
|
||||||
->orderBy('inicio', 'ASC')
|
->orderBy('inicio', 'ASC')
|
||||||
->get();
|
->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()) {
|
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)
|
$baseQuery = Cuentas::select('*')->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('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)
|
||||||
|
->withCount('historiales')
|
||||||
->where('estado', 'activo')
|
->where('estado', 'activo')
|
||||||
|
->Orderby('inicio', 'ASC');
|
||||||
|
|
||||||
|
|
||||||
|
$cuenta = Cuentas::fromSub($baseQuery, 'alias')
|
||||||
|
->where('historiales_count', '<=', $suma3)
|
||||||
->orderBy('inicio', 'ASC')
|
->orderBy('inicio', 'ASC')
|
||||||
->get();
|
->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) {
|
} elseif ((int) $pantalla_servicio_completa == (int) $this->pantallas_tarjetaPlan) {
|
||||||
|
|
||||||
//Cuentas completas
|
//Cuentas completas
|
||||||
$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('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')
|
||||||
@@ -377,35 +355,25 @@ class ShowServicios extends Component
|
|||||||
->where('estado', 'pendiente')
|
->where('estado', 'pendiente')
|
||||||
->doesntHave('perfil')
|
->doesntHave('perfil')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
|
||||||
} elseif ((int) $pantalla_servicio < (int) $cantidad_solicitada) {
|
} elseif ((int) $pantalla_servicio < (int) $cantidad_solicitada) {
|
||||||
|
|
||||||
$suma2 = $pantalla_servicio - $pantallas;
|
$suma2 = $pantalla_servicio - $pantallas;
|
||||||
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
||||||
/* $cuenta = Cuentas::where('servicio_id', $this->servicio_id)
|
$baseQuery = Cuentas::select('*')->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('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)
|
||||||
->where('estado', 'activo')
|
->Orderby('inicio', 'ASC')
|
||||||
|
->withCount('historiales')
|
||||||
|
->where('estado', 'activo');
|
||||||
|
|
||||||
|
$cuenta = Cuentas::fromSub($baseQuery, 'alias')
|
||||||
|
->where('historiales_count', '<=', $suma2)
|
||||||
->orderBy('inicio', 'ASC')
|
->orderBy('inicio', 'ASC')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$cuentas_filtradas = $consulta_cuentas->filter(function ($cuenta) use ($suma2) {
|
|
||||||
$historiales_count = $cuenta->historiales()->count();
|
|
||||||
return $historiales_count <= $suma2;
|
|
||||||
});
|
|
||||||
|
|
||||||
$cuenta = $cuentas_filtradas->values();
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$cuenta = null;
|
$cuenta = null;
|
||||||
@@ -414,7 +382,7 @@ class ShowServicios extends Component
|
|||||||
|
|
||||||
$cuentasMostar = '';
|
$cuentasMostar = '';
|
||||||
for ($h = 0; $h < (int) $cantidad_necesaria; $h++) {
|
for ($h = 0; $h < (int) $cantidad_necesaria; $h++) {
|
||||||
//dd($cuenta);
|
|
||||||
|
|
||||||
if (!empty($cuenta) && isset($cuenta[$h])) {
|
if (!empty($cuenta) && isset($cuenta[$h])) {
|
||||||
$esta_error = false;
|
$esta_error = false;
|
||||||
@@ -505,11 +473,11 @@ class ShowServicios extends Component
|
|||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// Hacer rollback de cualquier cambio realizado en la base de datos
|
// Hacer rollback de cualquier cambio realizado en la base de datos
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
|
|
||||||
// Establecer variables a su estado inicial o a un valor que indique error
|
// Establecer variables a su estado inicial o a un valor que indique error
|
||||||
$this->credenciales = false;
|
$this->credenciales = false;
|
||||||
$this->cuentas = [];
|
$this->cuentas = [];
|
||||||
|
|
||||||
// Mostrar un mensaje de alerta al usuario
|
// 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(), [
|
$this->alert('warning', 'Error al comprar: Esta cuenta ha sido tomada por otro usuario al mismo tiempo, intenta nuevamente. Error: ' . $e->getMessage(), [
|
||||||
'position' => 'top'
|
'position' => 'top'
|
||||||
|
|||||||
Reference in New Issue
Block a user