tipoivaview.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 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 <QWidget>
00022 
00023 #include "tipoivaview.h"
00024 #include "empresa.h"
00025 #include "busquedacuenta.h"
00026 
00027 
00029 
00033 tipoivaview::tipoivaview(Empresa *emp, QWidget *parent)
00034         : FichaBc(emp, parent) {
00035     _depura("tipoivaview::tipoivaview", 0);
00036 
00037     setTitleName(tr("Tipo IVA"));
00039     setDBTableName("tipoiva");
00040 
00041     this->setAttribute(Qt::WA_DeleteOnClose);
00042     setupUi(this);
00043     mui_codigoCtaTipoIVA->setEmpresaBase(emp);
00044     m_curtipoiva = NULL;
00045 
00046     dialogChanges_setQObjectExcluido(mui_comboTipoIVA);
00047 
00048     pintar();
00049     dialogChanges_cargaInicial();
00050     meteWindow(windowTitle(), this);
00051     _depura("END tipoivaview::tipoivaview", 0);
00052 }
00053 
00054 
00057 
00059 tipoivaview::~tipoivaview() {
00060     _depura("tipoivaview::~tipoivaview", 0);
00061     on_mui_guardar2_clicked();
00062     if (m_curtipoiva != NULL)
00063         delete m_curtipoiva;
00064     empresaBase()->sacaWindow(this);
00065     _depura("END tipoivaview::~tipoivaview", 0);
00066 }
00067 
00068 
00071 
00073 void tipoivaview::pintar(QString idtipoiva) {
00074     _depura("tipoivaview::pintar", 0);
00075     int posicion = 0;
00077     if (m_curtipoiva != NULL)
00078         delete m_curtipoiva;
00079     QString query = "SELECT * from tipoiva left join cuenta ON tipoiva.idcuenta = cuenta.idcuenta ORDER BY nombretipoiva";
00080     m_curtipoiva = empresaBase()->cargacursor(query);
00081     mui_comboTipoIVA->clear();
00082     int i = 0;
00083     while (!m_curtipoiva->eof()) {
00084         mui_comboTipoIVA->insertItem(i, m_curtipoiva->valor("nombretipoiva"));
00085         if (idtipoiva == m_curtipoiva->valor("idtipoiva") )
00086             posicion = i;
00087         m_curtipoiva->siguienteregistro();
00088         i++;
00089     } // end while
00090     _depura("END tipoivaview::pintar", 0);
00091 }
00092 
00093 
00095 
00097 void tipoivaview::mostrarplantilla(int pos) {
00098     _depura("tipoivaview::mostrarplantilla", 0);
00100     if (dialogChanges_hayCambios()) {
00101         if (QMessageBox::warning(this,
00102                                  tr("Guardar tipo de IVA"),
00103                                  tr("Desea guardar los cambios?"),
00104                                  QMessageBox::Ok,
00105                                  QMessageBox::Cancel) == QMessageBox::Ok)
00106             on_mui_guardar2_clicked();
00107     } // end if
00108     if (mui_comboTipoIVA->count() > 0) {
00109         if (pos != 0)
00110             mui_comboTipoIVA->setCurrentIndex(pos);
00111         m_posactual = mui_comboTipoIVA->currentIndex();
00112         mui_nombreTipoIVA->setText(m_curtipoiva->valor("nombretipoiva", m_posactual));
00113         mui_codigoCtaTipoIVA->setText(m_curtipoiva->valor("codigo", m_posactual));
00114         mui_porcentTipoIVA->setText(m_curtipoiva->valor("porcentajetipoiva", m_posactual));
00116         dialogChanges_cargaInicial();
00117     } // end if
00118     _depura("END tipoivaview::mostrarplantilla", 0);
00119 }
00120 
00121 
00123 
00125 void tipoivaview::on_mui_comboTipoIVA_currentIndexChanged(int) {
00126     _depura("tipoivaview::on_mui_comboTipoIVA_currentIndexChanged", 0);
00127     mostrarplantilla();
00128     _depura("END tipoivaview::on_mui_comboTipoIVA_currentIndexChanged", 0);
00129 }
00130 
00131 
00134 
00137 void tipoivaview::on_mui_guardar2_clicked() {
00138     _depura("tipoivaview::on_mui_guardar2_clicked", 0);
00139     QString idtipoiva = m_curtipoiva->valor("idtipoiva", m_posactual);
00140     QString query = "UPDATE tipoiva SET nombretipoiva = '" + mui_nombreTipoIVA->text() + "', porcentajetipoiva = " + mui_porcentTipoIVA->text() + " , idcuenta = id_cuenta('" + mui_codigoCtaTipoIVA->text() + "') WHERE idtipoiva = " + m_curtipoiva->valor("idtipoiva", m_posactual);
00141     empresaBase()->ejecuta(query);
00143     dialogChanges_cargaInicial();
00144     pintar(m_curtipoiva->valor("idtipoiva", m_posactual));
00145     _depura("END tipoivaview::on_mui_guardar2_clicked", 0);
00146 }
00147 
00148 
00150 
00153 void tipoivaview::on_mui_nuevo2_clicked() {
00154     _depura("tipoivaview::on_mui_nuevo2_clicked()", 0);
00155     try {
00157         if (dialogChanges_hayCambios()) {
00158             if (QMessageBox::warning(this,
00159                                      tr("Guardar tipo de IVA"),
00160                                      tr("Desea guardar los cambios?"),
00161                                      QMessageBox::Ok,
00162                                      QMessageBox::Cancel ) == QMessageBox::Ok)
00163                 on_mui_guardar2_clicked();
00164         } // end if
00165         QString query = "INSERT INTO tipoiva (nombretipoiva, porcentajetipoiva, idcuenta) VALUES ('NUEVO TIPO IVA', 0, id_cuenta('47'))";
00166         empresaBase()->begin();
00167         empresaBase()->ejecuta(query);
00168         cursor2 *cur = empresaBase()->cargacursor("SELECT max(idtipoiva) AS idtipoiva FROM tipoiva");
00169         empresaBase()->commit();
00170         pintar(cur->valor("idtipoiva"));
00171         delete cur;
00172     } catch (...) {
00173         empresaBase()->rollback();
00174         return;
00175     } // end try
00176     _depura("END tipoivaview::on_mui_nuevo2_clicked()", 0);
00177 }
00178 
00179 
00181 
00184 void tipoivaview::on_mui_borrar2_clicked() {
00185     _depura("tipoivaview::on_mui_borrar2_clicked", 0);
00186     switch (QMessageBox::warning(this,
00187                                  tr("Borrar tipo de IVA"),
00188                                  tr("Se va a borrar el tipo de IVA. \nEsto puede ocasionar perdida de datos."),
00189                                  QMessageBox::Ok,
00190                                  QMessageBox::Cancel)) {
00191     case QMessageBox::Ok: 
00192         empresaBase()->ejecuta("DELETE FROM tipoiva WHERE idtipoiva = " + m_curtipoiva->valor("idtipoiva", mui_comboTipoIVA->currentIndex()));
00193         pintar();
00194         break;
00195     case QMessageBox::Cancel: 
00196         break;
00197     } // end switch
00198     _depura("END tipoivaview::on_mui_borrar2_clicked", 0);
00199 }
00200 
00201 
00204 
00208 bool tipoivaview::close() {
00209     _depura("tipoivaview::close", 0);
00211     if (dialogChanges_hayCambios()) {
00212         if (QMessageBox::warning(this,
00213                                  tr("Guardar tipo de IVA"),
00214                                  tr("Desea guardar los cambios?"),
00215                                  QMessageBox::Ok,
00216                                  QMessageBox::Cancel) == QMessageBox::Ok)
00217             on_mui_guardar2_clicked();
00218     } // end if
00219     _depura("END tipoivaview::close", 0);
00220     return QWidget::close();
00221 }
00222 

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