inventario.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 <QFile>
00022 #include <QTextStream>
00023 
00024 #include "inventario.h"
00025 #include "company.h"
00026 #include "funcaux.h"
00027 
00028 
00030 
00034 Inventario::Inventario(Company *comp, QWidget *parent) : FichaBf(comp, parent) {
00035     _depura("Inventario::Inventario", 0);
00036     companyact = comp;
00037     setTitleName(tr("Inventario"));
00038     setDBTableName("inventario");
00039     setDBCampoId("idinventario");
00040     addDBCampo("idinventario", DBCampo::DBint, DBCampo::DBPrimaryKey, QApplication::translate("Inventario", "Identificador inventario"));
00041     addDBCampo("fechainventario", DBCampo::DBdate, DBCampo::DBNothing, QApplication::translate("Inventario", "Fecha inventario"));
00042     addDBCampo("nominventario", DBCampo::DBvarchar, DBCampo::DBNothing, QApplication::translate("Inventario", "Nombre inventario"));
00043     _depura("END Inventario::Inventario", 0);
00044 }
00045 
00046 
00048 
00050 Inventario::~Inventario() {
00051     _depura("Inventario::~Inventario", 0);
00052     _depura("END Inventario::~Inventario", 0);
00053 }
00054 
00055 
00057 
00060 int Inventario::borrar() {
00061     if (DBvalue("idinventario") != "") {
00062         _depura("vamos a borrar las lineas del inventario", 0);
00063         companyact->begin();
00064 
00065         listalineas->borrar();
00066         _depura("Vamos a borrar el resto",0);
00067         int error = companyact->ejecuta("DELETE FROM inventario WHERE idinventario = " + DBvalue("idinventario"));
00068         if (error) {
00069             companyact->rollback();
00070             return -1;
00071         } // end if
00072         companyact->commit();
00073     } // end if
00074     return 0;
00075 }
00076 
00077 
00079 
00081 void Inventario::vaciaInventario() {
00082     _depura("Inventario::vaciaInventario", 0);
00083     DBclear();
00084     _depura("END Inventario::vaciaInventario", 0);
00085 }
00086 
00087 
00089 
00091 void Inventario::pintaInventario() {
00092     _depura("pintaInventario\n", 0);
00093     pintaidinventario(DBvalue("idinventario"));
00094     pintanominventario(DBvalue("nominventario"));
00095     pintafechainventario(DBvalue("fechainventario"));
00097     //listalineas->pintaListControlStock();
00098 }
00099 
00100 
00102 
00106 int Inventario::cargar(QString idbudget) {
00107     QString query = "SELECT * FROM inventario WHERE idinventario = " + idbudget;
00108     cursor2 * cur= companyact->cargacursor(query);
00109     if (!cur->eof()) {
00110         DBload(cur);
00111     } // end if
00112     delete cur;
00113     listalineas->cargar(idbudget);
00114     pintaInventario();
00115     return 0;
00116 }
00117 
00118 
00120 
00123 int Inventario::guardar() {
00124     _depura("Inventario::guardar()", 0);
00125     companyact->begin();
00126     try {
00127         QString id;
00128         DBsave(id);
00129         setidinventario(id);
00130         listalineas->guardar();
00131         companyact->commit();
00132         cargar(id);
00133         _depura("END Inventario::guardar()", 0);
00134         return 0;
00135     } catch (...) {
00136         _depura("Error guardando el inventario", 2);
00137         companyact->rollback();
00138     _depura("END Inventario::guardar()", 0);
00139         return -1;
00140     } // end try
00141 }
00142 
00143 
00145 
00147 void Inventario::pregenerar() {
00148     _depura("Inventario::pregenerar", 0);
00149     listalineas->pregenerar();
00150     _depura("END Inventario::pregenerar", 0);
00151 }
00152 
00153 
00155 
00158 void Inventario::setListControlStock(ListControlStockView *a) {
00159     _depura("Inventario::setListControlStock", 0);
00160     listalineas = a;
00161     listalineas->setEmpresaBase(companyact);
00162     _depura("END Inventario::setListControlStock", 0);
00163 }
00164 
00165 
00167 
00170 ListControlStockView *Inventario::getlistalineas() {
00171     _depura("Inventario::getlistalineas", 0);
00172     _depura("Inventario::getlistalineas", 0);
00173     return listalineas;
00174 }
00175 
00176 
00178 
00180 void Inventario::pintaidinventario(QString) {
00181     _depura("Inventario::pintaidinventario", 0);
00182     _depura("END Inventario::pintaidinventario", 0);
00183 }
00184 
00185 
00187 
00189 void Inventario::pintafechainventario(QString) {
00190     _depura("Inventario::pintafechainventario", 0);
00191     _depura("END Inventario::pintafechainventario", 0);
00192 }
00193 
00194 
00196 
00198 void Inventario::pintanominventario(QString) {
00199     _depura("Inventario::pintanominventario", 0);
00200     _depura("END Inventario::pintanominventario", 0);
00201 }
00202 
00203 
00205 
00208 void Inventario::setidinventario(QString val) {
00209     _depura("Inventario::setidinventario", 0);
00210     setDBvalue("idinventario", val);
00211     listalineas->setColumnValue("idinventario", val);
00212     _depura("END Inventario::setidinventario", 0);
00213 }
00214 
00215 
00217 
00220 void Inventario::setfechainventario(QString val) {
00221     _depura("Inventario::setfechainventario", 0);
00222     setDBvalue("fechainventario", val);
00223     _depura("END Inventario::setfechainventario", 0);
00224 }
00225 
00226 
00228 
00231 void Inventario::setnominventario(QString val) {
00232     _depura("Inventario::setnominventario", 0);
00233     setDBvalue("nominventario", val);
00234     _depura("END Inventario::setnominventario", 0);
00235 }
00236 
00237 
00239 
00241 void Inventario::imprimirInventario() {
00242         _depura("Inventario::imprimirInventario", 0);
00243         QString txt = "<blockTable>\n";
00244         txt += "<tr><td></td>\n";
00245         
00246         QString query = "SELECT idarticulo, codigocompeltoarticulo, nomarticulo FROM articulo ";
00247         cursor2 *almacenes = companyact->cargacursor("SELECT * FROM almacen");
00248         while (!almacenes->eof()) {
00249                 QString idalmacen = almacenes->valor("idalmacen");
00250                 query += " LEFT JOIN ( SELECT stock, idarticulo FROM stock_almacen WHERE idalmacen="+almacenes->valor("idalmacen")+") AS t" + idalmacen +" ON " + " t"+idalmacen+".idarticulo = articulo.idarticulo";
00251                 txt += "<td>" + almacenes->valor("nomalmacen") + "</td>";
00252                 almacenes->siguienteregistro();
00253         } // end while
00254         delete almacenes;
00255         txt += "</tr>\n";
00256 
00257         cursor2 *cstock = companyact->cargacursor(query);
00258         while (!cstock->eof()) {
00259                 txt += "<tr>\n";
00260                 txt += "<td>" + cstock->valor("nomarticulo");
00261                 for (int i = 0; i < cstock->numcampos(); i++) {
00262                         txt += "<td>"+cstock->valor(i)+"</td>";
00263                 } // end for
00264                 cstock->siguienteregistro();
00265                 txt += "\n";
00266                 txt += "</tr>\n";
00267         } // end while
00268         delete cstock;
00269 
00270         _depura(txt, 2);
00271         _depura("END Inventario::imprimirInventario", 0);
00272 }
00273 

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