listlinprevcobroview.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 
00023 #include "images/cactivo.xpm"
00024 #include "images/cpasivo.xpm"
00025 #include "images/cneto.xpm"
00026 #include "images/cingresos.xpm"
00027 #include "images/cgastos.xpm"
00028 
00029 #include "registroivaview.h"
00030 
00031 #define COL_SELECCION                   0
00032 #define COL_FCOBROPREVCOBRO             1
00033 #define COL_CODIGOCTACLIENTE            2
00034 #define COL_NOMCTACLIENTE               3
00035 #define COL_CODIGOCUENTA                4
00036 #define COL_NOMCUENTA                   5
00037 #define COL_CANTIDADPREVCOBRO           6
00038 #define COL_IDREGISTROIVA               7
00039 #define COL_TIPOPREVCOBRO               8
00040 #define COL_DOCPREVCOBRO                9
00041 #define COL_IDPREVCOBRO                10
00042 #define COL_FPREVISTAPREVCOBRO         11
00043 #define COL_IDFPAGO                    12
00044 #define COL_IDCUENTA                   13
00045 #define COL_IDASIENTO                  14
00046 #define COL_CANTIDADPREVISTAPREVCOBRO  15
00047 #define COL_IDCTACLIENTE               16
00048 
00049 #include <QMessageBox>
00050 #include <QPixmap>
00051 #include <QKeyEvent>
00052 #include <QEvent>
00053 #include <QMenu>
00054 
00055 #include "configuracion.h"
00056 #include "asiento1view.h"
00057 #include "listlinprevcobroview.h"
00058 
00059 
00061 
00063 void ListLinPrevCobroView::presentacionFactura() {
00064     _depura("ListLinPrevCobroView::presentacionFactura", 0);
00065     hideColumn(COL_SELECCION);
00066     hideColumn(COL_IDPREVCOBRO);
00067     hideColumn(COL_IDFPAGO);
00068     hideColumn(COL_IDCUENTA);
00069     hideColumn(COL_IDASIENTO);
00070     hideColumn(COL_IDREGISTROIVA);
00071     hideColumn(COL_FPREVISTAPREVCOBRO);
00072     hideColumn(COL_CANTIDADPREVISTAPREVCOBRO);
00073     hideColumn(COL_IDCTACLIENTE);
00074     _depura("END ListLinPrevCobroView::presentacionFactura", 0);
00075 }
00076 
00077 
00079 
00081 void ListLinPrevCobroView::presentacionListado() {
00082     _depura("ListLinPrevCobroView::presentacionListado", 0);
00083     showColumn(COL_SELECCION);
00084     hideColumn(COL_IDPREVCOBRO);
00085     hideColumn(COL_IDFPAGO);
00086     hideColumn(COL_IDCUENTA);
00087     hideColumn(COL_IDASIENTO);
00088     hideColumn(COL_IDREGISTROIVA);
00089     hideColumn(COL_FPREVISTAPREVCOBRO);
00090     hideColumn(COL_CANTIDADPREVISTAPREVCOBRO);
00091     hideColumn(COL_IDCTACLIENTE);
00092     _depura("END ListLinPrevCobroView::presentacionListado", 0);
00093 }
00094 
00095 
00097 
00100 ListLinPrevCobroView::ListLinPrevCobroView(QWidget * parent)
00101         : QTableWidget(parent), ListLinPrevCobro() {
00102     _depura("ListLinPrevCobroView::ListLinPrevCobroView", 0);
00104     setColumnCount(17);
00105     setRowCount(10000);
00106     QStringList etiquetas;
00107 
00108     etiquetas << "COL_SELECCION" << "COL_FCOBROPREVCOBRO" << "COL_CODIGOCTACLIENTE" << "COL_NOMCTACLIENTE" << "COL_CODIGOCUENTA" << "COL_NOMCUENTA" << "COL_CANTIDADPREVCOBRO" << "COL_IDREGISTROIVA" << "COL_TIPOPREVCOBRO" << "COL_DOCPREVCOBRO" << "COL_IDPREVCOBRO" << "COL_FPREVISTAPREVCOBRO" << "COL_IDFPAGO" << "COL_IDCUENTA" << "COL_IDASIENTO" << "COL_CANTIDADPREVISTAPREVCOBRO" << "COL_IDCTACLIENTE";
00109     setHorizontalHeaderLabels(etiquetas);
00110 
00111     setColumnWidth(COL_SELECCION, 25);
00112     setColumnWidth(COL_IDPREVCOBRO, 100);
00113     setColumnWidth(COL_FPREVISTAPREVCOBRO, 100);
00114     setColumnWidth(COL_FCOBROPREVCOBRO, 100);
00115     setColumnWidth(COL_IDFPAGO, 100);
00116     setColumnWidth(COL_IDCUENTA, 74);
00117     setColumnWidth(COL_CODIGOCUENTA, 100);
00118     setColumnWidth(COL_CODIGOCTACLIENTE, 100);
00119     setColumnWidth(COL_NOMCUENTA, 150);
00120     setColumnWidth(COL_NOMCTACLIENTE, 150);
00121     setColumnWidth(COL_IDASIENTO, 100);
00122     setColumnWidth(COL_CANTIDADPREVISTAPREVCOBRO, 100);
00123     setColumnWidth(COL_CANTIDADPREVCOBRO, 100);
00124     setColumnWidth(COL_IDREGISTROIVA, 50);
00125     setColumnWidth(COL_TIPOPREVCOBRO, 100);
00126     setColumnWidth(COL_DOCPREVCOBRO, 100);
00127 
00128     setSelectionMode(QAbstractItemView::SingleSelection);
00129 
00130     //    setColumnReadOnly(COL_NOMCUENTA, true);
00131     //    setColumnReadOnly(COL_NOMCTACLIENTE, true);
00132 
00135     QPalette palette;
00136     palette.setColor(this->backgroundRole(), QColor("#FFFFFF"));
00137     this->setPalette(palette);
00138 
00139     presentacionListado();
00140     connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(valueLineChanged(int, int)));
00141     connect(this, SIGNAL(contextMenuRequested(int, int, const QPoint &)), this, SLOT(contextMenu(int, int, const QPoint &)));
00142     installEventFilter(this);
00143     _depura("END ListLinPrevCobroView::ListLinPrevCobroView", 0);
00144 }
00145 
00146 
00148 
00150 ListLinPrevCobroView::~ListLinPrevCobroView() {
00151     _depura("ListLinPrevCobroView::~ListLinPrevCobroView", 0);
00152     _depura("END ListLinPrevCobroView::~ListLinPrevCobroView", 0);
00153 }
00154 
00155 
00157 
00161 void ListLinPrevCobroView::pintalistlinprevcobro(linprevcobro *linea, int pos) {
00162     _depura("ListLinPrevCobroView::pintalistlinprevcobro", 0);
00163     item(pos, COL_IDPREVCOBRO)->setText(linea->idprevcobro());
00164     item(pos, COL_FPREVISTAPREVCOBRO)->setText(linea->fprevistaprevcobro());
00165     item(pos, COL_FCOBROPREVCOBRO)->setText(linea->fcobroprevcobro());
00166     item(pos, COL_IDFPAGO)->setText(linea->idfpago());
00167     item(pos, COL_IDCUENTA)->setText(linea->idcuenta());
00168     item(pos, COL_IDCTACLIENTE)->setText(linea->idctacliente());
00169     item(pos, COL_CODIGOCUENTA)->setText(linea->codigocuenta());
00170     item(pos, COL_CODIGOCTACLIENTE)->setText(linea->codigoctacliente());
00171     item(pos, COL_NOMCUENTA)->setText(linea->nomcuenta());
00172     item(pos, COL_NOMCTACLIENTE)->setText(linea->nomctacliente());
00173     item(pos, COL_IDASIENTO)->setText(linea->idasiento());
00174 
00175     if (linea->idasiento() == "") {
00176         item(pos, COL_SELECCION)->setFlags(Qt::ItemIsUserCheckable);
00177     } // end if
00178 
00179     item(pos, COL_CANTIDADPREVISTAPREVCOBRO)->setText(linea->cantidadprevistaprevcobro());
00180     item(pos, COL_CANTIDADPREVCOBRO)->setText(linea->cantidadprevcobro());
00181     item(pos, COL_IDREGISTROIVA)->setText(linea->idregistroiva());
00182 
00183     if (linea->tipoprevcobro() == "t") {
00184         item(pos, COL_TIPOPREVCOBRO)->setText(tr("Cobro"));
00185     } else {
00186         item(pos, COL_TIPOPREVCOBRO)->setText(tr("Pago"));
00187     } // end if
00188 
00189     item(pos, COL_DOCPREVCOBRO)->setText(linea->docprevcobro());
00190 
00192     cursor2 *cursoraux1 = m_companyact->cargacursor("SELECT tipocuenta FROM cuenta WHERE idcuenta = " + linea->idcuenta());
00193     if (!cursoraux1->eof()) {
00194         if (cursoraux1->valor("tipocuenta") == "1") {
00195             item(pos, COL_CODIGOCUENTA)->setIcon(QIcon(QPixmap(cactivo)));
00196         } else if (cursoraux1->valor("tipocuenta") == "2") {
00197             item(pos, COL_CODIGOCUENTA)->setIcon(QIcon(QPixmap(cpasivo)));
00198         } else if (cursoraux1->valor("tipocuenta") == "3") {
00199             item(pos, COL_CODIGOCUENTA)->setIcon(QIcon(QPixmap(cneto)));
00200         } else if (cursoraux1->valor("tipocuenta") == "4") {
00201             item(pos, COL_CODIGOCUENTA)->setIcon(QIcon(QPixmap(cingresos)));
00202         } else if (cursoraux1->valor("tipocuenta") == "5") {
00203             item(pos, COL_CODIGOCUENTA)->setIcon(QIcon(QPixmap(cgastos)));
00204         } // end if
00205     } // end if
00206     delete cursoraux1;
00207 
00209     cursoraux1= m_companyact->cargacursor("SELECT tipocuenta FROM cuenta WHERE idcuenta = " + linea->idctacliente());
00210     if (!cursoraux1->eof()) {
00211         if (cursoraux1->valor("tipocuenta") == "1") {
00212             item(pos, COL_CODIGOCTACLIENTE)->setIcon(QIcon(QPixmap(cactivo)));
00213         } else if (cursoraux1->valor("tipocuenta") == "2") {
00214             item(pos, COL_CODIGOCTACLIENTE)->setIcon(QIcon(QPixmap(cpasivo)));
00215         } else if (cursoraux1->valor("tipocuenta") == "3") {
00216             item(pos, COL_CODIGOCTACLIENTE)->setIcon(QIcon(QPixmap(cneto)));
00217         } else if (cursoraux1->valor("tipocuenta") == "4") {
00218             item(pos, COL_CODIGOCTACLIENTE)->setIcon(QIcon(QPixmap(cingresos)));
00219         } else if (cursoraux1->valor("tipocuenta") == "5") {
00220             item(pos, COL_CODIGOCTACLIENTE)->setIcon(QIcon(QPixmap(cgastos)));
00221         } // end if
00222     } // end if
00223     delete cursoraux1;
00224     _depura("END ListLinPrevCobroView::pintalistlinprevcobro", 0);
00225 }
00226 
00227 
00229 
00231 void ListLinPrevCobroView::pintalistlinprevcobro() {
00232     _depura("INICIO de pintalistlinprevcobro", 10);
00233     setRowCount(0);
00234     setRowCount(100);
00236     linprevcobro *linea;
00237     uint i = 0;
00238     QMutableListIterator<linprevcobro*> m_ilista(m_lista);
00240     m_ilista.toFront();
00242     while (m_ilista.hasNext()) {
00244         linea = m_ilista.next();
00245         pintalistlinprevcobro(linea, i);
00246     } // end while
00247 
00248     _depura("FIN de pintalistlinprevcobro", 10);
00249 }
00250 
00251 
00253 
00259 void ListLinPrevCobroView::contextMenu(int row, int col, const QPoint & pos) {
00260     _depura("ListLinPrevCobroView::contextMenu", 0);
00261     QMenu *popup = new QMenu();
00262     QAction *menuborrarlinea = popup->addAction(tr("Borrar linea"));
00263     QAction *menugenerarasiento = popup->addAction(tr("Generar asiento de cobro/pago"));
00264     QAction *menudesvinculaasiento = popup->addAction(tr("Desvincular asiento"));
00265     QAction *menuverasiento = popup->addAction(tr("Ver asiento"));
00266     QAction *menuverfact = popup->addAction(tr("Ver factura"));
00267     QAction *menucobro = popup->addAction(tr("Cobro"));
00268     QAction *menupago = popup->addAction(tr("Pago"));
00269 
00270     menugenerarasiento->setVisible(FALSE);
00271     menudesvinculaasiento->setVisible(FALSE);
00272     menuverasiento->setVisible(FALSE);
00273     menuverfact->setVisible(FALSE);
00274     menucobro->setVisible(FALSE);
00275     menupago->setVisible(FALSE);
00276 
00277     cursor2 *cur;
00278     QString query;
00279     linprevcobro *linea = lineaact();
00280     if (linea == NULL) {
00281         return;
00282     } // end if
00283     if (linea->idprevcobro() == "") {
00284         return;
00285     } // end if
00286     if (col == COL_TIPOPREVCOBRO) {
00287         menucobro->setVisible(TRUE);
00288         menupago->setVisible(TRUE);
00289     } // end if
00290 
00291     if (linea->idasiento() == "") {
00292         menugenerarasiento->setVisible(TRUE);
00293     } else {
00294         menudesvinculaasiento->setVisible(TRUE);
00295         menuverasiento->setVisible(TRUE);
00296     } // end if
00297     if (linea->idregistroiva() != "") {
00298         menuverfact->setVisible(TRUE);
00299     } // end if
00300 
00301     QAction *opcion = popup->exec(pos);
00302     delete popup;
00303 
00305 
00306     if (opcion == menuborrarlinea) {
00307         borralinprevcobro(row);
00308     } // end if
00309     if (opcion == menugenerarasiento) {
00312         if (linea->creaPago()) {
00313             pintalistlinprevcobro();
00314         } // end if
00315     } // end if
00316     if (opcion == menudesvinculaasiento) {
00317         if (linea->idasiento() != "") {
00318             query = "UPDATE prevcobro SET idasiento = NULL WHERE idprevcobro = " + linea->idprevcobro();
00319             m_companyact->ejecuta(query);
00320             linea->setidasiento("");
00321             pintalistlinprevcobro();
00322         } // end if
00323     } // end if
00324     if (opcion == menuverasiento) {
00325         if (linea->idasiento() != "") {
00326             m_companyact->intapuntsempresa()->muestraasiento(linea->idasiento().toInt());
00327         } // end if
00328     } // end if
00329     if (opcion == menuverfact) {
00330         query = "SELECT idborrador FROM registroiva WHERE idregistroiva = " + linea->idregistroiva();
00331         cur = m_companyact->cargacursor(query);
00332         if (linea->idregistroiva() != "") {
00333             RegistroIvaView *iva = new RegistroIvaView(m_companyact, 0);
00334             iva->inicializa1(cur->valor("idborrador").toInt());
00335             m_companyact->pWorkspace()->addWindow(iva);
00336             iva->show();
00337         } // end if
00338         delete cur;
00339     } // end if
00340     if (opcion == menucobro) {
00341         linea->settipoprevcobro("t");
00342         pintalistlinprevcobro(linea, row);
00343     } // end if
00344     if (opcion == menupago) {
00345         linea->settipoprevcobro("f");
00346         pintalistlinprevcobro(linea, row);
00347     } // end if
00348     _depura("END ListLinPrevCobroView::contextMenu", 0);
00349 }
00350 
00351 
00353 
00355 void ListLinPrevCobroView::borralinprevcobroact() {
00356     _depura("ListLinPrevCobroView::borralinprevcobroact", 0);
00357     borralinprevcobro(currentRow());
00358     _depura("END ListLinPrevCobroView::borralinprevcobroact", 0);
00359 }
00360 
00361 
00363 
00366 void ListLinPrevCobroView::pintalinlistlinprevcobro(int pos) {
00367     _depura("pintalinlistlinprevcobro", 10);
00368     linprevcobro *linea;
00369     linea = m_lista.at(pos);
00370     pintalistlinprevcobro(linea, pos);
00371 }
00372 
00373 
00376 
00380 void ListLinPrevCobroView::arreglaPosicion(int row, int col) {
00381     _depura("ListLinPrevCobroView::arreglaPosicion", 0);
00382     int newcol = col;
00383     int newrow = row;
00384     switch (col) {
00385     case COL_DOCPREVCOBRO:
00386         newcol = COL_FPREVISTAPREVCOBRO;
00387         newrow++;
00388         break;
00389     case COL_CODIGOCUENTA:
00390         newcol = COL_CANTIDADPREVCOBRO;
00391         break;
00392     case COL_CODIGOCTACLIENTE:
00393         newcol = COL_CODIGOCUENTA;
00394         break;
00395     default:
00396         newcol++;
00397         break;
00398     } // end switch
00399     setCurrentCell(newrow, newcol);
00400     _depura("END ListLinPrevCobroView::arreglaPosicion", 0);
00401 }
00402 
00404 
00408 void ListLinPrevCobroView::valueLineChanged(int row, int col) {
00409     _depura("valueLineChanged", 10);
00410     QString valor = item(row, col)->text();
00411     linprevcobro *linea;
00412     linea = lineaat(row);
00413     if (linea != NULL) {
00414         switch (col) {
00415         case COL_FPREVISTAPREVCOBRO:
00416             linea->setfprevistaprevcobro(normalizafecha(valor).toString("dd/MM/yyyy"));
00417             item(row, col)->setText(linea->fprevistaprevcobro());
00418             break;
00419         case COL_FCOBROPREVCOBRO:
00420             linea->setfcobroprevcobro(normalizafecha(valor).toString("dd/MM/yyyy"));
00421             linea->setfprevistaprevcobro(normalizafecha(valor).toString("dd/MM/yyyy"));
00422             item(row, col)->setText(linea->fcobroprevcobro());
00423             item(row, COL_FPREVISTAPREVCOBRO)->setText(linea->fprevistaprevcobro());
00424             break;
00425         case COL_CODIGOCUENTA:
00426             linea->setcodigocuenta(valor);
00427             item(row, col)->setText(linea->codigocuenta());
00428             item(row, COL_NOMCUENTA)->setText(linea->nomcuenta());
00429             item(row, COL_IDCUENTA)->setText(linea->idcuenta());
00430             break;
00431         case COL_CODIGOCTACLIENTE:
00432             linea->setcodigoctacliente(valor);
00433             item(row, col)->setText(linea->codigocuenta());
00434             item(row, COL_NOMCTACLIENTE)->setText(linea->nomctacliente());
00435             item(row, COL_IDCTACLIENTE)->setText(linea->idctacliente());
00436             break;
00437         case COL_CANTIDADPREVISTAPREVCOBRO:
00438             linea->setcantidadprevistaprevcobro(valor);
00439             item(row, col)->setText(linea->cantidadprevistaprevcobro());
00440             break;
00441         case COL_CANTIDADPREVCOBRO:
00442             linea->setcantidadprevcobro(valor);
00443             linea->setcantidadprevistaprevcobro(valor);
00444             item(row, col)->setText(linea->cantidadprevcobro());
00445             item(row, COL_CANTIDADPREVISTAPREVCOBRO)->setText(linea->cantidadprevistaprevcobro());
00446             break;
00447         case COL_DOCPREVCOBRO:
00448             linea->setdocprevcobro(valor);
00449             item(row, col)->setText(linea->docprevcobro());
00450             break;
00451         case COL_TIPOPREVCOBRO:
00452             if (valor == "COBRO") {
00453                 linea->settipoprevcobro("t");
00454                 item(row, col)->setText(tr("Cobro"));
00455             } else {
00456                 linea->settipoprevcobro("f");
00457                 item(row, col)->setText(tr("Pago"));
00458             } // end if
00459             break;
00460         } // end switch
00461     } // end if
00462 }
00463 
00464 
00466 
00469 linprevcobro *ListLinPrevCobroView::lineaact() {
00470     fprintf(stderr, "ListLinPrevCobroView::lineaact()\n");
00471     return lineaat(currentRow());
00472 }
00473 
00474 
00477 
00481 linprevcobro *ListLinPrevCobroView::lineaat(int row) {
00482     _depura("listlinprevcobro::lineaat", 2);
00483     linprevcobro *linea;
00484     if (row >= 0) {
00485         while (m_lista.value(row) == 0) {
00486             _depura("Creamos la linea", 10);
00487             linea = new linprevcobro(m_companyact);
00488             linea->setidregistroiva(mdb_idregistroiva);
00489             m_lista.append(linea);
00490         } // end while
00491         return m_lista.at(row);
00492     } else {
00493         _depura("Linea inexistente", 10);
00494         return NULL;
00495     } // end if
00496     _depura("END listlinprevcobro::lineaat", 2);
00497 }
00498 
00499 
00501 
00504 QString ListLinPrevCobroView::searchCuenta() {
00505     _depura("ListLinPrevCobroView::searchCuenta", 2, "Funcion no implementada");
00506 
00507     /*
00508         QString idcuenta;
00509         listcuentasview1 *listcuentas = new listcuentasview1(m_companyact);
00510         listcuentas->setModoLista();
00511         listcuentas->inicializa();
00512         listcuentas->exec();
00513         idcuenta = listcuentas->idcuenta();
00514         delete listcuentas;
00515         return idcuenta;
00516     */
00517     _depura("END ListLinPrevCobroView::searchCuenta", 2, "Funcion no implementada");
00518     return 0;
00519 }
00520 
00521 
00533 
00534 
00536 void ListLinPrevCobroView::s_creaPago() {
00537     _depura("ListLinPrevCobroView::s_creaPago", 0);
00541     for (int i = 0; i < rowCount(); i++) {
00542         _depura("Iteracion para los elementos de la lista", 10);
00543         /*
00544                 Q3TableItem *check = item(i,COL_SELECCION);
00545                 _depura ("Vamos a testear", 10);
00546                 if (check != NULL) {
00547                     Q3CheckTableItem *check1 = (Q3CheckTableItem *) check;
00548                     if (check1->isChecked()) {
00549                         linprevcobro *linea = lineaat(i);
00550                         linea->creaPago();
00551                     } // end if
00552                 } // end if
00553         */
00554     } // end for
00556     pintalistlinprevcobro();
00557     _depura("END ListLinPrevCobroView::s_creaPago", 0);
00558 }
00559 

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