00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "estadisticasview.h"
00018 #include <qlabel.h>
00019
00020 #ifdef GDCHART
00021 #include "gdc.h"
00022 #include "gdcpie.h"
00023 #include <gdchart.h>
00024 #endif
00025
00026 int estadisticasview::inicializa(postgresiface2 *conexion) {
00027 conexionbase = conexion;
00028 presentar();
00029 #ifdef GDCHART
00030 delete m_pie;
00031 #endif
00032
00033 #ifdef ESTADISTICAS
00034 delete m_imagen;
00035 #endif
00036
00037
00038 return(0);
00039 }
00040
00041 estadisticasview::estadisticasview(QWidget *parent, const char *name ) : estadisticasdlg(parent,name) {
00042 }
00043
00044
00045 estadisticasview::~estadisticasview(){
00046 }
00047
00048
00049 void estadisticasview::presentar() {
00050 int j,num1;
00051 QString query;
00052 cursor2 *cursorapt;
00053 QString finicial = "01/01/2003";
00054 QString ffinal = "31/12/2003";
00055 QString cinicial = "10";
00056 QString cfinal = "99";
00057
00058
00059
00060
00061
00062
00063 fprintf(stderr,"BALANCE: Empezamos a hacer la presentacion\n");
00064 conexionbase->begin();
00065 query.sprintf("CREATE TEMPORARY TABLE balance AS SELECT cuenta.idcuenta, codigo, nivel(codigo) AS nivel, cuenta.descripcion, padre, tipocuenta ,debe, haber, tdebe, thaber,(tdebe-thaber) AS tsaldo, (debe-haber) AS saldo, adebe, ahaber, (adebe-ahaber) AS asaldo FROM cuenta LEFT JOIN (SELECT idcuenta, sum(debe) AS tdebe, sum(haber) AS thaber FROM apunte WHERE fecha >= '%s' AND fecha<= '%s' GROUP BY idcuenta) AS t1 ON t1.idcuenta = cuenta.idcuenta LEFT JOIN (SELECT idcuenta, sum(debe) AS adebe, sum(haber) AS ahaber FROM apunte WHERE fecha < '%s' GROUP BY idcuenta) AS t2 ON t2.idcuenta = cuenta.idcuenta", finicial.ascii(), ffinal.ascii(), finicial.ascii() );
00066 conexionbase->ejecuta(query);
00067 query.sprintf("UPDATE BALANCE SET padre=0 WHERE padre ISNULL");
00068 conexionbase->ejecuta(query);
00069 query.sprintf("DELETE FROM balance WHERE debe=0 AND haber =0");
00070 conexionbase->ejecuta(query);
00071
00072
00073 query.sprintf("UPDATE BALANCE SET tsaldo=0 WHERE tsaldo ISNULL");
00074 conexionbase->ejecuta(query);
00075 query.sprintf("UPDATE BALANCE SET tdebe=0 WHERE tdebe ISNULL");
00076 conexionbase->ejecuta(query);
00077 query.sprintf("UPDATE BALANCE SET thaber=0 WHERE thaber ISNULL");
00078 conexionbase->ejecuta(query);
00079 query.sprintf("UPDATE BALANCE SET asaldo=0 WHERE asaldo ISNULL");
00080 conexionbase->ejecuta(query);
00081
00082
00083 query.sprintf("SELECT idcuenta FROM balance ORDER BY padre DESC");
00084 cursorapt = conexionbase->cargacursor(query,"Balance1view");
00085
00086 while (!cursorapt->eof()) {
00087 query.sprintf("SELECT * FROM balance WHERE idcuenta=%s",cursorapt->valor("idcuenta").ascii());
00088 cursor2 *mycur = conexionbase->cargacursor(query,"cursorrefresco");
00089
00090 query.sprintf("UPDATE balance SET tsaldo = tsaldo + (%2.2f), tdebe = tdebe + (%2.2f), thaber = thaber +(%2.2f), asaldo= asaldo+(%2.2f) WHERE idcuenta = %d",atof(mycur->valor("tsaldo").ascii()), atof(mycur->valor("tdebe").ascii()), atof(mycur->valor("thaber").ascii()),atof(mycur->valor("asaldo").ascii()), atoi(mycur->valor("padre").ascii()));
00091
00092 conexionbase->ejecuta(query);
00093 delete mycur;
00094 cursorapt->siguienteregistro();
00095 }
00096 delete cursorapt;
00097
00098
00099
00100 query.sprintf("DELETE FROM balance where nivel(codigo)>%s","2");
00101 conexionbase->ejecuta(query);
00102
00103
00104 query.sprintf("DELETE FROM balance WHERE idcuenta IN (SELECT padre FROM balance)");
00105 conexionbase->ejecuta(query);
00106
00107
00108 query.sprintf("SELECT * FROM balance WHERE debe <> 0 OR haber <> 0 ORDER BY codigo");
00109 cursorapt = conexionbase->cargacursor(query,"mycursor");
00110
00111
00112
00113 num1 = cursorapt->numregistros();
00114 j=0;
00115
00116 #ifdef GDCHART
00117 char *label[1000];
00118 float p[1000];
00119 #endif
00120 while (!cursorapt->eof()) {
00121
00122 float valor = atof(cursorapt->valor("tsaldo").ascii());
00123 if (valor > 0) {
00124 #ifdef ESTADISTICAS
00125 m_pie->addValue(valor,cursorapt->valor("descripcion").mid(0,15).ascii());
00126 #endif
00127 #ifdef GDCHART
00128 label[j]=new char[30];
00129 strcpy(label[j], cursorapt->valor("descripcion").mid(0,15).ascii());
00130 p[j]=valor;
00131 fprintf(stderr,"%s %d", label[j], p[j]);
00132 #endif
00133
00134 } else {
00135 #ifdef ESTADISTICAS
00136 m_pie->addValue(-valor,cursorapt->valor("descripcion").mid(0,15).ascii());
00137 #endif
00138 #ifdef GDCHART
00139 label[j]=new char[30];
00140 strcpy(label[j], cursorapt->valor("descripcion").mid(0,15).ascii());
00141 p[j]=-valor;
00142 fprintf(stderr,"%s %d", label[j], p[j]);
00143 #endif
00144 }
00145
00146
00147 cursorapt->siguienteregistro();
00148 j++;
00149 }
00150
00151
00152 delete cursorapt;
00153 query.sprintf("DROP TABLE balance");
00154 conexionbase->ejecuta(query);
00155 conexionbase->commit();
00156
00157
00158
00159 #ifdef GDCHART
00160 fprintf(stderr,"Llamamos a sacapie\n");
00161
00162 sacapie(p, label, (j-1>10 )? 10:j-1);
00163
00164 fprintf(stderr,"Hemos terminado sacapie \n");
00165 QPixmap *imag= new QPixmap("/tmp/pie.gif");
00166 fprintf(stderr,"Y ahora hemos creado la imagen\n");
00167 m_imagen->setPixmap(*imag);
00168 fprintf(stderr,"Y ahora la hemos mostrado\n");
00169
00170 for(int i=0;i<j;i++) delete label[i];
00171 delete imag;
00172 #endif
00173 }
00174
00175
00176 #ifdef GDCHART
00177 void estadisticasview::sacapie(float *p1,char **lbl1, int numslices1) {
00178
00179 fprintf(stderr,"Hemos terminado de compilar \n");
00180
00181 FILE *fp = fopen( "/tmp/pie.gif", "wb" );
00182
00183 char *lbl[] = { "CPQ\n(DEC)",
00184 "HP",
00185 "SCO",
00186 "IBM",
00187 "SGI",
00188 "SUN\nSPARC",
00189 "other" };
00190
00191 float p[] = { 12.5,
00192 20.1,
00193 2.0,
00194 22.0,
00195 5.0,
00196 18.0,
00197 13.0 };
00198
00199
00200 int expl[] = { 0, 0, 0, 0, 0, 20, 0 };
00201
00202
00203 unsigned char missing[] = { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE };
00204
00205
00206 unsigned long clr[] = { 0xFF4040L, 0x80FF80L, 0x8080FFL, 0xFF80FFL, 0xFFFF80L, 0x80FFFFL, 0x0080FFL };
00207
00208
00209
00210
00211
00212 GDCPIE_label_line = TRUE;
00213 GDCPIE_label_dist = 15;
00214
00215 GDCPIE_LineColor = 0x000000L;
00216 GDCPIE_label_size = GDC_SMALL;
00217 GDCPIE_3d_depth = 25;
00218 GDCPIE_3d_angle = 180;
00219 GDCPIE_perspective = 70;
00220 GDCPIE_explode = expl;
00221 GDCPIE_Color = clr;
00222 GDCPIE_BGColor = 0xFFFFFFL;
00223
00224
00225 GDCPIE_missing = missing;
00226
00227
00228
00229 GDCPIE_percent_labels = GDCPIE_PCT_BELOW;
00230 GDC_image_type = GDC_PNG;
00231
00232 GDC_out_pie( 300,
00233 200,
00234 fp,
00235 GDC_3DPIE,
00236 7,
00237 NULL,
00238 p );
00239
00240 fprintf(stderr,"Hemos terminado la imagen\n");
00241 fclose( fp );
00242
00243 }
00244 #endif
00245
00246