#define EURO 166.386 #define S_EURO "166.386" #define LEN_CODIGO_CUENTA 12 #define LEN_TITULO 40 #define LEN_NIF 15 #define LEN_DOMICILIO 35 #define LEN_POBLACION 25 #define LEN_PROVINCIA 20 #define LEN_CODPOSTAL 5 #define LEN_DIVISA 1 #define LEN_CTA_CODDIVISA 5 #define LEN_CTA_DOCUMENTO 1 #define LEN_AJUSTAME 1 #define LEN_TIPOIVA 1 #define LEN_ASIEN 6 #define LEN_FECHA 8 #define LEN_SUBCTA 12 #define LEN_CONTRA 12 #define LEN_PTADEBE 16 #define LEN_CONCEPTO 25 #define LEN_PTAHABER 16 #define LEN_FACTURA 8 #define LEN_BASEIMPO 16 #define LEN_IVA 5 #define LEN_RECEQUIV 5 #define LEN_DOCUMENTO 10 #define LEN_DEPARTA 3 #define LEN_CLAVE 6 #define LEN_ESTADO 1 #define LEN_NCASADO 6 #define LEN_TCASADO 1 #define LEN_TRANS 6 #define LEN_CAMBIO 16 #define LEN_DEBEME 16 #define LEN_HABERME 16 #define LEN_AUXILIAR 1 #define LEN_SERIE 1 #define LEN_SUCURSAL 4 #define LEN_CODDIVISA 5 #define LEN_IMPAUXME 16 #define LEN_MONEDAUSO 1 #define LEN_EURODEBE 16 #define LEN_EUROHABER 16 #define LEN_BASEEURO 16 #define LEN_NOCONV 1 #define LEN_NUMEROINV 10 /// Pasa archivos de Contaplus a BulmaGes int pgimportfiles::contaplus2Bulmages(QFile &subcuentas, QFile &asientos) { QString idasiento; QString lopd_str, cuenta_str; QString debe, haber; QString query; QDate fecha1; QDate fechain(1, 1, 1); QDate fechafi(2999, 12, 31); int orden = 0; if (m_fInicial != "") fechain.setYMD(m_fInicial.mid(6, 4).toInt(), m_fInicial.mid(3, 2).toInt(), m_fInicial.mid(0, 2).toInt()); if (m_fFinal != "") fechafi.setYMD(m_fFinal.mid(6, 4).toInt(), m_fFinal.mid(3, 2).toInt(), m_fFinal.mid(0, 2).toInt()); /// Subcuentas. QTextStream stream(&subcuentas); while (!subcuentas.atEnd()) { alerta(subcuentas.pos() + asientos.pos(), subcuentas.size() + asientos.size()); QString line = stream.readLine(); if (line.length() < 2) break; int pos = 0; QString cod = line.mid(pos, LEN_CODIGO_CUENTA).trimmed(); pos += LEN_CODIGO_CUENTA; QString titulo = line.mid(pos, LEN_TITULO).trimmed(); pos += LEN_TITULO; QString nif = line.mid(pos, LEN_NIF).trimmed(); pos += LEN_NIF; QString domicilio = line.mid(pos, LEN_DOMICILIO).trimmed(); pos += LEN_DOMICILIO; QString poblacion = line.mid(pos,LEN_POBLACION).trimmed(); pos += LEN_POBLACION; QString provincia = line.mid(pos, LEN_PROVINCIA).trimmed(); pos += LEN_PROVINCIA; QString codpostal = line.mid(pos, LEN_CODPOSTAL).trimmed(); pos += LEN_CODPOSTAL; QString divisa = line.mid(pos, LEN_DIVISA).trimmed(); pos += LEN_DIVISA; QString cta_coddivisa = line.mid(pos, LEN_CTA_CODDIVISA).trimmed(); pos += LEN_CTA_CODDIVISA; QString cta_documento = line.mid(pos, LEN_CTA_DOCUMENTO).trimmed(); pos += LEN_CTA_DOCUMENTO; QString ajustame = line.mid(pos, LEN_AJUSTAME).trimmed(); pos += LEN_AJUSTAME; QString tipoiva = line.mid(pos, LEN_TIPOIVA).trimmed(); pos += LEN_TIPOIVA; /// Antes de hacer una insercion comprobamos que la cuenta no exista ya en el sistema. QString query = "SELECT * FROM cuenta WHERE codigo = '" + cod + "'"; conexionbase->begin(); cursor2 *cursaux=conexionbase->cargacursor(query, "hol"); conexionbase->commit(); if (cursaux->eof()) { if(!cod.isEmpty()) { QString padre = searchParent(cod); QString idgrupo = cod.left(1); query = "INSERT INTO cuenta (imputacion, activo, tipocuenta, codigo, descripcion, cifent_cuenta, padre, idgrupo, nombreent_cuenta, dirent_cuenta, telent_cuenta, coment_cuenta, bancoent_cuenta, emailent_cuenta, webent_cuenta) VALUES (TRUE, TRUE, 1,'" + cod + "', '" + titulo + "', '" + nif + "', " + padre + ", " + idgrupo + ", 'importada de ContaPlus','" + domicilio + poblacion + provincia + codpostal + "','','','','','')"; conexionbase->begin(); int error = conexionbase->ejecuta(query); if (error) { conexionbase->rollback(); return 1; } // end if conexionbase->commit(); mensajeria(theApp->translate("pgimportfiles", "
  • Se ha insertado la cuenta ") + cod + "
  • \n"); } // end if } else { mensajeria(theApp->translate("pgimportfiles", "
  • Ya hay una cuenta con el codigo ") + cod + "
  • \n"); } // end if delete cursaux; } // end while QTextStream stream2(&asientos); QString lastasiento = "0"; int napunte = 0; while (!asientos.atEnd()) { alerta(subcuentas.pos() + asientos.pos(), subcuentas.size() + asientos.size()); QString line = stream2.readLine(); if (line.length() < 2) break; int pos = 0; QString asiento = line.mid(pos, LEN_ASIEN).trimmed(); pos += LEN_ASIEN; QString fecha = line.mid(pos, LEN_FECHA).trimmed(); fecha1.setYMD(fecha.mid(0, 4).toInt(), fecha.mid(4, 2).toInt(), fecha.mid(6, 2).toInt()); fecha = fecha.mid(0, 4) + "-" + fecha.mid(4, 2) + "-" + fecha.mid(6, 2); pos += LEN_FECHA; QString subcta = line.mid(pos, LEN_SUBCTA).trimmed(); pos += LEN_SUBCTA; QString contra = line.mid(pos, LEN_CONTRA).trimmed(); pos += LEN_CONTRA; QString ptadebe = line.mid(pos, LEN_PTADEBE).trimmed(); pos += LEN_PTADEBE; QString concepto = line.mid(pos, LEN_CONCEPTO).trimmed(); pos += LEN_CONCEPTO; QString ptahaber = line.mid(pos, LEN_PTAHABER).trimmed(); pos += LEN_PTAHABER; QString factura = line.mid(pos, LEN_FACTURA).trimmed(); pos += LEN_FACTURA; QString baseimpo = line.mid(pos, LEN_BASEIMPO).trimmed(); pos += LEN_BASEIMPO; QString iva = line.mid(pos, LEN_IVA).trimmed(); pos += LEN_IVA; QString recequiv = line.mid(pos, LEN_RECEQUIV).trimmed(); pos += LEN_RECEQUIV; QString documento = line.mid(pos, LEN_DOCUMENTO).trimmed(); pos += LEN_DOCUMENTO; QString departa = line.mid(pos, LEN_DEPARTA).trimmed(); pos += LEN_DEPARTA; QString clave = line.mid(pos, LEN_CLAVE).trimmed(); pos += LEN_CLAVE; QString estado = line.mid(pos, LEN_ESTADO).trimmed(); pos += LEN_ESTADO; QString ncasado = line.mid(pos, LEN_NCASADO).trimmed(); pos += LEN_NCASADO; QString tcasado = line.mid(pos, LEN_TCASADO).trimmed(); pos += LEN_TCASADO; QString trans = line.mid(pos, LEN_TRANS).trimmed(); pos += LEN_TRANS; QString cambio = line.mid(pos, LEN_CAMBIO).trimmed(); pos += LEN_CAMBIO; QString debeme = line.mid(pos, LEN_DEBEME).trimmed(); pos += LEN_DEBEME; QString haberme = line.mid(pos, LEN_HABERME).trimmed(); pos += LEN_HABERME; QString auxiliar = line.mid(pos, LEN_AUXILIAR).trimmed(); pos += LEN_AUXILIAR; QString serie = line.mid(pos, LEN_SERIE).trimmed(); pos += LEN_SERIE; QString sucursal = line.mid(pos, LEN_SUCURSAL).trimmed(); pos += LEN_SUCURSAL; QString coddivisa = line.mid(pos, LEN_CODDIVISA).trimmed(); pos += LEN_CODDIVISA; QString impauxme = line.mid(pos, LEN_IMPAUXME).trimmed(); pos += LEN_IMPAUXME; QString monedauso = line.mid(pos, LEN_MONEDAUSO).trimmed(); pos += LEN_MONEDAUSO; QString eurodebe = line.mid(pos, LEN_EURODEBE).trimmed(); pos += LEN_EURODEBE; QString eurohaber = line.mid(pos, LEN_EUROHABER).trimmed(); pos += LEN_EUROHABER; QString baseeuro = line.mid(pos, LEN_BASEEURO).trimmed(); pos += LEN_BASEEURO; QString noconv = line.mid(pos, LEN_NOCONV).trimmed(); pos += LEN_NOCONV; QString numeroinv = line.mid(pos, LEN_NUMEROINV).trimmed(); pos += LEN_NUMEROINV; if (asiento != lastasiento) { if (lastasiento != "0") { query = "SELECT cierraasiento(" + idasiento + ")"; if (!modoTest()) { conexionbase->begin(); cursor2 * cur = conexionbase->cargacursor(query, "hola"); conexionbase->commit(); delete cur; } // end if } // end if if (fecha1 >= fechain && fecha1 <= fechafi) { query="INSERT INTO asiento (fecha, comentariosasiento, clase) VALUES ('" + fecha + "','Importado de Contaplus', 1 )"; conexionbase->begin(); if (!modoTest()) { int error = conexionbase->ejecuta(query); if (error) { conexionbase->rollback(); return 1; } // end if } // end if query = "SELECT max(idasiento) as idasiento FROM asiento"; cursor2 *cur=conexionbase->cargacursor(query); idasiento = cur->valor("idasiento"); conexionbase->commit(); delete cur; napunte = 0; lastasiento = asiento; orden = 0; mensajeria(theApp->translate("pgimportfiles","
  • Insercion de asiento") + idasiento + "
  • \n"); } // end if } // end if napunte++; if (monedauso == "1") { /// Ptas. /// Aqui esta el peor error cometido, usar punto flotante debe = ptahaber + "/" + S_EURO; haber = ptadebe + "/" + S_EURO; } else { debe = eurodebe; haber = eurohaber; } // end if query = "SELECT * FROM cuenta WHERE codigo = '" + subcta + "'"; conexionbase->begin(); cursor2 *cur=conexionbase->cargacursor(query, "elquery"); conexionbase->commit(); if (!cur->eof()) { if (fecha1 >= fechain && fecha1 <= fechafi) { if (!modoTest() ) { query = "INSERT INTO borrador (idasiento, idcuenta, fecha, conceptocontable, debe, haber, orden) VALUES (" + idasiento + ", id_cuenta('" + subcta + "'), '" + fecha + "','" + concepto + "'," + debe + "," + haber + "," + QString::number(orden++) + " )"; conexionbase->begin(); int error = conexionbase->ejecuta(query); if (error) { conexionbase->rollback(); return 1; } // end if conexionbase->commit(); } // end if mensajeria(theApp->translate("pgimportfiles", "
  • Insercion de apunte") + subcta + "," + concepto + "
  • \n"); } else { mensajeria(theApp->translate("pgimportfiles", "
  • Apunte fuera de fecha
  • \n")); } // end if } // end if } // end while if (lastasiento != "0") { if(!modoTest()) { query = "SELECT cierraasiento(" + idasiento + ")"; cursor2 * cur = conexionbase->cargacursor(query); delete cur; } // end if } // end if mensajeria(theApp->translate("pgimportfiles", "
  • Terminado
  • \n")); alerta(subcuentas.size() + asientos.size(), subcuentas.size() + asientos.size()); return 0; }