extractoprintview.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Tomeu Borras Riera                              *
00003  *   tborras@conetxia.com                                                  *
00004  *   Copyright (C) 2003 by Antoni Mirabete i Teres                         *
00005  *   amirabet@biada.org                                                    *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 #include <unistd.h>
00024 
00025 #include <QWidget>
00026 #include <QCheckBox>
00027 
00028 #include "extractoprintview.h"
00029 #include "extractoview1.h"
00030 #include "listcuentasview1.h"
00031 #include "selectccosteview.h"
00032 #include "selectcanalview.h"
00033 #include "empresa.h"
00034 #include "busquedafecha.h"
00035 #include "busquedacuenta.h"
00036 
00037 using namespace std;
00038 
00040 
00044 ExtractoPrintView::ExtractoPrintView(Empresa *emp, QWidget *parent = 0)
00045         : QDialog(parent), PEmpresaBase(emp) {
00046     _depura("ExtractoPrintView::ExtractoPrintView", 0);
00047     setupUi(this);
00048     fichero = NULL;
00049     _depura("END ExtractoPrintView::ExtractoPrintView", 0);
00050 }
00051 
00052 
00054 
00056 ExtractoPrintView::~ExtractoPrintView() {
00057     _depura("ExtractoPrintView::~ExtractoPrintView", 0);
00058     _depura("END ExtractoPrintView::~ExtractoPrintView", 0);
00059 }
00060 
00061 
00063 
00065 void ExtractoPrintView::accept() {
00066     _depura("ExtractoPrintView::accept", 0);
00068     if (radiotexto->isChecked()) {
00069         presentar("txt");
00070     } else if (radiohtml->isChecked()) {
00071         presentar("html");
00072     } // end if
00073     _depura("END ExtractoPrintView::accept", 0);
00074 }
00075 
00076 
00078 
00083 QString ExtractoPrintView::montaQuery() {
00084     _depura("ExtractoPrintView::montaQuery", 0);
00085     extractoview1 *extracto = ((Empresa *)empresaBase())->extractoempresa();
00087     QString finicial = extracto->m_fechainicial1->text();
00088     QString ffinal = extracto->m_fechafinal1->text();
00089     QString cinicial = extracto->m_codigoinicial->text();
00090     QString cfinal = extracto->m_codigofinal->text();
00091     QString contra = extracto->mui_codigocontrapartida->text();
00092 
00094     QString tipopunteo;
00095     tipopunteo = "";
00096     if (extracto->mui_punteotodos->isChecked()) {
00097         tipopunteo = "";
00098     } else if (extracto->mui_punteopunteado->isChecked()) {
00099         tipopunteo = " AND apunte.punteo = TRUE ";
00100     } else {
00101         tipopunteo = " AND apunte.punteo = FALSE ";
00102     } // end if
00103     if (contra != "") {
00104         tipopunteo += " AND apunte.contrapartida = id_cuenta('" + contra + "') ";
00105     } // end if
00106 
00107     selectcanalview *scanal = ((Empresa *)empresaBase())->getselcanales();
00108     SelectCCosteView *scoste = ((Empresa *)empresaBase())->getselccostes();
00109     QString ccostes = scoste->cadcoste();
00110     if (ccostes != "") {
00111         ccostes.sprintf(" AND idc_coste IN (%s) ", ccostes.toAscii().constData());
00112     } // end if
00113     QString ccanales = scanal->cadcanal();
00114     if (ccanales != "") {
00115         ccanales.sprintf(" AND idcanal IN (%s) ", ccanales.toAscii().constData());
00116     } // end if
00117     QString tabla;
00118     if (extracto->mui_asAbiertos->isChecked()) {
00119         tabla = "borrador";
00120     } else {
00121         tabla = "apunte";
00122     } // end if
00123 
00124     QString query = "SELECT desccontrapartida, codcontrapartida, " + tabla + ".contrapartida AS contrapartida, ordenasiento, cuenta.descripcion AS descripcion, " + tabla + ".debe AS debe , " + tabla + ".haber AS haber, conceptocontable, idc_coste, codigo, cuenta.descripcion AS desc1, " + tabla + ".fecha AS fecha FROM " + tabla + "";
00125     query += " LEFT JOIN asiento ON " + tabla + ".idasiento = asiento.idasiento ";
00126     query += " LEFT JOIN cuenta ON " + tabla + ".idcuenta = cuenta.idcuenta ";
00127     query += " LEFT JOIN (SELECT codigo AS codcontrapartida, idcuenta as contrapartida, descripcion AS desccontrapartida FROM cuenta) AS t1 ON " + tabla + ".contrapartida = t1.contrapartida ";
00128     query += " WHERE " + tabla + ".idcuenta >= id_cuenta('" + cinicial + "')   AND " + tabla + ".idcuenta <= id_cuenta('" + cfinal + "') ";
00129     query += " AND " + tabla + ".fecha >= '" + finicial + "' AND " + tabla + ".fecha <= '" + ffinal + "'";
00130     query += tipopunteo;
00131     query += ccostes;
00132     query += ccanales;
00133     query += " ORDER BY codigo, fecha";
00134     _depura("END ExtractoPrintView::montaQuery", 0);
00135     return query;
00136 }
00137 
00138 
00140 
00143 void ExtractoPrintView::presentar(char *tipus) {
00144     _depura("ExtractoPrintView::presentar", 0);
00145     int txt, html;
00146     float debe, haber,saldo;
00147     float debeinicial = 0, haberinicial = 0, saldoinicial = 0;
00148     float debefinal, haberfinal, saldofinal;
00149     int idcuenta;
00150     int idasiento;
00151     int contrapartida;
00152     string codcontrapartida;
00153     int activo;
00154     string cad;
00155     cursor2 *cursoraux, *cursoraux1, *cursoraux2, *cursoraux3;
00156     extractoview1 *extracto = ((Empresa *)empresaBase())->extractoempresa();
00157     QString finicial = extracto->m_fechainicial1->text();
00158     QString ffinal = extracto->m_fechafinal1->text();
00159     QString cinicial = extracto->m_codigoinicial->text();
00160     QString cfinal = extracto->m_codigofinal->text();
00161 
00163     txt =! strcmp(tipus,"txt");
00164     html =! strcmp(tipus,"html");
00165 
00166     ofstream fitxersortidatxt("mayor.txt"); 
00167     ofstream fitxersortidahtml("mayor.htm");
00168 
00169     if (!fitxersortidatxt) {
00170         txt = 0; 
00171     } // end if
00172     if (!fitxersortidahtml) {
00173         html = 0; 
00174     } // end if
00176     if (txt | html) {
00177         if (txt) {
00179             fitxersortidatxt.setf(ios::fixed)
00180                 ;
00181             fitxersortidatxt.precision(2);
00182             fitxersortidatxt << "                                    MAYOR \n" ;
00183             fitxersortidatxt << "Fecha Inicial: " << finicial.toAscii().constData() << "   Fecha Final: " << ffinal.toAscii().constData() << endl;
00184             fitxersortidatxt << "_________________________________________________________________________________________________________\n";
00185         } // end if
00186         if (html) {
00188             fitxersortidahtml.setf(ios::fixed)
00189                 ;
00190             fitxersortidahtml.precision(2);
00191             fitxersortidahtml << "<html>\n";
00192             fitxersortidahtml << "<head>\n";
00193             fitxersortidahtml << "  <!DOCTYPE / public \"-//w3c//dtd xhtml 1.0 transitional//en\"\n";
00194             fitxersortidahtml << "    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
00195             fitxersortidahtml << "  <LINK REL=StyleSheet HREF=\"estils.css\" TYPE=\"text/css\" MEDIA=screen>\n";
00196             fitxersortidahtml << "  <title> Major </title>\n";
00197             fitxersortidahtml << "</head>\n";
00198             fitxersortidahtml << "<body>\n";
00199             fitxersortidahtml << "<table><tr><td colspan=\"6\" class=titolmajor> Mayor <hr></td></tr>\n\n";
00200             fitxersortidahtml << "<tr><td colspan=\"6\" class=periodemajor> Fecha Inicial: " << finicial.toAscii().constData() << " -  Fecha Final: " << ffinal.toAscii().constData() << "<hr></td></tr>\n\n";
00201         } // end if
00202         empresaBase()->begin();
00203         cursoraux = empresaBase()->cargacuentascodigo(-1,cinicial, cfinal);
00204         empresaBase()->commit();
00205         while (!cursoraux->eof()) {
00206             idcuenta = atoi(cursoraux->valor("idcuenta").toAscii());
00207             empresaBase()->begin();
00208             cursoraux1 = empresaBase()->cargaapuntesctafecha(idcuenta, finicial.toAscii(), ffinal.toAscii());
00209             empresaBase()->commit();
00210             if (!cursoraux1->eof()) {
00211                 activo = strcmp((char *) cursoraux->valor("activo").toAscii().constData(), "f");
00212                 if (txt) {
00213                     fitxersortidatxt << "\n\n" << setw(12) << cursoraux->valor("codigo").toAscii().constData() << setw(50) << cursoraux->valor("descripcion").toAscii().constData() << endl;
00214                     if (activo) {
00215                         fitxersortidatxt << " Cuenta de activo";
00216                     } else {
00217                         fitxersortidatxt << " Cuenta de pasivo";
00218                     } // end if
00219                 } // end if
00220                 if (html) {
00221                     fitxersortidahtml << "<tr><td colspan=\"6\" class=comptemajor>" << cursoraux->valor("codigo").toAscii().constData() << " "<< cursoraux->valor("descripcion").toAscii().constData() << "</td></tr>\n";
00222                     if (activo) {
00223                         fitxersortidahtml << "<tr><td colspan=\"6\" class=tipuscomptemajor> Cuenta de activo </td></tr>\n";
00224                     } else {
00225                         fitxersortidahtml << "<tr><td colspan=\"6\" class=tipuscomptemajor> Cuenta de pasivo </td></tr>\n";
00226                     } // end if
00227                 } // end if
00228                 empresaBase()->begin();
00229                 cursoraux2 = empresaBase()->cargasaldoscuentafecha(idcuenta, (char *)finicial.toAscii().constData());
00230                 empresaBase()->commit();
00231                 if (!cursoraux2->eof()) {
00232                     debeinicial = atof(cursoraux2->valor("tdebe").toAscii());
00233                     haberinicial = atof(cursoraux2->valor("thaber").toAscii());
00234                     if (activo) {
00235                         saldoinicial = debeinicial - haberinicial;
00236                     } else {
00237                         saldoinicial = haberinicial-debeinicial;
00238                     } // end if
00239 
00240                     if (txt) {
00242                         fitxersortidatxt << "\nAsiento  Fecha   Contrapartida   Descripcion                          Debe         Haber         Saldo\n";
00243                         fitxersortidatxt << "                                                 SUMAS ANTERIORES...   " << setw(10) << debeinicial << setw(10) << haberinicial << setw(10) << saldoinicial << endl;
00244                         fitxersortidatxt << "_________________________________________________________________________________________________________\n";
00245                     } // end if
00246 
00247                     if (html) {
00249                         fitxersortidahtml << "<tr><td class=titolcolumnamajor> Asiento </td><td class=titolcolumnamajor> Fecha </td><td class=titolcolumnamajor> Contrapartida </td><td class=titolcolumnamajor> Descripcion </td><td class=titolcolumnamajor> Debe </td><td class=titolcolumnamajor> Haber </td><td class=titolcolumnamajor> Saldo </td></tr>\n";
00250                         fitxersortidahtml << "<tr><td></td><td></td><td></td><td class=sumamajor> Sumes anteriors...</td><td class=dosdecimals> " << debeinicial << " </td><td class=dosdecimals> " << haberinicial << " </td><td class=dosdecimals> " << saldoinicial << "</td><td>\n";
00251                     } // end if
00252 
00253                     saldo = saldoinicial;
00254                     debefinal = debeinicial;
00255                     haberfinal = haberinicial;
00256 
00257                     for (; !cursoraux1->eof(); cursoraux1->siguienteregistro()) {
00258                         idasiento = atoi(cursoraux1->valor("idasiento").toAscii());
00259                         contrapartida = atoi(cursoraux1->valor("contrapartida").toAscii());
00260                         empresaBase()->begin();
00261                         cursoraux3 = empresaBase()->cargacuenta(contrapartida);
00262                         codcontrapartida = cursoraux3->valor("codigo").toAscii().constData();
00263                         empresaBase()->commit();
00264                         debe = atof(cursoraux1->valor("debe").toAscii());
00265                         haber = atof(cursoraux1->valor("haber").toAscii());
00266                         if (activo) {
00267                             saldo += debe - haber;
00268                         } else {
00269                             saldo += haber - debe;
00270                         } // end if
00271                         debefinal += debe;
00272                         haberfinal += haber;
00273                         cad = cursoraux1->valor("fecha").toAscii().constData();
00275                         if (txt) {
00276                             fitxersortidatxt <<  setw(5) << idasiento << setw(14) << cad.substr(0,10).c_str() << setw(10) << codcontrapartida << "  " << setw(40)  << setiosflags(ios::left) << cursoraux1->valor("conceptocontable").toAscii().constData() << setw(10) << resetiosflags(ios::left) << debe << setw(10) << haber << setw(10) << saldo << endl;
00277                         } // end if
00279                         if (html) {
00280                             fitxersortidahtml << " <tr><td class=assentamentmajor> " << idasiento << " </td><td> " << cad.substr(0,10).c_str() << " </td><td class=contrapartidamajor> " << codcontrapartida << " </td><td> " << cursoraux1->valor("conceptocontable").toAscii().constData() << " </td><td class=dosdecimals> " << debe << " </td><td class=dosdecimals> " << haber << " </td><td class=dosdecimals> " << saldo << " </td></tr>\n ";
00281                         } // end if
00282                         cursoraux3->cerrar();
00283                     } // end for
00284 
00285                     if (activo) {
00286                         saldofinal = debefinal - haberfinal;
00287                     } else {
00288                         saldofinal = haberfinal - debefinal;
00289                     } // end if
00290                     if (txt) {
00292                         fitxersortidatxt << "                                               __________________________________________________________\n";
00293                         fitxersortidatxt << "                                                  TOTAL SUBCUENTA...   " << setw(10) << debefinal << setw(10) << haberfinal << setw(10) << saldofinal << endl;
00294                     } // end if
00295                     if (html) {
00297                         fitxersortidahtml << "<tr><td></td><td></td><td></td><td class=sumamajor> Total subcompte... </td><td class=dosdecimals>" << debefinal << " </td><td class=dosdecimals> " << haberfinal << " </td><td class=dosdecimals> " << saldofinal << "</td></tr>\n\n";
00298                     } // end if
00299                     cursoraux2->cerrar();
00300                 } // end if
00301             }
00302             cursoraux1->cerrar();
00303             cursoraux->siguienteregistro();
00304         } // end while
00305         if (html) {
00307             fitxersortidahtml << "\n</table></body></html>\n";
00308         } // end if
00309         empresaBase()->commit();
00310         delete cursoraux;
00311     }
00312     if (txt) {
00314         fitxersortidatxt.close();
00315         QString cad = confpr->valor(CONF_EDITOR) + " mayor.txt";
00316         system(cad.toAscii().constData());
00317     } // end if
00318     if (html) {
00320         fitxersortidahtml.close();
00321         QString cad = confpr->valor(CONF_NAVEGADOR) + " mayor.html";
00322         system(cad.toAscii().constData());
00323     } // end if
00324     _depura("END ExtractoPrintView::presentar", 0);
00325 }
00326 

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