gongimportfiles.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Josep Burcion                                   *
00003  *   josep@burcion.com                                                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include <QDateTime>
00022 #include <QTextStream>
00023 
00024 #include "gongimportfiles.h"
00025 
00026 #define EURO                 166.386
00027 
00028 #define LEN_CODIGO_CUENTA    12
00029 #define LEN_TITULO           40
00030 #define LEN_NIF              15
00031 #define LEN_DOMICILIO        35
00032 #define LEN_POBLACION        25
00033 #define LEN_PROVINCIA        20
00034 #define LEN_CODPOSTAL        5
00035 #define LEN_DIVISA           1
00036 #define LEN_CTA_CODDIVISA    5
00037 #define LEN_CTA_DOCUMENTO    1
00038 #define LEN_AJUSTAME         1
00039 #define LEN_TIPOIVA          1
00040 
00041 
00042 #define LEN_ASIEN            6
00043 #define LEN_FECHA            8
00044 #define LEN_SUBCTA           12
00045 #define LEN_CONTRA           12
00046 #define LEN_PTADEBE          16
00047 #define LEN_CONCEPTO         25
00048 #define LEN_PTAHABER         16
00049 #define LEN_FACTURA          8
00050 #define LEN_BASEIMPO         16
00051 #define LEN_IVA              5
00052 #define LEN_RECEQUIV         5
00053 #define LEN_DOCUMENTO        10
00054 #define LEN_DEPARTA          3
00055 #define LEN_CLAVE            6
00056 #define LEN_ESTADO           1
00057 #define LEN_NCASADO          6
00058 #define LEN_TCASADO          1
00059 #define LEN_TRANS            6
00060 #define LEN_CAMBIO           16
00061 #define LEN_DEBEME           16
00062 #define LEN_HABERME          16
00063 #define LEN_AUXILIAR         1
00064 #define LEN_SERIE            1
00065 #define LEN_SUCURSAL         4
00066 #define LEN_CODDIVISA        5
00067 #define LEN_IMPAUXME         16
00068 #define LEN_MONEDAUSO        1
00069 #define LEN_EURODEBE         16
00070 #define LEN_EUROHABER        16
00071 #define LEN_BASEEURO         16
00072 #define LEN_NOCONV           1
00073 #define LEN_NUMEROINV        10
00074 
00075 
00077 
00083 int Contaplus2Fugit(QFile &fugitfile, QFile &subcuentas, QFile &asientos) {
00084     QTextStream fugit(&fugitfile);
00085 
00086     fugit << "<?xml version=\"1.0\" encoding = \"iso-8859-1\"?>\n"
00087     "<!DOCTYPE FUGIT>\n"
00088     "<FUGIT version='0.3.1' origen='contaplus'"
00089     " date='" << QDate().toString(Qt::ISODate) << "'>\n";
00090     QString lopd_str, cuenta_str;
00091 
00093     QTextStream stream(&subcuentas);
00094     while (!subcuentas.atEnd()) {
00095         QString line = stream.readLine();
00096         if (line.length() < 2) {
00097             break;
00098         } // end if
00099         int pos = 0;
00100         QString cod = line.mid(pos, LEN_CODIGO_CUENTA).trimmed();
00101         pos += LEN_CODIGO_CUENTA;
00102         QString titulo = line.mid(pos, LEN_TITULO).trimmed();
00103         pos += LEN_TITULO;
00104         QString nif = line.mid(pos, LEN_NIF).trimmed();
00105         pos += LEN_NIF;
00106         QString domicilio = line.mid(pos, LEN_DOMICILIO).trimmed();
00107         pos += LEN_DOMICILIO;
00108         QString poblacion = line.mid(pos, LEN_POBLACION).trimmed();
00109         pos += LEN_POBLACION;
00110         QString provincia = line.mid(pos, LEN_PROVINCIA).trimmed();
00111         pos += LEN_PROVINCIA;
00112         QString codpostal = line.mid(pos, LEN_CODPOSTAL).trimmed();
00113         pos += LEN_CODPOSTAL;
00114         QString divisa = line.mid(pos, LEN_DIVISA).trimmed();
00115         pos += LEN_DIVISA;
00116         QString cta_coddivisa = line.mid(pos, LEN_CTA_CODDIVISA).trimmed();
00117         pos += LEN_CTA_CODDIVISA;
00118         QString cta_documento = line.mid(pos, LEN_CTA_DOCUMENTO).trimmed();
00119         pos += LEN_CTA_DOCUMENTO;
00120         QString ajustame = line.mid(pos, LEN_AJUSTAME).trimmed();
00121         pos += LEN_AJUSTAME;
00122         QString tipoiva = line.mid(pos, LEN_TIPOIVA).trimmed();
00123         pos += LEN_TIPOIVA;
00124 
00125         if (!nif.isEmpty() || !domicilio.isEmpty() || !poblacion.isEmpty()
00126                 || !provincia.isEmpty() || !codpostal.isEmpty()) {
00127             lopd_str += "<LOPD>\n"
00128                         "\t<FIELD name='cif'>" + nif + "</FIELD>\n"
00129                         "\t<FIELD name='nombre'>" + titulo + "</FIELD>\n"
00130                         "\t<FIELD name='direccion'>" + domicilio + "</FIELD>\n"
00131                         "\t<FIELD name='localidad'>" + poblacion + "</FIELD>\n"
00132                         "\t<FIELD name='provincia'>" + provincia + "</FIELD>\n"
00133                         "\t<FIELD name='cp'>" + codpostal + "</FIELD>\n"
00134                         "</LOPD>\n";
00135         } // end if
00136         if (!cod.isEmpty()) {
00137             cuenta_str += "<CUENTA>\n"
00138                           "\t<FIELD name='cuenta'>" + cod + "</FIELD>\n"
00139                           "\t<FIELD name='descripcion'>" + titulo + "</FIELD>\n"
00140                           "\t<FIELD name='cif'>" + nif + "</FIELD>\n"
00141                           "</CUENTA>\n";
00142         } // end if
00143     } // end while
00144     fugit << "<FICHERO_LOPD>\n";
00145     fugit <<  lopd_str ;
00146     fugit << "</FICHERO_LOPD>\n";
00147     fugit << "<FICHERO_CUENTA>\n";
00148     fugit <<  cuenta_str ;
00149     fugit << "</FICHERO_CUENTA>\n\n";
00150 
00152     fugit << "<FICHERO_ASIENTO>\n";
00153     QTextStream stream2(&asientos);
00154     QString lastasiento;
00155     int napunte = 0;
00156     while (!asientos.atEnd()) {
00157         QString line = stream2.readLine();
00158         if (line.length() < 2) {
00159             break;
00160         } // end if
00161         int pos = 0;
00162         QString asiento = line.mid(pos, LEN_ASIEN).trimmed();
00163         pos += LEN_ASIEN;
00164         QString fecha = line.mid(pos, LEN_FECHA).trimmed();
00165         fecha = fecha.mid(0, 4) + "-" + fecha.mid(4, 2) + "-" + fecha.mid(6, 2);
00166         pos += LEN_FECHA;
00167         QString subcta = line.mid(pos, LEN_SUBCTA).trimmed();
00168         pos += LEN_SUBCTA;
00169         QString contra = line.mid(pos, LEN_CONTRA).trimmed();
00170         pos += LEN_CONTRA;
00171         QString ptadebe = line.mid(pos, LEN_PTADEBE).trimmed();
00172         pos += LEN_PTADEBE;
00173         QString concepto = line.mid(pos, LEN_CONCEPTO).trimmed();
00174         pos += LEN_CONCEPTO;
00175         QString ptahaber = line.mid(pos, LEN_PTAHABER).trimmed();
00176         pos += LEN_PTAHABER;
00177         QString factura = line.mid(pos, LEN_FACTURA).trimmed();
00178         pos += LEN_FACTURA;
00179         QString baseimpo = line.mid(pos, LEN_BASEIMPO).trimmed();
00180         pos += LEN_BASEIMPO;
00181         QString iva = line.mid(pos, LEN_IVA).trimmed();
00182         pos += LEN_IVA;
00183         QString recequiv = line.mid(pos, LEN_RECEQUIV).trimmed();
00184         pos += LEN_RECEQUIV;
00185         QString documento = line.mid(pos, LEN_DOCUMENTO).trimmed();
00186         pos += LEN_DOCUMENTO;
00187         QString departa = line.mid(pos, LEN_DEPARTA).trimmed();
00188         pos += LEN_DEPARTA;
00189         QString clave = line.mid(pos, LEN_CLAVE).trimmed();
00190         pos += LEN_CLAVE;
00191         QString estado = line.mid(pos, LEN_ESTADO).trimmed();
00192         pos += LEN_ESTADO;
00193         QString ncasado = line.mid(pos, LEN_NCASADO).trimmed();
00194         pos += LEN_NCASADO;
00195         QString tcasado = line.mid(pos, LEN_TCASADO).trimmed();
00196         pos += LEN_TCASADO;
00197         QString trans = line.mid(pos, LEN_TRANS).trimmed();
00198         pos += LEN_TRANS;
00199         QString cambio = line.mid(pos, LEN_CAMBIO).trimmed();
00200         pos += LEN_CAMBIO;
00201         QString debeme = line.mid(pos, LEN_DEBEME).trimmed();
00202         pos += LEN_DEBEME;
00203         QString haberme = line.mid(pos, LEN_HABERME).trimmed();
00204         pos += LEN_HABERME;
00205         QString auxiliar = line.mid(pos, LEN_AUXILIAR).trimmed();
00206         pos += LEN_AUXILIAR;
00207         QString serie = line.mid(pos, LEN_SERIE).trimmed();
00208         pos += LEN_SERIE;
00209         QString sucursal = line.mid(pos, LEN_SUCURSAL).trimmed();
00210         pos += LEN_SUCURSAL;
00211         QString coddivisa = line.mid(pos, LEN_CODDIVISA).trimmed();
00212         pos += LEN_CODDIVISA;
00213         QString impauxme = line.mid(pos, LEN_IMPAUXME).trimmed();
00214         pos += LEN_IMPAUXME;
00215         QString monedauso = line.mid(pos, LEN_MONEDAUSO).trimmed();
00216         pos += LEN_MONEDAUSO;
00217         QString eurodebe = line.mid(pos, LEN_EURODEBE).trimmed();
00218         pos += LEN_EURODEBE;
00219         QString eurohaber = line.mid(pos, LEN_EUROHABER).trimmed();
00220         pos += LEN_EUROHABER;
00221         QString baseeuro = line.mid(pos, LEN_BASEEURO).trimmed();
00222         pos += LEN_BASEEURO;
00223         QString noconv = line.mid(pos, LEN_NOCONV).trimmed();
00224         pos += LEN_NOCONV;
00225         QString numeroinv = line.mid(pos, LEN_NUMEROINV).trimmed();
00226         pos += LEN_NUMEROINV;
00227 
00228         if (asiento != lastasiento) {
00229             if (!lastasiento.isEmpty())
00230                 fugit <<  "</ASIENTO>\n";
00231             fugit << "<ASIENTO>\n"
00232             "\t<FIELD name='numasiento'>" + asiento + "</FIELD>\n"
00233             "\t<FIELD name='fecha'>" + fecha + "</FIELD>\n"
00234             "\t<FIELD name='numdocumento'>" + documento + "</FIELD>\n"
00235             "\t<FIELD name='numdiario'>" + departa + "</FIELD>\n"
00236             "\t<FIELD name='punteo'>" + estado + "</FIELD>\n";
00237             napunte = 0;
00238             lastasiento = asiento;
00239         } // end if
00240         napunte++;
00241         fugit << "\t<APUNTE>\n"
00242         "\t\t<FIELD name='numapunte'>" + QString::number(napunte) + "</FIELD>\n"
00243         "\t\t<FIELD name='cuenta'>" + subcta + "</FIELD>\n"
00244         "\t\t<FIELD name='contrapartida'>" + contra + "</FIELD>\n"
00245         "\t\t<FIELD name='concepto'>" + concepto + "</FIELD>\n";
00246         if (monedauso == "1") { 
00247             fugit <<
00248             "\t\t<FIELD name='debe'>" + QString::number((ptadebe.toDouble()) / EURO) + "</FIELD>\n"
00249             "\t\t<FIELD name='haber'>" + QString::number((ptahaber.toDouble()) / EURO) + "</FIELD>\n";
00250         } else {
00251             fugit <<
00252             "\t\t<FIELD name='debe'>" + QString::number((eurodebe.toDouble()) ) + "</FIELD>\n"
00253             "\t\t<FIELD name='haber'>" + QString::number((eurohaber.toDouble()) ) + "</FIELD>\n";
00254         } // end if
00255         fugit << "\t</APUNTE>\n";
00256     } // end while
00257     if (!lastasiento.isEmpty()) {
00258         fugit << "</ASIENTO>\n";
00259     } // end if
00260     fugit << "</FICHERO_ASIENTO>\n";
00261     fugit << "</FUGIT>";
00262 
00263     return 1;
00264 }
00265 

Generated on Sat Dec 15 00:01:15 2007 for BulmaGes by  doxygen 1.5.1