inventariosview.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 <QMessageBox>
00022 #include <QFile>
00023 #include <QTextStream>
00024 
00025 #include "inventariosview.h"
00026 #include "company.h"
00027 #include "funcaux.h"
00028 #include "inventarioview.h"
00029 
00030 
00032 
00034 void InventariosView::on_mui_listado_itemDoubleClicked(QTableWidgetItem *) {
00035     _depura("InventariosView::on_mui_listado_itemDoubleClicked", 0);
00036     on_mui_editar_clicked();
00037     _depura("END InventariosView::on_mui_listado_itemDoubleClicked", 0);
00038 }
00039 
00040 
00042 
00045 void InventariosView::on_mui_crear_clicked() {
00046             _depura("InventariosView::on_mui_crear_clicked", 0);
00047             InventarioView *bud = new InventarioView((Company *) empresaBase(), 0);
00048             if (bud->cargar("0"))
00049                 return;
00050             empresaBase()->m_pWorkspace->addWindow(bud);
00051             bud->show();
00052             bud->mui_nominventario->setFocus();
00053             _depura("END InventariosView::on_mui_crear_clicked", 0);
00054 }
00055 
00056 
00058 
00060 void InventariosView::on_mui_listado_itemDoubleClicked() {
00061     _depura("InventariosView::on_mui_listado_itemDoubleClicked", 0);
00062     on_mui_editar_clicked();
00063     _depura("END InventariosView::on_mui_listado_itemDoubleClicked", 0);
00064 }
00065 
00066 
00068 
00070 void InventariosView::presentar() {
00071     _depura("InventariosView::presentar", 0);
00072     mui_listado->cargar();
00073     _depura("END InventariosView::presentar", 0);
00074 }
00075 
00077 
00081 InventariosView::InventariosView(Company *comp, QWidget *parent, Qt::WFlags flag, edmode editmode)
00082         : Listado(comp, parent, flag, editmode) {
00083     _depura("InventariosView::InventariosView", 0);
00084     setAttribute(Qt::WA_DeleteOnClose);
00085     setupUi(this);
00086     mui_listado->setEmpresaBase(comp);
00087     mui_listado->cargar();
00089     if (modoEdicion()) {
00090         empresaBase()->meteWindow(windowTitle(), this);
00091     } else {
00092         setWindowTitle(tr("Selector de Inventarios"));
00093     } // end if
00094     _depura("END InventariosView::InventariosView", 0);
00095 }
00096 
00097 
00099 
00101 InventariosView::~InventariosView() {
00102     _depura("InventariosView::~InventariosView", 0);
00103     _depura("END InventariosView::~InventariosView", 0);
00104 }
00105 
00106 
00108 
00111 void InventariosView::on_mui_editar_clicked() {
00112     _depura("InventariosView::on_mui_editar_clicked", 0);
00113     int a = mui_listado->currentRow();
00114     if (a < 0) {
00115         mensajeInfo(tr("Tiene que seleccionar un inventario"));
00116         return;
00117     } else {
00118         QString idinventario = mui_listado->DBvalue("idinventario");
00119         if (idinventario != "") {
00120             InventarioView *bud = new InventarioView((Company *) empresaBase(), 0);
00121             if (bud->cargar(idinventario))
00122                 return;
00123             empresaBase()->m_pWorkspace->addWindow(bud);
00124             bud->show();
00125             bud->mui_nominventario->setFocus();
00126         } // end if
00127     } // end if
00128     _depura("END InventariosView::on_mui_editar_clicked", 0);
00129 }
00130 
00131 
00133 
00136 void InventariosView::on_mui_borrar2_clicked() {
00137     _depura("InventariosView::on_mui_borrar2_clicked", 0);
00138     int a = mui_listado->currentRow();
00139     if (a < 0) {
00140         mensajeInfo(tr("Tiene que seleccionar un inventario"));
00141         return;
00142     } else {
00143         QString idinventario = mui_listado->DBvalue("idinventario");
00144         if (idinventario != "") {
00145             InventarioView *inv = new InventarioView((Company *) empresaBase(), 0);
00146             empresaBase()->m_pWorkspace->addWindow(inv);
00147             inv->cargar(idinventario);
00149             inv->on_mui_borrar_clicked();
00150             mui_listado->cargar();
00151         } // end if
00152     } // end if
00153     _depura("END InventariosView::on_mui_borrar2_clicked", 0);
00154 }
00155 
00156 
00158 
00160 void InventariosView::on_mui_imprimir_clicked() {
00161         _depura("InventariosView::on_mui_imprimir_clicked", 0);
00162 
00163    QString archivo = confpr->valor(CONF_DIR_OPENREPORTS) + "listado.rml";
00164     QString archivod = confpr->valor(CONF_DIR_USER) + "listado.rml";
00165     QString archivologo = confpr->valor(CONF_DIR_OPENREPORTS) + "logo.jpg";
00166 
00168 #ifdef WINDOWS
00169 
00170     archivo = "copy " + archivo + " " + archivod;
00171 #else
00172 
00173     archivo = "cp " + archivo + " " + archivod;
00174 #endif
00175 
00176     system (archivo.toAscii().constData());
00178 #ifdef WINDOWS
00179 
00180     archivologo = "copy " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00181 #else
00182 
00183     archivologo = "cp " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00184 #endif
00185 
00186     system(archivologo.toAscii().constData());
00187 
00188 
00189     QFile file;
00190     file.setFileName(archivod);
00191     file.open(QIODevice::ReadOnly);
00192     QTextStream stream(&file);
00193     QString buff = stream.readAll();
00194     file.close();
00195 
00196 
00197         QString txt = "<blockTable style=\"tabla\" repeatRows=\"1\">\n";
00198         txt += "<tr>\n\t<td></td>\n";
00199         
00200         QString query = "SELECT * FROM articulo ";
00201         cursor2 *almacenes = empresaBase()->cargacursor("SELECT * FROM almacen");
00202         while (!almacenes->eof()) {
00203                 QString idalmacen = almacenes->valor("idalmacen");
00204                 query += " LEFT JOIN ( SELECT stock AS stock"+idalmacen+", idarticulo FROM stock_almacen WHERE idalmacen="+almacenes->valor("idalmacen")+") AS t" + idalmacen +" ON " + " t"+idalmacen+".idarticulo = articulo.idarticulo";
00205 
00206                 txt += "\t<td>" + almacenes->valor("nomalmacen") + "</td>\n";
00207                 almacenes->siguienteregistro();
00208         } // end while
00209         txt += "</tr>\n";
00210         query += " WHERE articulo.stockarticulo <> 0";
00211 
00212 
00213         cursor2 *cstock = empresaBase()->cargacursor(query);
00214         while (!cstock->eof()) {
00215                 txt += "<tr>\n";
00216                 txt += "\t<td>" + cstock->valor("nomarticulo")+"</td>\n";
00217                 almacenes->primerregistro();
00218                 while(!almacenes->eof()) {
00219                         txt += "\t<td>"+cstock->valor("stock"+almacenes->valor("idalmacen"))+"</td>\n";
00220                         almacenes->siguienteregistro();
00221                 } // end while
00222                 cstock->siguienteregistro();
00223                 txt += "</tr>\n";
00224         } // end while
00225         delete cstock;
00226         delete almacenes;
00227         txt += "</blockTable>\n";
00228 
00229     buff.replace("[story]", txt);
00230     buff.replace("[titulo]", "Listado de Stocks");
00231 
00232 
00233     if (file.open(QIODevice::WriteOnly)) {
00234         QTextStream stream(&file);
00235         stream << buff;
00236         file.close();
00237     } // end if
00238 
00239     invocaPDF("listado");
00240         _depura("END InventariosView::on_mui_imprimir_clicked", 0);
00241 }
00242 
00243 
00247 
00248 
00250 
00252 void InventariosSubForm::cargar() {
00253     _depura("InventariosSubForm::cargar", 0);
00254     QString SQLQuery = "SELECT * FROM inventario";
00255     SubForm3::cargar(SQLQuery);
00256     _depura("END InventariosSubForm::cargar", 0);
00257 }
00258 
00259 
00261 
00264 InventariosSubForm::InventariosSubForm(QWidget *parent) : SubForm2Bf(parent) {
00265     _depura("InventariosSubForm::InventariosSubForm", 0);
00266     setDBTableName("inventario");
00267     setDBCampoId("idinventario");
00268     addSHeader("idinventario", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNoView, tr("Id inventario"));
00269     addSHeader("nominventario", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Nombre del inventario"));
00270     addSHeader("fechainventario", DBCampo::DBvarchar, DBCampo::DBNoSave, SHeader::DBNone | SHeader::DBNoWrite, tr("Fecha del inventario"));
00271     setinsercion(FALSE);
00272     setDelete(FALSE);
00273     setSortingEnabled(TRUE);
00274     _depura("END InventariosSubForm::InventariosSubForm", 0);
00275 }
00276 

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