facturaslist.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 <QFile>
00022 #include <QMessageBox>
00023 #include <QTextStream>
00024 
00025 #include "busquedaarticulo.h"
00026 #include "busquedacliente.h"
00027 #include "busquedafecha.h"
00028 #include "company.h"
00029 #include "configuracion.h"
00030 #include "facturaslist.h"
00031 #include "facturaview.h"
00032 #include "funcaux.h"
00033 #include "plugins.h"
00034 
00035 
00045 FacturasList::FacturasList(QWidget *parent, Qt::WFlags flag, edmode editmodo)
00046         : Listado(NULL, parent, flag, editmodo) {
00047     _depura("FacturasList::FacturasList", 0);
00048     setupUi(this);
00049     iniciaForm();
00050     mdb_idfactura = "";
00051     setSubForm(mui_list);
00052     hideBusqueda();
00053     _depura("END FacturasList::FacturasList", 0);
00054 }
00055 
00056 
00065 FacturasList::FacturasList(Company *comp, QWidget *parent, Qt::WFlags flag, edmode editmodo)
00066         : Listado(comp, parent, flag, editmodo) {
00067     _depura("FacturasList::FacturasList", 0);
00068     setupUi(this);
00069     iniciaForm();
00070     m_cliente->setEmpresaBase(empresaBase());
00071     m_articulo->setEmpresaBase(empresaBase());
00072     mui_list->setEmpresaBase(empresaBase());
00073     setSubForm(mui_list);
00074     presentar();
00075     mdb_idfactura = "";
00076     if (modoEdicion()) {
00077         empresaBase()->meteWindow(windowTitle(), this);
00078     } // end if
00079     hideBusqueda();
00081     trataPermisos("factura");
00082     _depura("END FacturasList::FacturasList", 0);
00083 }
00084 
00085 
00087 
00090 void FacturasList::iniciaForm() {
00091     _depura("FacturasList::iniciaForm");
00093     int res = g_plugins->lanza("FacturasList_iniciaForm", this);
00094     if (res != 0)
00095         return;
00096     mui_procesada->insertItem(0, tr("Todas las facturas"));
00097     mui_procesada->insertItem(1, tr("Facturas procesadas"));
00098     mui_procesada->insertItem(2, tr("Facturas no procesadas"));
00099     _depura("END FacturasList::iniciaForm");
00100 }
00101 
00102 
00107 FacturasList::~FacturasList() {
00108     _depura("FacturasList::~FacturasList", 0);
00109     _depura("END FacturasList::~FacturasList", 0);
00110 }
00111 
00112 
00117 void FacturasList::presentar() {
00118     _depura("FacturasList::presenta", 0);
00119 
00120     mui_list->cargar("SELECT *, totalfactura AS total, bimpfactura AS base, impfactura AS impuestos FROM factura LEFT JOIN cliente ON factura.idcliente = cliente.idcliente LEFT JOIN almacen ON factura.idalmacen = almacen.idalmacen WHERE 1 = 1 " + generaFiltro());
00121 
00123     cursor2 *cur = empresaBase()->cargacursor("SELECT SUM(totalfactura) AS total, SUM(bimpfactura) AS base, SUM(impfactura) AS impuestos FROM factura LEFT JOIN cliente ON factura.idcliente = cliente.idcliente LEFT JOIN almacen ON factura.idalmacen = almacen.idalmacen WHERE 1 = 1 " + generaFiltro());
00125     if (cur ) {
00126         mui_totalbimponible->setText(cur->valor("base"));
00127         mui_totalimpuestos->setText(cur->valor("impuestos"));
00128         mui_totalfacturas->setText(cur->valor("total"));
00129         delete cur;
00130     } // end if
00131 
00132     _depura("END FacturasList::presentar", 0);
00133 }
00134 
00135 
00141 QString FacturasList::generaFiltro() {
00142     _depura("FacturasList::generaFiltro", 0);
00144     QString filtro = "";
00145     if (m_filtro->text() != "") {
00146         filtro = " AND ( lower(descfactura) LIKE lower('%" + m_filtro->text() + "%') ";
00147         filtro +=" OR reffactura LIKE '" + m_filtro->text() + "%' ";
00148         filtro +=" OR lower(nomcliente) LIKE lower('%" + m_filtro->text() + "%')) ";
00149     } else {
00150         filtro = "";
00151     } // end if
00152     if (m_cliente->idcliente() != "") {
00153         filtro += " AND factura.idcliente = " + m_cliente->idcliente();
00154     } // end if
00155 
00157     if (mui_procesada->currentIndex() == 1) {
00159         filtro += " AND procesadafactura ";
00160     } else if (mui_procesada->currentIndex() == 2) {
00162         filtro += " AND NOT procesadafactura ";
00163     } // end if
00164 
00165     if (m_articulo->idarticulo() != "") {
00166         filtro += " AND idfactura IN (SELECT DISTINCT idfactura FROM lfactura WHERE idarticulo = '" + m_articulo->idarticulo() + "') ";
00167     } // end if
00168     if (m_fechain->text() != "") {
00169         filtro += " AND ffactura >= '" + m_fechain->text() + "' ";
00170     } // end if
00171     if (m_fechafin->text() != "") {
00172         filtro += " AND ffactura <= '" + m_fechafin->text() + "' ";
00173     } // end if
00174     _depura("END FacturasList::generaFiltro", 0);
00175     return (filtro);
00176 }
00177 
00178 
00187 void FacturasList::editar(int row) {
00188     _depura("FacturasList::editar", 0);
00189     mdb_idfactura = mui_list->DBvalue(QString("idfactura"), row);
00190     if (modoEdicion()) {
00191         FacturaView *prov = ((Company *)empresaBase())->newFacturaView();
00192         if (prov->cargar(mdb_idfactura)) {
00193             delete prov;
00194             return;
00195         } // end if
00196         empresaBase()->m_pWorkspace->addWindow(prov);
00197         prov->show();
00198     } else {
00199         emit(selected(mdb_idfactura));
00200     } // end if
00201     _depura("END FacturasList::editar", 0);
00202 }
00203 
00204 
00205 
00211 void FacturasList::imprimir() {
00212     _depura("FacturasList::on_mui_imprimir_clicked", 0);
00213     mui_list->imprimirPDF(tr("Facturas a clientes"));
00214     _depura("FacturasList::on_mui_imprimir_clicked", 0);
00215 }
00216 
00217 
00223 
00224 
00227 void FacturasList::borrar() {
00228     _depura("FacturasList::borrar", 0);
00229     int a = mui_list->currentRow();
00230     if (a < 0) {
00231         mensajeInfo(tr("Debe seleccionar una linea"));
00232         return;
00233     } // end if
00234     try {
00235         mdb_idfactura = mui_list->DBvalue(QString("idfactura"));
00236         if (modoEdicion()) {
00237             FacturaView *fv = ((Company *)empresaBase())->newFacturaView();
00238             if (fv->cargar(mdb_idfactura))
00239                 throw -1;
00240             fv->on_mui_borrar_clicked();
00241             fv->close();
00242         } // end if
00243         presentar();
00244     } catch (...) {
00245         mensajeInfo(tr("Error al borrar la factura a cliente"));
00246     } // end try
00247     _depura("END FacturasList::borrar", 0);
00248 }
00249 
00250 
00252 
00255 void FacturasList::setEmpresaBase (Company *comp) {
00256     _depura("FacturasList::setEmpresaBase", 0);
00257     PEmpresaBase::setEmpresaBase(comp);
00258     m_cliente->setEmpresaBase(comp);
00259     m_articulo->setEmpresaBase(comp);
00260     mui_list->setEmpresaBase(comp);
00261     _depura("END FacturasList::setEmpresaBase", 0);
00262 }
00263 
00264 
00266 
00269 QString FacturasList::idfactura() {
00270     _depura("FacturasList::idfacturae", 0);
00271     _depura("END FacturasList::idfactura", 0);
00272     return mdb_idfactura;
00273 }
00274 
00275 
00277 
00280 void FacturasList::setidcliente(QString val) {
00281     _depura("FacturasList::setidcliente", 0);
00282     m_cliente->setidcliente(val);
00283     _depura("END FacturasList::setidcliente", 0);
00284 }
00285 
00286 
00288 
00291 void FacturasList::setidarticulo(QString val) {
00292     _depura("FacturasList::setidarticulo", 0);
00293     m_articulo->setidarticulo(val);
00294     _depura("END FacturasList::setidarticulo", 0);
00295 }
00296 
00297 
00299 
00301 void FacturasList::crear() {
00302     _depura("FacturasList::crear", 0);
00303         ((Company *)empresaBase())->s_newFacturaCli();
00304     _depura("END FacturasList::crear", 0);
00305 }
00306 
00310 
00316 FacturasListSubform::FacturasListSubform(QWidget *parent, const char *) : SubForm2Bf(parent) {
00317     _depura("FacturasListSubform::FacturasListSubform", 0);
00319     int res = g_plugins->lanza("FacturasListSubform_FacturasListSubform", this);
00320     if (res != 0)
00321         return;
00322     setDBTableName("factura");
00323     setDBCampoId("idfactura");
00324     addSHeader("numfactura", DBCampo::DBint, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Numero"));
00325     addSHeader("ffactura", DBCampo::DBdate, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Fecha"));
00326     addSHeader("nomcliente", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Nombre cliente"));
00327     addSHeader("telfactura", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Telefono factura"));
00328     addSHeader("base", DBCampo::DBnumeric, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Base imponible"));
00329     addSHeader("impuestos", DBCampo::DBnumeric, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Impuestos"));
00330     addSHeader("total", DBCampo::DBnumeric, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Total"));
00331     addSHeader("procesadafactura", DBCampo::DBboolean, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Procesada"));
00332     addSHeader("descfactura", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Descripcion"));
00333     addSHeader("idfactura", DBCampo::DBint, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Id factura"));
00334     addSHeader("reffactura", DBCampo::DBint, DBCampo::DBNotNull | DBCampo::DBPrimaryKey, SHeader::DBNoView | SHeader::DBNoWrite, tr("Ref factura"));
00335     addSHeader("codigoserie_factura", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Serie"));
00336     addSHeader("cifcliente", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("CIF cliente"));
00337     addSHeader("codigoalmacen", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Codigo almacen"));
00338     addSHeader("contactfactura", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Contact factura"));
00339     addSHeader("comentfactura", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Comentario factura"));
00340     addSHeader("idtrabajador", DBCampo::DBint, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Id trabajador"));
00341     addSHeader("idcliente", DBCampo::DBint, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Id cliente"));
00342     addSHeader("idalmacen", DBCampo::DBint, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Id almacen"));
00343     setinsercion(FALSE);
00344     setDelete(FALSE);
00345     setSortingEnabled(TRUE);
00346     _depura("END FacturasListSubform::FacturasListSubform", 0);
00347 }
00348 
00349 
00351 
00353 FacturasListSubform::~FacturasListSubform() {
00354     _depura("FacturasListSubform::~FacturasListSubform", 0);
00355     _depura("END FacturasListSubform::~FacturasListSubform", 0);
00356 }
00357 
00358 
00360 
00362 void FacturasListSubform::cargar() {
00363     _depura("FacturasListSubform::cargar\n", 0);
00364     QString SQLQuery = "SELECT * FROM factura";
00365     SubForm3::cargar(SQLQuery);
00366 }
00367 
00368 
00370 
00373 void FacturasListSubform::cargar(QString query) {
00374     _depura("FacturasListSubform::cargar", 0);
00375     SubForm3::cargar(query);
00376     _depura("END FacturasListSubform::cargar", 0);
00377 }
00378 

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