informereferencia.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Tomeu Borras Riera                              *
00003  *   tborras@conetxia.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 <QString>
00022 #include <QFile>
00023 #include <QTextStream>
00024 
00025 #include "informereferencia.h"
00026 #include "company.h"
00027 #include "postgresiface2.h"
00028 #include "funcaux.h"
00029 
00030 
00032 
00035 InformeReferencia::InformeReferencia(Company *comp) {
00036     _depura("InformeReferencia::InformeReferencia", 0);
00037     companyact = comp;
00038     _depura("END InformeReferencia::InformeReferencia", 0);
00039 }
00040 
00041 
00043 
00045 InformeReferencia::~InformeReferencia() {
00046     _depura("InformeReferencia::~InformeReferencia", 0);
00047     _depura("END InformeReferencia::~InformeReferencia", 0);
00048 }
00049 
00050 
00052 
00055 void InformeReferencia::setreferencia(QString val) {
00056         _depura("InformeReferencia::setreferencia", 0, val);
00057         m_referencia = val;
00058         _depura("END InformeReferencia::setreferencia", 0, val);
00059 }
00060 
00062 
00064 void InformeReferencia::generarinforme() {
00065     _depura("InformeReferencia::generarinforme", 0);
00066     QString archivo = confpr->valor(CONF_DIR_OPENREPORTS) + "informereferencia.rml";
00067     QString archivod = confpr->valor(CONF_DIR_USER) + "informereferencia.rml";
00068     QString archivologo = confpr->valor(CONF_DIR_OPENREPORTS) + "logo.jpg";
00070 #ifdef WINDOWS
00071 
00072     archivo = "copy " + archivo + " " + archivod;
00073 #else
00074 
00075     archivo = "cp " + archivo + " " + archivod;
00076 #endif
00077 
00078     system(archivo.toAscii().constData());
00080 #ifdef WINDOWS
00081 
00082     archivologo = "copy " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00083 #else
00084 
00085     archivologo = "cp " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00086 #endif
00087 
00088     QFile file;
00089     file.setFileName(archivod);
00090     file.open(QIODevice::ReadOnly);
00091     QTextStream stream(&file);
00092     QString buff = stream.readAll();
00093     file.close();
00094     QString fitxersortidatxt = "";
00095 
00096     buff.replace("[referencia]", m_referencia);
00097 
00098     QString SQLQuery = "SELECT * FROM cliente WHERE idcliente IN (";
00099     SQLQuery += "SELECT idcliente FROM presupuesto WHERE refpresupuesto = '" + m_referencia + "'";
00100     SQLQuery += "UNION SELECT idcliente FROM pedidocliente   WHERE refpedidocliente = '" + m_referencia + "'";
00101     SQLQuery += "UNION SELECT idcliente FROM albaran         WHERE refalbaran       = '" + m_referencia + "'";
00102     SQLQuery += "UNION SELECT idcliente FROM factura         WHERE reffactura       = '" + m_referencia + "'";
00103     SQLQuery += "UNION SELECT idcliente FROM pedidoproveedor WHERE refpedidoproveedor = '" + m_referencia + "'";
00104     SQLQuery += "UNION SELECT idcliente FROM albaranp        WHERE refalbaranp = '" + m_referencia + "'";
00105     SQLQuery += "UNION SELECT idcliente FROM facturap        WHERE reffacturap = '" + m_referencia + "'";
00106     SQLQuery += "UNION SELECT idcliente FROM cobro           WHERE refcobro    = '" + m_referencia + "'";
00107     SQLQuery += "UNION SELECT idcliente FROM pago            WHERE refpago    = '" + m_referencia + "'";
00108     SQLQuery += ")";  
00109     cursor2 *cur = companyact->cargacursor(SQLQuery);
00110     while (!cur->eof() ) {
00111         buff.replace("[nomcliente]", cur->valor("nomcliente"));
00112         buff.replace("[telcliente]", cur->valor("telcliente"));
00113         buff.replace("[dircliente]", cur->valor("dircliente"));
00114         buff.replace("[poblcliente]", cur->valor("poblcliente"));
00115         cur->siguienteregistro();
00116     } // end while
00117     delete cur;
00118 
00120     fitxersortidatxt = "<spacer length=\"15\"/>";
00121     fitxersortidatxt += "<para>Resumen de ventas por articulo</para>\n";
00122     fitxersortidatxt += "<blockTable style=\"tablaresumen\" colWidths=\"7cm, 3cm, 3cm, 3cm, 3cm\" repeatRows=\"1\">\n";
00123     fitxersortidatxt += "<tr>\n";
00124     fitxersortidatxt += "       <td>" + QApplication::translate("InformeReferencia", "Articulo") + "</td>\n";
00125     fitxersortidatxt += "       <td>" + QApplication::translate("InformeReferencia", "Pres.") + "</td>\n";
00126     fitxersortidatxt += "       <td>" + QApplication::translate("InformeReferencia", "Pedido") + "</td>\n";
00127     fitxersortidatxt += "       <td>" + QApplication::translate("InformeReferencia", "Entregado") + "</td>\n";
00128     fitxersortidatxt += "       <td>" + QApplication::translate("InformeReferencia", "Facturado") + "</td>\n";
00129     fitxersortidatxt += "</tr>\n";
00130 
00131     SQLQuery = " SELECT * FROM articulo ";
00132     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlpresupuesto) AS cantlpresupuestot  FROM lpresupuesto WHERE idpresupuesto IN (SELECT idpresupuesto FROM presupuesto WHERE refpresupuesto = '" + m_referencia + "') GROUP BY idarticulo) AS t1 ON t1.idarticulo = articulo.idarticulo ";
00133     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlpedidocliente) AS cantlpedidoclientet  FROM lpedidocliente WHERE idpedidocliente IN (SELECT idpedidocliente FROM pedidocliente WHERE refpedidocliente = '" + m_referencia + "') GROUP BY idarticulo) AS t2 ON t2.idarticulo = articulo.idarticulo ";
00134     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlalbaran) AS cantlalbarant  FROM lalbaran WHERE idalbaran IN (SELECT idalbaran FROM albaran WHERE refalbaran = '" + m_referencia + "') GROUP BY idarticulo) AS t3 ON t3.idarticulo = articulo.idarticulo ";
00135     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlfactura) AS cantlfacturat  FROM lfactura WHERE idfactura IN (SELECT idfactura FROM factura WHERE reffactura = '" + m_referencia + "') GROUP BY idarticulo) AS t4 ON t4.idarticulo = articulo.idarticulo ";
00136     SQLQuery += " WHERE  (cantlpresupuestot <>0 OR cantlpedidoclientet <> 0 OR cantlalbarant <> 0 OR cantlfacturat <> 0) ";
00137 
00138     cur = companyact->cargacursor(SQLQuery);
00139     while (!cur->eof() ) {
00140         fitxersortidatxt += "<tr>\n";
00141         fitxersortidatxt += "    <td>" + cur->valor("nomarticulo") + "</td>\n";
00142         fitxersortidatxt += "    <td>" + cur->valor("cantlpresupuestot") + "</td>\n";
00143         fitxersortidatxt += "    <td>" + cur->valor("cantlpedidoclientet") + "</td>\n";
00144         fitxersortidatxt += "    <td>" + cur->valor("cantlalbarant") + "</td>\n";
00145         fitxersortidatxt += "    <td>" + cur->valor("cantlfacturat") + "</td>\n";
00146         fitxersortidatxt += "</tr>\n";
00147         cur->siguienteregistro();
00148     } // end while
00149     delete cur;
00150 
00151     fitxersortidatxt += "</blockTable>\n";
00152 
00153     buff.replace("[referencia]", m_referencia);
00154 
00155     fitxersortidatxt += "<spacer length=\"15\"/>";
00156     fitxersortidatxt += "<para>Resumen de compras por articulo</para>\n";
00158     fitxersortidatxt += "<blockTable style=\"tablaresumen\" colWidths=\"10cm, 3cm, 3cm, 3cm\" repeatRows=\"1\">\n";
00159     fitxersortidatxt += "<tr>\n";
00160     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Articulo") + "</td>\n";
00161     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Pedido") + "</td>\n";
00162     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Entregado") + "</td>\n";
00163     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Facturado") + "</td>\n";
00164     fitxersortidatxt += "</tr>\n";
00165 
00166     SQLQuery = " SELECT * FROM articulo ";
00167     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlpedidoproveedor) AS cantlpedidoproveedort FROM lpedidoproveedor WHERE idpedidoproveedor IN (SELECT idpedidoproveedor FROM pedidoproveedor WHERE refpedidoproveedor = '" + m_referencia + "') GROUP BY idarticulo) AS t2 ON t2.idarticulo = articulo.idarticulo ";
00168 
00169     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlalbaranp) AS cantlalbaranpt FROM lalbaranp WHERE idalbaranp IN (SELECT idalbaranp FROM albaranp WHERE refalbaranp = '" + m_referencia + "') GROUP BY idarticulo) AS t3 ON t3.idarticulo = articulo.idarticulo ";
00170 
00171     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlfacturap) AS cantlfacturapt FROM lfacturap WHERE idfacturap IN (SELECT idfacturap FROM facturap WHERE reffacturap = '" + m_referencia + "') GROUP BY idarticulo) AS t4 ON t4.idarticulo = articulo.idarticulo ";
00172     SQLQuery += " WHERE  ( cantlpedidoproveedort <> 0 OR cantlalbaranpt <> 0 OR cantlfacturapt <> 0) ";
00173 
00174     fprintf(stdout,"%s\n",SQLQuery.toAscii().constData());
00175 
00176     cur = companyact->cargacursor(SQLQuery);
00177     while (!cur->eof() ) {
00178         fitxersortidatxt += "<tr>\n";
00179         fitxersortidatxt += "<td>" + cur->valor("nomarticulo") + "</td>\n";
00180         fitxersortidatxt += "<td>" + cur->valor("cantlpedidoproveedort") + "</td>\n";
00181         fitxersortidatxt += "<td>" + cur->valor("cantlalbaranpt") + "</td>\n";
00182         fitxersortidatxt += "<td>" + cur->valor("cantlfacturapt") + "</td>\n";
00183         fitxersortidatxt += "</tr>\n";
00184         cur->siguienteregistro();
00185     } // end while
00186     delete cur;
00187 
00188     fitxersortidatxt += "</blockTable>\n";
00189 
00190     buff.replace("[story]", fitxersortidatxt);
00191 
00192     fitxersortidatxt = "<spacer length=\"15\"/>";
00194     fitxersortidatxt += "<para>Totales ventas</para>\n";
00195     fitxersortidatxt += "<blockTable style=\"tablatotales\" colWidths=\"3cm, 3cm, 3cm, 3cm, 3cm\" repeatRows=\"1\">\n";
00196     fitxersortidatxt += "<tr>\n";
00197     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Pres.") + "</td>\n";
00198     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Pedido") + "</td>\n";
00199     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Entregado") + "</td>\n";
00200     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Facturado") + "</td>\n";
00201     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Cobrado") + "</td>\n";
00202     fitxersortidatxt += "</tr>\n";
00203 
00205     fitxersortidatxt += "<tr>\n";
00206 
00208     SQLQuery = "SELECT SUM(totalpresupuesto) AS tpres FROM presupuesto WHERE refpresupuesto='" + m_referencia + "' ";
00209     cur = companyact->cargacursor(SQLQuery);
00210     fitxersortidatxt += "    <td>" + cur->valor("tpres") + "</td>\n";
00211     delete cur;
00212 
00214     SQLQuery = "SELECT SUM(totalpedidocliente) AS tpedcli FROM pedidocliente WHERE refpedidocliente='" + m_referencia + "' ";
00215     cur = companyact->cargacursor(SQLQuery);
00216     fitxersortidatxt += "    <td>" + cur->valor("tpedcli") + "</td>\n";
00217     delete cur;
00218 
00220     SQLQuery = "SELECT SUM(totalalbaran) AS talb FROM albaran WHERE refalbaran='" + m_referencia + "' ";
00221     cur = companyact->cargacursor(SQLQuery);
00222     fitxersortidatxt += "    <td>" + cur->valor("talb") + "</td>\n";
00223     delete cur;
00224 
00226     SQLQuery = "SELECT SUM(totalfactura) AS tfact FROM factura WHERE reffactura='" + m_referencia + "' ";
00227     cur = companyact->cargacursor(SQLQuery);
00228     fitxersortidatxt += "    <td>" + cur->valor("tfact") + "</td>\n";
00229     delete cur;
00230 
00232     SQLQuery = "SELECT SUM(cantcobro) AS tcobro FROM cobro WHERE refcobro = '" + m_referencia + "'";
00233     cur = companyact->cargacursor(SQLQuery);
00234     fitxersortidatxt += "     <td>" + cur->valor("tcobro") + "</td>\n";
00235     delete cur;
00236 
00237     fitxersortidatxt += "</tr>\n";
00238     fitxersortidatxt += "</blockTable>\n";
00239 
00240     fitxersortidatxt += "<spacer length=\"15\"/>";
00242     fitxersortidatxt += "<para>Totales compras</para>\n";
00243     fitxersortidatxt += "<blockTable style=\"tablatotales\" colWidths=\" 4cm, 4cm, 4cm, 3cm\" repeatRows=\"1\">\n";
00244     fitxersortidatxt += "<tr>\n";
00245     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Pedido") + "</td>\n";
00246     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Entregado") + "</td>\n";
00247     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Facturado") + "</td>\n";
00248     fitxersortidatxt += "    <td>" + QApplication::translate("InformeReferencia", "Pagado") + "</td>\n";
00249     fitxersortidatxt += "</tr>\n";
00250 
00252     fitxersortidatxt += "<tr>\n";
00253 
00255     SQLQuery = "SELECT SUM(totalpedidoproveedor) AS tpedpro FROM pedidoproveedor WHERE refpedidoproveedor='" + m_referencia + "' ";
00256     cur = companyact->cargacursor(SQLQuery);
00257     fitxersortidatxt += "    <td>" + cur->valor("tpedpro") + "</td>\n";
00258     delete cur;
00259 
00261     SQLQuery = "SELECT SUM(totalalbaranp) AS talbp FROM albaranp WHERE refalbaranp='" + m_referencia + "' ";
00262     cur = companyact->cargacursor(SQLQuery);
00263     fitxersortidatxt += "    <td>" + cur->valor("talbp") + "</td>\n";
00264     delete cur;
00265 
00267     SQLQuery = "SELECT SUM(totalfacturap) AS tfactp FROM facturap WHERE reffacturap = '" + m_referencia + "' ";
00268     cur = companyact->cargacursor(SQLQuery);
00269     fitxersortidatxt += "    <td>" + cur->valor("tfactp") + "</td>\n";
00270     delete cur;
00271 
00273     SQLQuery = "SELECT SUM(cantpago) AS tpago FROM pago WHERE refpago = '" + m_referencia + "'";
00274     cur = companyact->cargacursor(SQLQuery);
00275     fitxersortidatxt += "     <td>" + cur->valor("tpago") + "</td>\n";
00276     delete cur;
00277 
00278     fitxersortidatxt += "</tr>\n";
00279     fitxersortidatxt += "</blockTable>\n";
00280 
00281     buff.replace("[totales]", fitxersortidatxt);
00282 
00283     if (file.open(QIODevice::WriteOnly)) {
00284         QTextStream stream(&file);
00285         stream << buff;
00286         file.close();
00287     } // end if
00288     invocaPDF("informereferencia");
00289     _depura("END InformeReferencia::generarinforme", 0);
00290 }
00291 
00292 
00296 
00299 InformeCliente::InformeCliente(Company *comp) {
00300     _depura("InformeCliente::InformeCliente", 0);
00301     companyact = comp;
00302     _depura("END InformeCliente::InformeCliente", 0);
00303 }
00304 
00305 
00307 
00309 InformeCliente::~InformeCliente() {
00310     _depura("InformeCliente::~InformeCliente", 0);
00311     _depura("END InformeCliente::~InformeCliente", 0);
00312 }
00313 
00314 
00316 
00319 void InformeCliente::setCliente(QString val) {
00320     _depura("InformeCliente::setCliente", 0);
00321         m_idcliente = val;
00322     _depura("END InformeCliente::setCliente", 0);
00323 }
00324 
00325 
00327 
00329 void InformeCliente::generarInforme() {
00330     _depura("InformeCliente::generarInforme", 0);
00331     QString archivo = confpr->valor(CONF_DIR_OPENREPORTS) + "informecliente.rml";
00332     QString archivod = confpr->valor(CONF_DIR_USER) + "informecliente.rml";
00333     QString archivologo = confpr->valor(CONF_DIR_OPENREPORTS) + "logo.jpg";
00335 #ifdef WINDOWS
00336 
00337     archivo = "copy " + archivo + " " + archivod;
00338 #else
00339 
00340     archivo = "cp " + archivo + " " + archivod;
00341 #endif
00342 
00343     system(archivo.toAscii().constData());
00345 #ifdef WINDOWS
00346 
00347     archivologo = "copy " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00348 #else
00349 
00350     archivologo = "cp " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00351 #endif
00352 
00353     QFile file;
00354     file.setFileName(archivod);
00355     file.open(QIODevice::ReadOnly);
00356     QTextStream stream(&file);
00357     QString buff = stream.readAll();
00358     file.close();
00359     QString fitxersortidatxt = "";
00360 
00362     QString SQLQuery = "SELECT * FROM cliente WHERE idcliente = " + m_idcliente;
00363     cursor2 *cur = companyact->cargacursor(SQLQuery);
00364     while (!cur->eof() ) {
00365         buff.replace("[nomcliente]", cur->valor("nomcliente"));
00366         buff.replace("[telcliente]", cur->valor("telcliente"));
00367         buff.replace("[dircliente]", cur->valor("dircliente"));
00368         buff.replace("[poblcliente]", cur->valor("poblcliente"));
00369         cur->siguienteregistro();
00370     } // end while
00371     delete cur;
00372 
00374     QString referencias = "(";
00375     QString coma = "";
00376     SQLQuery = "SELECT refpresupuesto AS referencia FROM presupuesto WHERE idcliente = " + m_idcliente;
00377     SQLQuery += " UNION SELECT refpedidocliente AS referencia FROM pedidocliente WHERE idcliente = " + m_idcliente;
00378     SQLQuery += " UNION SELECT refalbaran FROM albaran AS referencia WHERE idcliente = " + m_idcliente;
00379     SQLQuery += " UNION SELECT reffactura FROM factura AS referencia WHERE idcliente = " + m_idcliente;
00380     SQLQuery += " UNION SELECT refcobro   FROM cobro   AS referencia WHERE idcliente = " + m_idcliente;
00381     cur = companyact->cargacursor(SQLQuery);
00382     if (cur->eof()) {
00383         delete cur;
00384         return;
00385     } // end if
00386     while (!cur->eof() ) {
00387         referencias += coma + "'" + cur->valor("referencia") + "' ";
00388         coma = ",";
00389         cur->siguienteregistro();
00390     } 
00391     delete cur;
00392     referencias += ")";
00393 
00395     fitxersortidatxt = "<spacer length=\"15\"/>";
00396     fitxersortidatxt += "<para>Resumen de ventas por articulo</para>\n";
00397     fitxersortidatxt += "<blockTable style=\"tablaresumen\" colWidths=\"9cm, 2.5cm, 2.5cm, 2.5cm, 2.5cm\" repeatRows=\"1\">\n";
00398     fitxersortidatxt += "<tr>\n";
00399     fitxersortidatxt += "       <td>" + QApplication::translate("InformeCliente", "Articulo") + "</td>\n";
00400     fitxersortidatxt += "       <td>" + QApplication::translate("InformeCliente", "Pres.") + "</td>\n";
00401     fitxersortidatxt += "       <td>" + QApplication::translate("InformeCliente", "Pedido") + "</td>\n";
00402     fitxersortidatxt += "       <td>" + QApplication::translate("InformeCliente", "Entregado") + "</td>\n";
00403     fitxersortidatxt += "       <td>" + QApplication::translate("InformeCliente", "Facturado") + "</td>\n";
00404     fitxersortidatxt += "</tr>\n";
00405 
00406     SQLQuery = " SELECT * FROM articulo ";
00407     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlpresupuesto) AS cantlpresupuestot FROM lpresupuesto WHERE idpresupuesto IN (SELECT idpresupuesto FROM presupuesto WHERE refpresupuesto IN " + referencias + ") GROUP BY idarticulo) AS t1 ON t1.idarticulo = articulo.idarticulo ";
00408     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlpedidocliente) AS cantlpedidoclientet FROM lpedidocliente WHERE idpedidocliente IN (SELECT idpedidocliente FROM pedidocliente WHERE refpedidocliente IN " + referencias + ") GROUP BY idarticulo) AS t2 ON t2.idarticulo = articulo.idarticulo ";
00409     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlalbaran) AS cantlalbarant FROM lalbaran WHERE idalbaran IN (SELECT idalbaran FROM albaran WHERE refalbaran IN " + referencias + ") GROUP BY idarticulo) AS t3 ON t3.idarticulo = articulo.idarticulo ";
00410     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlfactura) AS cantlfacturat FROM lfactura WHERE idfactura IN (SELECT idfactura FROM factura WHERE reffactura IN " + referencias + ") GROUP BY idarticulo) AS t4 ON t4.idarticulo = articulo.idarticulo ";
00411     SQLQuery += " WHERE (cantlpresupuestot <> 0 OR cantlpedidoclientet <> 0 OR cantlalbarant <> 0 OR cantlfacturat <> 0) ";
00412     cur = companyact->cargacursor(SQLQuery);
00413     while (!cur->eof() ) {
00414         fitxersortidatxt += "<tr>\n";
00415         fitxersortidatxt += "<td>" + cur->valor("nomarticulo") + "</td>\n";
00416         fitxersortidatxt += "<td>" + cur->valor("cantlpresupuestot") + "</td>\n";
00417         fitxersortidatxt += "<td>" + cur->valor("cantlpedidoclientet") + "</td>\n";
00418         fitxersortidatxt += "<td>" + cur->valor("cantlalbarant") + "</td>\n";
00419         fitxersortidatxt += "<td>" + cur->valor("cantlfacturat") + "</td>\n";
00420         fitxersortidatxt += "</tr>\n";
00421         cur->siguienteregistro();
00422     } // end while
00423     delete cur;
00424 
00425     fitxersortidatxt += "</blockTable>\n";
00426 
00428     fitxersortidatxt += "<spacer length=\"15\"/>";
00429     fitxersortidatxt += "<para>Resumen de compras por articulo</para>\n";
00430     fitxersortidatxt += "<blockTable style=\"tablaresumen\" colWidths=\"10cm, 3cm, 3cm, 3cm\" repeatRows=\"1\">\n";
00431     fitxersortidatxt += "<tr>\n";
00432     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Articulo") + "</td>\n";
00433     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Pedido") + "</td>\n";
00434     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Entregado") + "</td>\n";
00435     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Facturado") + "</td>\n";
00436     fitxersortidatxt += "</tr>\n";
00437 
00438     SQLQuery = " SELECT * FROM articulo ";
00439     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlpedidoproveedor) AS cantlpedidoproveedort  FROM lpedidoproveedor WHERE idpedidoproveedor IN (SELECT idpedidoproveedor FROM pedidoproveedor WHERE refpedidoproveedor IN " + referencias + ") GROUP BY idarticulo) AS t2 ON t2.idarticulo = articulo.idarticulo ";
00440 
00441     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlalbaranp) AS cantlalbaranpt  FROM lalbaranp WHERE idalbaranp IN (SELECT idalbaranp FROM albaranp WHERE refalbaranp IN " + referencias + ") GROUP BY idarticulo) AS t3 ON t3.idarticulo = articulo.idarticulo ";
00442 
00443     SQLQuery += " LEFT JOIN (SELECT idarticulo, SUM(cantlfacturap) AS cantlfacturapt  FROM lfacturap WHERE idfacturap IN (SELECT idfacturap FROM facturap WHERE reffacturap IN " + referencias + ") GROUP BY idarticulo) AS t4 ON t4.idarticulo = articulo.idarticulo ";
00444     SQLQuery += " WHERE  ( cantlpedidoproveedort <> 0 OR cantlalbaranpt <> 0 OR cantlfacturapt <> 0) ";
00445 
00446     fprintf(stdout,"%s\n",SQLQuery.toAscii().constData());
00447 
00448     cur = companyact->cargacursor(SQLQuery);
00449     while (!cur->eof() ) {
00450         fitxersortidatxt += "<tr>\n";
00451         fitxersortidatxt += "    <td>" + cur->valor("nomarticulo") + "</td>\n";
00452         fitxersortidatxt += "    <td>" + cur->valor("cantlpedidoproveedort") + "</td>\n";
00453         fitxersortidatxt += "    <td>" + cur->valor("cantlalbaranpt") + "</td>\n";
00454         fitxersortidatxt += "    <td>" + cur->valor("cantlfacturapt") + "</td>\n";
00455         fitxersortidatxt += "</tr>\n";
00456         cur->siguienteregistro();
00457     } // end while
00458     delete cur;
00459 
00460     fitxersortidatxt += "</blockTable>\n";
00461 
00462 
00463     buff.replace("[story]", fitxersortidatxt);
00464 
00465     fitxersortidatxt = "<spacer length=\"15\"/>";
00467     fitxersortidatxt += "<para>Totales ventas</para>\n";
00468     fitxersortidatxt += "<blockTable style=\"tablatotales\" colWidths=\"3cm, 3cm, 3cm, 3cm, 3cm\" repeatRows=\"1\">\n";
00469     fitxersortidatxt += "<tr>\n";
00470     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Pres.") + "</td>\n";
00471     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Pedido") + "</td>\n";
00472     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Entregado") + "</td>\n";
00473     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Facturado") + "</td>\n";
00474     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Cobrado") + "</td>\n";
00475     fitxersortidatxt += "</tr>\n";
00476 
00478     fitxersortidatxt += "<tr>\n";
00479 
00481     SQLQuery = "SELECT SUM(totalpresupuesto) AS tpres FROM presupuesto WHERE refpresupuesto IN " + referencias;
00482     cur = companyact->cargacursor(SQLQuery);
00483     fitxersortidatxt += "    <td>" + cur->valor("tpres") + "</td>\n";
00484     delete cur;
00485 
00487     SQLQuery = "SELECT SUM(totalpedidocliente) AS tpedcli FROM pedidocliente WHERE refpedidocliente IN " + referencias;
00488     cur = companyact->cargacursor(SQLQuery);
00489     fitxersortidatxt += "    <td>" + cur->valor("tpedcli") + "</td>\n";
00490     delete cur;
00491 
00493     SQLQuery = "SELECT SUM(totalalbaran) AS talb FROM albaran WHERE refalbaran IN " + referencias;
00494     cur = companyact->cargacursor(SQLQuery);
00495     fitxersortidatxt += "    <td>" + cur->valor("talb") + "</td>\n";
00496     delete cur;
00497 
00499     SQLQuery = "SELECT SUM(totalfactura) AS tfact FROM factura WHERE reffactura IN " + referencias;
00500     cur = companyact->cargacursor(SQLQuery);
00501     fitxersortidatxt += "    <td>" + cur->valor("tfact") + "</td>\n";
00502     delete cur;
00503 
00505     SQLQuery = "SELECT SUM(cantcobro) AS tcobro FROM cobro WHERE refcobro IN " + referencias;
00506     cur = companyact->cargacursor(SQLQuery);
00507     fitxersortidatxt += "     <td>" + cur->valor("tcobro") + "</td>\n";
00508     delete cur;
00509 
00510     fitxersortidatxt += "</tr>\n";
00511     fitxersortidatxt += "</blockTable>\n";
00512 
00513     fitxersortidatxt += "<spacer length=\"15\"/>";
00515     fitxersortidatxt += "<para>Totales compras</para>\n";
00516     fitxersortidatxt += "<blockTable style=\"tablatotales\" colWidths=\" 4cm, 4cm, 4cm, 3cm\" repeatRows=\"1\">\n";
00517     fitxersortidatxt += "<tr>\n";
00518     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Pedido") + "</td>\n";
00519     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Entregado") + "</td>\n";
00520     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Facturado") + "</td>\n";
00521     fitxersortidatxt += "    <td>" + QApplication::translate("InformeCliente", "Pagado") + "</td>\n";
00522     fitxersortidatxt += "</tr>\n";
00523 
00525     fitxersortidatxt += "<tr>\n";
00526 
00528     SQLQuery = "SELECT SUM(totalpedidoproveedor) AS tpedpro FROM pedidoproveedor WHERE refpedidoproveedor IN " + referencias;
00529     cur = companyact->cargacursor(SQLQuery);
00530     fitxersortidatxt += "    <td>" + cur->valor("tpedpro") + "</td>\n";
00531     delete cur;
00532 
00534     SQLQuery = "SELECT SUM(totalalbaranp) AS talbp FROM albaranp WHERE refalbaranp IN " + referencias;
00535     cur = companyact->cargacursor(SQLQuery);
00536     fitxersortidatxt += "    <td>" + cur->valor("talbp") + "</td>\n";
00537     delete cur;
00538 
00540     SQLQuery = "SELECT SUM(totalfacturap) AS tfactp FROM facturap WHERE reffacturap IN " + referencias;
00541     cur = companyact->cargacursor(SQLQuery);
00542     fitxersortidatxt += "    <td>" + cur->valor("tfactp") + "</td>\n";
00543     delete cur;
00544 
00546     SQLQuery = "SELECT SUM(cantpago) AS tpago FROM pago WHERE refpago IN " + referencias;
00547     cur = companyact->cargacursor(SQLQuery);
00548     fitxersortidatxt += "     <td>" + cur->valor("tpago") + "</td>\n";
00549     delete cur;
00550 
00551     fitxersortidatxt += "</tr>\n";
00552     fitxersortidatxt += "</blockTable>\n";
00553 
00554 
00555     buff.replace("[totales]", fitxersortidatxt);
00556 
00557 
00558     if (file.open(QIODevice::WriteOnly)) {
00559         QTextStream stream(&file);
00560         stream << buff;
00561         file.close();
00562     } // end if
00563     invocaPDF("informecliente");
00564     _depura("END InformeCliente::generarInforme", 0);
00565 }
00566 
00567 

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