extractoview1.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 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 <QLineEdit>
00022 #include <QWidget>
00023 #include <QToolButton>
00024 #include <QLayout>
00025 #include <QTextStream>
00026 #include <QCheckBox>
00027 #include <QFileDialog>
00028 
00029 #include "extractoview1.h"
00030 #include "extractoprintview.h"
00031 #include "libromayorprint.h"
00032 #include "empresa.h"
00033 #include "asiento1view.h"
00034 #include "balanceview.h"
00035 #include "diarioview.h"
00036 #include "listcuentasview1.h"
00037 #include "selectccosteview.h"
00038 #include "selectcanalview.h"
00039 #include "busquedafecha.h"
00040 #include "busquedacuenta.h"
00041 #include "extractosubform.h"
00042 
00046 
00050 extractoview1::extractoview1(Empresa *emp, QWidget *parent, int) : FichaBc(emp, parent) {
00051     _depura("extractoview1::extractoview1", 0);
00052     setupUi(this);
00053 
00054     setTitleName(tr("Extracto de Cuentas"));
00055     setDBTableName("apunte");
00056 
00057     mui_list->setEmpresaBase( emp );
00058 
00060     m_codigoinicial->setEmpresaBase( emp );
00061     m_codigofinal->setEmpresaBase( emp );
00062     mui_codigocontrapartida->setEmpresaBase( emp );
00063     m_codigoinicial->hideNombre();
00064     m_codigofinal->hideNombre();
00065 
00068     QString cadena;
00069     cadena.sprintf ( "%2.2d/%2.2d/%4.4d", 1, 1, QDate::currentDate().year() );
00070     m_fechainicial1->setText ( cadena );
00071     cadena.sprintf ( "%2.2d/%2.2d/%4.4d", 31, 12, QDate::currentDate().year() );
00072     m_fechafinal1->setText ( cadena );
00073     m_cursorcta = NULL;
00074     meteWindow ( windowTitle(), this );
00075     _depura ( "END extractoview1::extractoview1", 0 );
00076 }
00077 
00078 
00080 
00082 extractoview1::~extractoview1() {
00083     _depura ( "extractoview1::~extractoview1", 0 );
00084     delete m_cursorcta;
00085     empresaBase()->sacaWindow ( this );
00086     _depura ( "END extractoview1::~extractoview1", 0 );
00087 }
00088 
00089 
00091 
00094 void extractoview1::on_mui_list_cellDoubleClicked(int, int columna) {
00095     _depura("asientosview::on_mui_list_cellDoubleClicked", 0);
00096     QString textoHeader;
00097     textoHeader =  mui_list->cabecera()->at(columna)->nomcampo().toAscii();
00098     if (textoHeader == "ordenasiento") {
00099         QString idasiento = mui_list->DBvalue("idasiento");
00100         empresaBase()->intapuntsempresa()->muestraasiento(idasiento);
00101         empresaBase()->intapuntsempresa()->show();
00102         empresaBase()->intapuntsempresa()->setFocus();
00103         empresaBase()->muestraapuntes1();
00104     } // end if
00105     _depura("END asientosview::on_mui_list_cellDoubleClicked", 0);
00106 }
00107 
00108 
00110 
00112 void extractoview1::on_mui_actualizar_clicked() {
00113     _depura("extractoview1::on_mui_actualizar_clicked", 0);
00114     accept();
00115     _depura("END extractoview1::on_mui_actualizar_clicked", 0);
00116 }
00117 
00118 
00120 void extractoview1::on_mui_configurar_clicked() {
00121     _depura("extractoview1::on_mui_configurar_clicked", 0);
00122     mui_list->showConfig();
00123     _depura("END extractoview1::on_mui_configurar_clicked", 0);
00124 }
00125 
00126 
00128 
00132 void extractoview1::accept() {
00133     _depura ( "extractoview1::accept", 0 );
00134     QString codinicial = m_codigoinicial->codigocuenta();
00135     QString codfinal = m_codigofinal->codigocuenta();
00136     QString query;
00139     if ( codinicial == "" ) {
00140         codinicial = "0";
00141     } // end if
00142     if ( codfinal == "" ) {
00143         codfinal = "9999999";
00144     } // end if
00145     query = "SELECT * FROM cuenta WHERE idcuenta IN (SELECT idcuenta FROM apunte) AND codigo >= '" + codinicial + "' AND codigo <= '" + codfinal + "' ORDER BY codigo";
00146 
00147     if ( m_cursorcta != NULL ) {
00148         delete m_cursorcta;
00149     } // end if
00150     m_cursorcta = empresaBase()->cargacursor ( query );
00151     presentar();
00152     _depura ( "END extractoview1::accept",0 );
00153 }
00154 
00155 
00157 
00159 void extractoview1::boton_siguiente() {
00160     _depura ( "extractoview1::boton_siguiente", 0 );
00161     if ( m_cursorcta != NULL ) {
00162         if ( !m_cursorcta->esultimoregistro() ) {
00163             guardar();
00164             m_cursorcta->siguienteregistro();
00165             presentar();
00166         } // end if
00167     } // end if
00168     _depura ( "END extractoview1::boton_siguiente", 0 );
00169 }
00170 
00171 
00173 
00175 void extractoview1::boton_anterior() {
00176     _depura ( "extractoview1::boton_anterior", 0 );
00177     if ( m_cursorcta != NULL ) {
00178         if ( !m_cursorcta->esprimerregistro() ) {
00179             guardar();
00180             m_cursorcta->registroanterior();
00181             presentar();
00182         } // end if
00183     } // end if
00184     _depura ( "END extractoview1::boton_anterior", 0 );
00185 }
00186 
00188 
00190 void extractoview1::boton_inicio() {
00191     _depura ( "extractoview1::boton_inicio", 0 );
00192     if ( m_cursorcta != NULL ) {
00193         guardar();
00194         m_cursorcta->primerregistro();
00195         presentar();
00196     } // end if
00197     _depura ( "END extractoview1::boton_inicio", 0 );
00198 }
00199 
00201 
00203 void extractoview1::boton_fin() {
00204     _depura ( "extractoview1::boton_fin", 0 );
00205     if ( m_cursorcta != NULL ) {
00206         guardar();
00207         m_cursorcta->ultimoregistro();
00208         presentar();
00209     } // end if
00210     _depura ( "END extractoview1::boton_fin", 0 );
00211 }
00212 
00213 
00215 
00217 void extractoview1::boton_imprimir() {
00218     _depura ( "extractoview1::boton_imprimir", 0 );
00219     ExtractoPrintView *print = new ExtractoPrintView ( empresaBase(), 0 );
00220     print->exec();
00221     _depura ( "END extractoview1::boton_imprimir", 0 );
00222 }
00223 
00224 
00226 
00228 void extractoview1::boton_guardar() {
00229     _depura ( "extractoview1::boton_guardar", 0 );
00230     QString fn = QFileDialog::getSaveFileName ( this,
00231                  tr ( "Guardar libro diario" ),
00232                  confpr->valor ( CONF_DIR_USER ),
00233                  tr ( "Diarios (*.txt)" ) );
00234 
00235     if ( !fn.isEmpty() ) {
00236         libromayorprint libromayor(empresaBase());
00237         QString finicial = m_fechainicial1->text().toAscii().constData();
00238         QString ffinal = m_fechafinal1->text().toAscii().constData();
00239         libromayor.inicializa1 ( m_codigoinicial->text(), m_codigofinal->text(), finicial, ffinal );
00240         libromayor.inicializa2 ( ( char * ) fn.toAscii().constData() );
00241         libromayor.accept();
00242     } // end if
00243     _depura ( "END extractoview1::boton_guardar", 0 );
00244 }
00245 
00246 
00248 
00250 void extractoview1::vaciar() {
00251     _depura ( "extractoview1::vaciar", 0 );
00252     inicialdebe->setText ( "0" );
00253     inicialhaber->setText ( "0" );
00254     inicialsaldo->setText ( "0" );
00255     totaldebe->setText ( "0" );
00256     totalhaber->setText ( "0" );
00257     totalsaldo->setText ( "0" );
00258     _depura ( "END extractoview1::vaciar", 0 );
00259 }
00260 
00261 
00263 
00265 void extractoview1::ajustes() {
00266     _depura("extractoview1::ajustes", 0);
00267     _depura("END extractoview1::ajustes", 0);
00268 }
00269 
00270 
00272 
00274 int extractoview1::guardar() {
00275     _depura ( "extractoview1::on_mui_guardar_clicked", 0 );
00276     if ( mui_asAbiertos->isChecked() ) return 0;
00277     mui_list->guardar();
00278     return 0;
00279     _depura ( "END extractoview1::on_mui_guardar_clicked", 0 );
00280 
00281 }
00282 
00283 
00285 
00288 void extractoview1::presentar() {
00289     _depura ( "extractoview1::presentar", 0 );
00290     Fixed debe("0.00"), haber("0.00"), saldo("0.00");
00291     Fixed debeinicial("0.00"), haberinicial("0.00"), saldoinicial("0.00");
00292     Fixed debefinal("0.00"), haberfinal("0.00"), saldofinal("0.00");
00293     QString idcuenta;
00294     QString finicial = m_fechainicial1->text();
00295     QString ffinal = m_fechafinal1->text();
00296     QString contra = mui_codigocontrapartida->text();
00297     QString cad;
00298     QString cadaux;
00299     cursor2 *cursorapt = NULL;
00300     cursor2 *cursoraux = NULL;
00301     try {
00303         QString tipopunteo;
00304         tipopunteo = "";
00305         if ( mui_punteotodos->isChecked() ) {
00306             tipopunteo = "";
00307         } else if ( mui_punteopunteado->isChecked() ) {
00308             tipopunteo = " AND punteo = TRUE ";
00309         } else {
00310             tipopunteo = " AND punteo = FALSE ";
00311         } // end if
00312 
00313 
00314         if ( m_cursorcta->eof() || m_cursorcta->bof() )
00315             return;
00316 
00317         idcuenta = m_cursorcta->valor ( "idcuenta" );
00319         codigocuenta->setText ( m_cursorcta->valor ( "codigo" ) );
00320         nombrecuenta->setText ( m_cursorcta->valor ( "descripcion" ) );
00322         QString query = "";
00325         selectcanalview *scanal = empresaBase()->getselcanales();
00326         SelectCCosteView *scoste = empresaBase()->getselccostes();
00327         QString ccostes = scoste->cadcoste();
00328         if ( ccostes != "" ) {
00329             ccostes.sprintf ( " AND idc_coste IN (%s) ", ccostes.toAscii().constData() );
00330         } // end if
00331         QString ccanales = scanal->cadcanal();
00332         if ( ccanales != "" ) {
00333             ccanales.sprintf ( " AND idcanal IN (%s) ", ccanales.toAscii().constData() );
00334         } // end if
00335         QString tabla;
00336         QString cont;
00337         if ( mui_asAbiertos->isChecked() ) {
00338             tabla = "borrador";
00339             cont = " FALSE AS punteo, * ";
00340         } else {
00341             tabla = "apunte";
00342             cont = " * ";
00343         } // end if
00344 
00345         if ( contra != "" ) {
00346             tipopunteo += " AND " + tabla + ".contrapartida = id_cuenta('" + contra + "') ";
00347         } // end if
00348 
00349         query = "SELECT * FROM ((SELECT " + cont + " FROM " + tabla + " WHERE  idcuenta = " + idcuenta + " AND fecha >= '" + finicial + "' AND fecha <= '" + ffinal + "' " + ccostes + " " + ccanales + " " + tipopunteo + ") AS t2 ";
00350         query += " LEFT JOIN (SELECT idcuenta AS idc, descripcion, codigo, tipocuenta FROM cuenta) AS t9 ON t2.idcuenta = t9.idc) AS t1";
00351         query += " LEFT JOIN asiento ON asiento.idasiento = t1.idasiento ";
00352         query += " LEFT JOIN (SELECT idc_coste AS idccoste, nombre AS nombrec_coste FROM c_coste) AS t5 ON t5.idccoste = t1.idc_coste ";
00353         query += " LEFT JOIN (SELECT idcanal AS id_canal, nombre AS nombrecanal FROM canal) AS t6 ON t6.id_canal = t1.idcanal ";
00354         query += " LEFT JOIN (SELECT idcuenta AS idcontrapartida, codigo AS codcontrapartida FROM cuenta) as t8 ON t8.idcontrapartida = t1.contrapartida";
00355         query += " ORDER BY t1.fecha, ordenasiento, t1.orden";
00356 
00357         mui_list->cargar ( query );
00358 
00359 
00360         cursorapt = empresaBase()->cargacursor ( query );
00361         cursorapt->primerregistro();
00362         if ( !cursorapt->eof() ) {
00364             query = "SELECT sum(debe) AS tdebe, sum(haber) AS thaber FROM apunte WHERE idcuenta =" + idcuenta + " AND fecha < '" + finicial + "'";
00365             cursoraux = empresaBase()->cargacursor ( query );
00366             if ( !cursoraux->eof() ) {
00367                 debeinicial = Fixed ( cursoraux->valor ( "tdebe" ) );
00368                 haberinicial = Fixed ( cursoraux->valor ( "thaber" ) );
00369                 saldoinicial = debeinicial - haberinicial;
00370             } // end if
00371             delete cursoraux;
00372             cursoraux = NULL;
00373 
00375             inicialdebe->setText ( debeinicial.toQString() );
00376             inicialhaber->setText ( haberinicial.toQString() );
00377             inicialsaldo->setText ( saldoinicial.toQString() );
00378             saldo = saldoinicial;
00379             debefinal = debeinicial;
00380             haberfinal = haberinicial;
00381 
00383             int i = 0;
00384             while ( !cursorapt->eof() ) {
00385                 debe = Fixed(cursorapt->valor ( "debe" ));
00386                 haber = Fixed ( cursorapt->valor ( "haber" ) );
00387                 saldo = saldo + debe - haber;
00388                 debefinal = debefinal + debe;
00389                 haberfinal = haberfinal + haber;
00390                 if (mui_list->lineaat(i)) 
00391                         mui_list->setDBvalue("saldo", i++, saldo.toQString());
00392                 cursorapt->siguienteregistro();
00393             } // end while
00394 
00395             saldofinal = debefinal - haberfinal;
00396             totaldebe->setText ( debefinal.toQString() );
00397             totalhaber->setText ( haberfinal.toQString() );
00398             totalsaldo->setText ( saldofinal.toQString() );
00399         } // end if
00400         delete cursorapt;
00401         cursorapt = NULL;
00402         ajustes();
00403     } catch (...) {
00404         mensajeInfo("Error en los calculos");
00406         if (cursorapt) delete cursorapt;
00407         if (cursoraux) delete cursoraux;
00408         return;
00409     } // end catch
00410     _depura ( "END extractoview1::presentar", 0 );
00411 }
00412 
00413 
00415 
00421 void extractoview1::inicializa1 ( QString codinicial, QString codfinal, QString fecha1, QString fecha2, int ) {
00422     _depura ( "extractoview1::inicializa1", 0 );
00423     m_codigoinicial->setText ( codinicial );
00424     m_codigofinal->setText ( codfinal );
00425     m_fechainicial1->setText ( normalizafecha ( fecha1 ).toString ( "dd/MM/yyyy" ) );
00426     m_fechafinal1->setText ( normalizafecha ( fecha2 ).toString ( "dd/MM/yyyy" ) );
00427     _depura ( "END extractoview1::inicializa1", 0 );
00428 }
00429 
00430 
00432 
00434 void extractoview1::on_mui_casacion_clicked() {
00435     _depura ( "extractoview1::on_mui_casacion_clicked", 0 );
00436     QString query;
00437     query.sprintf ( "SELECT * FROM apunte WHERE punteo = FALSE AND haber <> 0 AND idcuenta = %s ORDER BY fecha", m_cursorcta->valor ( "idcuenta" ).toAscii().constData() );
00438     empresaBase()->begin();
00439     cursor2 *curshaber = empresaBase()->cargacursor ( query, "curshaber" );
00440     empresaBase()->commit();
00441     while ( !curshaber->eof() ) {
00442         query.sprintf ( "SELECT * FROM apunte WHERE punteo = FALSE AND debe = %s AND idcuenta = %s ORDER BY fecha", curshaber->valor ( "haber" ).toAscii().constData(), m_cursorcta->valor ( "idcuenta" ).toAscii().constData() );
00443         empresaBase()->begin();
00444         cursor2 *cursdebe = empresaBase()->cargacursor ( query.toAscii(), "cursdebe" );
00445         empresaBase()->commit();
00446         if ( !cursdebe->eof() ) {
00447             query.sprintf ( "UPDATE apunte set punteo = TRUE WHERE idapunte = %s", curshaber->valor ( "idapunte" ).toAscii().constData() );
00448             empresaBase()->begin();
00449             empresaBase()->ejecuta ( query );
00450             query.sprintf ( "UPDATE apunte SET punteo = TRUE WHERE idapunte = %s", cursdebe->valor ( "idapunte" ).toAscii().constData() );
00451             empresaBase()->ejecuta ( query );
00452             empresaBase()->commit();
00453         } // end if
00454         delete cursdebe;
00455         curshaber->siguienteregistro();
00456     } // end while
00457     delete curshaber;
00458     presentar();
00459     _depura ( "END extractoview1::on_mui_casacion_clicked", 0 );
00460 }
00461 
00462 
00464 
00466 void extractoview1::on_mui_guardarpunteo_clicked() {
00467     _depura ( "extractoview1::on_mui_guardarpunteo_clicked", 0 );
00468     QString fn = QFileDialog::getSaveFileName ( this,
00469                  tr ( "Guardar punteo" ),
00470                  confpr->valor ( CONF_DIR_USER ),
00471                  tr ( "Punteos (*.pto)" ) );
00472 
00473     if ( !fn.isEmpty() ) {
00474         FILE *mifile;
00475         mifile = fopen ( ( char * ) fn.toAscii().constData(), "wt" );
00476         if ( mifile != NULL ) {
00477             QString query;
00478             query = "SELECT * FROM apunte WHERE punteo = TRUE";
00479             cursor2 *cursp = empresaBase()->cargacursor ( query, "punteos" );
00480             while ( !cursp->eof() ) {
00481                 fprintf ( mifile,"%s\n", cursp->valor ( "idapunte" ).toAscii().constData() );
00482                 cursp->siguienteregistro();
00483             } // end while
00484             delete cursp;
00485             fclose ( mifile );
00486         } // end if
00487     } // end if
00488     _depura ( "END extractoview1::on_mui_guardarpunteo_clicked", 0 );
00489 }
00490 
00491 
00493 
00498 void extractoview1::on_mui_borrapunteo_clicked() {
00499     _depura ( "extractoview1::on_mui_borrapunteo_clicked", 0 );
00500     int valor = QMessageBox::warning ( 0,
00501                                        tr ( "Borrar punteo" ),
00502                                        tr ( "Se dispone a borrar el punteo. Este cambio \
00503                                             es irrecuperable si no ha guardado su el punte. \
00504                                             Desea continuar?" ),
00505                                        QMessageBox::Yes, QMessageBox::No );
00506     if ( valor == QMessageBox::Yes ) {
00507         empresaBase()->begin()
00508         ;
00509         empresaBase()->ejecuta ( "UPDATE apunte SET punteo = FALSE" );
00510         empresaBase()->commit();
00511         presentar();
00512     } // end if
00513     _depura ( "END extractoview1::on_mui_borrapunteo_clicked", 0 );
00514 }
00515 
00516 
00518 
00522 void extractoview1::on_mui_cargarpunteos_clicked() {
00523     _depura ( "extractoview1::on_mui_cargarpunteos_clicked", 0 );
00524     QString fn = QFileDialog::getOpenFileName ( this,
00525                  tr ( "Cargar punteo" ),
00526                  confpr->valor ( CONF_DIR_USER ),
00527                  tr ( "Punteo (*.pto)" ) );
00528 
00529     if ( !fn.isEmpty() ) {
00530         QFile file ( fn );
00531         if ( !file.open ( QIODevice::ReadOnly | QIODevice::Text ) ) {
00532             return;
00533         } // end if
00534         QTextStream filestr ( &file );
00535         QString a;
00536         empresaBase()->ejecuta ( "UPDATE apunte SET punteo = FALSE" );
00537         while ( !filestr.atEnd() ) {
00538             filestr >> a;
00539             QString query;
00540             query = "UPDATE apunte SET punteo = TRUE WHERE idapunte = "+ a;
00541             empresaBase()->ejecuta ( query );
00542         } // end while
00543         file.close();
00544     } // end if
00545     presentar();
00546     _depura ( "END extractoview1::on_mui_cargarpunteos_clicked", 0 );
00547 }
00548 
00549 
00551 
00555 QString extractoview1::imprimeExtractoCuenta ( QString idcuenta ) {
00556     _depura ( "extractoview1::imprimeExtractoCuenta", 0, idcuenta );
00557     QString salida = "";
00558     Fixed debeinicial ( "0" ), haberinicial ( "0" ), saldoinicial ( "0" );
00559     Fixed debefinal ( "0" ), haberfinal ( "0" ), saldofinal ( "0" );
00560     QString finicial = m_fechainicial1->text();
00561     QString ffinal = m_fechafinal1->text();
00562     QString contra = mui_codigocontrapartida->text();
00563 
00565     QString tipopunteo;
00566     tipopunteo = "";
00567     if ( mui_punteotodos->isChecked() ) {
00568         tipopunteo = "";
00569     } else if ( mui_punteopunteado->isChecked() ) {
00570         tipopunteo = " AND punteo = TRUE ";
00571     } else {
00572         tipopunteo = " AND punteo = FALSE ";
00573     } // end if
00574 
00575     if ( contra != "" ) {
00576         tipopunteo += " AND apunte.contrapartida = id_cuenta('" + contra + "') ";
00577     } // end if
00578 
00579     QString cad;
00580     QString cadaux;
00581     cursor2 *cursorapt;
00582 
00583     if ( idcuenta == "" )
00584         return "";
00585 
00587     QString query = "";
00590     selectcanalview *scanal = empresaBase()->getselcanales();
00591     SelectCCosteView *scoste = empresaBase()->getselccostes();
00592     QString ccostes = scoste->cadcoste();
00593     if ( ccostes != "" ) {
00594         ccostes.sprintf ( " AND idc_coste IN (%s) ", ccostes.toAscii().constData() );
00595     } // end if
00596     QString ccanales = scanal->cadcanal();
00597     if ( ccanales != "" ) {
00598         ccanales.sprintf ( " AND idcanal IN (%s) ", ccanales.toAscii().constData() );
00599     } // end if
00600     QString tabla;
00601     QString cont;
00602     if ( mui_asAbiertos->isChecked() ) {
00603         tabla = "borrador";
00604         cont = " FALSE AS punteo, * ";
00605     } else {
00606         tabla = "apunte";
00607         cont = " * ";
00608     } // end if
00609 
00610     query = "SELECT * FROM ((SELECT "+cont+" FROM " + tabla + " WHERE  idcuenta = " + idcuenta + " AND fecha >= '" + finicial + "' AND fecha <= '" + ffinal + "' " + ccostes + " " + ccanales + " " + tipopunteo + ") AS t2 LEFT JOIN cuenta ON t2.idcuenta = cuenta.idcuenta) AS t1 LEFT JOIN asiento ON asiento.idasiento = t1.idasiento ";
00611     query += " LEFT JOIN (SELECT idc_coste, nombre AS nombrec_coste FROM c_coste) AS t5 ON t5.idc_coste = t1.idc_coste ";
00612     query += " LEFT JOIN (SELECT idcanal, nombre AS nombrecanal FROM canal) AS t6 ON t6.idcanal = t1.idcanal ";
00613     query += " ORDER BY t1.fecha, ordenasiento, t1.orden";
00614 
00615     cursorapt=empresaBase()->cargacursor ( query );
00616 
00618     cursor2 *cursoraux;
00619     query = "SELECT sum(debe) AS tdebe, sum(haber) AS thaber FROM apunte WHERE idcuenta =" + idcuenta + " AND fecha < '" + finicial + "'";
00620     cursoraux = empresaBase()->cargacursor ( query );
00621     if ( !cursoraux->eof() ) {
00622         debeinicial = Fixed ( cursoraux->valor ( "tdebe" ) );
00623         haberinicial = Fixed ( cursoraux->valor ( "thaber" ) );
00624         saldoinicial = debeinicial - haberinicial;
00625         debefinal = debeinicial;
00626         haberfinal = haberinicial;
00627     } // end if
00628     delete cursoraux;
00629 
00631     cursor2 *cursorcta = empresaBase()->cargacursor ( "SELECT * FROM cuenta WHERE idcuenta="+idcuenta );
00632 
00633     salida += "<blockTable>\n";
00634     salida += "<tr>";
00635     salida += "<td> Codigo: "+cursorcta->valor ( "codigo" ) +" </td>";
00636     salida += "<td> Fecha Inicial: "+finicial+" </td>";
00637     salida += "<td> Fecha Final: "+ffinal+" </td>";
00638     salida += "<td> Debe Inicial: "+debeinicial.toQString() +" </td>";
00639     salida += "<td> Debe Final: "+haberinicial.toQString() +" </td>";
00640     salida += "</tr>";
00641     salida += "<tr>";
00642     salida += "<td> Cuenta: "+cursorcta->valor ( "descripcion" ) +" </td>";
00643     salida += "<td> </td>";
00644     salida += "<td> </td>";
00645     salida += "<td> </td>";
00646     salida += "<td> </td>";
00647     salida += "</tr>";
00648     salida += "</blockTable>\n";
00649     salida += "<spacer length=\"5mm\" width=\"1mm\"/>\n";
00650 
00651     delete cursorcta;
00653     salida += "<blockTable style=\"tabla\" repeatRows=\"1\">\n";
00654     salida += "<tr>\n";
00655     salida += "<td> Fecha </td>";
00656     salida += "<td> Asiento </td>";
00657     salida += "<td> Concepto </td>";
00658     salida += "<td> Debe </td>";
00659     salida += "<td> Haber </td>";
00660     salida += "<td> Saldo </td>";
00661     salida += "</tr>\n";
00662 
00663     while ( ! cursorapt->eof() ) {
00664         saldofinal = saldofinal + Fixed ( cursorapt->valor ( "debe" ) ) - Fixed ( cursorapt->valor ( "haber" ) );
00665         debefinal = debefinal + Fixed ( cursorapt->valor ( "debe" ) );
00666         haberfinal = haberfinal + Fixed ( cursorapt->valor ( "haber" ) );
00667 
00668         salida +=  "<tr>\n";
00669         salida +=  "<td>"+cursorapt->valor ( "fecha" ) +"</td>";
00670         salida +=  "<td>"+cursorapt->valor ( "orden" ) +"</td>";
00671         salida +=  "<td>"+cursorapt->valor ( "conceptocontable" ) +"</td>";
00672         salida +=  "<td>"+cursorapt->valor ( "debe" ) +"</td>";
00673         salida +=  "<td>"+cursorapt->valor ( "haber" ) +"</td>";
00674         salida +=  "<td>"+saldofinal.toQString() +"</td>";
00675         salida +=  "</tr>\n";
00676         cursorapt->siguienteregistro();
00677     } // end while
00678 
00679     salida += "</blockTable>\n";
00680 
00681     salida += "<spacer length=\"5mm\" width=\"1mm\"/>\n";
00682 
00683 
00684     salida += "<blockTable>\n";
00685     salida += "<tr>\n";
00686     salida += "<td> Debe Final: "+debefinal.toQString() +" </td>\n";
00687     salida += "<td> Haber Final: "+haberfinal.toQString() +" </td>\n";
00688     salida += "<td> Saldo Final: "+saldofinal.toQString() +"</td>\n";
00689     salida += "</tr>\n";
00690     salida += "</blockTable>\n";
00691 
00692     delete cursorapt;
00693     _depura ( "END extractoview1::imprimeExtractoCuenta", 0 );
00694     return salida;
00695 }
00696 
00697 
00698 
00700 
00702 void extractoview1::on_mui_imprimir_clicked() {
00703     _depura ( "extractoview1::on_mui_imprimir_clicked", 0 );
00704 
00705     QString archivo = confpr->valor ( CONF_DIR_OPENREPORTS ) + "extracto.rml";
00706     QString archivod = confpr->valor ( CONF_DIR_USER ) + "extracto.rml";
00707     QString archivologo = confpr->valor ( CONF_DIR_OPENREPORTS ) + "logo.jpg";
00709 #ifdef WINDOWS
00710 
00711     archivo = "copy " + archivo + " " + archivod;
00712 #else
00713 
00714     archivo = "cp " + archivo + " " + archivod;
00715 #endif
00716 
00717     system ( archivo.toAscii().constData() );
00719 #ifdef WINDOWS
00720 
00721     archivologo = "copy " + archivologo + " " + confpr->valor ( CONF_DIR_USER ) + "logo.jpg";
00722 #else
00723 
00724     archivologo = "cp " + archivologo + " " + confpr->valor ( CONF_DIR_USER ) + "logo.jpg";
00725 #endif
00726 
00727     system ( archivologo.toAscii().constData() );
00728     QFile file;
00729     file.setFileName ( archivod );
00730     file.open ( QIODevice::ReadOnly );
00731     QTextStream stream ( &file );
00732     QString buff = stream.readAll();
00733     file.close();
00734     QString fitxersortidatxt = "";
00735 
00736     QString codinicial = m_codigoinicial->codigocuenta();
00737     QString codfinal = m_codigofinal->codigocuenta();
00738 
00739     QString query;
00742     if ( codinicial == "" ) {
00743         codinicial = "0";
00744     } // end if
00745     if ( codfinal == "" ) {
00746         codfinal = "9999999";
00747     } // end if
00748     query = "SELECT * FROM cuenta WHERE idcuenta IN (SELECT idcuenta FROM apunte) AND codigo >= '" + codinicial + "' AND codigo <= '" + codfinal + "' ORDER BY codigo";
00749     cursor2 *curcta = empresaBase()->cargacursor ( query );
00750     if (!curcta) return;
00751     while ( ! curcta->eof() ) {
00752         fitxersortidatxt += imprimeExtractoCuenta ( curcta->valor ( "idcuenta" ) );
00753         curcta->siguienteregistro();
00754         if ( ! curcta->eof() )
00755             fitxersortidatxt += "<nextFrame/><nextPage/>";
00756     }// end while
00757     delete curcta;
00758 
00759 
00760     buff.replace ( "[story]",fitxersortidatxt );
00761     if ( file.open ( QIODevice::WriteOnly ) ) {
00762         QTextStream stream ( &file );
00763         stream << buff;
00764         file.close();
00765     } // end if
00767     invocaPDF ( "extracto" );
00768     _depura ( "END extractoview1::on_mui_imprimir_clicked", 0 );
00769 }
00770 

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