listcuentasview1.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2002 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 <stdlib.h>
00022 
00023 #include <QMap>
00024 #include <QPixmap>
00025 #include <QKeyEvent>
00026 #include <QFileDialog>
00027 #include <QTextStream>
00028 
00029 #include "listcuentasview1.h"
00030 #include "funcaux.h"
00031 #include "cuentaview.h"
00032 #include "empresa.h"
00033 
00035 #include "images/cactivo.xpm"
00036 #include "images/cpasivo.xpm"
00037 #include "images/cneto.xpm"
00038 #include "images/cingresos.xpm"
00039 #include "images/cgastos.xpm"
00040 
00041 
00043 
00049 listcuentasview1::listcuentasview1(Empresa *emp, QWidget *parent, Qt::WFlags flag, edmode editmode)
00050         : FichaBc(emp, parent, flag), pgimportfiles(emp) {
00051     _depura("listcuentasview1::listcuentasview1", 0);
00052     setupUi(this);
00053 
00054     setTitleName(tr("Cuenta"));
00056     setDBTableName("cuenta");
00057 
00058     m_modo = editmode;
00060     QStringList headers;
00061     headers << tr("Codigo cuenta") << tr("Nombre cuenta") << tr("Debe") << tr("Haber") << tr("ID cuenta") << tr("Bloqueada") << tr("Nodebe") << tr("Nohaber") << tr("Regularizacion") << tr("Imputacion") << tr("Grupo") << tr("Tipo cuenta");
00062     ListView1->setHeaderLabels(headers);
00063     ccuenta = 0;
00064     cdesccuenta = 1;
00065     cdebe = 2;
00066     chaber = 3;
00067     cidcuenta = 4;
00068     cbloqueada = 5;
00069     cnodebe = 6;
00070     cnohaber = 7;
00071     cregularizacion = 8;
00072     cimputacion = 9;
00073     cgrupo = 10;
00074     ctipocuenta = 11;
00075 
00076     ListView1->setColumnWidth(ccuenta,175);
00077     ListView1->setColumnWidth(cdesccuenta,400);
00078     ListView1->hideColumn(cidcuenta);
00079     ListView1->hideColumn(cnodebe);
00080     ListView1->hideColumn(cnohaber);
00081     ListView1->hideColumn(cregularizacion);
00082     ListView1->hideColumn(cimputacion);
00083     ListView1->hideColumn(cgrupo);
00084     ListView1->hideColumn(ctipocuenta);
00085 
00086     tablacuentas->setColumnCount(3);
00087     headers << tr("CODIGO") << tr("NOMBRE");
00088     tablacuentas->setHorizontalHeaderLabels(headers);
00089 
00090     tablacuentas->hideColumn(2);
00091     tablacuentas->setColumnWidth(1, 400);
00092     tablacuentas->setColumnWidth(0, 100);
00093 
00094     installEventFilter(this);
00095     if (m_modo == EditMode)
00096         empresaBase()->meteWindow(windowTitle(), this);
00097     _depura("END listcuentasview1::listcuentasview1", 0);
00098 }
00099 
00100 
00102 
00104 listcuentasview1::~listcuentasview1() {
00105     _depura("listcuentasview1::~listcuentasview1", 10);
00106     if (m_modo == EditMode) {
00107         empresaBase()->sacaWindow(this);
00108     }// end if
00109     _depura("END listcuentasview1::~listcuentasview1", 10);
00110 }
00111 
00112 
00114 
00117 bool listcuentasview1::eventFilter(QObject *obj, QEvent *event) {
00118     _depura("listcuentasview1::eventFilter", 0);
00119     return QWidget::eventFilter(obj, event);
00120 }
00121 
00122 
00124 
00129 int listcuentasview1::inicializa() {
00130     _depura("listcuentasview1::inicializa", 0);
00131     QTreeWidgetItem *it;
00132     QMap <int, QTreeWidgetItem*> Lista1;
00133     int idcuenta;
00134     int padre;
00135     ListView1->clear();
00136 
00138     cursor2 *ctas = empresaBase()->cargacursor("SELECT * FROM cuenta ORDER BY codigo");
00139     if (ctas->eof()) {
00140         _depura("El query esta vacio\n", 0);
00141     } else {
00142         fprintf(stderr, "El query tiene registros \n");
00143     } // end if
00144     while (!ctas->eof()) {
00145         idcuenta = ctas->valor("idcuenta").toInt();
00146         padre = ctas->valor("padre").toInt();
00147         if (padre == 0) {
00148             it = new QTreeWidgetItem(ListView1);
00149             Lista1[idcuenta] = it;
00150         } else {
00151             fprintf(stderr, "Cuentas de subnivel: %d\n", padre);
00152             it = new QTreeWidgetItem(Lista1[padre]);
00153             Lista1[idcuenta] = it;
00154         } // end if
00155         it->setText(ccuenta, ctas->valor("codigo"));
00156         it->setText(cdesccuenta, ctas->valor("descripcion"));
00157         it->setText(cidcuenta, ctas->valor("idcuenta"));
00158         it->setText(cbloqueada, ctas->valor("bloqueada"));
00159         it->setText(cnodebe, ctas->valor("nodebe"));
00160         it->setText(cnohaber, ctas->valor("nohaber"));
00161         it->setText(cregularizacion, ctas->valor("regularizacion"));
00162         it->setText(cimputacion, ctas->valor("imputacion"));
00163         it->setText(cdebe, ctas->valor("debe"));
00164         it->setText(chaber, ctas->valor("haber"));
00166         if (ctas->valor("tipocuenta") == "1")
00167             it->setIcon(ccuenta, QPixmap(cactivo));
00168         else if (ctas->valor("tipocuenta") == "2")
00169             it->setIcon(ccuenta, QPixmap(cpasivo));
00170         else if (ctas->valor("tipocuenta") == "3")
00171             it->setIcon(ccuenta, QPixmap(cneto));
00172         else if (ctas->valor("tipocuenta") == "4")
00173             it->setIcon(ccuenta, QPixmap(cingresos));
00174         else if (ctas->valor("tipocuenta") == "5")
00175             it->setIcon(ccuenta, QPixmap(cgastos));
00176         ListView1->setItemExpanded(it, TRUE);
00177         ctas->siguienteregistro();
00178     } // end while
00179     delete ctas;
00180 
00183     numdigitos = empresaBase()->numdigitosempresa();
00184 
00185     inicializatabla();
00186     _depura("END listcuentasview1::inicializa", 0);
00187     return 0;
00188 }
00189 
00190 
00192 
00196 void listcuentasview1::inicializatabla()  {
00197     _depura("listcuentasview1::inicializatabla", 0);
00198     QString query;
00199     query = "SELECT * FROM cuenta ORDER BY codigo";
00200     cursor2 *cursoraux1 = empresaBase()->cargacursor(query);
00201     tablacuentas->setRowCount(cursoraux1->numregistros());
00202     int i = 0;
00203     QTableWidgetItem *dato;
00204     while (!cursoraux1->eof()) {
00205         dato = new QTableWidgetItem(cursoraux1->valor("codigo"));
00206         dato->setFlags(Qt::ItemIsEnabled);
00208         if (cursoraux1->valor("tipocuenta") == "1")
00209             dato->setIcon(QPixmap(cactivo));
00210         else if (cursoraux1->valor("tipocuenta") == "2")
00211             dato->setIcon(QPixmap(cpasivo));
00212         else if (cursoraux1->valor("tipocuenta") == "3")
00213             dato->setIcon(QPixmap(cneto));
00214         else if (cursoraux1->valor("tipocuenta") == "4")
00215             dato->setIcon(QPixmap(cingresos));
00216         else if (cursoraux1->valor("tipocuenta") == "5")
00217             dato->setIcon(QPixmap(cgastos));
00218         tablacuentas->setItem(i, 0, dato);
00219         dato = new QTableWidgetItem(cursoraux1->valor("descripcion"));
00220         dato->setFlags(Qt::ItemIsEnabled);
00221         tablacuentas->setItem(i, 1, dato);
00222         dato->setFlags(Qt::ItemIsEnabled);
00223         dato = new QTableWidgetItem(cursoraux1->valor("idcuenta"));
00224         tablacuentas->setItem(i, 2, dato);
00225 
00226         QString codigo = cursoraux1->valor("codigo");
00227         if ((unsigned int)codigo.length() != numdigitos) {
00228             tablacuentas->hideRow(i);
00229         } // end if
00230         cursoraux1->siguienteregistro();
00231         i++;
00232     } // end while
00233     delete cursoraux1;
00234     _depura("END listcuentasview1::inicializatabla", 0);
00235 }
00236 
00237 
00239 
00245 void listcuentasview1::on_ListView1_itemClicked(QTreeWidgetItem *it, int) {
00246     _depura("listcuentasview1::on_ListView1_itemClicked", 0);
00247     QString idcuenta = it->text(cidcuenta);
00248     QString cad;
00249     for (int i = 0; i < tablacuentas->rowCount() - 1; i++) {
00250         cad = tablacuentas->item(i, 2)->text();
00251         if (cad == idcuenta) {
00252             tablacuentas->setCurrentCell(i, 2);
00253             tablacuentas->scrollToItem(tablacuentas->item(i, 2), QAbstractItemView::EnsureVisible);
00254             break;
00255         } // end if
00256     } // end for
00257     _depura("END listcuentasview1::on_ListView1_itemClicked", 0);
00258 }
00259 
00260 
00262 
00267 void listcuentasview1::on_mui_busqueda_textChanged(const QString &string1) {
00268     _depura("listcuentasview1::on_mui_busqueda_textChanged", 0);
00269     QList<QTreeWidgetItem *> it;
00270     QString cod = extiendecodigo(string1, (int) numdigitos);
00271     it = ListView1->findItems(cod, Qt::MatchStartsWith, ccuenta);
00272     if (it.count() > 0) {
00273         ListView1->setCurrentItem(it.first());
00274     } else {
00275         QTreeWidgetItemIterator it(ListView1);
00276         QRegExp patron("^.*" + string1 + ".*$");
00277         patron.setCaseSensitivity(Qt::CaseInsensitive);
00278         while (*it){
00279             if (patron.exactMatch((*it)->text(cdesccuenta)))
00280                 ListView1->setCurrentItem(*it);
00281             ++it;
00282         } // end while
00283     } // end if
00284     _depura("END listcuentasview1::on_mui_busqueda_textChanged", 0);
00285 }
00286 
00287 
00289 
00296 void listcuentasview1::on_ListView1_itemDoubleClicked(QTreeWidgetItem *it, int) {
00297     _depura("listcuentasview1::on_ListView1_doubleClicked", 0);
00298     on_ListView1_itemClicked(it, 0);
00299     mdb_codcuenta = it->text(ccuenta);
00300     mdb_idcuenta = it->text(cidcuenta);
00301     mdb_desccuenta = it->text(cdesccuenta);
00302     if (m_modo == EditMode) {
00303         CuentaView *nuevae = new CuentaView(empresaBase(), 0);
00304         nuevae->cargar(idcuenta());
00305         inicializa();
00306         empresaBase()->pWorkspace()->addWindow(nuevae);
00307         nuevae->show();
00308     } else {
00309         emit(selected(mdb_idcuenta));
00310     } // end if
00311     _depura("listcuentasview1::on_ListView1_doubleClicked", 0);
00312 }
00313 
00314 
00317 
00324 void listcuentasview1::on_mui_crear_clicked()  {
00325     _depura("listcuentasview1::on_mui_crear_clicked", 0);
00326     QString codigo;
00327 
00328     CuentaView *nuevae = new CuentaView(empresaBase(), 0);
00329 
00330     if (ListView1->selectedItems().count() > 0) {
00331     QTreeWidgetItem *it;
00332         it = ListView1->currentItem();
00333         if (it) {
00334                 codigo = it->text(ccuenta);
00335                 nuevae->nuevacuenta(codigo);
00336         } // end if
00337     } // end if
00338 
00339     empresaBase()->pWorkspace()->addWindow(nuevae);
00340     nuevae->show();
00341     _depura("END listcuentasview1::on_mui_crear_clicked", 0);
00342 }
00343 
00344 
00347 
00354 void listcuentasview1::on_mui_editar_clicked()  {
00355     _depura("listcuentasview1::on_mui_editar_clicked", 0);
00356     QTreeWidgetItem *it;
00357     it = ListView1->currentItem();
00358     if (!it) {
00359         mensajeInfo(tr("Debe seleccionar una cuenta"));
00360         return;
00361     }
00362     on_ListView1_itemClicked(it, 0);
00363     mdb_codcuenta = it->text(ccuenta);
00364     mdb_idcuenta = it->text(cidcuenta);
00365     mdb_desccuenta = it->text(cdesccuenta);
00366     CuentaView *nuevae = new CuentaView(empresaBase(), 0);
00367     nuevae->cargar(idcuenta());
00368     empresaBase()->pWorkspace()->addWindow(nuevae);
00369     nuevae->show();
00370     _depura("END listcuentasview1::on_mui_editar_clicked", 0);
00371 }
00372 
00373 
00375 
00378 void listcuentasview1::on_mui_borrar_clicked() {
00379     _depura("listcuentasview1::on_mui_borrar_clicked", 0);
00380     QTreeWidgetItem *it;
00381     it = ListView1->currentItem();
00382     if (!it) {
00383         mensajeInfo(tr("Debe seleccionar una cuenta"));
00384         return;
00385     } // end if
00386     int valor = QMessageBox::warning(0,
00387                                      tr("Borrar cuenta"),
00388                                      tr("Se procedera a borrar la cuenta."),
00389                                      QMessageBox::Yes, QMessageBox::No);
00390     if (valor ==  QMessageBox::Yes) {
00391         int idcuenta = atoi((char *) it->text(cidcuenta).toAscii().constData());
00392         empresaBase()->begin();
00393         if (empresaBase()->borrarcuenta(idcuenta) == 0) {
00394             delete it;
00395         } else {
00396             mensajeInfo("No se ha podido borrar la cuenta." );
00397         } // end if
00398         empresaBase()->commit();
00399     } // end if
00400     _depura("END listcuentasview1::on_mui_borrar_clicked", 0);
00401 }
00402 
00403 
00405 
00410 void listcuentasview1::on_tablacuentas_doubleClicked(int row, int, int, const QPoint &) {
00411     _depura("listcuentasview1::on_tablacuentas_doubleClicked", 0);
00412     QString idcuenta = tablacuentas->item(row, 2)->text();
00413     QList <QTreeWidgetItem *> it;
00414     it = ListView1->findItems(idcuenta, Qt::MatchExactly, cidcuenta);
00415     ListView1->setCurrentItem(it.first());
00416     on_ListView1_itemDoubleClicked(it.first(), 0);
00417     _depura("END listcuentasview1::on_tablacuentas_doubleClicked", 0);
00418 }
00419 
00420 
00422 
00424 void listcuentasview1::on_mui_busqueda_editFinished() {
00425     _depura("listcuentasview1::on_mui_busqueda_editFinished", 0);
00426     QTreeWidgetItem *it = ListView1->currentItem();
00427     if (it != 0) {
00428         on_ListView1_itemDoubleClicked(it, 0);
00429     } // end if
00430     _depura("END listcuentasview1::on_mui_busqueda_editFinished", 0);
00431 }
00432 
00433 
00435 
00442 void listcuentasview1::on_mui_imprimir_clicked() {
00443     _depura("listcuentasview1::on_mui_imprimir_clicked", 0);
00444     QString archivo = confpr->valor(CONF_DIR_OPENREPORTS) + "listado.rml";
00445     QString archivod = confpr->valor(CONF_DIR_USER) + "listado.rml";
00446     QString archivologo = confpr->valor(CONF_DIR_OPENREPORTS) + "logo.jpg";
00448 #ifdef WINDOWS
00449 
00450     archivo = "copy " + archivo + " " + archivod;
00451 #else
00452 
00453     archivo = "cp " + archivo + " " + archivod;
00454 #endif
00455 
00456     system (archivo.toAscii());
00458 #ifdef WINDOWS
00459 
00460     archivologo = "copy " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00461 #else
00462 
00463     archivologo = "cp " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00464 #endif
00465 
00466     system(archivologo.toAscii().constData());
00467 
00468     QFile file;
00469     file.setFileName(archivod);
00470     file.open(QIODevice::ReadOnly);
00471     QTextStream stream(&file);
00472     QString buff = stream.readAll();
00473     file.close();
00474     QString fitxersortidatxt;
00475 
00476     QString query = "SELECT * FROM cuenta ORDER BY codigo";
00477     cursor2 *cur = empresaBase()->cargacursor(query);
00478 
00480     fitxersortidatxt = "<blockTable style=\"tabla\" repeatRows=\"1\">";
00481     fitxersortidatxt += "<tr><td>Codigo</td>\n";
00482     fitxersortidatxt += "<td>Descripcion</td>\n";
00483     fitxersortidatxt += "<td>Debe</td>\n";
00484     fitxersortidatxt += "<td>Haber</td></tr>\n";
00485     while(!cur->eof()) {
00486         fitxersortidatxt += "<tr>\n";
00487         fitxersortidatxt += "<td>"+cur->valor("codigo")+"</td>\n";
00488         fitxersortidatxt += "<td>"+cur->valor("descripcion")+"</td>\n";
00489         fitxersortidatxt += "<td>"+cur->valor("debe")+"</td>\n";
00490         fitxersortidatxt += "<td>"+cur->valor("haber")+"</td>\n";
00491         fitxersortidatxt += "</tr>\n";
00492         cur->siguienteregistro();
00493     } // end while
00494     fitxersortidatxt += "</blockTable>";
00495 
00496     delete cur;
00497 
00498     buff.replace("[story]", fitxersortidatxt);
00499     buff.replace("[titulo]", "Cuentas");
00500 
00501     if (file.open(QIODevice::WriteOnly)) {
00502         QTextStream stream(&file);
00503         stream << buff;
00504         file.close();
00505     } // end if
00506 
00507     invocaPDF("listado");
00508     _depura("END listcuentasview1::on_mui_imprimir_clicked", 0);
00509 }
00510 
00511 
00514 void listcuentasview1::on_mui_exportar_clicked() {
00515     _depura("listcuentasview1::on_mui_exportar_clicked", 0);
00516     QFile filexml(QFileDialog::getSaveFileName(this,
00517                   tr("Elija el archivo"),
00518                   confpr->valor(CONF_DIR_USER),
00519                   tr("Plan contable (*.xml)")));
00520     if (filexml.open(QIODevice::WriteOnly)) {
00521         bulmages2XML(filexml, IMPORT_CUENTAS);
00522         filexml.close();
00523     } else {
00524         mensajeInfo("Error al abrir archivo\n");
00525     } // end if
00526     _depura("END listcuentasview1::on_mui_exportar_clicked", 0);
00527 }
00528 
00529 
00532 void listcuentasview1::on_mui_importar_clicked() {
00533     _depura("listcuentasview1::on_mui_importar_clicked", 0);
00534     QFile filexml(QFileDialog::getOpenFileName(this,
00535                   tr("Elija el archivo"),
00536                   confpr->valor(CONF_DIR_USER),
00537                   tr("Plan contable (*.xml)")));
00538     if (filexml.open(QIODevice::ReadOnly)) {
00539         XML2Bulmages(filexml, IMPORT_CUENTAS);
00540         filexml.close();
00541         inicializa();
00542     } else {
00543         mensajeInfo("Error al abrir archivo\n");
00544     } // end if
00545     _depura("END listcuentasview1::on_mui_importar_clicked", 0);
00546 }
00547 
00548 
00550 
00552 void listcuentasview1::selectMode() {
00553     _depura("listcuentasview1::selectMode", 0);
00554     m_modo = SelectMode;
00555     _depura("listcuentasview1::selectMode", 0);
00556 }
00557 
00558 
00560 
00562 void listcuentasview1::editMode() {
00563     _depura("listcuentasview1::editMode", 0);
00564     m_modo = EditMode;
00565     _depura("END listcuentasview1::editMode", 0);
00566 }
00567 
00568 
00570 
00572 QString listcuentasview1::codcuenta() {
00573     _depura("listcuentasview1::codcuenta", 0);
00574     return mdb_codcuenta;
00575     _depura("listcuentasview1::codcuenta", 0);
00576 }
00577 
00578 
00580 
00583 QString listcuentasview1::idcuenta() {
00584     _depura("listcuentasview1::idcuenta", 0);
00585     _depura("listcuentasview1::idcuenta", 0);
00586     return mdb_idcuenta;
00587 }
00588 
00590 
00593 QString listcuentasview1::desccuenta() {
00594     _depura("listcuentasview1::desccuenta", 0);
00595     _depura("listcuentasview1::desccuenta", 0);
00596     return mdb_desccuenta;
00597 }
00598 
00599 
00600 void listcuentasview1::on_mui_actualizar_clicked() {
00601     _depura("listcuentasview1::on_mui_actualizar_clicked", 0);
00602     _depura("END listcuentasview1::on_mui_actualizar_clicked", 0);
00603     inicializa();
00604 }
00605 

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