public function Inventarios()
 {
     $nItems = 0;
     $nErrores = 0;
     $dbLink = mysql_connect("localhost", "root", "albatronic");
     $query = "TRUNCATE {$this->dbDestino}.ErpInventariosCab";
     mysql_query($query);
     $query = "TRUNCATE {$this->dbDestino}.ErpInventariosLineas";
     mysql_query($query);
     $query = "select distinct IDSucursal,DATE_FORMAT(Fecha,'%Y-%m-%d') as FInventario, Cerrado FROM {$this->dbOrigen}.inventarios order by DATE_FORMAT(Fecha,'%Y-%m-%d') asc";
     $result = mysql_query($query, $dbLink);
     while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
         $i = new InventariosCab();
         $i->setIDAlmacen($row['IDSucursal']);
         $i->setFecha($row['FInventario']);
         $i->setCerrado($row['Cerrado']);
         $id = $i->create();
         if (!$id) {
             $errores[] = $i->getErrores();
             $nErrores++;
         } else {
             $i->setIDInventario($id);
             $i->setPrimaryKeyMD5(md5($id));
             $i->save();
             $nItems++;
             $this->LineasInventario($row['FInventario'], $id, $dbLink);
         }
     }
     echo "Inventarios cabeceras {$nItems}<br/>";
     if (count($errores)) {
         echo "<pre>";
         print_r($errores);
         echo "</pre>";
     }
 }
 /**
  * Cierra el inventario
  */
 public function cerrarAction()
 {
     if ($this->values['permisos']['permisosModulo']['UP']) {
         $datos = new InventariosCab($this->request['InventariosCab']['IDInventario']);
         $datos->cierra();
         $this->values['errores'] = $datos->getErrores();
         $this->values['alertas'] = $datos->getAlertas();
         $datos = new InventariosCab($this->request['InventariosCab']['IDInventario']);
         $this->values['datos'] = $datos;
         unset($datos);
         return array('template' => $this->entity . '/edit.html.twig', 'values' => $this->values);
     } else {
         return array('template' => '_global/forbiden.html.twig');
     }
 }