예제 #1
0
 /**
  * Devuelve un array con los $nTop objetos Articulos más vendidos
  * 
  * @param int $nTop Por defecto 20
  * @return array \Articulos
  */
 public function getTops($nTop = 20)
 {
     if ($nTop <= 0) {
         $nTop = 20;
     }
     $lineasAlbaranes = new AlbaranesLineas();
     $rows = $lineasAlbaranes->cargaCondicion("IDArticulo,sum(Unidades)", "1 group by IDArticulo", "sum(Unidades) DESC limit {$nTop}");
     unset($lineasAlbaranes);
     $array = array();
     foreach ($rows as $row) {
         $array[] = new Articulos($row['IDArticulo']);
     }
     return $array;
 }
 /**
  * Genera un array con la informacion necesaria para imprimir el documento
  * Recibe un array con los ids de albaran
  * No muestra las lineas cuyas unidades son cero.
  *
  * @param array $idsDocumento Array con los ids de albaranes
  * @return array Array con dos elementos: master es un objeto albaran y detail es un array de objetos lineas de albaran
  */
 protected function getDatosDocumento(array $idsDocumento)
 {
     $master = array();
     $detail = array();
     // Recorro el array de los albaranes a imprimir
     foreach ($idsDocumento as $key => $idDocumento) {
         // Instancio la cabecera del albaran
         $master[$key] = new AlbaranesCab($idDocumento);
         // LLeno el array con objetos de lineas de albaran
         $lineas = array();
         $albaranLineas = new AlbaranesLineas();
         $rows = $albaranLineas->cargaCondicion('IDLinea', "IDAlbaran='{$idDocumento}' and Unidades<>0", "IDLinea ASC");
         foreach ($rows as $row) {
             $lineas[] = new AlbaranesLineas($row['IDLinea']);
         }
         $detail[$key] = $lineas;
     }
     return array('master' => $master, 'detail' => $detail);
 }
