public function Existencias()
 {
     $nItems = 0;
     $nErrores = 0;
     $dbLink = mysql_connect("localhost", "root", "albatronic");
     $query = "TRUNCATE {$this->dbDestino}.ErpExistencias";
     mysql_query($query);
     $query = "select e.*,a.IDArticulo as id from {$this->dbOrigen}.existencias e left join {$this->dbDestino}.ErpArticulos a on e.IDArticulo=a.Codigo";
     $result = mysql_query($query, $dbLink);
     while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
         $e = new Existencias();
         $e->setIDAlmacen($row['IDSucursal']);
         $e->setIDArticulo($row['id']);
         $e->setReales($row['Reales']);
         $e->setReservadas($row['Reservadas']);
         $e->setEntrando($row['Entrando']);
         $e->setMaximo($row['Maximo']);
         $e->setMinimo($row['Minimo']);
         $id = $e->create();
         if (!$id) {
             $errores[] = $e->getErrores();
             $nErrores++;
         } else {
             $e->setPrimaryKeyMD5(md5($id));
             $e->save();
             $nItems++;
         }
     }
     echo "Existencias {$nItems}<br/>";
     if (count($errores)) {
         echo "<pre>";
         print_r($errores);
         echo "</pre>";
     }
 }