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
+6 -44
View File
@@ -286,28 +286,13 @@ class MenuController extends Controller
if((int)$pantalla_servicio_completa >= (int)$cantidad_solicitada ){
$suma = $pantalla_servicio-$cantidad_solicitada;
$cuenta = Cuentas::where('servicio_id', $servicio_id)
->whereDate('inicio', '>=', $fecha)
->orderBy('created_at', 'ASC')
->withCount('historiales')
->where('estado', 'activo')
->havingRaw('COUNT(historiales.id) <= ?', [$suma]) // ✅ Corrección
->first();
$cuenta = Cuentas::where('servicio_id',$servicio_id)->whereDate('inicio','>=',$fecha)->Orderby('created_at', 'ASC')->withCount('historiales')->where('estado','activo')->having('historiales_count', '<=', $suma)->first();
}elseif((int)$pantalla_servicio_completa == (int)$cantidad_solicitada){
$this->fecha_final_1 = $today = Carbon::now()->addDays($pantallas->dias-15);
$this->fecha_final_2 = $today = Carbon::now()->addDays($pantallas->dias+15);
//completas
$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('created_at', 'ASC')
->withCount('historiales')
->where('estado', 'pendiente')
->havingRaw('COUNT(historiales.id) = 0') // ✅ Corrección
->first();
$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('created_at', 'ASC')->withCount('historiales')->where('estado','pendiente')->having('historiales_count', '==', 0)->first();
}else{
$cuenta=null;
}
@@ -347,14 +332,7 @@ class MenuController extends Controller
for ($h=0; $h < (int)$cantidad_tarjetaPlan ; $h++) {
//dd($n);
$cuenta = Cuentas::where('servicio_id', $servicio_id)
->whereDate('inicio', '>=', $fecha)
->orderBy('created_at', 'ASC')
->with('historiales')
->withCount('historiales')
->where('estado', 'activo')
->havingRaw('historiales_count <= ?', [(int) $suma2]) // ✅ SQL nativo
->first();
$cuenta = Cuentas::where('servicio_id',$servicio_id)->whereDate('inicio','>=',$fecha)->Orderby('created_at', 'ASC')->with('historiales')->withCount('historiales')->where('estado','activo')->having('historiales_count', '<=', (int)$suma2)->first();
//dd($cuenta);
if (!empty($cuenta)) {
$perfil = $cuenta->historiales_count;
@@ -403,25 +381,9 @@ class MenuController extends Controller
if ($pantalla_servicio_completa == $pantallas_tarifa) {
$this->fecha_final_1 = $today = Carbon::now()->addDays($tarifa->dias-15);
$this->fecha_final_2 = $today = Carbon::now()->addDays($tarifa->dias+15);
$cuenta = Cuentas::where('servicio_id', $servicio_id)
->whereDate('inicio', '>=', $fecha)
->whereDate('vencimiento', '>=', $this->fecha_final_1)
->whereDate('vencimiento', '<=', $this->fecha_final_2)
->orderBy('created_at', 'ASC')
->with('historiales')
->withCount('historiales')
->where('estado', 'pendiente')
->havingRaw('historiales_count = ?', [0]) // ✅ SQL nativo
->first();
$cuenta = Cuentas::where('servicio_id',$servicio_id)->whereDate('inicio','>=',$fecha)->whereDate('vencimiento','>=',$this->fecha_final_1)->whereDate('vencimiento','<=',$this->fecha_final_2)->Orderby('created_at', 'ASC')->with('historiales')->withCount('historiales')->where('estado','pendiente')->having('historiales_count', '==', 0)->first();
}else{
$cuenta = Cuentas::where('servicio_id', $servicio_id)
->whereDate('inicio', '>=', $fecha)
->orderBy('created_at', 'ASC')
->with('historiales')
->withCount('historiales')
->where('estado', 'activo')
->havingRaw('historiales_count <= ?', [(int) $faltante]) // ✅ SQL nativo
->first();
$cuenta = Cuentas::where('servicio_id', $servicio_id)->whereDate('inicio','>=',$fecha)->Orderby('created_at', 'ASC')->with('historiales')->withCount('historiales')->where('estado', 'activo')->having('historiales_count', '<=', (int)$faltante)->first();
}
//dd($tarifa);
+6 -8
View File
@@ -275,31 +275,29 @@ class ShowPromociones extends Component
//dd($tarifa);
if ($pantalla_servicio_completa == $pantallas_tarifa) {
$this->fecha_final_1 = Carbon::now()->addDays($tarifa->dias - 20);
$this->fecha_final_2 = 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);
$cuenta = Cuentas::where('servicio_id', $servicio_id)
->whereDate('inicio', '>=', $this->fecha)
->whereDate('vencimiento', '>=', $this->fecha_final_1)
->whereDate('vencimiento', '<=', $this->fecha_final_2)
->orderBy('inicio', 'ASC')
->with('historiales')
->Orderby('inicio', 'ASC')->with('historiales')
->withCount('historiales')
->havingRaw('COUNT(historiales.id) = 0') // ✅ Corrección
->where('estado', 'pendiente')
->having('historiales_count', '==', 0)
->first();
} else {
$cuenta = Cuentas::where('servicio_id', $servicio_id)
->whereDate('inicio', '>=', $this->fecha)
->orderBy('inicio', 'ASC')
->Orderby('inicio', 'ASC')
->with('historiales')
->withCount('historiales')
->havingRaw('COUNT(historiales.id) <= ?', [(int) $faltante]) // ✅ Corrección
->where('estado', 'activo')
->having('historiales_count', '<=', (int) $faltante)
->first();
}
if (!is_null($cuenta)) {
$perfil = $cuenta->historiales_count;
for ($y = 0; $y < (int) $pantallas_tarifa; $y++) {
+10 -9
View File
@@ -178,19 +178,20 @@ 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)
$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')
->havingRaw('historiales_count <= ?', [$cantidad_restante])
//->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