예제 #3
0
 public function NavegarAction()
 {
     if ($this->values['permisos']['permisosModulo']['CO']) {
         $idAlbaran = $this->request['AlbaranesCab']['IDAlbaran'];
         switch ($this->request['accion']) {
             case 'nuevo':
                 $albaran = new AlbaranesCab();
                 $albaran->setIDSucursal($_SESSION['suc']);
                 break;
             case 'crear':
                 $albaran = $this->guardar($this->request['AlbaranesCab']);
                 break;
             case 'buscar':
                 $albaran = new AlbaranesCab($idAlbaran);
                 break;
             case 'guardar':
                 $albaran = $this->guardar($this->request['AlbaranesCab']);
                 break;
             case 'borrar':
                 $albaran = $this->borrar($this->request['AlbaranesCab']);
                 break;
             case 'U':
                 $albaran = $this->getUltimo();
                 break;
             case 'P':
                 $albaran = $this->getPrimero();
                 break;
             case 'A':
                 $albaran = $this->getAnterior($idAlbaran);
                 break;
             case 'S':
                 $albaran = $this->getSiguiente($idAlbaran);
                 break;
         }
         /**
          if ($albaran->getIDEstado()->getIDTipo() == '0') {
          // Si el albaran está pte de confirmar, puedo modificar sus líneas y
          // por lo tanto le añado un objeto linea vacío
          $objetoNuevo = new AlbaranesLineas();
          $objetoNuevo->setIDAlbaran($albaran->getIDAlbaran());
          $lineas[] = $objetoNuevo;
          unset($objetoNuevo);
          }
         */
         $lin = new AlbaranesLineas();
         $rows = $lin->cargaCondicion("IDLinea", "IDAlbaran='{$albaran->getIDAlbaran()}'", "IDLinea ASC");
         unset($lin);
         foreach ($rows as $linea) {
             $lineas[] = new AlbaranesLineas($linea['IDLinea']);
         }
         // Cargo los favoritos del tpv
         $fav = new FavoritosTpv();
         $this->values['favoritos'] = $fav->cargaCondicion("Id,IDArticulo,Descripcion", "IDTpv='{$_SESSION['tpv']}'", "SortOrder ASC");
         unset($fav);
         $this->values['albaran'] = $albaran;
         $this->values['lineas'] = $lineas;
         $template = "Tpv/index.html.twig";
         unset($albaran);
         unset($lineas);
     } else {
         $template = "_global/forbiden.html.twig";
     }
     return array('template' => $template, 'values' => $this->values);
 }
 /**
  * Edita, actualiza o borrar un registro
  *
  * Si viene por GET es editar
  * Si viene por POST puede ser actualizar o borrar
  * según el valor de $this->request['accion']
  *
  * @return array con el template y valores a renderizar
  */
 public function editAction()
 {
     switch ($this->request["METHOD"]) {
         case 'GET':
             if ($this->values['permisos']['permisosModulo']['CO']) {
                 //SI EN LA POSICION 3 DEL REQUEST VIENE ALGO,
                 //SE ENTIENDE QUE ES EL VALOR DE LA CLAVE PARA LINKAR CON LA ENTIDAD PADRE
                 //ESTO SE UTILIZA PARA LOS FORMULARIOS PADRE->HIJO
                 if ($this->request['3'] != '') {
                     $this->values['linkBy']['value'] = $this->request['3'];
                 }
                 //MOSTRAR DATOS. El ID viene en la posicion 2 del request
                 $datos = new $this->entity();
                 $datos = $datos->find('PrimaryKeyMD5', $this->request[2]);
                 if ($datos->getStatus()) {
                     $lineasAlbaranes = new AlbaranesLineas();
                     $promoAplicada = $lineasAlbaranes->cargaCondicion("IDPromocion", "IDPromocion='{$datos->getIDPromocion()}'");
                     $this->values['promoAplicada'] = count($promoAplicada);
                     $this->values['datos'] = $datos;
                     $this->values['errores'] = $datos->getErrores();
                     return array('template' => $this->entity . '/edit.html.twig', 'values' => $this->values);
                 } else {
                     $this->values['errores'] = array("Valor no encontrado. El objeto que busca no existe. Es posible que haya sido eliminado por otro usuario.");
                     return array('template' => $this->entity . '/new.html.twig', 'values' => $this->values);
                 }
             } else {
                 return array('template' => '_global/forbiden.html.twig');
             }
             break;
         case 'POST':
             //COGER DEL REQUEST EL LINK A LA ENTIDAD PADRE
             if ($this->values['linkBy']['id'] != '') {
                 $this->values['linkBy']['value'] = $this->request[$this->entity][$this->values['linkBy']['id']];
             }
             switch ($this->request['accion']) {
                 case 'Guardar':
                     //GUARDAR DATOS
                     if ($this->values['permisos']['permisosModulo']['UP']) {
                         // Cargo la entidad
                         $datos = new $this->entity($this->request[$this->entity][$this->form->getPrimaryKey()]);
                         // Vuelco los datos del request
                         $datos->bind($this->request[$this->entity]);
                         if ($datos->valida($this->form->getRules())) {
                             $this->values['alertas'] = $datos->getAlertas();
                             $datos->save();
                             //Recargo el objeto para refrescar las propiedas que
                             //hayan podido ser objeto de algun calculo durante el proceso
                             //de guardado.
                             $datos = new $this->entity($this->request[$this->entity][$datos->getPrimaryKeyName()]);
                         } else {
                             $this->values['errores'] = $datos->getErrores();
                             $this->values['alertas'] = $datos->getAlertas();
                         }
                         $this->values['datos'] = $datos;
                         return array('template' => $this->entity . '/edit.html.twig', 'values' => $this->values);
                     } else {
                         return array('template' => '_global/forbiden.html.twig');
                     }
                     break;
                 case 'Borrar':
                     //BORRAR DATOS
                     if ($this->values['permisos']['permisosModulo']['DE']) {
                         $datos = new $this->entity();
                         $datos->bind($this->request[$this->entity]);
                         if ($datos->erase()) {
                             $datos = new $this->entity();
                             $this->values['datos'] = $datos;
                             $this->values['errores'] = array();
                             return array('template' => $this->entity . '/new.html.twig', 'values' => $this->values);
                         } else {
                             $this->values['datos'] = $datos;
                             $this->values['errores'] = $datos->getErrores();
                             $this->values['alertas'] = $datos->getAlertas();
                             return array('template' => $this->entity . '/edit.html.twig', 'values' => $this->values);
                         }
                     } else {
                         return array('template' => '_global/forbiden.html.twig');
                     }
                     break;
             }
             break;
     }
 }