#include #include #include #include #include #include #include #include #include "..\libs\make_bot\make_bot.h" #include "sv_util.h" #include "sv_graph.h" #include "sv_ref_x.h" #define Letra_Boton setcolor(1); #define Azul 1 #define Texto_Normal setcolor(63); #define Texto_Negrita setcolor(0); extern int x_raton, y_raton, raton; extern int boton_izq, boton_der; extern void desactiva_raton(void); extern void activa_raton(void); extern void Anclar_Raton(void); extern void inicializa_raton_grafico(int x1, int y1, int x2, int y2, int px, int py); extern int Espera_Tecla_o_Raton(void); extern void BEEP(void); extern void textxy(int x, int y, char *text); extern void Abre_Ficha_Compras(void); extern void GetLineComp(void); // extern int Confirma(char *f1, char *f2, char *f3); extern int Comprueba_Impresora(void); extern void Abre_Ficha_Stock(void); extern void Lee_Datos_Ganancias(unsigned long *Compras_mes); void Imprimir_Gra_Compras_C(unsigned long *Compras_mes); void Prepara_Pantalla_GC2(void); void Lee_Datos_C(unsigned long *Compras_mes); void Muestra_Datos_C(unsigned long *Compras_mes, int Cod); extern void Calcula_Porcentaje_C(unsigned long *Compras_mes); struct Comp_inx { unsigned int Fin; }; struct Compras { struct date Fecha; int Ref; int Und; char Cod; }; //////////// extern void Prepara_Porcentaje_Circular(void); extern void GetLineClientes_Compras2(void); extern void Displayado_de_Datos(int Para_quien); extern void Acota_Contenido(void); extern int Viable_Apertura(void); extern void Abre_Ficha_Clientes(void); extern void Abre_Ficha_Clientes_Ncontrato(void); extern void Abre_Ficha_Vendedores(void); extern void Carga_Todos_los_Vendedores(void); extern int CurrRow1_Clien, CurrRow2_Clien; extern int CurrCol1_Clien, CurrCol2_Clien; extern int CurrTopLine_Clien, CurrTopLine_Clien1; extern void GetLineClientes(void); extern void Abre_Ficha_Clientes_Compras(void); extern int *Vend_Dir; struct Clientes_inx_NContrato { unsigned long Inicio; unsigned int Records; unsigned char Libre; }; struct Clientes_inx { char Ncontrato_ocupado_SN[10000]; unsigned int Fin; }; struct Clientes { int Address; char Nombre[15+1]; char Apellido1[15+1]; char Apellido2[15+1]; char DNI[15+1]; unsigned long Telefono1; char Calle1[30+1]; char Num1[5+1]; char Local[30+1]; unsigned long Telefono2; char Calle2[30+1]; char Num2[5+1]; char Poblacion[18+1]; char Provincia[16+1]; unsigned long CP; unsigned char GC; unsigned char MR; unsigned char SP; unsigned char DP; unsigned int MA; struct date Fecha; int Vend; int NContrato; }; // Se almacenan 1000 registros por archivo // En un caso extremo son: 9 bit ---> Espacio por Dato // 31 ---> Dias por mes // 2 ---> Productos por d¡a // 12 ---> 12 meses // 1000 ---> Clientes // struct Clientes_compras { // C UU VEN REF struct date Fecha; // 1 99 999 9999 unsigned long Cod_Und_Vend_Ref; }; struct Vend_inx { unsigned int Fin; }; struct Vendedores { int Num_V; char Nombre[15+1]; char Apellido1[15+1]; char Apellido2[15+1]; char DNI[15+1]; unsigned long Telefono1; unsigned long Telefono2; char Calle[30+1]; char Num[3+1]; char Piso[3+1]; char Poblacion[18+1]; char Provincia[16+1]; unsigned long CP; unsigned long CC; unsigned int PP; unsigned int Cr; }; /* extern struct Stock_inx { unsigned int Fin; }; extern struct Stock_actual { int Ref; long Und_0; long Und_1; }; */ extern struct Stock_actual Ventas1; extern struct Stock_inx Ventas1_inx; extern void Actualizar_Stock(int Referencia, int Unidades, int Codigo); extern struct JD cabecera; extern struct Clientes Clientes1; extern struct Clientes_inx Clientes1_inx; extern struct Clientes_compras Clientes2; extern struct Clientes_inx_NContrato Clientes1_inx_NContrato; // struct Clientes Clientes1_Buscar; extern struct Vendedores Vend1; extern struct Vend_inx Vend1_inx; extern FILE *Vend; // Fichero Vendedores extern FILE *Stock; extern FILE *Ventas; extern FILE *Clientes; // Fichero Clientes extern FILE *Clientes_C; // Fichero Clientes con las Compras. extern FILE *Clientes_NC; // Fichero Clientes con los n£meros de contrato activos. extern int Usa_Pc; extern int Start_Comp_Clien; extern int Comp_Clien_Records; extern int oldCNI; char Buffer_Clien[15][80]; //////////// extern struct Compras Comp1; extern struct Comp_inx Comp1_inx; struct boton *PGC2;//[7] extern struct boton Comunes[9]; extern int CurrRowComp1; extern int CurrColComp1; extern int CurrTopLineComp; extern unsigned long TOTAL, TOTAL1, TOTAL0; extern int Fecha; int Dir_Pers[15]; int Buff_Contr[15]; void Menu_Graficas_de_Clientes(int Current_Date); void Menu_Graficas_de_Clientes(int Current_Date){ Fecha = Current_Date; int i; for( i=0; i<15; i++) { Dir_Pers[i] = 0; Buff_Contr[i] = 0; strcpy( Buffer_Clien[i], "\0"); } int finished = 0, bpush; unsigned long *Compras_mes; if( ( PGC2 = (struct boton *) malloc( sizeof(struct boton)*20 ) ) == NULL ) { Confirma("Memoria insuficiente", "para crear tablas de", "posisi¢n PGC."); return ; } if( ( Compras_mes = (unsigned long *) malloc( sizeof(long)*24 ) ) == NULL ) { Confirma("Memoria insuficiente", "para crear tablas de", "Compras_mes."); free(PGC2); return ; } for(bpush=0; bpush<24; bpush++) Compras_mes[bpush]=0; ////////////////// if( !Viable_Apertura() ) return ; Abre_Ficha_Clientes(); Abre_Ficha_Clientes_Ncontrato(); Abre_Ficha_Referencias(); Carga_Referencias(); if( ( Vend_Dir = (int *) malloc( sizeof(int)*1024 ) ) == NULL ) { Confirma("Memoria insuficiente", "para crear tablas para", "Vend_Dir"); return ; } Abre_Ficha_Vendedores(); Carga_Todos_los_Vendedores(); CurrRow1_Clien = 1; CurrTopLine_Clien1 = 1; GetLineClientes(); Abre_Ficha_Clientes_Compras(); ////////////////// Lee_Datos_C(Compras_mes); Prepara_Pantalla_GC2(); Calcula_Porcentaje_C(Compras_mes); Muestra_Datos_C(Compras_mes, 1); do{ if(raton!=0) activa_raton(); Espera_Tecla_o_Raton(); if(raton!=0) desactiva_raton(); if(kbhit()){ if( getch()==0 ) { switch( (getch()) ){ // Flecha Arriba case 72: break; // Flecha Izquierda case 75: case 15: break; // Flecha Derecha case 77: case 9: break; // Flecha Abajo case 80: break; // Codigo 1 F2 case 60: // Muestra_Datos_C(Compras_mes, 1); break; // Codigo 0 F3 case 61: // Muestra_Datos_C(Compras_mes, 0); break; // Codigo 1y0 F4 case 62: // Muestra_Datos_C(Compras_mes, 2); break; // Imprimir Compras F5 case 63: Imprimir_Gra_Compras_C(Compras_mes); break; // F9 --> A¥ADIR case 67: break; // F10 -> BORRAR case 68: break; // INICIO case 71: break; // FIN case 79: break; // ReP g case 73: // CurrRow = 1; break; // AvP g case 81: break; // Salir F1 case 59: finished = 1; break; default: break; } } } else if(raton!=0 && ( boton_izq==1 || boton_der==1 ) ) if( (bpush = CheckButon( 9, Comunes))>0 ) { switch(bpush){ // Flecha Arriba case 1: break; // Buscar case 2: break; // Flecha Abajo case 3: break; case 4: break; // Imprimir case 5: Imprimir_Gra_Compras_C(Compras_mes); break; // A¤adir case 6: break; // Borrar case 7: break; // Salir case 9: finished = 1; break; default: break; } } }while(!finished); fclose(Clientes); // Fichero Clientes fclose(Clientes_NC); // Fichero Clientes fclose(Clientes_C); // Fichero Clientes fclose(Ref); // Fichero Vendedores if(Memory_ok==1) farfree(Addr); else free(Ref_inx_addr); free(PGC2); free(Vend_Dir); free(Compras_mes); } void Lee_Datos_C(unsigned long *Compras_mes){ setcolor(ROJO); setfillstyle( SOLID_FILL, ROJO ); Pantalla_de_Facturas(); /* char Buffer[80]; */ int /*day, mon, Ref,*/ Und,/* Cod, Vend,*/ ok, Compara, sustf; unsigned long Suma_Total = 0, /*Suma_IVA = 0,*/ Total; int tmp = CurrRow1_Clien, Ptotal; CurrTopLine_Clien1 = 1; Usa_Pc = 1; CurrTopLine_Clien = 1; Prepara_Porcentaje_Circular(); setcolor(4); setfillstyle(SOLID_FILL, 60); for(CurrRow1_Clien = 1; CurrRow1_Clien <= ( Clientes1_inx.Fin + 1); CurrRow1_Clien++){ GetLineClientes(); if( ( (Clientes1.Address)/100/*0*/ ) != oldCNI ){ oldCNI = ( (Clientes1.Address) / 100/*0*/ ); fclose(Clientes_C); Abre_Ficha_Clientes_Compras(); } Acota_Contenido(); // Porcentaje(); Displayado_de_Datos(5); setcolor(4); setfillstyle(SOLID_FILL, 60); ////////////////////////////////////////////////////// Suma_Total = 0; for(CurrRow2_Clien = 1; (CurrTopLine_Clien + CurrRow2_Clien - 1) <= Comp_Clien_Records; CurrRow2_Clien++) { GetLineClientes_Compras2(); // X 99 999 9999 /// Cod = ( Clientes2.Cod_Und_Vend_Ref/1000000000L ); // day= Clientes2.Fecha.da_day; // mon= Clientes2.Fecha.da_mon; // sprintf(Buffer, "%02d/%02d/%02d", day, mon, Clientes2.Fecha.da_year ); // 1 99 999 XXXX /// Ref = ( Clientes2.Cod_Und_Vend_Ref - ((Clientes2.Cod_Und_Vend_Ref/10000)*10000) ); // 1 XX 999 9999 Und = ( ( Clientes2.Cod_Und_Vend_Ref/10000000L ) - ( ( (Clientes2.Cod_Und_Vend_Ref/10000000L)/100)*100 ) ); // 1 99 XXX 9999 /// Vend = ( ( Clientes2.Cod_Und_Vend_Ref/10000 ) - ( ( ( Clientes2.Cod_Und_Vend_Ref/10000 ) / 1000) * 1000 ) ); Total = ( (Und * Ref1.PVP) + ( ( Und * Ref1.PVP*Ref1.P2)/100) ); Suma_Total += Total; if (Usa_Pc == 1) pieslice(400, 265, (( ( 360 * ( ( CurrRow2_Clien * 100 ) / Comp_Clien_Records ) ) / 100 ) - 1), 0, 38); } //ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ //ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ ok = 0; for( Compara=0; Compara<12 && !ok ; Compara++ ) { if( Compras_mes[Compara] < Suma_Total ) { for( sustf = 11; sustf >= Compara; sustf-- ) { Compras_mes[sustf] = Compras_mes[sustf-1]; Dir_Pers[sustf] = Dir_Pers[sustf-1]; strcpy( Buffer_Clien[sustf], Buffer_Clien[sustf-1]); Buff_Contr[sustf] = Buff_Contr[sustf-1]; } Compras_mes[Compara] = Suma_Total; Dir_Pers[Compara] = CurrRow1_Clien; sprintf( Buffer_Clien[Compara], "%-21s", Clientes1.Local); Buff_Contr[Compara] = Clientes1.NContrato; ok = 1; } } //ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ // fprintf( stdprn, "%04d\n\r", Clientes1.NContrato); // fprintf( stdprn, " %s\n\r",Clientes1.Local); // fprintf( stdprn, " %s %s, %s\n\r", Clientes1.Apellido1, Clientes1.Apellido2, Clientes1.Nombre); //ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ ////////////////////////////////////////////////////// // Calculamos el porcentaje total realizado // Si todo es el: ( Clientes1_inx.Fin + 1 ) es decir 100 % // CurrRow1_Clien el el X % // X = ( CurrRow1_Clien * 100 ) / ( Clientes1_inx.Fin + 1 ) // Si 285 es el 100 % // x es el X anterior // x = ( 285 * X ) / 100 Ptotal = ( ( 283 * ( ( CurrRow1_Clien * 100 ) / ( Clientes1_inx.Fin + 1 ) ) ) / 100 ); bar(167, 172, 167 + Ptotal, 182 ); Prepara_Porcentaje_Circular(); } CurrRow1_Clien = tmp; Usa_Pc = 0; } void Muestra_Datos_C(unsigned long *Compras_mes, int Cod){ char Buffer[80]; setcolor(ROJO); for(int i=0; i<12; i++){ ImprimeBoton (1, NEGRO, BLANCO, GRIS_O, PGC2[i]); /// if(Cod == 1){ /// setcolor(EGA_LIGHTBLUE); /// sprintf(Buffer, "%18ld", Compras_mes[i*2 + 1] ); /// } else if(Cod == 0){ /// sprintf(Buffer, "%18ld", Compras_mes[i*2] ); /// setcolor(ROJO); /// } else if(Cod == 2){ setcolor(EGA_YELLOW); sprintf(Buffer, "%13ld", Compras_mes[i /* *2 + 1 */]/* + Compras_mes[i*2]*/ ); /// } outtextxy(PGC2[i].left+2, PGC2[i].up+2, Buffer); } Fuente(SMALL_FONT, 4); for(i=0; i<12; i++) textxy( PGC2[i].left - 78 - 40 - 5, PGC2[i].up+2, Buffer_Clien[i] ); Fuente(SMALL_FONT, 6); // ImprimeBoton (1, NEGRO, BLANCO, GRIS_O, PGC2[12]); // setcolor(BLANCO); /// if(Cod == 1) sprintf(Buffer, "%46ld", TOTAL1 ); /// else if(Cod == 0) sprintf(Buffer, "%46ld", TOTAL0 ); /// else if(Cod == 2) sprintf(Buffer, "%46ld", TOTAL ); /// outtextxy(PGC2[12].left+2, PGC2[12].up+2, Buffer); // bar(152,372, ( 152 + 245 ), 388); } void Calcula_Porcentaje_C(unsigned long *Compras_mes){ /* long double */ TOTAL = 0; /* long double */ TOTAL1 = 0; /* long double */ TOTAL0 = 0; char Buffer[80]; int i, ADD = 15; long P1tmp, P0tmp, Ltmp; for(i=0; i<12; i++) { TOTAL0 += Compras_mes[ i/* *2 */ ]; // TOTAL1 += Compras_mes[ i*2 + 1 ]; } TOTAL1 = 0; TOTAL = /* TOTAL1 + */ TOTAL0 ; setcolor(BLANCO); // sprintf(Buffer, "%46ld", TOTAL1 ); // outtextxy(PGC2[12].left+2, PGC2[12].up+2, Buffer); ImprimeBoton (1, NEGRO, BLANCO, GRIS_O, PGC2[13]); // PGC2[13].up = 195; PGC2[13].down = 440; // PGC2[13].left = 5; PGC2[13].right = 549; Fuente(SMALL_FONT, 4); setcolor(BLANCO); outtextxy( 10, 350 + 15+ 5 - 150, "100 %"); outtextxy( 10, 350 + 15+ 5 - 75, " 50 %"); outtextxy( 10, 350 + 15+ 5, " 0 %"); setcolor(ROJO); outtextxy( 10, 350 + 15+ 5 - 75 - 37, " 75 %"); outtextxy( 10, 350 + 15+ 5 - 37, " 25 %"); for(i=0; i<12; i++){ //bar3d( (ADD + 45 + (i*35 + 2 + i*5) ), 215, (ADD + 45 + (i*35 + 2 + i*5) + 35 ), 350, 10, 1); if ( (Compras_mes[ i /* * 2 + 1 */ ] /* + Compras_mes[ i * 2 ] */ ) != 0 ) { // Porcentaje de las compras 1 en un mes /// P1tmp = (Compras_mes[ i /* * 2 + 1 */ ] * 100)/(Compras_mes[ i /* * 2 + 1 */ ]/* + Compras_mes[ i * 2 ]*/); /// P0tmp = (Compras_mes[ i * 2 ] * 100)/(Compras_mes[ i * 2 + 1 ] + Compras_mes[ i * 2 ]); P0tmp = 0; P1tmp = 100; Ltmp = ( ( 150 * ( ( (Compras_mes[ i /* * 2 + 1 */ ] /*+ Compras_mes[ i * 2 ]*/) * 100 ) / TOTAL ) ) / 100 ); if( P1tmp != 0 && P0tmp == 0 ){ setcolor(AZUL); setfillstyle( i, AZUL ); bar3d( (ADD + 45 + (i*35 + 2 + i*5) ) - 15 - 5, 350 + 15+ 5 - ( (Ltmp * P1tmp) / 100), (ADD + 45 + (i*35 + 2 + i*5) + 35 ) - 15 - 5, 350 + 15+5, 30, 1); } if( P1tmp != 0 && P0tmp != 0 ){ setcolor(AZUL); setfillstyle( i, AZUL ); bar3d( (ADD + 45 + (i*35 + 2 + i*5) ) - 15 - 5, 350 + 15+ 5 - ( (Ltmp * P1tmp) / 100), (ADD + 45 + (i*35 + 2 + i*5) + 35 ) - 15 - 5, 350 + 15+5, 30, 0); } if( P0tmp != 0 ){ setcolor(ROJO); setfillstyle( i, ROJO ); bar3d( (ADD + 45 + (i*35 + 2 + i*5) ) - 15 - 5, (350 + 15+ 5 - ( (Ltmp * P1tmp) / 100) ) - ( (Ltmp * P0tmp) / 100), (ADD + 45 + (i*35 + 2 + i*5) + 35 ) - 15 - 5, (350 + 15+5 - ( (Ltmp * P1tmp) / 100) ), 30, 1); } setcolor(EGA_YELLOW); sprintf(Buffer, " %04d", Buff_Contr[i] ); outtextxy( (ADD + 45 + (i*35 + 2 + i*5) ) - 15 - 5 - 5 - 1, 380 - 5, Buffer); } } Fuente(SMALL_FONT, 6); } void Prepara_Pantalla_GC2(void) { cleardevice(); Pantalla_Graficas_Compras_C(PGC2); Fuente(SMALL_FONT, 5); // Coloca_Nombres_a_botones(); /* textxy(Comunes[0].left+2, Comunes[0].up, "C¢digos" ); textxy(Comunes[0].left+2, Comunes[0].up+18, " F2" ); textxy(Comunes[1].left+2, Comunes[1].up, "C¢digos 0" ); textxy(Comunes[1].left+2, Comunes[1].up+18, " F3" ); textxy(Comunes[2].left+2, Comunes[2].up, "Totales" ); textxy(Comunes[2].left+2, Comunes[2].up+18, " F4" ); */ textxy(Comunes[4].left+2, Comunes[4].up, " Imprimir" ); textxy(Comunes[4].left+2, Comunes[4].up+18, " F5" ); textxy(Comunes[8].left+2, Comunes[8].up, " Salir" ); textxy(Comunes[8].left+2, Comunes[8].up+18, " F1" ); Fuente(SMALL_FONT, 6); } void Imprimir_Gra_Compras_C(unsigned long *Compras_mes){ char mes[][12] = {"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"}; if ( Comprueba_Impresora() == 0 ) { Confirma("Error Imprimiendo.", "Impresora Fuera de", "Servicio."); return; } fprintf( stdprn, "úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú\n\r"); for(int i=0; i<12; i++) { CurrRow1_Clien = Dir_Pers[i]; GetLineClientes(); fprintf( stdprn, "N§ de Contrato: %04d Local: %s\n\r", Clientes1.NContrato, Clientes1.Local); fprintf( stdprn, "Propietario: %s %s %s ", Clientes1.Nombre, Clientes1.Apellido1, Clientes1.Apellido2); fprintf( stdprn, "Tlf: %lu\n\r", Clientes1.Telefono2); fprintf( stdprn, "Valor de las Compras: %10ld\n\r", Compras_mes[i]); fprintf( stdprn, "úúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúúú\n\r"); } fprintf( stdprn, "\n\r"); fprintf( stdprn, "\n\r"); fprintf( stdprn, "Indice de ventas referente al mes de %s\n\r", mes[Fecha-1]); fputc(12, stdprn); }