00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <fstream>
00024 #include <iostream>
00025 #include <unistd.h>
00026
00027 #include <QString>
00028 #include <QComboBox>
00029 #include <QRadioButton>
00030 #include <QLineEdit>
00031 #include <QMessageBox>
00032 #include <QObject>
00033
00034 #include "modelo300.h"
00035 #include "configuracion.h"
00036 #include "postgresiface2.h"
00037 #include "funcaux.h"
00038
00039
00042
00046 Mod300ps::Mod300ps(QWidget *parent) : QDialog(parent) {
00047 _depura("Mod300ps::Mod300ps", 0);
00048 setupUi(this);
00049 QString query = "SELECT descripcion, bancoent_cuenta, codigo FROM cuenta WHERE codigo LIKE '572%%' AND codigo > 572";
00050
00051 postgresiface2 *metabase = new postgresiface2();
00052
00053 metabase->inicializa("bulmages");
00054
00055 metabase->begin();
00056 fprintf(stderr, "%s\n", query.toAscii().constData());
00057 cursor2 *cur = metabase->cargacursor(query, "bancos");
00058
00059 int nTuples = cur->numregistros();
00060 nombresccc = new QString[nTuples];
00061
00062 numerccc = new QString[nTuples];
00063
00064 for (int i = 0; i < nTuples; i++) {
00065 nombresccc[i] = cur->valor("descripcion");
00066 nombresccc[i] += " ";
00067 nombresccc[i] += cur->valor("codigo");
00068
00069 numerccc[i] = cur->valor("bancoent_cuenta");
00070
00071 combocuentas->addItem(nombresccc[i]);
00072 cur->siguienteregistro();
00073 }
00074 delete cur;
00075 delete metabase;
00076
00077 if (nTuples == 0)
00078 {
00079 sincuentasbancarias = true;
00080 personalButton->setChecked(true);
00081 personalButtonPressed();
00082 cuentaButton->setDisabled(true);
00083 }
00084 _depura("END Mod300ps::Mod300ps", 0);
00085 }
00086
00087
00089
00091 Mod300ps::~Mod300ps() {
00092 _depura("Mod300ps::~Mod300ps", 0);
00093 _depura("END Mod300ps::~Mod300ps", 0);
00094 }
00095
00096
00098
00100 void Mod300ps::accept() {
00101 _depura("Mod300ps::accept", 0);
00102 m_es_borrador = borradorcheckbox->isChecked();
00103
00104 if (cuentaButton->isChecked()) {
00105 ccc = new numerocuenta(numerccc[combocuentas->currentIndex()]);
00106 } else
00107 ccc = new numerocuenta(banco->text(), entidad->text(), dc->text(), cuenta->text());
00108
00109
00110
00111
00112 if (!ccc->cuentaesvalida()) {
00113 switch (QMessageBox::warning(this,
00114 QObject::tr("Formulario 300"),
00115 QObject::tr("Aviso: El numero de cuenta bancario introducido\n"
00116 "no se corresponde con un CCC correcto."),
00117 QObject::tr("Generar de todas formas"), QObject::tr("Volver"), 0,
00118 0, 1 )) {
00119 case 0:
00120 generaps();
00121 break;
00122 case 1:
00123 break;
00124 }
00125 } else {
00126 generaps();
00127 }
00128 _depura("END Mod300ps::accept", 0);
00129 }
00130
00132
00135 void Mod300ps::generaps() {
00136 _depura("Mod300ps::generaps", 0);
00137 QString pdfname, tempname, psname, command;
00138 char *cad1 = NULL;
00139 QString cadaux;
00140
00141
00142
00143 tempname = QString(getenv("HOME")) + "/.bulmages/mod300temp.ps";
00144 pdfname = QString(getenv("HOME")) + "/.bulmages/formularios/mod300e.pdf";
00145
00146 if (!QFile::exists(pdfname))
00147 pdfname = confpr->valor(CONF_PROGDATA) + "formularios/mod300e.pdf";
00148
00149 bool doit = true;
00150 if (!QFile::exists(pdfname)) {
00151 QMessageBox::warning(this,
00152 QObject::tr("Formulario 300"),
00153 QObject::tr("Lo siento, no encuentro el formulario original en pdf.\n"
00154 "Pruebe a descargarlo desde www.aeat.es y guaedelo en\n"
00155 "/usr/share/bulmages/formularios/ o en\n"
00156 "~/.bulmages/formularios/."),
00157 QObject::tr("&Aceptar"), 0, 0, 0, 1);
00158 doit = false;
00159 }
00160
00161 if (doit) {
00162
00163 if (m_es_borrador) {
00164 command = "pdftops " + pdfname + " " + tempname;
00165 system(command.toAscii().constData());
00166 } else {
00167 Psprogressdialog progress(tr("Creando formulario"), tr("&Cancelar"), 0, 50, this, 0);
00168 this->convierte_a_postscript = new Genps_thread(pdfname, tempname, &progress);
00169 progress.setValue(0);
00170
00174 this->convierte_a_postscript->start();
00175
00176 progress.setModal(true);
00177 progress.exec();
00178 if (progress.wasCanceled()) {
00179 system("kill $(ps aux|grep 'Xvfb :5.0'|grep -v grep|awk '{print $2}')");
00180 doit = false;
00181 }
00182 }
00183 }
00184
00186 if (doit) {
00187 psname = QString(getenv("HOME")) + "/.bulmages/mod300.ps";
00188
00189 m_fich.setFileName(psname);
00190 if (m_fich.open(QIODevice::WriteOnly)) {
00191 m_output.setDevice(&m_fich);
00192 m_fichlec.setFileName(tempname);
00193 if (!m_fichlec.open(QIODevice::ReadOnly)) {
00194 _depura("Error al abrir fichero de lectura!!", 2);
00195 exit(1);
00196 }
00197 m_fichlec.readLine(cad1, 256);
00198 cadaux = cad1;
00199 while (cadaux.left(7) != "%%Page:") {
00200 m_output << cad1 ;
00201 m_fichlec.readLine(cad1, 256);
00202 }
00203 m_output << cad1;
00205 escribe_postscriptdefs();
00206
00207 m_fichlec.readLine(cad1, 256);
00208 while (cad1 != "showpage\n")
00209 {
00210 m_output << cad1;
00211 m_fichlec.readLine(cad1, 256);
00212 }
00213 if (m_es_borrador) {
00214 marcadeagua_borrador();
00215 }
00216 rellena_identificacion();
00217 rellena_liquidacion();
00218 rellena_compensacion();
00219 m_output << cad1;
00220
00221 m_fichlec.readLine(cad1, 256);
00222 while (cad1 != "showpage\n")
00223 {
00224 m_output << cad1;
00225 m_fichlec.readLine(cad1, 256);
00226 }
00227 if (m_es_borrador) {
00228 marcadeagua_borrador();
00229 }
00230 rellena_identificacion();
00231 rellena_liquidacion();
00232 rellena_compensacion();
00233 m_output << cad1;
00234
00235 m_fichlec.readLine(cad1, 256);
00236 while (cad1 != "showpage\n")
00237 {
00238 m_output << cad1;
00239 m_fichlec.readLine(cad1, 256);
00240 }
00241 if (m_es_borrador) {
00242 marcadeagua_borrador();
00243 }
00244 rellena_identificacion();
00245 rellena_compensacion();
00246 m_output << cad1;
00247
00248 while (!m_fichlec.atEnd())
00249 {
00250 m_fichlec.readLine(cad1, 256);
00251 m_output << cad1 << "\n";
00252 }
00253
00254 m_fichlec.close();
00255 m_fich.close();
00256
00257
00258
00259
00260
00261 command = "rm " + tempname + "; kghostview " + psname;
00262 system(command.toAscii().constData());
00263 } else {
00264 _depura("EEEEHH!!! !QUE NO HE ABIERTO EL FICHEROOOOOOOOOO!", 2);
00265 }
00266 }
00267 _depura("END Mod300ps::generaps", 0);
00268 }
00269
00270
00272
00274 void Mod300ps::personalButtonPressed() {
00275 _depura("Mod300ps::personalButtonPressed", 0);
00276 bool dis = cuentaButton->isChecked();
00277 banco->setDisabled(dis);
00278 entidad->setDisabled(dis);
00279 dc->setDisabled(dis);
00280 cuenta->setDisabled(dis);
00281 combocuentas->setDisabled(!dis);
00282 _depura("END Mod300ps::personalButtonPressed", 0);
00283 }
00284
00286
00292 void Mod300ps::escribe_postscriptdefs() {
00293 _depura("Mod300ps::escribe_postscriptdefs", 0);
00294
00295 m_output << "%bulmages\n"
00296 "%Texto introducido manualmente\n"
00297 "/Courier-Bold\n"
00298 "findfont\n"
00299 "12 scalefont\n"
00300 "setfont\n"
00301 "%(texto) numcar escrizq\n"
00302 "% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
00303 "/escrizq{\n"
00304 "% (texto) x_barrita y_barrita numcar escrizq\n"
00305 " -7 mul -5 add exch 3 add 3 -2 roll add exch moveto\n"
00306 " show\n"
00307 " } def\n"
00308 " %\n"
00309 " /escrder{\n"
00310 " % (texto) x_barrita y_barrita numcar escrizq\n"
00311 " %newpath\n"
00312 " exch 3 add 3 -2 roll add 5 add exch moveto\n"
00313 " show} def\n";
00314 _depura("END Mod300ps::escribe_postscriptdefs", 0);
00315 }
00316
00317
00319
00323 void Mod300ps::escribe_cuenta_bancaria(int x, int y) {
00324 _depura("Mod300ps::escribe_cuenta_bancaria", 0);
00325
00326 const int steps[] = {
00327 0, 11, 11, 11, 12, 11, 11, 11, 12, 11, 12, 11, 11, 11, 12, 11,
00328 11, 11, 12, 11, 11
00329 };
00330
00331
00332 int acum = x;
00333 QString tem = ccc->getcodigo();
00334 for (int i = 0; i < 20; i++) {
00335 acum += steps[i];
00336 marca_casilla(QString(tem[i]), acum, y);
00337 }
00338 _depura("END Mod300ps::escribe_cuenta_bancaria", 0);
00339 }
00340
00341
00343
00346 void Mod300ps::rellena_identificacion() {
00347 _depura("Mod300ps::rellena_identificacion", 0);
00348 QString cad1;
00349
00350 postgresiface2 *m = new postgresiface2();
00351
00352 m->inicializa("bulmages");
00353 escrder(m->propiedadempresa("CIF"), 78, 601);
00354 escrder(m->propiedadempresa("NombreEmpresa"), 213, 601);
00355 escrder(m->propiedadempresa("TipoVia"), 78, 576);
00356 escrder(m->propiedadempresa("NombreVia"), 141, 576);
00357 escrder(m->propiedadempresa("NumeroVia"), 389, 576);
00358 escrder(m->propiedadempresa("Escalera"), 431, 576);
00359 escrder(m->propiedadempresa("Piso"), 461, 576);
00360 escrder(m->propiedadempresa("Puerta"), 490, 576);
00362 escrder(m->propiedadempresa("Municipio"), 78, 550);
00363 escrder(m->propiedadempresa("Provincia"), 360, 550);
00364 escribe_codigo_postal(m->propiedadempresa("CodPostal"));
00365
00366 delete m;
00367
00368 cad1.sprintf("%d", trimestre->currentIndex() + 1);
00369
00370 marca_casilla(cad1, 452, 690);
00371 marca_casilla("T", 467, 690);
00372
00373 escrder(empresa, 209, 601);
00374 for (int i = 0; i < 4; i++) {
00375 marca_casilla(QString(ano[i]), 453 + i * 14, 706);
00376 }
00377 _depura("END Mod300ps::rellena_identificacion", 0);
00378 }
00379
00380
00382
00384 void Mod300ps::rellena_liquidacion() {
00385 _depura("Mod300ps::rellena_liquidacion", 0);
00386 escrizqder(baser16, 328, 516);
00387 escrizqder(baser7, 328, 502);
00388 escrizqder(baser4, 328, 487);
00389 escrizq(16, 435, 516);
00390 escrizq(7, 435, 502);
00391 escrizq(4, 435, 487);
00392 escrizqder(ivar16, 531, 516);
00393 escrizqder(ivar7, 531, 502);
00394 escrizqder(ivar4, 531, 487);
00395 escrizqder(ivar16 + ivar7 + ivar4, 531, 400);
00396 escrizqder(ivas4 + ivas7 + ivas16, 532, 366);
00397 escrizqder(ivas4 + ivas7 + ivas16, 532, 295);
00398 cas34 = ivas4 + ivas7 + ivas16 - (ivar16 + ivar7 + ivar4);
00399 escrizqder(cas34, 532, 196);
00400 _depura("END Mod300ps::rellena_liquidacion", 0);
00401 }
00402
00403
00405
00407 void Mod300ps::rellena_compensacion() {
00408 _depura("Mod300ps::rellena_compensacion", 0);
00409 if (cas34 < 0) {
00410 escrizqder(-cas34, 248, 145);
00411 if (trimestre->currentIndex() == 3) {
00412 escribe_cuenta_bancaria(76,32);
00413 }
00414 } else {
00415 if (trimestre->currentIndex() == 3)
00416 {
00417 marca_casilla("X", 464, 134);
00418 escribe_cuenta_bancaria(338, 73);
00419 }
00420 }
00421 _depura("END Mod300ps::rellena_compensacion", 0);
00422 }
00423
00424
00427
00430 void Mod300ps::escribe_codigo_postal(QString cod) {
00431 _depura("Mod300ps::escribe_codigo_postal", 0);
00432 int offset = 3;
00433 marca_casilla(QString(cod[0]), 528 - offset, 550);
00434 marca_casilla(QString(cod[1]), 537 - offset, 550);
00435 marca_casilla(QString(cod[2]), 546 - offset, 550);
00436 marca_casilla(QString(cod[3]), 554 - offset, 550);
00437 marca_casilla(QString(cod[4]), 563 - offset, 550);
00438 _depura("END Mod300ps::escribe_codigo_postal", 0);
00439 }
00440