511 lines
20 KiB
C++
511 lines
20 KiB
C++
#include <alloc.h>
|
||
#include <conio.h>
|
||
#include <string.h>
|
||
#include <stdlib.h>
|
||
#include <graphics.h>
|
||
|
||
#include "c:\program\src_dos\libs\make_bot\make_bot.h"
|
||
#include "c:\program\src_dos\libs\bdatos\bdatos.hh"
|
||
#include "tpv_def.h"
|
||
|
||
#define NLINEAS_CMPg 7
|
||
|
||
#define NORMAL 0
|
||
#define BARRAS 1
|
||
|
||
extern BDatos BCmp; // Base de datos de Compras
|
||
extern COMPRAS SCmp; // Estructura de referencias
|
||
|
||
// Dia y mes actual para la gestion
|
||
extern char DiaActual, MesActual;
|
||
extern long RegCompras[31 + 2];// Indice para cado uno de los dias del mes + 2
|
||
|
||
extern char EmpresaActual[9]; // Empresa a la que se le realizan las gestiones
|
||
|
||
extern char AjusteCalendario; // Ajuste para los dias del calendario
|
||
extern char DiasMes; // Dias que tiene el mes actual
|
||
|
||
|
||
/*************************************\
|
||
| |
|
||
| Parte Principal del M¢dulo |
|
||
| |
|
||
\*************************************/
|
||
void GraficaCompras( void );
|
||
void GraficaComprasMes( void );
|
||
|
||
extern long SumaGastosCompras( char DiaSuma, char MesSuma );
|
||
|
||
extern unsigned long GastosCompras; // Gastos del dia a evaluar
|
||
|
||
extern unsigned long GastosComprasD[32];
|
||
|
||
extern void ObtenCoordenadasICmp( char columna, char linea, int *X0, int *Y0, int *X1, int *Y1 );
|
||
extern void MuestraICmp( char columna, long linea, char como );
|
||
extern void SeleccionaMesCompras( int NivelAcceso );
|
||
extern void MuestraMesActual( char MesMostrar );
|
||
extern void MuestraAyudaICmp ( char columna );
|
||
extern long PosicionDia( char Dia );
|
||
|
||
void MuestraDatosGCmp( long RowStart );
|
||
|
||
|
||
// ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
|
||
// Û Parte principal del m¢dulo Û
|
||
// ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
|
||
|
||
|
||
/**************************************************************************\
|
||
|* *|
|
||
|* GraficaCompras *|
|
||
|* *|
|
||
|* Descripci¢n: *|
|
||
|* Recorre el mes dado, y nos ofrece una gr fica de las compras*|
|
||
|* *|
|
||
|* Entradas: (ninguna) *|
|
||
|* Salidas: (ninguna) *|
|
||
|* *|
|
||
\**************************************************************************/
|
||
void GraficaCompras( void )
|
||
{
|
||
char ok = 0, i, dia;
|
||
int BPush;
|
||
int CurrRow, CurrCol, oldCol;
|
||
long CurrGCmp;
|
||
|
||
// Actualizasmos el mes y dia actual en curso
|
||
MesActual = FechaGestionActual.da_mon;
|
||
|
||
// Rellenamos la pantalla con un fondo atractivo...
|
||
setfillstyle( Config.FillBgS, Config.FillBgC ); bar( 0, 0, 640, 480 );
|
||
Imprime_Estaticos( 43, "systm\\Tpv.img"); // Imprime botones estaticos 'Seccion 40'
|
||
|
||
// Calculamos los dias que tiene el mes y el ajuste necesario
|
||
CalculaAjusteDias( &AjusteCalendario, &DiasMes, MesActual, FechaGestionActual.da_year );
|
||
// Abre el archivo coreccto y se posiciona en el dia
|
||
// actual de gestion...
|
||
GastosCompras = 0;
|
||
for ( i = 1; i <= DiasMes && i <= 31; i++ )
|
||
{
|
||
GastosComprasD[i] = SumaGastosCompras( i, MesActual );
|
||
GastosCompras += GastosComprasD[i];
|
||
}
|
||
|
||
SeleccionaMesCompras( NINGUNO );
|
||
MuestraDatosGCmp( 0 );
|
||
|
||
CurrRow = 0;
|
||
CurrGCmp = 0;
|
||
CurrCol = 0; oldCol = -1;
|
||
|
||
if ( BCmp.LeeReg( (void *)&SCmp, (CurrGCmp + CurrRow ) ) == ERROR )
|
||
Error(0x01, BCmp.cError );
|
||
|
||
for ( dia = 1; dia < 31; dia++ )
|
||
if ( (CurrGCmp + CurrRow ) >= PosicionDia( dia ) && (CurrGCmp + CurrRow ) < PosicionDia( dia + 1 ) )
|
||
{
|
||
DiaActual = dia /*- 1*/;
|
||
break;
|
||
}
|
||
|
||
// Mostramos el mes Actual
|
||
MuestraMesActual( MesActual );
|
||
GraficaComprasMes();
|
||
|
||
ok = 0;
|
||
do {
|
||
if ( CurrCol != oldCol )
|
||
{
|
||
oldCol = CurrCol; MuestraAyudaICmp ( CurrCol + 5 );
|
||
}
|
||
|
||
MuestraICmp( CurrCol + 5, CurrRow, INTENSO );
|
||
BPush = Comprueba_Secuencia( 2, NULL );
|
||
MuestraICmp( CurrCol + 5, CurrRow, NORMAL );
|
||
|
||
switch ( BPush )
|
||
{
|
||
case 0: // No se pulso ningun BOTON
|
||
while( kbhit() ) getch(); // Limpiamos posibles teclas en BUFFER
|
||
break;
|
||
case -2: // Hay una tecla normal en BUFFER
|
||
while( kbhit() ) getch(); // Limpiamos posibles teclas en BUFFER
|
||
break;
|
||
case -1: // Hay una tecla especial en BUFFER
|
||
switch( getch() )
|
||
{
|
||
// Flecha Izquierda
|
||
case 75:
|
||
case 15:
|
||
CurrCol--;
|
||
if ( CurrCol < 0 ) CurrCol = 4;
|
||
break;
|
||
// Flecha Derecha
|
||
case 77:
|
||
case 9:
|
||
// Solo se permite acceder a Todo cuando el Codigo es 0
|
||
CurrCol++;
|
||
if ( CurrCol > 4 ) CurrCol = 0;
|
||
break;
|
||
// Flecha Arriba
|
||
case 72:
|
||
if ( (CurrRow + CurrGCmp ) > 0 )
|
||
{
|
||
if ( ( CurrRow ) <= 0 )
|
||
{
|
||
CurrRow = NLINEAS_CMPg - 1; CurrGCmp -= NLINEAS_CMPg;
|
||
if ( CurrGCmp < 0 ) CurrGCmp = 0;
|
||
|
||
while( ( CurrRow + CurrGCmp ) >= BCmp.Registros() && CurrRow > 0 ) CurrRow--;
|
||
while( ( CurrRow + CurrGCmp ) >= BCmp.Registros() && CurrGCmp > 0 ) CurrGCmp++;
|
||
|
||
// Mostramos datos hasta que se nos acabe la pantalla
|
||
MuestraDatosGCmp( CurrGCmp );
|
||
} else {
|
||
CurrRow --; if ( CurrRow < 0 ) CurrRow = 0;
|
||
}
|
||
|
||
if ( BCmp.LeeReg( (void *)&SCmp, (CurrGCmp + CurrRow ) ) == ERROR )
|
||
Error(0x01, BCmp.cError );
|
||
// GraficaComprasMes();
|
||
for ( dia = 1; dia < 31; dia++ )
|
||
if ( (CurrGCmp + CurrRow ) >= PosicionDia( dia ) && (CurrGCmp + CurrRow ) < PosicionDia( dia + 1 ) )
|
||
{
|
||
DiaActual = dia /*- 1*/;
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
// Flecha Abajo
|
||
case 80:
|
||
if ( ( CurrRow + CurrGCmp ) < ( BCmp.Registros() - 1 ) )
|
||
{
|
||
if ( ( CurrRow ) >= NLINEAS_CMPg - 1 )
|
||
{
|
||
CurrRow = 0; CurrGCmp += NLINEAS_CMPg;
|
||
|
||
while ( (CurrGCmp + CurrRow) >= BCmp.Registros() ) CurrGCmp--;
|
||
|
||
// Mostramos datos hasta que se nos acabe la pantalla
|
||
MuestraDatosGCmp( CurrGCmp );
|
||
} else
|
||
CurrRow++;
|
||
}
|
||
|
||
if ( BCmp.LeeReg( (void *)&SCmp, (CurrGCmp + CurrRow ) ) == ERROR )
|
||
Error(0x01, BCmp.cError );
|
||
// GraficaComprasMes();
|
||
for ( dia = 1; dia < 31; dia++ )
|
||
if ( (CurrGCmp + CurrRow ) >= PosicionDia( dia ) && (CurrGCmp + CurrRow ) < PosicionDia( dia + 1 ) )
|
||
{
|
||
DiaActual = dia /*- 1*/;
|
||
break;
|
||
}
|
||
|
||
break;
|
||
// Inicio
|
||
case 71:
|
||
CurrRow = 0;
|
||
if ( CurrGCmp != 0 )
|
||
{
|
||
CurrGCmp = 0;
|
||
|
||
// Mostramos datos hasta que se nos acabe la pantalla
|
||
MuestraDatosGCmp( CurrGCmp );
|
||
}
|
||
|
||
if ( BCmp.LeeReg( (void *)&SCmp, (CurrGCmp + CurrRow ) ) == ERROR )
|
||
Error(0x01, BCmp.cError );
|
||
|
||
for ( dia = 1; dia < 31; dia++ )
|
||
if ( (CurrGCmp + CurrRow ) >= PosicionDia( dia ) && (CurrGCmp + CurrRow ) < PosicionDia( dia + 1 ) )
|
||
{
|
||
DiaActual = dia /*- 1*/;
|
||
break;
|
||
}
|
||
// GraficaComprasMes();
|
||
break;
|
||
// Fin
|
||
case 79:
|
||
CurrRow = 0;
|
||
if ( CurrGCmp != BCmp.Registros() - NLINEAS_CMPg )
|
||
{
|
||
CurrGCmp = BCmp.Registros() - NLINEAS_CMPg;
|
||
if ( CurrGCmp < 0 )
|
||
{
|
||
CurrGCmp = 0;
|
||
CurrRow = BCmp.Registros()-1;
|
||
}
|
||
// Mostramos datos hasta que se nos acabe la pantalla
|
||
MuestraDatosGCmp( CurrGCmp );
|
||
}
|
||
|
||
if ( BCmp.LeeReg( (void *)&SCmp, (CurrGCmp + CurrRow ) ) == ERROR )
|
||
Error(0x01, BCmp.cError );
|
||
// GraficaComprasMes();
|
||
for ( dia = 1; dia < 31; dia++ )
|
||
if ( (CurrGCmp + CurrRow ) >= PosicionDia( dia ) && (CurrGCmp + CurrRow ) < PosicionDia( dia + 1 ) )
|
||
{
|
||
DiaActual = dia /*- 1*/;
|
||
break;
|
||
}
|
||
break;
|
||
}
|
||
break;
|
||
// Imprimir Compras
|
||
case 1:
|
||
break;
|
||
// Menu Principal
|
||
case 2:
|
||
ok = 1;
|
||
break;
|
||
#ifndef DEMOSTRACION
|
||
// Mes Anterior
|
||
case 3:
|
||
MesActual --; if ( MesActual < 1 ) MesActual = 1;
|
||
// Abre el archivo coreccto y se posiciona en el dia
|
||
// actual de gestion...
|
||
BCmp.CerrarReg();
|
||
GastosCompras = 0;
|
||
for ( i = 1; i <= DiasMes && i <= 31; i++ )
|
||
{
|
||
GastosComprasD[i] = SumaGastosCompras( i, MesActual );
|
||
GastosCompras += GastosComprasD[i];
|
||
}
|
||
SeleccionaMesCompras( NINGUNO );
|
||
|
||
// Mostramos el mes Actual
|
||
MuestraMesActual( MesActual );
|
||
|
||
CurrGCmp = CurrRow = 0;
|
||
// Mostramos datos hasta que se nos acabe la pantalla
|
||
MuestraDatosGCmp( CurrGCmp );
|
||
|
||
// Leemos el registro sobre el que estamos posicionados
|
||
if ( BCmp.LeeReg( (void *)&SCmp, CurrRow + CurrGCmp ) == ERROR )
|
||
Error(0x01, BCmp.cError );
|
||
for ( dia = 1; dia < 31; dia++ )
|
||
if ( (CurrGCmp + CurrRow ) >= PosicionDia( dia ) && (CurrGCmp + CurrRow ) < PosicionDia( dia + 1 ) )
|
||
{
|
||
DiaActual = dia /*- 1*/;
|
||
break;
|
||
}
|
||
GraficaComprasMes();
|
||
break;
|
||
// Mes Siguiente
|
||
case 4:
|
||
MesActual ++; if ( MesActual > 12 ) MesActual = 12;
|
||
// Abre el archivo coreccto y se posiciona en el dia
|
||
// actual de gestion...
|
||
|
||
BCmp.CerrarReg();
|
||
GastosCompras = 0;
|
||
for ( i = 1; i <= DiasMes && i <= 31; i++ )
|
||
{
|
||
GastosComprasD[i] = SumaGastosCompras( i, MesActual );
|
||
GastosCompras += GastosComprasD[i];
|
||
}
|
||
SeleccionaMesCompras( NINGUNO );
|
||
|
||
// Mostramos el mes Actual
|
||
MuestraMesActual( MesActual );
|
||
|
||
CurrGCmp = CurrRow = 0;
|
||
// PosicionDia( DiaActual
|
||
// Mostramos datos hasta que se nos acabe la pantalla
|
||
MuestraDatosGCmp( CurrGCmp );
|
||
|
||
// Leemos el registro sobre el que estamos posicionados
|
||
if ( BCmp.LeeReg( (void *)&SCmp, CurrRow + CurrGCmp ) == ERROR )
|
||
Error(0x01, BCmp.cError );
|
||
GraficaComprasMes();
|
||
for ( dia = 1; dia < 31; dia++ )
|
||
if ( (CurrGCmp + CurrRow ) >= PosicionDia( dia ) && (CurrGCmp + CurrRow ) < PosicionDia( dia + 1 ) )
|
||
{
|
||
DiaActual = dia - 1;
|
||
break;
|
||
}
|
||
break;
|
||
#else
|
||
// Retroceder//Avanzar mes
|
||
case 3:
|
||
case 4:
|
||
Optar( 0, "VERSION DEMOSTRACION", "En esta versi¢n no se", "permiten m¢dificar la clave.", NULL );
|
||
break;
|
||
#endif
|
||
|
||
// Retroceso R pido
|
||
case 5:
|
||
#ifndef DEMOSTRACION
|
||
CurrRow = NLINEAS_CMPg - 1; CurrGCmp -= NLINEAS_CMPg;
|
||
if ( CurrGCmp < 0 ) CurrGCmp = 0;
|
||
|
||
while( ( CurrRow + CurrGCmp ) >= BCmp.Registros() && CurrRow > 0 ) CurrRow--;
|
||
while( ( CurrRow + CurrGCmp ) >= BCmp.Registros() && CurrGCmp > 0 ) CurrGCmp++;
|
||
|
||
// Mostramos datos hasta que se nos acabe la pantalla
|
||
MuestraDatosGCmp( CurrGCmp );
|
||
// Leemos el registro sobre el que estamos posicionados
|
||
if ( BCmp.LeeReg( (void *)&SCmp, CurrRow + CurrGCmp ) == ERROR )
|
||
Error(0x01, BCmp.cError );
|
||
// GraficaComprasMes();
|
||
for ( dia = 1; dia < 31; dia++ )
|
||
if ( (CurrGCmp + CurrRow ) >= PosicionDia( dia ) && (CurrGCmp + CurrRow ) < PosicionDia( dia + 1 ) )
|
||
{
|
||
DiaActual = dia - 1;
|
||
break;
|
||
}
|
||
#endif
|
||
break;
|
||
// P gina principal de la compra
|
||
case 6:
|
||
// MuestraDatosGCmp( NUEVA_BUSQUEDA );
|
||
break;
|
||
// Cambiar el mes a observar
|
||
case 7:
|
||
break;
|
||
// Siguiente p guina de compras
|
||
case 8:
|
||
// MuestraDatosGCmp( ADELANTE );
|
||
break;
|
||
// AvanceR pido
|
||
case 9:
|
||
#ifndef DEMOSTRACION
|
||
CurrRow = 0; CurrGCmp += NLINEAS_CMPg;
|
||
|
||
while ( (CurrGCmp + CurrRow) >= BCmp.Registros() ) CurrGCmp--;
|
||
|
||
// Mostramos datos hasta que se nos acabe la pantalla
|
||
MuestraDatosGCmp( CurrGCmp );
|
||
// Leemos el registro sobre el que estamos posicionados
|
||
if ( BCmp.LeeReg( (void *)&SCmp, CurrRow + CurrGCmp ) == ERROR )
|
||
Error(0x01, BCmp.cError );
|
||
// GraficaComprasMes();
|
||
for ( dia = 1; dia < 31; dia++ )
|
||
if ( (CurrGCmp + CurrRow ) >= PosicionDia( dia ) && (CurrGCmp + CurrRow ) < PosicionDia( dia + 1 ) )
|
||
{
|
||
DiaActual = dia - 1;
|
||
break;
|
||
}
|
||
#endif
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
} while( !ok );
|
||
|
||
|
||
BCmp.CerrarReg();
|
||
|
||
}
|
||
|
||
|
||
|
||
/**************************************************************************\
|
||
|* *|
|
||
|* GraficaComprasMes *|
|
||
|* *|
|
||
|* Descripci¢n: *|
|
||
|* Muestra el porcentaje de compras por mesese *|
|
||
|* *|
|
||
|* Entradas: (ninguna) *|
|
||
|* Salidas: (ninguna) *|
|
||
|* *|
|
||
\**************************************************************************/
|
||
void GraficaComprasMes( void )
|
||
{
|
||
char Mensajes[][12] = { "1", "2", "3", "4", "5", "6", "7", "8", "9","10",
|
||
"11","12","13","14","15","16","17","18","19","20",
|
||
"21","22","23","24","25","26","27","28","29","30",
|
||
"31"
|
||
};
|
||
char buffer[80], buffer1[80];
|
||
int x, y;
|
||
|
||
// Mostramos la grafica
|
||
MuestraGraficas( 10, 15, 380, 95, DiasMes, (long *)GastosComprasD, Mensajes );
|
||
|
||
setfillstyle( SOLID_FILL, Config.TxtBgN );
|
||
bar( 5, 160, 80, 295 ); bar( 86, 160, 210, 295 );
|
||
|
||
bar( 215, 160, 290, 295 ); bar( 296, 160, 420, 295 );
|
||
|
||
bar( 425, 160, 500, 295 ); bar( 506, 160, 635, 295 );
|
||
|
||
settextstyle( SMALL_FONT, HORIZ_DIR, 4 );
|
||
|
||
// Mostramos los datos num‚ricos
|
||
for ( x = 0; x < 3; x++ )
|
||
for ( y = 0; y < 11; y ++ )
|
||
{
|
||
if ( (x*11+y+1) <= DiasMes )
|
||
{
|
||
formatea_long( GastosComprasD[x*11+y+1], buffer1 );
|
||
sprintf( buffer, "%02d-%02d-%04d %20s", (x*11+y+1), MesActual, FechaGestionActual.da_year, buffer1 );
|
||
outtextxy( 11 + x*210, 165 + y*11, buffer );
|
||
}
|
||
}
|
||
|
||
formatea_long( GastosCompras, buffer1 );
|
||
sprintf( buffer, "TOTAL: %20s", buffer1 );
|
||
outtextxy( 11 + 2*210, 165 + 10*11, buffer );
|
||
|
||
|
||
}
|
||
|
||
/**************************************************************************\
|
||
|* *|
|
||
|* MuestraDatosGCmp *|
|
||
|* *|
|
||
|* Descripci¢n: *|
|
||
|* Dado un registro, se muestran sucesivamente este y todos *|
|
||
|* los que hay por debajo de ‚l, hasta que se agote la base *|
|
||
|* o no quepan mas en la pantalla. *|
|
||
|* *|
|
||
|* Entradas: Registro por el que comenzar *|
|
||
|* Salidas: (ninguna) *|
|
||
|* *|
|
||
\**************************************************************************/
|
||
void MuestraDatosGCmp( long RowStart )
|
||
{
|
||
int linea, campo;
|
||
char dev, dia;
|
||
int X0, Y0, X1, Y1;
|
||
|
||
settextstyle( SMALL_FONT, HORIZ_DIR, 5 );
|
||
|
||
// Imprimo la NLINEAS_PROVcmp que caben en la pantalla
|
||
dev = OK;
|
||
for ( linea=0; linea < NLINEAS_CMPg && dev == OK; linea++ )
|
||
{
|
||
dev = BCmp.LeeReg( (void *)&SCmp, RowStart + linea );
|
||
if ( dev == OK )
|
||
{
|
||
for ( dia = 1; dia < 31; dia++ )
|
||
if ( (RowStart + linea) >= PosicionDia( dia ) && (RowStart + linea) < PosicionDia( dia + 1 ) )
|
||
{
|
||
DiaActual = dia/* - 1*/;
|
||
break;
|
||
}
|
||
// Por cada linea hay 5 campos, ehhh!!!
|
||
for ( campo=0; campo < 5; campo++ )
|
||
MuestraICmp( campo + 5, linea, NORMAL );
|
||
}
|
||
}
|
||
|
||
// Ahora limpio los restantes huecos si los hay
|
||
if ( dev != OK ) linea--;
|
||
|
||
if ( linea < NLINEAS_CMPg )
|
||
{
|
||
setfillstyle( SOLID_FILL, Config.TxtBgN );
|
||
for ( ; linea < NLINEAS_CMPg; linea++ )
|
||
for ( campo=0; campo < 5; campo++ )
|
||
{
|
||
ObtenCoordenadasICmp( campo + 5, linea, &X0, &Y0, &X1, &Y1 );
|
||
bar( X0, Y0, X1, Y1 );
|
||
}
|
||
}
|
||
}
|