441 lines
10 KiB
C++
441 lines
10 KiB
C++
#include<graphics.h>
|
||
#include<dos.h>
|
||
#include<conio.h>
|
||
#include<stdio.h>
|
||
#include<string.h>
|
||
#include<ctype.h>
|
||
#include<alloc.h>
|
||
#include<stdlib.h>
|
||
|
||
|
||
#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(unsigned long *Compras_mes);
|
||
void Prepara_Pantalla_GC(void);
|
||
void Lee_Datos(unsigned long *Compras_mes);
|
||
void Muestra_Datos(unsigned long *Compras_mes, int Cod);
|
||
void Calcula_Porcentaje(unsigned long *Compras_mes);
|
||
struct Comp_inx { unsigned int Fin; };
|
||
|
||
|
||
struct Compras {
|
||
struct date Fecha;
|
||
int Ref;
|
||
int Und;
|
||
char Cod;
|
||
};
|
||
|
||
extern struct Compras Comp1;
|
||
extern struct Comp_inx Comp1_inx;
|
||
|
||
|
||
struct boton *PGC;//[7]
|
||
extern struct boton Comunes[9];
|
||
|
||
extern FILE *Comp; // Fichero de Compras
|
||
|
||
extern int CurrRowComp1;
|
||
extern int CurrColComp1;
|
||
extern int CurrTopLineComp;
|
||
|
||
unsigned long TOTAL = 0, TOTAL1 = 0, TOTAL0 = 0;
|
||
|
||
|
||
void Menu_Graficas_de_Compras(int Compras_Ventas);
|
||
/////////////// Voy a readactar el men£ para que la inicializaci¢n se pueda
|
||
/////////////// hacer desde varios puntos, y un mismo m¢dulo sirva para dos
|
||
/////////////// o tres cosas...
|
||
|
||
void Menu_Graficas_de_Compras(int Compras_Ventas) {
|
||
|
||
int finished = 0, bpush;
|
||
unsigned long *Compras_mes;
|
||
|
||
if( ( PGC = (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(PGC);
|
||
return ;
|
||
}
|
||
for(bpush=0; bpush<24; bpush++)
|
||
Compras_mes[bpush]=0;
|
||
|
||
|
||
Prepara_Pantalla_GC();
|
||
if ( Compras_Ventas == 0 )
|
||
Abre_Ficha_Compras();
|
||
Abre_Ficha_Referencias();
|
||
|
||
Carga_Referencias();
|
||
if ( Compras_Ventas == 0 )
|
||
Lee_Datos(Compras_mes);
|
||
else if ( Compras_Ventas == 1 )
|
||
Lee_Datos_Ganancias(Compras_mes);
|
||
else
|
||
Lee_Datos_Ganancias(Compras_mes);
|
||
|
||
Calcula_Porcentaje(Compras_mes);
|
||
Muestra_Datos(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(Compras_mes, 1);
|
||
break;
|
||
// Codigo 0 F3
|
||
case 61:
|
||
Muestra_Datos(Compras_mes, 0);
|
||
break;
|
||
// Codigo 1y0 F4
|
||
case 62:
|
||
Muestra_Datos(Compras_mes, 2);
|
||
break;
|
||
// Imprimir Compras F5
|
||
case 63:
|
||
Imprimir_Gra_Compras(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(Compras_mes);
|
||
break;
|
||
// A¤adir
|
||
case 6:
|
||
break;
|
||
// Borrar
|
||
case 7:
|
||
break;
|
||
// Salir
|
||
case 9:
|
||
finished = 1;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
}while(!finished);
|
||
|
||
if ( Compras_Ventas == 0 ) fclose(Comp); // Fichero Vendedores
|
||
fclose(Ref); // Fichero Vendedores
|
||
if(Memory_ok==1) farfree(Addr); else free(Ref_inx_addr);
|
||
free(PGC); // Libera la memoria
|
||
free(Compras_mes);
|
||
|
||
}
|
||
|
||
|
||
void Lee_Datos(unsigned long *Compras_mes){
|
||
|
||
setcolor(ROJO);
|
||
setfillstyle( SOLID_FILL, ROJO );
|
||
CurrTopLineComp=1;
|
||
for(CurrRowComp1 = 1; CurrRowComp1 <= (Comp1_inx.Fin + 1); CurrRowComp1++){
|
||
|
||
GetLineComp();
|
||
Compras_mes[ (Comp1.Fecha.da_mon - 1)*2 + (Comp1.Cod ? 1 : 0 ) ]
|
||
+= ( Comp1.Cod
|
||
?
|
||
(((Ref1.P_und * Ref1.P1)/100) + Ref1.P_und)
|
||
:
|
||
( Ref1.P_und )
|
||
)*Comp1.Und;
|
||
|
||
bar(152,372, 152 + ( (240*(CurrRowComp1*100)/(Comp1_inx.Fin + 1)) / 100 ), 388);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
void Muestra_Datos(unsigned long *Compras_mes, int Cod){
|
||
|
||
char Buffer[80];
|
||
|
||
setcolor(ROJO);
|
||
|
||
for(int i=0; i<12; i++){
|
||
ImprimeBoton (1, NEGRO, BLANCO, GRIS_O, PGC[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, "%18ld", Compras_mes[i*2 + 1] + Compras_mes[i*2] );
|
||
}
|
||
outtextxy(PGC[i].left+2, PGC[i].up+2, Buffer);
|
||
|
||
}
|
||
|
||
ImprimeBoton (1, NEGRO, BLANCO, GRIS_O, PGC[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(PGC[12].left+2, PGC[12].up+2, Buffer);
|
||
|
||
// bar(152,372, ( 152 + 245 ), 388);
|
||
|
||
}
|
||
|
||
void Calcula_Porcentaje(unsigned long *Compras_mes){
|
||
|
||
char mes[][11] = { " Enero", "Febrero", " Marzo",
|
||
" Abril", " Mayo", " Junio",
|
||
" Julio", "Agosto", "Sept.",
|
||
"Octub.", "Nov.", "Diciemb."
|
||
};
|
||
|
||
/* 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 ];
|
||
}
|
||
|
||
TOTAL = TOTAL1 + TOTAL0 ;
|
||
|
||
setcolor(BLANCO);
|
||
|
||
// sprintf(Buffer, "%46ld", TOTAL1 );
|
||
// outtextxy(PGC[12].left+2, PGC[12].up+2, Buffer);
|
||
|
||
ImprimeBoton (1, NEGRO, BLANCO, GRIS_O, PGC[13]);
|
||
|
||
|
||
|
||
// PGC[13].up = 195; PGC[13].down = 440;
|
||
// PGC[13].left = 5; PGC[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 ]);
|
||
|
||
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(BLANCO);
|
||
outtextxy( (ADD + 45 + (i*35 + 2 + i*5) ) - 15 - 5 - 5 - 1, 380 - 5, mes[i]);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
Fuente(SMALL_FONT, 6);
|
||
}
|
||
|
||
|
||
|
||
void Prepara_Pantalla_GC(void) {
|
||
cleardevice();
|
||
Pantalla_Graficas_Compras(PGC);
|
||
Fuente(SMALL_FONT, 4);
|
||
|
||
// Coloca_Nombres_a_botones();
|
||
|
||
textxy(Comunes[0].left+2, Comunes[0].up, "C¢digos 1" );
|
||
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(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++)
|
||
fprintf( stdprn, "%-10s ->> Cod.1: %10ld Cod.0: %10ld Total: %15ld\n\r", mes[i], Compras_mes[i*2 + 1], Compras_mes[i*2], Compras_mes[i*2 + 1]+Compras_mes[i*2]);
|
||
|
||
fprintf( stdprn, "\n\r");
|
||
fprintf( stdprn, "\n\r");
|
||
fprintf( stdprn, "\n\r");
|
||
fprintf( stdprn, "ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù\n\r");
|
||
fprintf( stdprn, "TOTAL 1: %20ld\n\r", TOTAL1);
|
||
fprintf( stdprn, "TOTAL 0: %20ld\n\r", TOTAL0);
|
||
fprintf( stdprn, "TOTAL : %20ld\n\r", (TOTAL1 + TOTAL0) );
|
||
fprintf( stdprn, "ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù\n\r");
|
||
|
||
fputc(12, stdprn);
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|