fichabf.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 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 <QFile>
00022 #include <QTextStream>
00023 
00024 #include "fichabf.h"
00025 #include "plugins.h"
00026 
00027 
00028 class Fixed;
00029 
00030 
00032 
00038 FichaBf::FichaBf(Company *comp, QWidget *parent, Qt::WFlags f, edmode modo)
00039         : Ficha(comp, parent, f, modo) {
00040     _depura("FichaBf::FichaBf", 0);
00041     m_listalineas = NULL;
00042     m_listadescuentos = NULL;
00043     _depura("END FichaBf::FichaBf", 0);
00044 }
00045 
00046 
00048 
00051 FichaBf::~FichaBf() {
00052     _depura("FichaBf::~FichaBf", 0, this->windowTitle());
00053     empresaBase()->sacaWindow(this);
00054     _depura("END FichaBf::~FichaBf", 0);
00055 }
00056 
00057 
00059 
00062 Company * FichaBf::empresaBase() {
00063     _depura("FichaBf::getcompany", 0);
00064     _depura("END FichaBf::getcompany", 0);
00065     return (Company *) Ficha::empresaBase();
00066 }
00067 
00068 
00075 void FichaBf::calculaypintatotales() {
00076     _depura("FichaBf::calculaypintatotales", 0);
00077     base basesimp;
00078     base basesimpreqeq;
00079     SDBRecord *linea;
00081     QString l;
00082     Fixed irpf("0");
00083 
00084     cursor2 *cur = empresaBase()->cargacursor("SELECT * FROM configuracion WHERE nombre = 'IRPF'");
00085     if (cur) {
00086         if (!cur->eof()) {
00087             irpf = Fixed(cur->valor("valor"));
00088         } // end if
00089         delete cur;
00090     } // end if
00091 
00092     if (exists("idproveedor") && DBvalue("idproveedor") != "") {
00093         cur = empresaBase()->cargacursor("SELECT irpfproveedor FROM proveedor WHERE idproveedor = " + DBvalue("idproveedor"));
00094         if (cur) {
00095             if (!cur->eof()) {
00096                 irpf = Fixed(cur->valor("irpfproveedor"));
00097             } // end if
00098             delete cur;
00099         } // end if
00100     } // end if
00101 
00102     Fixed descuentolinea("0.00");
00103     for (int i = 0; i < m_listalineas->rowCount(); ++i) {
00104         linea = m_listalineas->lineaat(i);
00105         Fixed cant(linea->DBvalue("cant" + m_listalineas->tableName()).toAscii().constData());
00106         Fixed pvpund(linea->DBvalue("pvp" + m_listalineas->tableName()).toAscii().constData());
00107         Fixed desc1(linea->DBvalue("descuento" + m_listalineas->tableName()).toAscii().constData());
00108         Fixed cantpvp = cant * pvpund;
00109         Fixed base = cantpvp - cantpvp * desc1 / 100;
00110         descuentolinea = descuentolinea + (cantpvp * desc1 / 100);
00111         basesimp[linea->DBvalue("iva" + m_listalineas->tableName())] = basesimp[linea->DBvalue("iva" + m_listalineas->tableName())] + base;
00112         basesimpreqeq[linea->DBvalue("reqeq" + m_listalineas->tableName())] = basesimpreqeq[linea->DBvalue("reqeq" + m_listalineas->tableName())] + base;
00113     } // end for
00114 
00115     Fixed basei("0.00");
00116     base::Iterator it;
00117     for (it = basesimp.begin(); it != basesimp.end(); ++it) {
00118         basei = basei + it.value();
00119     } // end for
00120 
00122     Fixed porcentt("0.00");
00123     SDBRecord *linea1;
00124     if (m_listadescuentos->rowCount()) {
00125         for (int i = 0; i < m_listadescuentos->rowCount(); ++i) {
00126             linea1 = m_listadescuentos->lineaat(i);
00127             Fixed propor(linea1->DBvalue("proporcion" + m_listadescuentos->tableName()).toAscii().constData());
00128             porcentt = porcentt + propor;
00129         } // end for
00130     } // end if
00131 
00133     Fixed totbaseimp("0.00");
00134     Fixed parbaseimp("0.00");
00135     for (it = basesimp.begin(); it != basesimp.end(); ++it) {
00136         if (porcentt > Fixed("0.00")) {
00137             parbaseimp = it.value() - it.value() * porcentt / 100;
00138         } else {
00139             parbaseimp = it.value();
00140         } // end if
00141         totbaseimp = totbaseimp + parbaseimp;
00142     } // end for
00143 
00145     Fixed totiva("0.00");
00146     Fixed pariva("0.00");
00147     for (it = basesimp.begin(); it != basesimp.end(); ++it) {
00148         Fixed piva(it.key().toAscii().constData());
00149         if (porcentt > Fixed("0.00")) {
00150             pariva = (it.value() - it.value() * porcentt / 100) * piva / 100;
00151         } else {
00152             pariva = it.value() * piva / 100;
00153         } // end if
00154         totiva = totiva + pariva;
00155     } // end for
00156 
00158     Fixed totreqeq("0.00");
00159     Fixed parreqeq("0.00");
00160     for (it = basesimpreqeq.begin(); it != basesimpreqeq.end(); ++it) {
00161         Fixed preqeq(it.key().toAscii().constData());
00162         if (porcentt > Fixed("0.00")) {
00163             parreqeq = (it.value() - it.value() * porcentt / 100) * preqeq / 100;
00164         } else {
00165             parreqeq = it.value() * preqeq / 100;
00166         } // end if
00167         totreqeq = totreqeq + parreqeq;
00168     } // end for
00169 
00170     Fixed totirpf = totbaseimp * irpf / 100;
00171     pintatotales(totiva, totbaseimp, totiva + totbaseimp + totreqeq - totirpf, (basei * porcentt / 100) + descuentolinea, totirpf, totreqeq);
00172     _depura("FichaBf::calculaypintatotales", 0);
00173 }
00174 
00175 
00178 
00181 void FichaBf::trataTags(QString &buff) {
00182     _depura("FichaBf::trataTags", 0);
00183     int pos =  0;
00184 
00186     QRegExp rx("<!--\\s*LINEAS\\s*DETALLE\\s*-->(.*)<!--\\s*END\\s*LINEAS\\s*DETALLE\\s*-->");
00187     rx.setMinimal(TRUE);
00188     while ((pos = rx.indexIn(buff, pos)) != -1) {
00189         QString ldetalle = trataLineasDetalle(rx.cap(1));
00190         buff.replace(pos, rx.matchedLength(), ldetalle);
00191         pos = 0;
00192     } // end while
00193 
00195     pos = 0;
00196     QRegExp rx3("<!--\\s*IF\\s*DESCUENTOS\\s*-->(.*)<!--\\s*END\\s*IF\\s*DESCUENTOS\\s*-->");
00197     rx3.setMinimal(TRUE);
00198     while ((pos = rx3.indexIn(buff, pos)) != -1) {
00199         if (m_listadescuentos->rowCount() -1 <= 0) {
00200             buff.replace(pos, rx3.matchedLength(), "");
00201             pos = 0;
00202         } else {
00203             pos += rx3.matchedLength();
00204         } // end if
00205     } // end while
00206 
00208     pos = 0;
00209     QRegExp rx2("<!--\\s*LINEAS\\s*DESCUENTO\\s*-->(.*)<!--\\s*END\\s*LINEAS\\s*DESCUENTO\\s*-->");
00210     rx2.setMinimal(TRUE);
00211     while ((pos = rx2.indexIn(buff, pos)) != -1) {
00212         QString ldetalle = trataLineasDescuento(rx2.cap(1));
00213         buff.replace(pos, rx2.matchedLength(), ldetalle);
00214         pos = 0;
00215     } // end while
00216 
00218     pos = 0;
00219     QRegExp rx5("<!--\\s*TOTALES\\s*-->(.*)<!--\\s*END\\s*TOTALES\\s*-->");
00220     rx5.setMinimal(TRUE);
00221     while ((pos = rx5.indexIn(buff, pos)) != -1) {
00222         QString ldetalle = trataTotales(rx5.cap(1));
00223         buff.replace(pos, rx5.matchedLength(), ldetalle);
00224         pos = 0;
00225     } // end while
00226 
00227     Ficha::trataTags(buff);
00228 
00229     _depura("END FichaBf::trataTags", 0);
00230 }
00231 
00232 
00233 
00234 
00235 
00237 
00241 QString FichaBf::trataLineasDetalle(const QString &det) {
00242     _depura("FichaBf::trataLineasDetalle", 0);
00243     QString result = "";
00244 
00246     SDBRecord *linea;
00248     for (int i = 0; i < (m_listalineas->rowCount() - 1); ++i) {
00249         QString salidatemp = det;
00250         linea = m_listalineas->lineaat(i);
00251         Fixed base = Fixed(linea->DBvalue("cant" + m_listalineas->tableName()).toAscii().constData()) * Fixed(linea->DBvalue("pvp"+m_listalineas->tableName()).toAscii().constData());
00252         QString l;
00253 
00255         QString desc = linea->DBvalue("desc" + m_listalineas->tableName());
00256         QStringList descp = desc.split("\n");
00257         QString desc1 = "";
00258         for (int i = 0; i < descp.size(); ++i) {
00259             if (descp[i] != "") {
00260                 if (descp[i].startsWith(" ")) {
00261                     desc1 += "<pre>" + XMLProtect(descp[i]) + "</pre>\n";
00262                 } else {
00263                    desc1 += "<para>" + XMLProtect(descp[i]) + "</para>\n";
00264                 } // end if
00265             } else {
00266                desc1 += "<spacer length=\"0.1cm\"/>\n";
00267             } // end if
00268         } // end for
00269 
00270 
00271         salidatemp.replace("[desc"+m_listalineas->tableName()+"]", desc1);
00272 
00273         salidatemp.replace("[cant" + m_listalineas->tableName()+"]", l.sprintf("%s", linea->DBvalue("cant" + m_listalineas->tableName()).toAscii().constData()));
00274         salidatemp.replace("[pvp" + m_listalineas->tableName()+"]", l.sprintf("%s", XMLProtect(linea->DBvalue("pvp" + m_listalineas->tableName())).toAscii().constData()));
00275         salidatemp.replace("[descuento" + m_listalineas->tableName()+"]" , l.sprintf("%s", XMLProtect(linea->DBvalue("descuento" + m_listalineas->tableName())).toAscii().constData()));
00276         salidatemp.replace("[total" + m_listalineas->tableName()+"]" , l.sprintf("%s", (base - base * Fixed(linea->DBvalue("descuento" + m_listalineas->tableName())) / 100).toQString().toAscii().constData()));
00277 
00279         QRegExp rx("\\[(\\w*)\\]");
00280         int pos =  0;
00281         while ((pos = rx.indexIn(salidatemp, pos)) != -1) {
00282             if (linea->exists(rx.cap(1))) {
00283                 salidatemp.replace(pos, rx.matchedLength(), linea->DBvalue(rx.cap(1)));
00284                 pos = 0;
00285             } else {
00286                 pos += rx.matchedLength();
00287             }
00288         } // end while
00289 
00290         result += salidatemp;
00291     } // end for
00292     _depura("END FichaBf::trataLineasDetalle", 0);
00293     return result;
00294 }
00295 
00296 
00298 
00302 QString FichaBf::trataLineasDescuento(const QString &det) {
00303     _depura("FichaBf::trataLineasDescuento", 0);
00304     QString result = "";
00305 
00306     base basesimp;
00307     base basesimpreqeq;
00308 
00310     SDBRecord *linea;
00312     for (int i = 0; i < (m_listalineas->rowCount() - 1); ++i) {
00313         linea = m_listalineas->lineaat(i);
00314         Fixed base = Fixed(linea->DBvalue("cant" + m_listalineas->tableName()).toAscii().constData()) * Fixed(linea->DBvalue("pvp"+m_listalineas->tableName()).toAscii().constData());
00315         basesimp[linea->DBvalue("iva"+m_listalineas->tableName())] = basesimp[linea->DBvalue("iva"+m_listalineas->tableName())] + base - base * Fixed(linea->DBvalue("descuento" + m_listalineas->tableName()).toAscii().constData()) / 100;
00316         basesimpreqeq[linea->DBvalue("reqeq" + m_listalineas->tableName())] = basesimpreqeq[linea->DBvalue("reqeq"+m_listalineas->tableName())] + base - base * Fixed(linea->DBvalue("descuento" + m_listalineas->tableName()).toAscii().constData()) / 100;
00317 
00318     } // end for
00319 
00320     Fixed basei("0.00");
00321     base::Iterator it;
00322     for (it = basesimp.begin(); it != basesimp.end(); ++it) {
00323         basei = basei + it.value();
00324     } // end for
00325 
00327     SDBRecord *linea1;
00329     for (int i = 0; i < (m_listadescuentos->rowCount() - 1); ++i) {
00330         QString salidatemp = det;
00331         linea1 = m_listadescuentos->lineaat(i);
00332         QString l;
00333         salidatemp.replace("[concept"+ m_listadescuentos->tableName()+"]", XMLProtect(linea1->DBvalue("concept" + m_listadescuentos->tableName())));
00334         salidatemp.replace("[proporciondesc" + m_listadescuentos->tableName()+"]", l.sprintf("%s", linea1->DBvalue("proporcion" + m_listadescuentos->tableName()).toAscii().constData()));
00335         salidatemp.replace("[totaldesc" + m_listadescuentos->tableName()+"]", l.sprintf("-%s", (Fixed(linea1->DBvalue("proporcion" + m_listadescuentos->tableName())) * basei / 100).toQString().toAscii().constData()));
00336 
00338         QRegExp rx("\\[(\\w*)\\]");
00339         int pos =  0;
00340         while ((pos = rx.indexIn(salidatemp, pos)) != -1) {
00341             if (linea1->exists(rx.cap(1))) {
00342                 salidatemp.replace(pos, rx.matchedLength(), linea1->DBvalue(rx.cap(1)));
00343                 pos = 0;
00344             } else {
00345                 pos += rx.matchedLength();
00346             }
00347         } // end while
00348 
00349         result += salidatemp;
00350     } // end for
00351     _depura("END FichaBf::trataLineasDescuento", 0);
00352     return result;
00353 }
00354 
00355 
00362 QString FichaBf::trataTotales(const QString &det) {
00363     _depura("FichaBf::trataTotales", 0);
00364     QString result = "";
00365     QString salidatemp = "";
00366     base basesimp;
00367     base basesimpreqeq;
00368     SDBRecord *linea;
00370     QString l;
00371     Fixed irpf("0");
00372 
00373     cursor2 *cur = empresaBase()->cargacursor("SELECT * FROM configuracion WHERE nombre = 'IRPF'");
00374     if (cur) {
00375         if (!cur->eof()) {
00376             irpf = Fixed(cur->valor("valor"));
00377         } // end if
00378         delete cur;
00379     } // end if
00380 
00381     if (exists("idproveedor") && DBvalue("idproveedor") != "") {
00382         cur = empresaBase()->cargacursor("SELECT irpfproveedor FROM proveedor WHERE idproveedor = " + DBvalue("idproveedor"));
00383         if (cur) {
00384             if (!cur->eof()) {
00385                 irpf = Fixed(cur->valor("irpfproveedor"));
00386             } // end if
00387             delete cur;
00388         } // end if
00389     } // end if
00390 
00391     Fixed descuentolinea("0.00");
00392     for (int i = 0; i < m_listalineas->rowCount() -1; ++i) {
00393         linea = m_listalineas->lineaat(i);
00394         Fixed cant(linea->DBvalue("cant" + m_listalineas->tableName()).toAscii().constData());
00395         Fixed pvpund(linea->DBvalue("pvp" + m_listalineas->tableName()).toAscii().constData());
00396         Fixed desc1(linea->DBvalue("descuento" + m_listalineas->tableName()).toAscii().constData());
00397         Fixed cantpvp = cant * pvpund;
00398         Fixed base = cantpvp - cantpvp * desc1 / 100;
00399         descuentolinea = descuentolinea + (cantpvp * desc1 / 100);
00400         basesimp[linea->DBvalue("iva" + m_listalineas->tableName())] = basesimp[linea->DBvalue("iva" + m_listalineas->tableName())] + base;
00401         basesimpreqeq[linea->DBvalue("reqeq" + m_listalineas->tableName())] = basesimpreqeq[linea->DBvalue("reqeq" + m_listalineas->tableName())] + base;
00402     } // end for
00403 
00404     Fixed basei("0.00");
00405     base::Iterator it;
00406     for (it = basesimp.begin(); it != basesimp.end(); ++it) {
00407         basei = basei + it.value();
00408     } // end for
00409 
00411     Fixed porcentt("0.00");
00412     SDBRecord *linea1;
00413     if (m_listadescuentos->rowCount()) {
00414         for (int i = 0; i < m_listadescuentos->rowCount(); ++i) {
00415             linea1 = m_listadescuentos->lineaat(i);
00416             Fixed propor(linea1->DBvalue("proporcion" + m_listadescuentos->tableName()).toAscii().constData());
00417             porcentt = porcentt + propor;
00418         } // end for
00419     } // end if
00420 
00422     Fixed totbaseimp("0.00");
00423     Fixed parbaseimp("0.00");
00424     Fixed totdesc("0.00");
00425     for (it = basesimp.begin(); it != basesimp.end(); ++it) {
00426         if (porcentt > Fixed("0.00")) {
00427             parbaseimp = it.value() - it.value() * porcentt / 100;
00428             totdesc = totdesc + it.value() * porcentt / 100;
00429         } else {
00430             parbaseimp = it.value();
00431         } // end if
00432         totbaseimp = totbaseimp + parbaseimp;
00433     } // end for
00434 
00436     Fixed totiva("0.00");
00437     Fixed pariva("0.00");
00438     for (it = basesimp.begin(); it != basesimp.end(); ++it) {
00439         Fixed piva(it.key().toAscii().constData());
00440         if (porcentt > Fixed("0.00")) {
00441             pariva = (it.value() - it.value() * porcentt / 100) * piva / 100;
00442         } else {
00443             pariva = it.value() * piva / 100;
00444         } // end if
00445         totiva = totiva + pariva;
00446     } // end for
00447 
00449     Fixed totreqeq("0.00");
00450     Fixed parreqeq("0.00");
00451     for (it = basesimpreqeq.begin(); it != basesimpreqeq.end(); ++it) {
00452         Fixed preqeq(it.key().toAscii().constData());
00453         if (porcentt > Fixed("0.00")) {
00454             parreqeq = (it.value() - it.value() * porcentt / 100) * preqeq / 100;
00455         } else {
00456             parreqeq = it.value() * preqeq / 100;
00457         } // end if
00458         totreqeq = totreqeq + parreqeq;
00459     } // end for
00460 
00461     Fixed totirpf = totbaseimp * irpf / 100;
00462 
00463     base::Iterator ot;
00464     base::Iterator at;
00465     at = basesimpreqeq.begin();
00466     for (ot = basesimp.begin(); ot != basesimp.end(); ++ot) {
00467         salidatemp = det;
00468         if (porcentt > Fixed("0.00")) {
00469             parbaseimp = ot.value() - ot.value() * porcentt / 100;
00470         } else {
00471             parbaseimp = ot.value();
00472         } // end if
00473         salidatemp.replace("[bimp]", parbaseimp.toQString());
00474         salidatemp.replace("[tbimp]", ot.key());
00475 
00476         Fixed piva(ot.key().toAscii().constData());
00477         if (porcentt > Fixed("0.00")) {
00478             pariva = (ot.value() - ot.value() * porcentt / 100) * piva / 100;
00479         } else {
00480             pariva = ot.value() * piva / 100;
00481         } // end if
00482         salidatemp.replace("[iva]", pariva.toQString());
00483         salidatemp.replace("[tiva]", ot.key());
00484 
00485         // Recargos de equivalencia
00486         Fixed preqeq(at.key().toAscii().constData());
00487         if (porcentt > Fixed("0.00")) {
00488             parreqeq = (at.value() - at.value() * porcentt / 100) * preqeq / 100;
00489         } else {
00490             parreqeq = at.value() * preqeq / 100;
00491         } // end if
00492         salidatemp.replace("[re]", parreqeq.toQString());
00493         salidatemp.replace("[tre]", at.key());
00494 
00495         salidatemp.replace("[irpf]", totirpf.toQString());
00496         salidatemp.replace("[tirpf]", irpf.toQString());
00497 
00498         salidatemp.replace("[totalre]", totreqeq.toQString());
00499         salidatemp.replace("[teoricbimp]", basei.toQString());
00500         salidatemp.replace("[totalbimp]", totbaseimp.toQString());
00501         salidatemp.replace("[totaldesc]", totdesc.toQString());
00502         salidatemp.replace("[totaliva]", totiva.toQString());
00503         salidatemp.replace("[total]", (totiva + totbaseimp + totreqeq - totirpf).toQString().toAscii().constData());
00504 
00505         result += salidatemp;
00506         ++at;
00507     } // end for
00508 
00509     _depura("END FichaBf::trataTotales", 0);
00510     return result;
00511 }
00512 
00513 
00514 
00516 
00518 void FichaBf::generaRML() {
00519     _depura("FichaBf::generaRML", 0);
00520     generaRML(m_tablename + ".rml");
00521     _depura("END FichaBf::generaRML", 0);
00522 
00523 }
00524 
00526 
00529 void FichaBf::generaRML(const QString &arch) {
00530     _depura("FichaBf::generaRML", 0, arch);
00531     cursor2 *cur = NULL;
00532     try {
00534         int res = g_plugins->lanza("FichaBf_generaRML", this);
00535         if (res != 0) {
00536             return;
00537         } // end if
00538         base basesimp;
00539         base basesimpreqeq;
00540         QString archivo = confpr->valor(CONF_DIR_OPENREPORTS) + arch;
00541         QString archivod = confpr->valor(CONF_DIR_USER) + arch;
00542         QString archivologo = confpr->valor(CONF_DIR_OPENREPORTS) + "logo.jpg";
00543 
00544         Fixed irpf("0");
00545 
00546         cur = empresaBase()->cargacursor("SELECT * FROM configuracion WHERE nombre = 'IRPF'");
00547         if (cur) {
00548             if (!cur->eof()) {
00549                 irpf = Fixed(cur->valor("valor"));
00550             } // end if
00551             delete cur;
00552         } // end if
00553 
00555 #ifdef WINDOWS
00556 
00557         archivo = "copy " + archivo + " " + archivod;
00558 #else
00559 
00560         archivo = "cp " + archivo + " " + archivod;
00561 #endif
00562 
00563         system (archivo.toAscii().constData());
00565 #ifdef WINDOWS
00566 
00567         archivologo = "copy " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00568 #else
00569 
00570         archivologo = "cp " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00571 #endif
00572 
00573         system(archivologo.toAscii().constData());
00574         QFile file;
00575         file.setFileName(archivod);
00576         file.open(QIODevice::ReadOnly);
00577         QTextStream stream(&file);
00578         QString buff = stream.readAll();
00579         file.close();
00580 
00582         trataTags(buff);
00583 
00584         QString fitxersortidatxt = "";
00585 
00586 
00587 
00589         QString SQLQuery = "SELECT * FROM cliente WHERE idcliente = " + DBvalue("idcliente");
00590         cur = empresaBase()->cargacursor(SQLQuery);
00591         if (!cur) throw -1;
00592         if (!cur->eof()) {
00593             buff.replace("[dircliente]", cur->valor("dircliente"));
00594             buff.replace("[poblcliente]", cur->valor("poblcliente"));
00595             buff.replace("[telcliente]", cur->valor("telcliente"));
00596             buff.replace("[nomcliente]", cur->valor("nomcliente"));
00597             buff.replace("[cifcliente]", cur->valor("cifcliente"));
00598             buff.replace("[idcliente]", cur->valor("idcliente"));
00599             buff.replace("[cpcliente]", cur->valor("cpcliente"));
00600             buff.replace("[codcliente]", cur->valor("codcliente"));
00601         } // end if
00602         delete cur;
00603 
00604         if (exists("id" + m_tablename))
00605             buff.replace("[id" + m_tablename + "]", DBvalue("id" + m_tablename));
00606         if (exists("num" + m_tablename))
00607             buff.replace("[num" + m_tablename + "]", DBvalue("num" + m_tablename));
00608         if (exists("f" + m_tablename))
00609             buff.replace("[f" + m_tablename + "]", DBvalue("f" + m_tablename));
00610         if (exists("venc" + m_tablename))
00611             buff.replace("[venc" + m_tablename + "]", DBvalue("venc" + m_tablename));
00612         if (exists("contact" + m_tablename))
00613             buff.replace("[contact" + m_tablename + "]", DBvalue("contact" + m_tablename));
00614         if (exists("tel" + m_tablename))
00615             buff.replace("[tel" + m_tablename+"]", DBvalue("tel" + m_tablename));
00616         if (exists("coment" + m_tablename))
00617             buff.replace("[coment" + m_tablename+"]", DBvalue("coment" + m_tablename));
00618         if (exists("desc" + m_tablename))
00619             buff.replace("[desc" + m_tablename + "]", DBvalue("desc" + m_tablename));
00620         if (exists("ref" + m_tablename))
00621             buff.replace("[ref" + m_tablename + "]", DBvalue("ref" + m_tablename));
00622         if (exists("codigoserie_" + m_tablename) )
00623             buff.replace("[codigoserie_" + m_tablename+"]", DBvalue("codigoserie_" + m_tablename));
00624         if (exists("fecha" + m_tablename) )
00625             buff.replace("[fecha" + m_tablename + "]", DBvalue("fecha" + m_tablename));
00627         QString l;
00628 
00630         SDBRecord *linea;
00632         for (int i = 0; i < (m_listalineas->rowCount() - 1); ++i) {
00633             linea = m_listalineas->lineaat(i);
00634             Fixed base = Fixed(linea->DBvalue("cant" + m_listalineas->tableName()).toAscii().constData()) * Fixed(linea->DBvalue("pvp"+m_listalineas->tableName()).toAscii().constData());
00635             basesimp[linea->DBvalue("iva"+m_listalineas->tableName())] = basesimp[linea->DBvalue("iva"+m_listalineas->tableName())] + base - base * Fixed(linea->DBvalue("descuento" + m_listalineas->tableName()).toAscii().constData()) / 100;
00636             basesimpreqeq[linea->DBvalue("reqeq" + m_listalineas->tableName())] = basesimpreqeq[linea->DBvalue("reqeq"+m_listalineas->tableName())] + base - base * Fixed(linea->DBvalue("descuento" + m_listalineas->tableName()).toAscii().constData()) / 100;
00637 
00638             fitxersortidatxt += "<tr>\n";
00639             fitxersortidatxt += "    <td>" + XMLProtect(linea->DBvalue("codigocompletoarticulo")) + "</td>\n";
00640             fitxersortidatxt += "    <td><para>" + XMLProtect(linea->DBvalue("desc" + m_listalineas->tableName())).replace(QChar('\n'), "</para><para>") + "</para></td>\n";
00641             fitxersortidatxt += "    <td>" + linea->DBvalue("cant" + m_listalineas->tableName()) + "</td>\n";
00642             fitxersortidatxt += "    <td>" + l.sprintf("%s", XMLProtect(linea->DBvalue("pvp" + m_listalineas->tableName())).toAscii().constData()) + "</td>\n";
00643             fitxersortidatxt += "    <td>" + l.sprintf("%s", XMLProtect(linea->DBvalue("descuento" + m_listalineas->tableName())).toAscii().constData()) + " %</td>\n";
00644             fitxersortidatxt += "    <td>" + l.sprintf("%s", (base - base * Fixed(linea->DBvalue("descuento" + m_listalineas->tableName())) / 100).toQString().toAscii().constData()) + "</td>\n";
00645             fitxersortidatxt += "</tr>";
00646         } // end for
00647 
00648         buff.replace("[story]", fitxersortidatxt);
00649 
00650         Fixed basei("0.00");
00651         base::Iterator it;
00652         for (it = basesimp.begin(); it != basesimp.end(); ++it) {
00653             basei = basei + it.value();
00654         } // end for
00655 
00657         fitxersortidatxt = "";
00658         Fixed porcentt("0.00");
00659         SDBRecord *linea1;
00660         if (m_listadescuentos->rowCount() - 1) {
00661             fitxersortidatxt += "<blockTable style=\"tabladescuento\">\n";
00662             fitxersortidatxt += "<tr>\n";
00663             fitxersortidatxt += "    <td>" + QApplication::translate("Presupuesto", "Descuento") + "</td>\n";
00664             fitxersortidatxt += "    <td>" + QApplication::translate("Presupuesto", "Porcentaje") + "</td>\n";
00665             fitxersortidatxt += "    <td>" + QApplication::translate("Presupuesto", "Total Desc.") + "</td>\n";
00666             fitxersortidatxt += "</tr>\n";
00667             for (int i = 0; i < (m_listadescuentos->rowCount() - 1); ++i) {
00668                 linea1 = m_listadescuentos->lineaat(i);
00669                 porcentt = porcentt + Fixed(linea1->DBvalue("proporcion" + m_listadescuentos->tableName()).toAscii().constData());
00670                 fitxersortidatxt += "<tr>\n";
00671                 fitxersortidatxt += "    <td>" + XMLProtect(linea1->DBvalue("concept" + m_listadescuentos->tableName())) + "</td>\n";
00672                 fitxersortidatxt += "    <td>" + l.sprintf("%s", linea1->DBvalue("proporcion" + m_listadescuentos->tableName()).toAscii().constData()) + " %</td>\n";
00673                 fitxersortidatxt += "    <td>" + l.sprintf("-%s", (Fixed(linea1->DBvalue("proporcion" + m_listadescuentos->tableName())) * basei / 100).toQString().toAscii().constData()) + "</td>\n";
00674                 fitxersortidatxt += "</tr>";
00675             } // end for
00676             fitxersortidatxt += "</blockTable>\n";
00677         } // end if
00678         buff.replace("[descuentos]", fitxersortidatxt);
00679 
00681         fitxersortidatxt = "";
00682         QString tr1 = ""; 
00683         QString tr2 = ""; 
00684         fitxersortidatxt += "<blockTable style=\"tabladescuento\" >\n";
00685         Fixed totbaseimp("0.00");
00686         Fixed parbaseimp("0.00");
00687         Fixed totdesc("0.00");
00688         for (it = basesimp.begin(); it != basesimp.end(); ++it) {
00689             if (porcentt > 0) {
00690                 parbaseimp = it.value() - it.value() * porcentt / 100;
00691                 totdesc = totdesc + it.value() * porcentt / 100;
00692             } else {
00693                 parbaseimp = it.value();
00694             } // end if
00695             totbaseimp = totbaseimp + parbaseimp;
00696             tr1 += "    <td>" + QApplication::translate("Presupuesto", "Base Imponible") + " " + XMLProtect(it.key()) + " %</td>\n";
00697             tr2 += "    <td>" + l.sprintf(" %s ", parbaseimp.toQString().toAscii().constData()) + "</td>\n";
00698         } // end for
00699 
00701         Fixed totiva("0.0");
00702         Fixed pariva("0.0");
00703         for (it = basesimp.begin(); it != basesimp.end(); ++it) {
00704             if (porcentt > 0) {
00705                 pariva = (it.value() - it.value() * porcentt / 100) * Fixed(it.key()) / 100;
00706             } else {
00707                 pariva = it.value() * Fixed(it.key()) / 100;
00708             } // end if
00709             totiva = totiva + pariva;
00710             tr1 += "    <td>" + QApplication::translate("Presupuesto", "I.V.A.") + " " + XMLProtect(it.key()) + " %</td>\n";
00711             tr2 += "    <td>" + l.sprintf(" %s ", pariva.toQString().toAscii().constData()) + "</td>\n";
00712         } // end for
00713 
00715         Fixed totreqeq("0.0");
00716         Fixed parreqeq("0.0");
00717         for (it = basesimpreqeq.begin(); it != basesimpreqeq.end(); ++it) {
00718             if (porcentt > 0) {
00719                 parreqeq = (it.value() - it.value() * porcentt / 100) * Fixed(it.key()) / 100;
00720             } else {
00721                 parreqeq = it.value() * Fixed(it.key()) / 100;
00722             } // end if
00723             totreqeq = totreqeq + parreqeq;
00724             if (parreqeq > 0) {
00725                 tr1 += "    <td>" + QApplication::translate("Presupuesto", "R.E.") + " " + XMLProtect(it.key()) + " %</td>\n";
00726                 tr2 += "    <td>" + l.sprintf(" %s ", parreqeq.toQString().toAscii().constData()) + "</td>\n";
00727             } // end if
00728         } // end for
00729 
00730         Fixed totirpf = totbaseimp * irpf / 100;
00731         if (totirpf > 0) {
00732             tr1 += "    <td>" + QApplication::translate("Presupuesto", "I.R.P.F (-") + " " + XMLProtect(irpf.toQString()) + ") %</td>\n";
00733             tr2 += "    <td>" + l.sprintf(" %s ", totirpf.toQString().toAscii().constData()) + "</td>\n";
00734         } // end if
00735 
00736         tr1 += "    <td>" + QApplication::translate("Presupuesto", "Total") + "</td>\n";
00737         tr2 += "    <td>" + l.sprintf(" %s ", (totiva + totbaseimp + totreqeq - totirpf).toQString().toAscii().constData()) + "</td>\n";
00738         fitxersortidatxt += "<tr>" + tr1 + "</tr><tr>" + tr2 + "</tr></blockTable>\n";
00739         buff.replace("[totales]", fitxersortidatxt);
00740 
00741 
00742 
00743         buff.replace("[irpf]", totirpf.toQString());
00744         buff.replace("[tirpf]", irpf.toQString());
00745         buff.replace("[totalre]", totreqeq.toQString());
00746         buff.replace("[teoricbimp]", basei.toQString());
00747         buff.replace("[totalbimp]", totbaseimp.toQString());
00748         buff.replace("[totaldesc]", totdesc.toQString());
00749         buff.replace("[totaliva]", totiva.toQString());
00750         buff.replace("[total]", (totiva + totbaseimp + totreqeq - totirpf).toQString().toAscii().constData());
00751 
00752 
00755 #ifndef WINDOWS
00756         //   buff.replace("[detallearticulos]", detalleArticulos());
00757 #endif
00758 
00759         if (file.open(QIODevice::WriteOnly)) {
00760             QTextStream stream(&file);
00761             stream << buff;
00762             file.close();
00763         } // end if
00764 
00765         _depura("END FichaBf::generaRML", 0);
00766     } catch (...) {
00767         if (cur) delete cur;
00768         throw -1;
00769     } // end try
00770 }
00771 
00772 
00774 
00777 void FichaBf::imprimir() {
00778     _depura("FichaBf::imprimir", 0);
00779     try {
00781         int res = g_plugins->lanza("FichaBf_imprimir", this);
00782         if (res != 0) {
00783             return;
00784         } // end if
00785         generaRML();
00786         invocaPDF(m_tablename);
00787         _depura("END FichaBf::imprimir", 0);
00788     } catch (...) {
00789         mensajeInfo(tr("Error inesperado en la impresion"));
00790     } // end try
00791 }
00792 
00793 
00795 
00798 void FichaBf::setListaLineas(SubForm2Bf *form) {
00799     _depura("FichaBf::setListaLineas", 0);
00800     m_listalineas = form;
00801     _depura("END FichaBf::setListaLineas", 0);
00802 }
00803 
00805 
00808 void FichaBf::setListaDescuentos(SubForm2Bf *form) {
00809     _depura("FichaBf::setListaDescuentos", 0);
00810     m_listadescuentos = form;
00811     _depura("END FichaBf::setListaDescuentos", 0);
00812 }
00813 
00814 
00816 
00819 SubForm2Bf* FichaBf::getlistalineas() {
00820     _depura("FichaBf::getlistalineas", 0);
00821     _depura("END FichaBf::getlistalineas", 0);
00822     return m_listalineas;
00823 }
00824 
00825 
00827 
00830 SubForm2Bf* FichaBf::getlistadescuentos() {
00831     _depura("FichaBf::getlistadescuentos", 0);
00832     _depura("END FichaBf::getlistadescuentos", 0);
00833     return m_listadescuentos;
00834 }
00835 
00836 

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