numerocuenta.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by David Gutierrez Rubio                           *
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU General Public License     *
00015  *   along with this program; if not, write to the                         *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00018  ***************************************************************************/
00019 
00020 #include <QString>
00021 
00022 #include "numerocuenta.h"
00023 
00024 
00026 
00029 bool numerocuenta::cuentaesvalida() {
00030     return (getdc() == dc);
00031 }
00032 
00033 
00035 
00039 QString numerocuenta::getcodigo(QString sep) {
00040     return (banco + sep + entidad + sep + dc + sep + numcuenta);
00041 }
00042 
00043 
00045 
00048 QString numerocuenta::getnumcuenta() {
00049     return numcuenta;
00050 }
00051 
00052 
00054 
00057 QString numerocuenta::getbanco() {
00058     return banco;
00059 }
00060 
00061 
00063 
00066 QString numerocuenta::getentidad() {
00067     return entidad;
00068 }
00069 
00070 
00072 
00075 void numerocuenta::setnumcuenta(QString cad) {
00076     numcuenta = cad.rightJustified(10, '0');
00077 }
00078 
00079 
00081 
00084 void numerocuenta::setbanco(QString cad) {
00085     banco = cad.rightJustified(4, '0');
00086 }
00087 
00088 
00090 
00093 void numerocuenta::setentidad(QString cad) {
00094     entidad = cad.rightJustified(4, '0');
00095 }
00096 
00097 
00103 numerocuenta::numerocuenta(QString bancopar, QString entidadpar, QString dcpar, QString numcuentapar) {
00104     setbanco(bancopar);
00105     setentidad(entidadpar);
00106     setnumcuenta(numcuentapar);
00107     dc = dcpar;
00108 }
00109 
00110 
00112 
00117 numerocuenta::numerocuenta(QString bancopar, QString entidadpar, QString numcuentapar) {
00118     setbanco(bancopar);
00119     setentidad(entidadpar);
00120     setnumcuenta(numcuentapar);
00121     dc = getdc();
00122 }
00123 
00124 
00126 
00129 numerocuenta::numerocuenta(QString cuenpar) {
00130     QString tem = cuenpar;
00131     tem.remove("-"); 
00132     banco = tem.mid(0, 4);
00133     entidad = tem.mid(4, 4);
00134     dc = tem.mid(8, 2);
00135     numcuenta = tem.mid(10, 10);
00136 }
00137 
00138 
00140 
00142 numerocuenta::~numerocuenta() {}
00143 
00144 
00146 
00149 QString numerocuenta::getdc() {
00150     QString resul;
00151     int i;
00152     int sum = 0;
00153 
00164 
00165     const int we[] = {
00166                          1, 2, 4, 8, 5, 10, 9, 7, 3, 6
00167                      };
00168 
00169     for (i = 0; i < 4; i++)
00170         sum += QString(banco[i]).toInt() * we[i + 2];
00171 
00172     for (i = 0; i < 4; i++)
00173         sum += QString(entidad[i]).toInt() * we[i + 6];
00174 
00175     sum = (sum % 11);
00176     sum = 11 - sum;
00177 
00178     if (sum == 11)
00179         sum = 0;
00180     if (sum == 10)
00181         sum = 1;
00182 
00183     int sum2 = 0;
00184     for (i = 0; i < 10; i++)
00185         sum2 += QString(numcuenta[i]).toInt() * we[i];
00186 
00187     sum2 = (sum2 % 11);
00188     sum2 = 11 - sum2;
00189 
00190     if (sum2 == 11)
00191         sum2 = 0;
00192     if (sum2 == 10)
00193         sum2 = 1;
00194 
00195     resul.sprintf("%d%d", sum, sum2);
00196     return resul;
00197 }
00198 

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