iva.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 "iva.h"
00022 #include "empresa.h"
00023 
00024 
00026 
00028 void Iva::definetabla() {
00029     _depura("Iva::definetabla", 0);
00030     setDBTableName("iva");
00031     setDBCampoId("idiva");
00032     addDBCampo("idiva", DBCampo::DBint, DBCampo::DBPrimaryKey, "Identificador");
00033     addDBCampo("idtipoiva", DBCampo::DBint, DBCampo::DBNotNull, "Id tipo IVA");
00034     addDBCampo("idregistroiva", DBCampo::DBint, DBCampo::DBNotNull, "Id registro IVA");
00035     addDBCampo("baseiva", DBCampo::DBnumeric, DBCampo::DBNotNull, "Cantidad");
00036     addDBCampo("ivaiva", DBCampo::DBnumeric, DBCampo::DBNotNull, "Precio linea presupuesto");
00037     addDBCampo("idcuenta", DBCampo::DBint, DBCampo::DBNoSave, "Id. cuenta");
00038     addDBCampo("codigo", DBCampo::DBvarchar, DBCampo::DBNoSave, "Codigo");
00039     addDBCampo("nombretipoiva", DBCampo::DBvarchar, DBCampo::DBNoSave, "Nombre tipo IVA");
00040     _depura("END Iva::definetabla",0);
00041 }
00042 
00043 
00045 
00048 Iva::Iva(Empresa *comp) : DBRecord(comp) {
00049     _depura("Iva::Iva", 0);
00050     m_companyact = comp;
00051     definetabla();
00052     _depura("END Iva::Iva", 0);
00053 }
00054 
00055 
00057 
00061 Iva::Iva(Empresa *comp, QString idiva) : DBRecord(comp) {
00062     _depura("Iva::Iva", 0);
00063     m_companyact = comp;
00064     definetabla();
00065     QString SQLQuery = "SELECT * FROM iva LEFT JOIN tipoiva ON iva.idtipoiva = tipoiva.idtipoiva LEFT JOIN cuenta ON cuenta.idcuenta = tipoiva.idtipoiva WHERE idiva = " + idiva;
00066     cursor2 *cur = m_companyact->cargacursor(SQLQuery);
00067     if (!cur->eof()) {
00068         DBload(cur);
00069     } else {
00070         vaciaIva();
00071     } // end if
00072     _depura("END Iva::Iva", 0);
00073 }
00074 
00075 
00077 
00081 Iva::Iva(Empresa *comp, cursor2 *cur) : DBRecord(comp) {
00082     _depura("Iva::Iva", 0);
00083     m_companyact = comp;
00084     definetabla();
00085     DBload(cur);
00086     _depura("END Iva::Iva", 0);
00087 }
00088 
00089 
00091 
00093 Iva::~Iva() {
00094     _depura("Iva::~Iva", 0);
00095     _depura("END Iva::~Iva", 0);
00096 }
00097 
00098 
00100 
00102 void Iva::vaciaIva() {
00103     _depura("Iva::vaciaIva", 0);
00104     DBclear();
00105     _depura("END Iva::vaciaIva", 0);
00106 }
00107 
00108 
00110 
00113 int Iva::borrar() {
00114     _depura("Iva::borrar", 0);
00115     if (DBvalue("idiva") != "") {
00116         m_companyact->begin();
00117         int error = m_companyact->ejecuta("DELETE FROM iva WHERE idiva = " + DBvalue("idiva"));
00118         if (error) {
00119             m_companyact->rollback();
00120             return -1;
00121         } // end if
00122         m_companyact->commit();
00123         vaciaIva();
00124     } // end if
00125     _depura("END Iva::borrar", 0);
00126     return 0;
00127 }
00128 
00129 
00131 
00134 void Iva::guardaIva() {
00135     _depura("Iva::guardaIva", 0);
00136     QString id;
00137     m_companyact->begin();
00138     int error = DBsave(id);
00139     if (error) {
00140         m_companyact->rollback();
00141         return;
00142     } // end if
00143     setDBvalue("idiva", id);
00144     m_companyact->commit();
00145     _depura("END Iva::guardaIva", 0);
00146 }
00147 
00148 
00150 
00153 void Iva::setidtipoiva(const QString &val) {
00154     _depura("Iva::setidtipoiva", 0);
00155     QString SQLQuery = "SELECT * FROM tipoiva LEFT JOIN cuenta ON cuenta.idcuenta = tipoiva.idcuenta WHERE idtipoiva = " + val;
00156     cursor2 *cur= m_companyact->cargacursor(SQLQuery);
00157     if (!cur->eof()) {
00158         _depura(cur->valor("codigo"), 0);
00159         setDBvalue("idcuenta",cur->valor("idcuenta"));
00160         setDBvalue("codigo", cur->valor("codigo"));
00161         setDBvalue("nombretipoiva", cur->valor("nombretipoiva"));
00162     } // end if
00163     delete cur;
00164     setDBvalue("idtipoiva", val);
00165 }
00166 

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