ccosteview.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 "ccosteview.h"
00022 #include "empresa.h"
00023 #include "selectccosteview.h"
00024 #include "subform2bc.h"
00025 
00026 #define COL_NOM_COSTE  0
00027 #define COL_DESC_COSTE 1
00028 #define COL_IDC_COSTE  2
00029 
00030 
00033 
00037 ccosteview::ccosteview(Empresa  *emp, QWidget *parent)
00038         : FichaBc(emp, parent) {
00039     _depura("ccosteview::ccosteview", 0);
00040     setAttribute(Qt::WA_DeleteOnClose);
00041     setupUi(this);
00042 
00043     setTitleName(tr("Centro de Coste"));
00045     setDBTableName("c_coste");
00046     setDBCampoId("idc_coste");
00047     addDBCampo("idc_coste", DBCampo::DBint, DBCampo::DBPrimaryKey, tr("Id. Centro Coste"));
00048     addDBCampo("nombre", DBCampo::DBvarchar, DBCampo::DBNotNull, tr("Nombre"));
00049     addDBCampo("descripcion", DBCampo::DBvarchar, DBCampo::DBNotNull, tr("Descripcion"));
00050 
00052     mui_cdistribuidos->setEmpresaBase(emp);
00053     mui_cdistribuidos->setDBTableName("c_costedist");
00054     mui_cdistribuidos->setFileConfig("ccostedist");
00055     mui_cdistribuidos->setDBCampoId("idc_costedist");
00056     mui_cdistribuidos->addSHeader("nomc_coste", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNone, tr("Nombre Destinatario"));
00057     mui_cdistribuidos->addSHeader("porcentc_costedist", DBCampo::DBnumeric, DBCampo::DBNotNull, SHeader::DBNone, tr("Porcentaje"));
00058     mui_cdistribuidos->addSHeader("idc_costedist", DBCampo::DBint, DBCampo::DBPrimaryKey, SHeader::DBNoWrite | SHeader::DBNoView, tr("Id"));
00059     mui_cdistribuidos->addSHeader("idc_coste", DBCampo::DBint, DBCampo::DBNothing, SHeader::DBNoWrite | SHeader::DBNoView, tr("Destinatario"));
00060     mui_cdistribuidos->addSHeader("iddestc_coste", DBCampo::DBint, DBCampo::DBNotNull, SHeader::DBNoWrite | SHeader::DBNoView, tr("Origen"));
00061     mui_cdistribuidos->setinsercion(TRUE);
00062     mui_cdistribuidos->setOrdenEnabled(FALSE);
00063     idc_coste = 0;
00064 
00065 
00067     int res = g_plugins->lanza("ccosteview_ccosteview", this);
00068     if (res != 0) {
00069         return;
00070     } // end if
00071 
00072 
00073     mui_list->setColumnCount(3);
00074     QStringList headers;
00075     headers << tr("Nombre") << tr("Descripcion") << tr("Id centro de coste");
00076     mui_list->setColumnWidth(0, 200);
00077     mui_list->setHeaderLabels(headers);
00078     mui_list->setColumnHidden(COL_IDC_COSTE, TRUE);
00079     dialogChanges_setQObjectExcluido(mui_list);
00080     dialogChanges_cargaInicial();
00081     meteWindow(windowTitle(), this);
00082     repintar();
00083     _depura("END ccosteview::ccosteview", 0);
00084 }
00085 
00086 
00088 
00090 ccosteview::~ccosteview() {
00091     _depura("ccosteview::~ccosteview", 0);
00092     empresaBase()->sacaWindow(this);
00093     _depura("END ccosteview::~ccosteview", 0);
00094 }
00095 
00096 
00098 
00100 void ccosteview::repintar() {
00101     _depura("ccosteview::pintar", 0);
00102     QTreeWidgetItem *it;
00103     QMap <int, QTreeWidgetItem *> Lista;
00104     int padre;
00105     int idc_coste1 = 0;
00106     cursor2 *cursoraux1, *cursoraux2;
00107 
00109     mui_list->clear();
00110 
00112     cursoraux1 = empresaBase()->cargacursor("SELECT * FROM c_coste WHERE padre ISNULL ORDER BY idc_coste");
00113     while (!cursoraux1->eof()) {
00114         padre = atoi( cursoraux1->valor("padre").toAscii());
00115         idc_coste1 = atoi( cursoraux1->valor("idc_coste").toAscii());
00116         it = new QTreeWidgetItem(mui_list);
00117         Lista[idc_coste1] = it;
00118         it->setText(COL_IDC_COSTE, cursoraux1->valor("idc_coste"));
00119         it->setText(COL_DESC_COSTE,cursoraux1->valor("descripcion"));
00120         it->setText(COL_NOM_COSTE, cursoraux1->valor("nombre"));
00121         mui_list->expandItem(it);
00122         cursoraux1->siguienteregistro();
00123     } // end while
00124     delete cursoraux1;
00125 
00127     cursoraux2= empresaBase()->cargacursor("SELECT * FROM c_coste WHERE padre IS NOT NULL ORDER BY idc_coste");
00128     while (!cursoraux2->eof()) {
00129         padre = cursoraux2->valor("padre").toInt();
00130         idc_coste1 = cursoraux2->valor("idc_coste").toInt();
00131         if (Lista[padre]) {
00132             it = new QTreeWidgetItem(Lista[padre]);
00133             Lista[idc_coste1] = it;
00134             it->setText(COL_IDC_COSTE, cursoraux2->valor("idc_coste"));
00135             it->setText(COL_DESC_COSTE, cursoraux2->valor("descripcion"));
00136             it->setText(COL_NOM_COSTE, cursoraux2->valor("nombre"));
00137             mui_list->expandItem(it);
00138         } else {
00139             _depura(tr("Error en la carga de centros de coste"), 2);
00140         } // end if
00141         cursoraux2->siguienteregistro();
00142     } // end while
00143     delete cursoraux2;
00144 
00145 //    if (idc_coste != 0) {
00146 //        mostrarplantilla();
00147 //    } // end if
00148 
00151     SelectCCosteView *scoste = empresaBase()->getselccostes();
00152     scoste->cargacostes();
00153     _depura("END ccosteview::pintar", 0);
00154 }
00155 
00156 
00158 
00161 void ccosteview::on_mui_list_itemClicked(QTreeWidgetItem *it, int) {
00162     _depura("ccosteview::on_mui_list_itemClicked", 0);
00163     int previdccoste = it->text(COL_IDC_COSTE).toInt();
00164     if (dialogChanges_hayCambios()) {
00165         if (QMessageBox::warning(this,
00166                                  tr("Guardar centro de coste"),
00167                                  tr("Desea guardar los cambios?"),
00168                                  tr("&Guardar"), tr("&Cancelar"), 0, 0, 1) == 0) {
00169             on_mui_guardar_clicked();
00170         } // end if
00171     } // end if
00172     idc_coste = previdccoste;
00173     mostrarplantilla();
00174     _depura("END ccosteview::on_mui_list_itemClicked", 0);
00175 }
00176 
00177 
00179 
00181 void ccosteview::mostrarplantilla() {
00182     _depura("ccosteview::mostrarplantilla", 0);
00183 
00184     QString query;
00185 
00186     _depura("mostrarplantilla", 2, QString::number(idc_coste));
00187     FichaBc::cargar(QString::number(idc_coste));
00188 
00189     query = "SELECT * FROM c_costedist LEFT JOIN (SELECT idc_coste AS idcc, nombre AS nomc_coste FROM c_coste) AS t1 ON c_costedist.idc_Coste = t1.idcc WHERE iddestc_coste=" + QString::number(idc_coste);
00190     mui_cdistribuidos->cargar(query);
00191 
00192 
00193     dialogChanges_cargaInicial();
00194     _depura("END ccosteview::mostrarplantilla", 0);
00195 }
00196 
00197 
00199 
00201 int ccosteview::guardar() {
00202     _depura("ccosteview::guardar", 0);
00203     FichaBc::guardar();
00204 
00205     mui_cdistribuidos->setColumnValue("iddestc_coste", QString::number(idc_coste));
00206     mui_cdistribuidos->guardar();
00207 
00208     dialogChanges_cargaInicial();
00209     repintar();
00210     _depura("END ccosteview::guardar", 0);
00211     return 0;
00212 }
00213 
00214 
00216 
00218 void ccosteview::on_mui_crear_clicked() {
00219     _depura("ccosteview::on_mui_crear_clicked", 0);
00221     if (dialogChanges_hayCambios()) {
00222         if (QMessageBox::warning(this,
00223                                  tr("Guardar centro de coste"),
00224                                  tr("Desea guardar los cambios?"),
00225                                  QMessageBox::Ok,
00226                                  QMessageBox::Cancel) == QMessageBox::Ok) {
00227             on_mui_guardar_clicked();
00228         } // end if
00229     } // end if
00230 
00231     QString query;
00232     QTreeWidgetItem *it;
00233     it = mui_list->currentItem();
00234     if (it) {
00235         idc_coste = atoi(it->text(COL_IDC_COSTE).toAscii());
00236         query.sprintf("INSERT INTO c_coste (padre, nombre, descripcion) VALUES (%d, 'Nuevo centro de coste', 'Escriba su descripcion')", idc_coste);
00237         empresaBase()->begin();
00238         empresaBase()->ejecuta(query);
00239     } else {
00240         query.sprintf("INSERT INTO c_coste (nombre, descripcion) VALUES ('Nuevo centro de coste', 'Escriba su descripcion')");
00241         empresaBase()->begin();
00242         empresaBase()->ejecuta(query);
00243     } // end if
00244     query.sprintf("SELECT MAX(idc_coste) AS id_coste FROM c_coste");
00245     cursor2 *cur = empresaBase()->cargacursor(query);
00246     idc_coste = atoi(cur->valor("id_coste").toAscii());
00247     delete cur;
00248     empresaBase()->commit();
00249     repintar();
00250     _depura("END ccosteview::on_mui_crear_clicked", 0);
00251 }
00252 
00253 
00255 
00257 void ccosteview::on_mui_borrar_clicked() {
00258     _depura("ccosteview::on_mui_borrar_clicked", 0);
00259     try {
00260         switch (QMessageBox::warning(this,
00261                                      tr("Borrar centro de coste"),
00262                                      tr("Se va a borrar el centro de coste.\nEsta operacion puede ocasionar perdida de datos."),
00263                                      tr("&Borrar"), tr("&Cancelar"), 0, 0, 1)) {
00264         case 0: 
00265             QString query;
00266             query.sprintf("DELETE FROM c_coste WHERE idc_coste = %d", idc_coste);
00267             empresaBase()->begin();
00268             empresaBase()->ejecuta(query);
00269             empresaBase()->commit();
00270             idc_coste = 0;
00271             repintar();
00272         } // end switch
00273     } catch (...) {
00274         mensajeInfo(tr("No se pudo borrar el Centro de Coste"));
00275         empresaBase()->rollback();
00276         return;
00277     } // end try
00278     _depura("END ccosteview::on_mui_borrar_clicked", 0);
00279 }
00280 
00281 
00282 

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