listado347.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 <errno.h>
00022 #include <QLocale>
00023 #include <QFile>
00024 #include <QTextStream>
00025 
00026 #include "listado347.h"
00027 #include "funcaux.h"
00028 
00029 
00031 
00037 Listado347::Listado347(Empresa *emp, QString ejerActual, QWidget *parent, Qt::WFlags f)
00038         : QDialog(parent, f), PEmpresaBase(emp) {
00039    _depura("Listado347::Listado347", 0);
00040    setupUi(this);
00041    importe->setText("3005.06");
00042    finicial->setText(normalizafecha("01/01/" + ejerActual).toString("dd/MM/yyyy"));
00043    ffinal->setText(normalizafecha("31/12/" + ejerActual).toString("dd/MM/yyyy"));
00045    on_m_boton_recalcular_clicked();
00046    centrarEnPantalla(this);
00047    _depura("END Listado347::Listado347", 0);
00048 }
00049 
00050 
00052 
00054 Listado347::~Listado347() {
00055     _depura("Listado347::~Listado347", 0);
00056     centrarEnPantalla(this);
00057     _depura("END Listado347::~Listado347", 0);
00058 }
00059 
00060 
00062 
00064 void Listado347::on_m_boton_recalcular_clicked() {
00065     _depura("Listado347::click_recargar", 0);
00066 
00067     QLocale::setDefault(QLocale(QLocale::Spanish, QLocale::Spain));
00068     QLocale spanish;
00069 
00071     QString query =  "SELECT codigo, descripcion, cifent_cuenta as cif, cpent_cuenta as cp, importe FROM cuenta ";
00072             query += "INNER JOIN (SELECT idcuenta, sum(apunte.debe) as importe FROM apunte ";
00073             query += "WHERE conceptocontable NOT SIMILAR TO '%(Asiento de Cierre|Asiento de Apertura)%' AND ";
00074             query += "idasiento IN (SELECT idasiento FROM (SELECT idcuenta FROM cuenta ";
00075             query += "WHERE codigo LIKE '4770%') AS iva INNER JOIN apunte USING (idcuenta) ";
00076             query += "WHERE fecha <= '" + ffinal->text() + "' AND fecha >= '" + finicial->text() + "' ";
00077             query += "GROUP BY idasiento) AND idcuenta IN (SELECT idcuenta FROM cuenta ";
00078             query += "WHERE codigo LIKE '4300%') GROUP BY idcuenta) AS facturado USING(idcuenta) ";
00079             query += "WHERE importe > " + importe->text() + " ORDER BY descripcion";
00080 
00081     empresaBase()->begin();
00082     cursor2 *recordSet = empresaBase()->cargacursor(query, "recordSet");
00083     empresaBase()->commit();
00084 
00085     tablaventas->setColumnCount(5);
00086     tablaventas->setRowCount(recordSet->numregistros());
00087     QStringList cabecera;
00088     cabecera  << "codigo" << "descripcion" << "cif/nif" << "cp" << "importe";
00089     tablaventas->setHorizontalHeaderLabels(cabecera);
00090     int i = 0;
00091     QTableWidgetItem *item;
00092     while (!recordSet->eof()) {
00093         item = new QTableWidgetItem(recordSet->valor("codigo"));
00094         tablaventas->setItem(i, 0, item);
00095         item = new QTableWidgetItem(recordSet->valor("descripcion"));
00096         tablaventas->setItem(i, 1, item);
00097         item = new QTableWidgetItem(recordSet->valor("cif"));
00098         tablaventas->setItem(i, 2, item);
00099         item = new QTableWidgetItem(recordSet->valor("cp"));
00100         tablaventas->setItem(i, 3, item);
00101         query = spanish.toString(recordSet->valor("importe").toDouble(), 'f', 2);
00102         item = new QTableWidgetItem(query);
00103         item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
00104         tablaventas->setItem(i, 4, item);
00105         ++i;
00106         recordSet->siguienteregistro();
00107     } // end while
00109     query =  "SELECT codigo, descripcion, cifent_cuenta as cif, cpent_cuenta as cp, importe FROM cuenta ";
00110     query += "INNER JOIN (SELECT idcuenta, sum(apunte.haber) as importe FROM apunte ";
00111     query += "WHERE conceptocontable NOT SIMILAR TO '%(Asiento de Cierre|Asiento de Apertura)%' ";
00112     query += "AND idasiento IN (SELECT idasiento FROM (SELECT idcuenta FROM cuenta ";
00113     query += "WHERE codigo LIKE '4720%') AS iva ";
00114     query += "INNER JOIN apunte USING (idcuenta) ";
00115     query += "WHERE fecha <= '" + ffinal->text() + "' AND fecha >= '" + finicial->text() + "' ";
00116     query += "GROUP BY idasiento) AND idcuenta IN (SELECT idcuenta FROM cuenta ";
00117     query += "WHERE codigo SIMILAR TO '4(0|1)00%') GROUP BY idcuenta) AS facturado USING(idcuenta) ";
00118     query += "WHERE importe > " + importe->text() + " ORDER BY descripcion";
00119 
00120     empresaBase()->begin();
00121     recordSet = empresaBase()->cargacursor(query, "recordSet");
00122     empresaBase()->commit();
00123 
00124     tablacompras->setColumnCount(5);
00125     tablacompras->setRowCount(recordSet->numregistros());
00126     tablacompras->setHorizontalHeaderLabels(cabecera);
00127     i = 0;
00128     while (!recordSet->eof()) {
00129         item = new QTableWidgetItem(recordSet->valor("codigo"));
00130         tablacompras->setItem(i, 0, item);
00131         item = new QTableWidgetItem(recordSet->valor("descripcion"));
00132         tablacompras->setItem(i, 1, item);
00133         item = new QTableWidgetItem(recordSet->valor("cif"));
00134         tablacompras->setItem(i, 2, item);
00135         item = new QTableWidgetItem(recordSet->valor("cp"));
00136         tablacompras->setItem(i, 3, item);
00137         query = spanish.toString(recordSet->valor("importe").toDouble(), 'f', 2);
00138         item = new QTableWidgetItem(query);
00139         item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
00140         tablacompras->setItem(i, 4, item);
00141         ++i;
00142         recordSet->siguienteregistro();
00143     } // end while
00144     tablacompras->resizeColumnsToContents();
00145     tablaventas->resizeColumnsToContents();
00146 
00147     QLocale::setDefault(QLocale::C);
00148 
00149     _depura("END Listado347::click_recargar", 0);
00150 }
00151 
00152 
00154 
00156 void Listado347::on_m_boton_imprimir_clicked() {
00157     _depura("Listado347::click_imprimir", 0);
00158     int i, numventas, numcompras;
00159     QString codigo, descripcion, cif, importe, cp;
00160     QFile fichero(confpr->valor(CONF_DIR_USER)+"listado347.txt");
00161     if (fichero.open(QIODevice::WriteOnly | QIODevice::Text)) {
00162     QTextStream listado(&fichero);
00163         listado << "LISTADO 347\n";
00164         listado << "\nCuenta     Deudor                         CIF/NIF     CP  Importe\n";
00165         listado << "________________________________________________________________________________________\n";
00166         numventas = tablaventas->rowCount();
00167         for (i = 0; i < numventas; i++) {
00168             codigo = tablaventas->item(i, 0)->text();
00169             descripcion = tablaventas->item(i, 1)->text();
00170             cif = tablaventas->item(i, 2)->text();
00171             cp = tablaventas->item(i, 3)->text();
00172             importe = tablaventas->item(i, 4)->text();
00173             listado << qSetFieldWidth(9) << left << codigo.toAscii().constData() << qSetFieldWidth(50) << descripcion.toAscii().constData() << qSetFieldWidth(11) << cif.toAscii().constData() << qSetFieldWidth(6) << cp.toAscii().constData() << qSetFieldWidth(12) << right << importe.toAscii() << endl;
00174         } // end for
00175         numcompras = tablacompras->rowCount();
00176         listado << "\nCuenta     Acreedor                       CIF/NIF     CP  Importe\n";
00177         listado << "________________________________________________________________________________________\n";
00178         numcompras = tablacompras->rowCount();
00179         for (i = 0; i < numcompras; i++) {
00180             codigo = tablacompras->item(i, 0)->text();
00181             descripcion = tablacompras->item(i, 1)->text();
00182             cif = tablacompras->item(i, 2)->text();
00183             cp = tablacompras->item(i, 3)->text();
00184             importe = tablacompras->item(i, 4)->text();
00185             listado << qSetFieldWidth(9) << left << codigo.toAscii().constData() << qSetFieldWidth(50) << descripcion.toAscii().constData() << qSetFieldWidth(11) << cif.toAscii().constData() << qSetFieldWidth(6) << cp.toAscii().constData() << qSetFieldWidth(12) << right << importe.toAscii() << endl;
00186         } // end for
00187         fichero.close();
00188     } // end if
00189     QString comando = confpr->valor(CONF_EDITOR).toAscii() + " " + fichero.fileName();
00190     system(comando.toAscii().constData());
00191 
00192     _depura("END Listado347::click_imprimir", 0);
00193 }
00194 
00195 
00197 
00199 void Listado347::on_finicial_editingFinished() {
00200     _depura("Listado347::finicial_exit", 0);
00201     finicial->setText(normalizafecha(finicial->text()).toString("dd/MM/yyyy"));
00202     _depura("END Listado347::finicial_exit", 0);
00203 }
00204 
00205 
00207 
00209 void Listado347::on_ffinal_editingFinished(){
00210     _depura("Listado347::ffinal_exit", 0);
00211     ffinal->setText(normalizafecha(ffinal->text()).toString("dd/MM/yyyy"));
00212     _depura("END Listado347::ffinal_exit", 0);
00213 }
00214 

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