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
+8 -46
View File
@@ -286,28 +286,13 @@ class MenuController extends Controller
if((int)$pantalla_servicio_completa >= (int)$cantidad_solicitada ){ if((int)$pantalla_servicio_completa >= (int)$cantidad_solicitada ){
$suma = $pantalla_servicio-$cantidad_solicitada; $suma = $pantalla_servicio-$cantidad_solicitada;
$cuenta = Cuentas::where('servicio_id', $servicio_id) $cuenta = Cuentas::where('servicio_id',$servicio_id)->whereDate('inicio','>=',$fecha)->Orderby('created_at', 'ASC')->withCount('historiales')->where('estado','activo')->having('historiales_count', '<=', $suma)->first();
->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){ }elseif((int)$pantalla_servicio_completa == (int)$cantidad_solicitada){
$this->fecha_final_1 = $today = Carbon::now()->addDays($pantallas->dias-15); $this->fecha_final_1 = $today = Carbon::now()->addDays($pantallas->dias-15);
$this->fecha_final_2 = $today = Carbon::now()->addDays($pantallas->dias+15); $this->fecha_final_2 = $today = Carbon::now()->addDays($pantallas->dias+15);
//completas //completas
$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('created_at', 'ASC')->withCount('historiales')->where('estado','pendiente')->having('historiales_count', '==', 0)->first();
->whereDate('inicio', '>=', $this->fecha) }else{
->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; $cuenta=null;
} }
@@ -347,15 +332,8 @@ class MenuController extends Controller
for ($h=0; $h < (int)$cantidad_tarjetaPlan ; $h++) { for ($h=0; $h < (int)$cantidad_tarjetaPlan ; $h++) {
//dd($n); //dd($n);
$cuenta = Cuentas::where('servicio_id', $servicio_id) $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();
->whereDate('inicio', '>=', $fecha) //dd($cuenta);
->orderBy('created_at', 'ASC')
->with('historiales')
->withCount('historiales')
->where('estado', 'activo')
->havingRaw('historiales_count <= ?', [(int) $suma2]) // ✅ SQL nativo
->first();
//dd($cuenta);
if (!empty($cuenta)) { if (!empty($cuenta)) {
$perfil = $cuenta->historiales_count; $perfil = $cuenta->historiales_count;
for ($y=0; $y < (int)$pantallas ; $y++) { for ($y=0; $y < (int)$pantallas ; $y++) {
@@ -403,26 +381,10 @@ class MenuController extends Controller
if ($pantalla_servicio_completa == $pantallas_tarifa) { if ($pantalla_servicio_completa == $pantallas_tarifa) {
$this->fecha_final_1 = $today = Carbon::now()->addDays($tarifa->dias-15); $this->fecha_final_1 = $today = Carbon::now()->addDays($tarifa->dias-15);
$this->fecha_final_2 = $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) $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();
->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{ }else{
$cuenta = Cuentas::where('servicio_id', $servicio_id) $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();
->whereDate('inicio', '>=', $fecha) }
->orderBy('created_at', 'ASC')
->with('historiales')
->withCount('historiales')
->where('estado', 'activo')
->havingRaw('historiales_count <= ?', [(int) $faltante]) // ✅ SQL nativo
->first();
}
//dd($tarifa); //dd($tarifa);
+11 -13
View File
@@ -275,31 +275,29 @@ class ShowPromociones extends Component
//dd($tarifa); //dd($tarifa);
if ($pantalla_servicio_completa == $pantallas_tarifa) { if ($pantalla_servicio_completa == $pantallas_tarifa) {
$this->fecha_final_1 = Carbon::now()->addDays($tarifa->dias - 20); $this->fecha_final_1 = $today = Carbon::now()->addDays($tarifa->dias - 20);
$this->fecha_final_2 = Carbon::now()->addDays($tarifa->dias + 20); $this->fecha_final_2 = $today = Carbon::now()->addDays($tarifa->dias + 20);
$cuenta = Cuentas::where('servicio_id', $servicio_id) $cuenta = Cuentas::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') ->Orderby('inicio', 'ASC')->with('historiales')
->with('historiales')
->withCount('historiales') ->withCount('historiales')
->havingRaw('COUNT(historiales.id) = 0') // ✅ Corrección
->where('estado', 'pendiente') ->where('estado', 'pendiente')
->having('historiales_count', '==', 0)
->first(); ->first();
} else { } else {
$cuenta = Cuentas::where('servicio_id', $servicio_id) $cuenta = Cuentas::where('servicio_id', $servicio_id)
->whereDate('inicio', '>=', $this->fecha) ->whereDate('inicio', '>=', $this->fecha)
->orderBy('inicio', 'ASC') ->Orderby('inicio', 'ASC')
->with('historiales') ->with('historiales')
->withCount('historiales') ->withCount('historiales')
->havingRaw('COUNT(historiales.id) <= ?', [(int) $faltante]) // ✅ Corrección
->where('estado', 'activo') ->where('estado', 'activo')
->having('historiales_count', '<=', (int) $faltante)
->first(); ->first();
} }
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++) {
@@ -365,7 +363,7 @@ class ShowPromociones extends Component
$logsGeneral = new Log_general(); $logsGeneral = new Log_general();
$logsGeneral->user_id = Auth::user()->id; $logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado la promocion ' . $this->consulta->nombre . ' - ' . $this->consulta->descripcion . ' cantidad de ' . $this->historial->cantidad . ' por un valor de $' . $this->historial->valor . ', Saldo anterior: $' . $saldo_anterior . ', Nuevo saldo disponible: $' . $nuevo_saldo; $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado la promocion ' . $this->consulta->nombre . ' - ' . $this->consulta->descripcion . ' cantidad de ' . $this->historial->cantidad . ' por un valor de $' . $this->historial->valor .', Saldo anterior: $'.$saldo_anterior.', Nuevo saldo disponible: $'.$nuevo_saldo;
$logsGeneral->tipo = 'compra'; $logsGeneral->tipo = 'compra';
$logsGeneral->historial_id = $historial->id; $logsGeneral->historial_id = $historial->id;
$logsGeneral->save(); $logsGeneral->save();
@@ -407,7 +405,7 @@ class ShowPromociones extends Component
$logsGeneral = new Log_general(); $logsGeneral = new Log_general();
$logsGeneral->user_id = Auth::user()->id; $logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado la promocion ' . $this->consulta->nombre . ' - ' . $this->consulta->descripcion . ' cantidad de ' . $this->historial->cantidad . ' por un valor de $' . $this->historial->valor ?? '' . ' y algunos han quedado pendientes' . ', Saldo anterior: $' . $saldo_anterior . ', Nuevo saldo disponible: $' . $nuevo_saldo; $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado la promocion ' . $this->consulta->nombre . ' - ' . $this->consulta->descripcion . ' cantidad de ' . $this->historial->cantidad . ' por un valor de $' . $this->historial->valor ?? '' . ' y algunos han quedado pendientes'.', Saldo anterior: $'.$saldo_anterior.', Nuevo saldo disponible: $'.$nuevo_saldo;
$logsGeneral->tipo = 'compra'; $logsGeneral->tipo = 'compra';
$logsGeneral->historial_id = $this->historial->id; $logsGeneral->historial_id = $this->historial->id;
$logsGeneral->save(); $logsGeneral->save();
@@ -417,9 +415,9 @@ class ShowPromociones extends Component
Historial_cuenta::whereIn('id', $this->n)->delete(); Historial_cuenta::whereIn('id', $this->n)->delete();
$logsGeneral = new Log_general(); $logsGeneral = new Log_general();
$logsGeneral->user_id = Auth::user()->id; $logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error en el cobro, Comprando la promoción ' . $this->consulta->nombre . ' cantidad de ' . $this->historial->cantidad . ' por un valor de $' . $this->historial->valor . ' No se desconto el saldo, ni se asignaron cuentas.'; $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error en el cobro, Comprando la promoción ' . $this->consulta->nombre . ' cantidad de ' . $this->historial->cantidad . ' por un valor de $' . $this->historial->valor .' No se desconto el saldo, ni se asignaron cuentas.';
$logsGeneral->tipo = 'compra_error'; $logsGeneral->tipo = 'compra_error';
$logsGeneral->historial_id = $this->historial->id; $logsGeneral->historial_id = $this->historial->id;
$logsGeneral->save(); $logsGeneral->save();
$this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [ $this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [
'position' => 'top' 'position' => 'top'
@@ -441,7 +439,7 @@ class ShowPromociones extends Component
Historial_cuenta::whereIn('id', $this->n)->delete(); Historial_cuenta::whereIn('id', $this->n)->delete();
$logsGeneral = new Log_general(); $logsGeneral = new Log_general();
$logsGeneral->user_id = Auth::user()->id; $logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Cancelo la compra del plan ' . $this->consulta->nombre . ' cantidad de ' . $this->historial->cantidad . ' por un valor de $' . $this->historial->valor . ' No se desconto el saldo, ni se asignaron cuentas.'; $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Cancelo la compra del plan ' . $this->consulta->nombre . ' cantidad de ' . $this->historial->cantidad . ' por un valor de $' . $this->historial->valor.' No se desconto el saldo, ni se asignaron cuentas.';
$logsGeneral->tipo = 'compra_cancelada'; $logsGeneral->tipo = 'compra_cancelada';
$logsGeneral->historial_id = $this->historial->id; $logsGeneral->historial_id = $this->historial->id;
$logsGeneral->save(); $logsGeneral->save();
+18 -17
View File
@@ -178,20 +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::select('cuentas.*') $cuentas_pantallas = Cuentas::whereDate('inicio', '>=', $this->fecha)
->selectSub(function ($query) { ->whereDate('vencimiento', '>=', $this->fecha_final_1)
$query->from('historiales') ->whereDate('vencimiento', '<=', $this->fecha_final_2)
->join('historial_cuentas', 'historiales.id', '=', 'historial_cuentas.historial_id') ->where('servicio_id', $servicio_tarifa->id)
->whereColumn('historial_cuentas.cuenta_id', 'cuentas.id') ->where('estado', 'activo')
->selectRaw('count(*)'); //->with('perfil')
}, 'historiales_count') //->whereDoesntHave('perfil', function ($query) use ($cantidad_restante) {
->whereDate('inicio', '>=', $this->fecha) // $query->select('cuenta_id')
->whereDate('vencimiento', '>=', $this->fecha_final_1) // ->groupBy('cuenta_id')
->whereDate('vencimiento', '<=', $this->fecha_final_2) // ->havingRaw("COUNT(*) >= $cantidad_restante");
->where('servicio_id', $servicio_tarifa->id) //})
->where('estado', 'activo') ->withCount('historiales')
->havingRaw('historiales_count <= ?', [$cantidad_restante]) ->where('estado', 'activo')
->get(); ->having('historiales_count', '<=', $cantidad_restante)
->get();
//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
@@ -473,12 +474,12 @@ class ShowServicios extends Component
DB::rollBack(); DB::rollBack();
$this->credenciales = false; $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' 'position' => 'top'
]); ]);
} }
} }