Beispiel #1
0
 /**
  * Devuelve las promociones vigentes para el cliente
  * y la fecha indicada.
  *
  * El formato de fecha pasado debe ser YYYY-mm-dd
  *
  * @param date $fecha La fecha
  * @return array Array con objetos promociones
  */
 public function getPromosVigentes($fecha = '')
 {
     if ($fecha == '') {
         $fecha = date('Y-m-d');
     }
     $promos = array();
     $promociones = new Promociones();
     $promoClientes = new PromocionesClientes();
     $familias = new Familias();
     $em = new EntityManager($promociones->getConectionName());
     if ($em->getDbLink()) {
         $query = "SELECT DISTINCT t1.IDPromocion\n                FROM {$promociones->getDataBaseName()}.{$promociones->getTableName()} as t1,\n                     {$promoClientes->getDataBaseName()}.{$promoClientes->getTableName()} as t2,\n                     {$familias->getDataBaseName()}.{$familias->getTableName()} as t3\n                WHERE t1.FinPromocion>='{$fecha}'\n                AND t1.IDPromocion=t2.IDPromocion\n                AND ( (t2.IDCliente='{$this->IDCliente}') OR (t2.IDGrupo='{$this->getIDGrupo()->getIDGrupo()}') )\n                AND ( t1.IDFamilia = t3.IDFamilia OR (1))\n                ORDER BY t1.FinPromocion ASC, t1.IDArticulo DESC,t3.Familia";
         $em->query($query);
         $rows = $em->fetchResult();
         $em->desConecta();
         foreach ($rows as $row) {
             $promos[] = new Promociones($row['IDPromocion']);
         }
     }
     unset($em);
     unset($promociones);
     unset($promoClientes);
     unset($familias);
     return $promos;
 }
Beispiel #2
0
 static function getTopNFamilias($n = 10, $diasAtras = 365)
 {
     $femi = new FemitidasCab();
     $tablaFacturas = $femi->getDataBaseName() . "." . $femi->getTableName();
     $lineas = new FemitidasLineas();
     $tablaLineas = $lineas->getDataBaseName() . "." . $lineas->getTableName();
     $arti = new Articulos();
     $tablaArticulos = $arti->getDataBaseName() . "." . $arti->getTableName();
     $fami = new Familias();
     $tablaFamilias = $fami->getDataBaseName() . "." . $fami->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 (f.Fecha>='{$desde}')";
     $em = new EntityManager($femi->getConectionName());
     if ($em->getDbLink()) {
         $query = "select c.Familia,sum(l.Importe) as Total \n                from {$tablaLineas} as l \n                    left join {$tablaArticulos} as a on l.IDArticulo=a.IDArticulo\n                    left join {$tablaFacturas} as f on l.IDFactura=f.IDFactura\n                    left join {$tablaFamilias} as c on a.IDFamilia=c.IDFamilia\n                where {$filtro}\n                group by c.IDFamilia\n                order by sum(l.Importe) DESC\n                limit 0,{$n}";
         $em->query($query);
         $rows = $em->fetchResult();
     }
     unset($em);
     unset($femi);
     unset($lineas);
     unset($arti);
     return $rows;
 }