static function getTopNComerciales($n = 10, $diasAtras = 365) { $femi = new FemitidasCab(); $tablaFacturas = $femi->getDataBaseName() . "." . $femi->getTableName(); $idRol = $_SESSION['usuarioPortal']['IdRol']; if ($idRol != '0' and $idRol != '9') { $filtro = "(f.IDComercial='{$_SESSION['usuarioPortal']['Id']}')"; } else { $filtro = "(1)"; } $hoy = new Fecha(); $desde = $hoy->sumaDias(-$diasAtras); $filtro .= " AND (Fecha>='{$desde}')"; $em = new EntityManager($femi->getConectionName()); if ($em->getDbLink()) { $query = "select IDComercial,sum(TotalBases) as Total \n from {$tablaFacturas}\n where {$filtro}\n group by IDComercial\n order by sum(TotalBases) DESC\n limit 0,{$n}"; $em->query($query); $rows = $em->fetchResult(); } foreach ($rows as $key => $row) { $comercial = new Agentes($row['IDComercial']); $rows[$key]['Nombre'] = $comercial->getNombreApellidos(); } unset($comercial); unset($em); unset($femi); return $rows; }