havinraw
This commit is contained in:
@@ -286,13 +286,28 @@ 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')->having('historiales_count', '<=', $suma)->first();
|
||||
$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();
|
||||
|
||||
}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')->having('historiales_count', '==', 0)->first();
|
||||
}else{
|
||||
$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=null;
|
||||
}
|
||||
|
||||
@@ -332,8 +347,15 @@ 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')->having('historiales_count', '<=', (int)$suma2)->first();
|
||||
//dd($cuenta);
|
||||
$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();
|
||||
//dd($cuenta);
|
||||
if (!empty($cuenta)) {
|
||||
$perfil = $cuenta->historiales_count;
|
||||
for ($y=0; $y < (int)$pantallas ; $y++) {
|
||||
@@ -381,10 +403,26 @@ 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')->having('historiales_count', '==', 0)->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')
|
||||
->havingRaw('historiales_count = ?', [0]) // ✅ SQL nativo
|
||||
->first();
|
||||
}else{
|
||||
$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();
|
||||
}
|
||||
$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();
|
||||
}
|
||||
//dd($tarifa);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user