This commit is contained in:
lizandrogd
2025-04-02 01:15:12 -05:00
parent 5fa0eecf8c
commit 8d419edbed
3 changed files with 37 additions and 76 deletions
+18 -17
View File
@@ -178,20 +178,21 @@ 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::select('cuentas.*')
->selectSub(function ($query) {
$query->from('historiales')
->join('historial_cuentas', 'historiales.id', '=', 'historial_cuentas.historial_id')
->whereColumn('historial_cuentas.cuenta_id', 'cuentas.id')
->selectRaw('count(*)');
}, 'historiales_count')
->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')
->havingRaw('historiales_count <= ?', [$cantidad_restante])
->get();
$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')
//->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();
//dd($cuentas_pantallas); // con count da un numero entero
$cuentas_pantallas_tomadas = Historial_cuenta::whereIn('cuenta_id', $cuentas_pantallas
@@ -473,12 +474,12 @@ class ShowServicios extends Component
DB::rollBack();
$this->credenciales = false;
$this->cuentas = [];
$this->cuentas =[];
$this->alert('warning', 'Error al comprar: Esta cuenta ha sido tomada por otro usuario al mismo tiempo, intenta nuevamente', [
$this->alert('warning', 'Error al comprar: Esta cuenta ha sido tomada por otro usuario al mismo tiempo, intenta nuevamente' , [
'position' => 'top'
]);
}
}