Files
SV/SV_COMP.CPP
2021-09-08 21:43:28 +02:00

1138 lines
30 KiB
C++
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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 int InputCadenaG(char *s, int numalp, int lmax, int cc, int cf, struct boton Campo);
extern int InputCadenaG_l(char *s, int numalp, int lmax, int cc, int cf, struct boton Campo, int Row);
void Menu_de_Compras(void);
void Mueve_Arriba_Comp(void);
void Mueve_Abajo_Comp(void);
void EditCursorComp(int ShowHide);
void PrintLineComp(void);
void PrintWholeScreenComp(void);
void Edit_Item_Comp(void);
void Abre_Ficha_Compras(void);
void DeleteRecordComp(void);
void AddRecordComp(void);
void PutLineComp(void);
void GetLineComp(void);
void Current_Struct_to_Zero_Compras(void);
extern void Coloca_Nombres_a_botones(void);
void Imprimir_Compras(int desde, int hasta, int codigos);
void Imprimir_Compras_Menu(void);
// void Llena_con_Comp_basicas(void);
void CompruebaLineasComp(void);
// extern int Confirma(char *f1, char *f2, char *f3);
extern int Comprueba_Impresora(void);
extern void Abre_Ficha_Stock(void);
struct Comp_inx { unsigned int Fin; };
struct Compras {
struct date Fecha;
int Ref;
int Und;
char Cod;
};
struct Compras Comp1;
struct Comp_inx Comp1_inx;
struct boton *PC;//[7]
extern struct boton Comunes[9];
FILE *Comp; // Fichero de Compras
extern FILE *Stock; // Fichero de Stock
int CurrRowComp1;
int CurrColComp1;
int CurrTopLineComp;
void Menu_de_Compras(void) {
int finished = 0, key, bpush;
CurrRowComp1 = 1; CurrColComp1 = 1;
CurrTopLineComp = 1;
//ÛÛÛÛÛÛÛ inicializa_raton_grafico(0, 0, 624, 464, 320, 240);
//ÛÛÛÛÛÛÛ if(raton!=0) desactiva_raton();
if( ( PC = (struct boton *) malloc( sizeof(struct boton)*7 ) ) == NULL )
{
Confirma("Memoria insuficiente", "para crear tablas de", "posisi¢n PC.");
return ;
}
cleardevice();
Dibuja_Pantalla_Compras(PC);
Fuente(SMALL_FONT, 5);
Coloca_Nombres_a_botones();
setcolor(GRIS_C);
outtextxy(Comunes[3].left, Comunes[3].up, " SWAP" );
outtextxy(Comunes[3].left, Comunes[3].up+18, " F6 " );
Fuente(SMALL_FONT, 6);
Abre_Ficha_Compras();
Abre_Ficha_Referencias();
Abre_Ficha_Stock();
Carga_Referencias();
// Realiza el c lculo para situarse en el £ltimo registro \\
// ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß \\
CurrTopLineComp = Comp1_inx.Fin-2;
// if(CurrTopLineComp + CurrRowComp1 - 2 >= Comp1_inx.Fin ) CurrRowComp1 = 1;
if ( CurrTopLineComp < 1 ){ CurrTopLineComp = 1; CurrRowComp1 = 1; }
CurrRowComp1 = 26;
while( (CurrTopLineComp + CurrRowComp1 - 1) != ( Comp1_inx.Fin + 1 ) ) CurrRowComp1--;
//ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß
PrintWholeScreenComp();
GetLineComp();
int oldCR1=0, oldCC1=0;
do{
if(oldCR1!=CurrRowComp1 || oldCC1!=CurrColComp1 )
EditCursorComp(0);
oldCR1 = CurrRowComp1; oldCC1 = CurrColComp1;
if(raton!=0) activa_raton();
Espera_Tecla_o_Raton();
if(raton!=0) desactiva_raton();
if(kbhit()){
EditCursorComp(1);
key = getch();
if( isprint(key) || isspace(key) ) {
EditCursorComp(0);
if(key!=13) ungetch(key);
Edit_Item_Comp();
EditCursorComp(0);
} else if( key == 0 ) {
switch( (key=getch()) ){
// Flecha Arriba
case 72:
Mueve_Arriba_Comp();
break;
// Flecha Izquierda
case 75:
case 15:
CurrColComp1--;
if ( CurrColComp1<1 ) CurrColComp1=4;
break;
// Flecha Derecha
case 77:
case 9:
CurrColComp1++;
if ( CurrColComp1>4 ) CurrColComp1=1;
break;
// Flecha Abajo
case 80:
Mueve_Abajo_Comp();
break;
// Buscar F2
case 60:
// BuscarComp();
break;
// Imprimir Compras F5
case 63:
Imprimir_Compras_Menu();
Fuente(SMALL_FONT, 6);
break;
// F9 --> A¥ADIR
case 67:
AddRecordComp();
break;
// F10 -> BORRAR
case 68:
if( Confirma("Desea eliminar la", "Compra Actual", "") ) DeleteRecordComp();
break;
// INICIO
case 71:
CurrColComp1 = 1;
break;
// FIN
case 79:
CurrColComp1 = 4;
break;
// ReP g
case 73:
// CurrRow = 1;
if( CurrTopLineComp > /*28*/26 ) { CurrTopLineComp -= /*28*/26; } else { CurrTopLineComp = 1; }
if( CurrTopLineComp < 1 ) { CurrTopLineComp = 1; }
PrintWholeScreenComp();
GetLineComp();
EditCursorComp(0);
break;
// AvP g
case 81:
// CurrRow = 1;
CurrTopLineComp += /*28*/26;
if ( (CurrTopLineComp+CurrRowComp1) > Comp1_inx.Fin) { CurrTopLineComp = Comp1_inx.Fin; CurrRowComp1 = 1; }
if (CurrTopLineComp==0) CurrTopLineComp = 1;
PrintWholeScreenComp();
GetLineComp();
EditCursorComp(0);
break;
// Salir F1
case 59:
finished = 1;
break;
default:
break;
}
EditCursorComp(0);
}
} else if(raton!=0 && ( boton_izq==1 || boton_der==1 ) )
if( (bpush = CheckButon( 9, Comunes))>0 ) {
EditCursorComp(1);
switch(bpush){
// Flecha Arriba
case 1:
Mueve_Arriba_Comp();
break;
// Buscar
case 2:
// BuscarVend();
break;
// Flecha Abajo
case 3:
Mueve_Abajo_Comp();
break;
case 4:
break;
// Imprimir
case 5:
Imprimir_Compras_Menu();
Fuente(SMALL_FONT, 6);
break;
// A¤adir
case 6:
AddRecordComp();
break;
// Borrar
case 7:
if( Confirma("Desea eliminar la", "Compra Actual", "") ) DeleteRecordComp();
break;
// Salir
case 9:
finished = 1;
break;
default:
break;
}
EditCursorComp(0);
} else CompruebaLineasComp();
}while(!finished);
fclose(Comp); // Fichero Vendedores
fclose(Ref); // Fichero Vendedores
fclose(Stock); // Fichero Vendedores
if(Memory_ok==1) farfree(Addr); else free(Ref_inx_addr);
free(PC); // Libera la memoria
}
void Mueve_Abajo_Comp(void){
int CurrRecord = CurrTopLineComp + CurrRowComp1 - 1;
if (CurrRowComp1==/*28*/26) {
if ( (CurrRecord - 1) >= Comp1_inx.Fin) { BEEP(); EditCursorComp(0); }
else {
///////////
/*///////*/
/*///////*/ CurrRowComp1 = 1;
/*///////*/ CurrTopLineComp += /*28*/26;
/*///////*/ if ( (CurrTopLineComp+CurrRowComp1) > Comp1_inx.Fin) { CurrTopLineComp = Comp1_inx.Fin; CurrRowComp1 = 1; }
/*///////*/ if (CurrTopLineComp==0) CurrTopLineComp = 1;
/*///////*/ PrintWholeScreenComp();
/*///////*/ GetLineComp();
/*///////*/ EditCursorComp(0);
/////////// CurrTopLineComp++;
/////////// PrintWholeScreenComp();
//ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß
//ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß
//ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß
/////////// GetLineComp();
// PrintLineComp();
}
} else {
if( (CurrRecord - 1) >= Comp1_inx.Fin) { BEEP(); EditCursorComp(0); }
else { CurrRowComp1++;
GetLineComp();
// PrintLineComp();
}
}
}
void Mueve_Arriba_Comp(void){
int CurrRecord = CurrTopLineComp + CurrRowComp1 - 1;
if (CurrRowComp1==1) {
if ((CurrRecord - 1) <= 0) { BEEP(); EditCursorComp(0); }
else {
////////////
/*////////*/
/*////////*/ if( CurrTopLineComp > /*28*/26 ) { CurrTopLineComp -= /*28*/26; } else { CurrTopLineComp = 1; }
/*////////*/ if( CurrTopLineComp < 1 ) { CurrTopLineComp = 1; }
/*////////*/
/*////////*/ CurrRowComp1 = 26;
/*////////*/ while(CurrTopLineComp + CurrRowComp1 - 2 >= Comp1_inx.Fin ) CurrRowComp1--;
/*////////*/ PrintWholeScreenComp();
/*////////*/
/*////////*/ GetLineComp();
/*////////*/ EditCursorComp(0);
//////////// CurrTopLineComp--;
//////////// PrintWholeScreenComp();
//ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß
//ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß
//ÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜßÜß
//////////// GetLineComp();
// PrintLineComp();
}
} else {
if( (CurrRecord - 1) <= 0) BEEP();
else { CurrRowComp1--;
GetLineComp();
// PrintLineComp();
}
}
}
void EditCursorComp(int ShowHide) {
char Buffer[80];
setcolor(GRIS_C);
setfillstyle(SOLID_FILL, GRIS_C);
bar(10, 455, 545, 473);
int bar_p;
switch(CurrColComp1){
case 1:
bar_p=0;
break;
case 2:
bar_p=1;
break;
case 3:
bar_p=3;
break;
case 4:
bar_p=4;
break;
}
if (!ShowHide) {
setcolor(63);
setfillstyle(SOLID_FILL, 63); //Û// //Û// //Û// //Û//
bar((PC[bar_p].left+2), PC[bar_p].up+4+(CurrRowComp1-1)*/*9*//*14*/15+2, PC[bar_p].right-2, PC[bar_p].up+/*3*/4+((CurrRowComp1)-1)*/*9*//*14*/15+/*9*/16);
setcolor(0);
} else {
setcolor(0);
setfillstyle(SOLID_FILL, 0); //Û// //Û// //Û// //Û//
bar((PC[bar_p].left+2), PC[bar_p].up+4+(CurrRowComp1-1)*/*9*//*14*/15+2, PC[bar_p].right-2, PC[bar_p].up+/*3*/4+((CurrRowComp1)-1)*/*9*//*14*/15+/*9*/16);
Texto_Normal
}
if(Ref_no_valid) setcolor(ROJO);
switch(CurrColComp1){
case 1:
int day, mon;
day= Comp1.Fecha.da_day;
mon= Comp1.Fecha.da_mon;
sprintf(Buffer, "%02d/%02d/%02d", day, mon, Comp1.Fecha.da_year );
outtextxy( PC[0].left+2, (PC[0].up+2)+(CurrRowComp1-1)*/*9*//*14*/15, Buffer );
outtextxy( 15, 455, "Fecha de Compra. . 4 digitos m ximo.");
break;
case 2:
sprintf(Buffer, "%04d", Comp1.Ref); // 4
outtextxy( PC[1].left+2, (PC[1].up+2)+(CurrRowComp1-1)*/*9*//*14*/15, Buffer);
outtextxy( 15, 455, "Referencia de Compra. 20 digitos m ximo.");
break;
case 3:
sprintf(Buffer, "%4d", Comp1.Und); // 4
outtextxy( PC[3].left+2, (PC[3].up+2)+(CurrRowComp1-1)*/*9*//*14*/15, Buffer );
outtextxy( 15, 455, "Unidades Compradas. 5 digitos m ximo.");
break;
case 4:
int num = Comp1.Cod;
sprintf(Buffer, "%1d", num); // 4
outtextxy( PC[4].left+2, (PC[4].up+2)+(CurrRowComp1-1)*/*9*//*14*/15, Buffer );
outtextxy( 15, 455, "C¢digo de Registro. 1 digito m ximo.");
break;
}
}
void PrintLineComp(void){
char Buffer[80];
long total;
setcolor(0);
setfillstyle(SOLID_FILL, 0); //Û// //Û// //Û// //Û//
bar((PC[2].left+2), PC[2].up+4+(CurrRowComp1-1)*/*9*//*14*/15+2, PC[2].right-2, PC[2].up+/*3*/4+((CurrRowComp1)-1)*/*9*//*14*/15+/*9*/16);
bar((PC[4].left+2), PC[4].up+4+(CurrRowComp1-1)*/*9*//*14*/15+2, PC[4].right-2, PC[4].up+/*3*/4+((CurrRowComp1)-1)*/*9*//*14*/15+/*9*/16);
bar((PC[5].left+2), PC[5].up+4+(CurrRowComp1-1)*/*9*//*14*/15+2, PC[5].right-2, PC[5].up+/*3*/4+((CurrRowComp1)-1)*/*9*//*14*/15+/*9*/16);
bar((PC[6].left+2), PC[6].up+4+(CurrRowComp1-1)*/*9*//*14*/15+2, PC[6].right-2, PC[6].up+/*3*/4+((CurrRowComp1)-1)*/*9*//*14*/15+/*9*/16);
Texto_Normal
if(Ref_no_valid) setcolor(ROJO);
int day, mon;
day= Comp1.Fecha.da_day;
mon= Comp1.Fecha.da_mon;
sprintf(Buffer, "%02d/%02d/%02d", day, mon, Comp1.Fecha.da_year );
outtextxy( PC[0].left+2, (PC[0].up+2)+(CurrRowComp1-1)*/*9*//*14*/15, Buffer );
sprintf(Buffer, "%04d", Comp1.Ref); // 4
outtextxy( PC[1].left+2, (PC[1].up+2)+(CurrRowComp1-1)*/*9*//*14*/15, Buffer);
outtextxy( PC[2].left+2, (PC[2].up+2)+(CurrRowComp1-1)*/*9*//*14*/15,Ref1.Concepto );
sprintf(Buffer, "%4d", Comp1.Und); // 4
outtextxy( PC[3].left+2, (PC[3].up+2)+(CurrRowComp1-1)*/*9*//*14*/15, Buffer );
day = Comp1.Cod;
sprintf(Buffer, "%1d", day); // 1
outtextxy( PC[4].left+2, (PC[4].up+2)+(CurrRowComp1-1)*/*9*//*14*/15, Buffer );
if(day==1)
total = (((Ref1.P_und * Ref1.P1)/100) + Ref1.P_und);
else
total = ( Ref1.P_und );
sprintf(Buffer, "% 7ld", total );
outtextxy( PC[5].left/*+2*/-10, (PC[5].up+2)+(CurrRowComp1-1)*/*9*//*14*/15, Buffer );
sprintf(Buffer, "% 11lu", ( Comp1.Und * total ) );
outtextxy( PC[6].left/*+2*/-19, (PC[6].up+2)+(CurrRowComp1-1)*/*9*//*14*/15,Buffer );
}
void PrintWholeScreenComp(void){
int tmp = CurrRowComp1;
for(int i=0; i<7; i++)
ImprimeBoton (1, NEGRO, GRIS_O, BLANCO, PC[i]);
for(CurrRowComp1 = 1; CurrRowComp1 < (/*28*/26+1); CurrRowComp1++)
if ( (CurrTopLineComp + CurrRowComp1 - 1) <= (Comp1_inx.Fin + 1) ) {
GetLineComp();
PrintLineComp();
}
CurrRowComp1 = tmp;
}
void Edit_Item_Comp(void){
char buffer[80];
long Fecha;
switch (CurrColComp1) {
case 1:
int day, mon;
day= Comp1.Fecha.da_day;
mon= Comp1.Fecha.da_mon;
sprintf(buffer, "%02d%02d%02d", day, mon, Comp1.Fecha.da_year );
do{
InputCadenaG_l( buffer, 1, 6, 63, 57, PC[0], CurrRowComp1-1);
Fecha = atol(buffer);
Comp1.Fecha.da_day = (Fecha/10000);
Comp1.Fecha.da_mon = (Fecha/100) - ((Comp1.Fecha.da_day) * 100);
Comp1.Fecha.da_year = Fecha - ( (Comp1.Fecha.da_day*10000) + (Comp1.Fecha.da_mon*100) );
}while( ( Comp1.Fecha.da_day<1 || Comp1.Fecha.da_day>31 ) || (Comp1.Fecha.da_mon<1 || Comp1.Fecha.da_mon > 12) || strlen(buffer)!=6 );
PutLineComp();
break;
case 2: int old_ref = Comp1.Ref;
sprintf( buffer, "%d", Comp1.Ref);
InputCadenaG_l( buffer, 1, 4, 63, 57, PC[1], CurrRowComp1-1);
Comp1.Ref = atoi(buffer);
PutLineComp();
/*ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ*/
/*Û*/ GetLineComp(); /*Û*/
/*ßßßßßßßßßßßßßßßßßßßßßß*/
if(old_ref != Comp1.Ref) {
/*if(!Ref_no_valid)*/ Actualizar_Stock( old_ref, (Comp1.Und)*(-1), Comp1.Cod);
/*if(!Ref_no_valid)*/ Actualizar_Stock( Comp1.Ref, Comp1.Und, Comp1.Cod);
}
break;
case 3: int old_und = Comp1.Und;
sprintf( buffer, "%d", Comp1.Und);
InputCadenaG_l( buffer, 1, 4, 63, 57, PC[3], CurrRowComp1-1);
Comp1.Und = atol(buffer);
PutLineComp();
if(old_und != Comp1.Und)
Actualizar_Stock( Comp1.Ref, ((Comp1.Und)-old_und), Comp1.Cod);
break;
case 4: int Cod = Comp1.Cod;
sprintf( buffer, "%d", Cod);
ungetch(8);
InputCadenaG_l( buffer, 1, 1, 63, 57, PC[4], CurrRowComp1-1);
Comp1.Cod = (char)atoi(buffer);
PutLineComp();
if(Cod != atoi(buffer)) {
Actualizar_Stock( Comp1.Ref, (Comp1.Und)*(-1), Cod);
Actualizar_Stock( Comp1.Ref, Comp1.Und, atoi(buffer));
}
break;
default:
return;
}
PrintLineComp();
}
void Abre_Ficha_Compras(void){
char ArchivoDatos[]="SV_Comp.DAT";
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ//
//Û Comprueba apertura correcta de Indice, y Datos y creaci¢n... Û//
//ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß//
int LSJ = sizeof(struct JD);
int LSI = sizeof(struct Comp_inx);
int LSC = sizeof(struct Compras);
if ( (Comp = fopen( ArchivoDatos, "r+b"))==NULL) {
FILE *fa;
if ( (fa = fopen( ArchivoDatos, "wb" ) )!=NULL ) {
Current_Struct_to_Zero_Compras();
Comp1_inx.Fin = 0;
rewind(fa);
fwrite(&cabecera, LSJ, 1, fa); fseek(fa, (long)LSJ, SEEK_SET);
fwrite(&Comp1_inx, LSI, 1, fa); fseek(fa, (long)LSJ+LSI, SEEK_SET);
fwrite(&Comp1, LSC, 1, fa);
if (fclose(fa) == EOF ) exit(1);
}
if ( (Comp = fopen( ArchivoDatos, "r+b"))==NULL) {
restorecrtmode();
printf("NO SE PUDO ABRIR EL FICHERO INDICE EN LA 2§ PASADA");
exit(1);
}
}
fseek(Comp, (long)LSJ, SEEK_SET);
if ( fread(&Comp1_inx, LSI, 1, Comp) != 1 ) {
restorecrtmode();
printf("NO SE PUDO LEER EN EL FICHERO: INDICE");
exit(1);
}
fseek(Comp, (long)LSJ+LSI, SEEK_SET);
if ( fread(&Comp1, LSC, 1, Comp) != 1 ) {
restorecrtmode();
printf("NO SE PUDO LEER EN EL FICHERO: DATOS");
exit(1);
}
}
void DeleteRecordComp(void) {
unsigned int CurrRecord;
int LSJ = sizeof(struct JD);
int LSI = sizeof(struct Comp_inx);
int LSC = sizeof(struct Compras);
CurrRecord = CurrTopLineComp + CurrRowComp1 - 1;
if ( (Comp1_inx.Fin == 0) ) { BEEP();
Actualizar_Stock( Comp1.Ref, (Comp1.Und)*(-1), Comp1.Cod);
Current_Struct_to_Zero_Compras();
fseek(Comp, (long)LSJ + LSI + ( LSC * ( 0 ) ), SEEK_SET); // Se coloca
fwrite(&Comp1, LSC, 1, Comp); // Y escribe
/* ßßßÛ */ PrintWholeScreenComp();
/* ß */ GetLineComp();
EditCursorComp(0);
}else {
Comp1_inx.Fin -= 1;
unsigned int p = CurrRecord - 1;
while( p <= Comp1_inx.Fin ) {
fseek(Comp, (long)LSJ + LSI + ( LSC * ( p + 1 ) ), SEEK_SET); // Se coloca
fread(&Comp1, LSC, 1, Comp); // Y lee
fseek(Comp, (long)LSJ + LSI + ( LSC * p ), SEEK_SET); // Se coloca
fwrite(&Comp1, LSC, 1, Comp); // Y escribe
p++;
};
fseek(Comp, (long)LSJ, SEEK_SET);
fwrite(&Comp1_inx, LSI, 1, Comp); // Acualiza n§ de registros
/* Û */ if ((CurrRecord - 1) == Comp1_inx.Fin + 1) CurrRowComp1--;
/* Û */
/* ßßßÛ */ PrintWholeScreenComp();
/* ß */ GetLineComp();
EditCursorComp(0);
// PrintLineComp();
}
}
void AddRecordComp(void){
unsigned int CurrRecord= CurrTopLineComp + CurrRowComp1 - 1;
int LSJ = sizeof(struct JD);
int LSI = sizeof(struct Comp_inx);
int LSC = sizeof(struct Compras);
if(CurrRecord < 10000 ) {
long avance = Comp1_inx.Fin /*+ 1*/;
while( avance >= (CurrRecord-1) ) {
fseek(Comp, (long)LSJ + LSI + ( LSC * avance ), SEEK_SET); // Se coloca
fread(&Comp1, LSC, 1, Comp); // Y lee
fseek(Comp, (long)LSJ + LSI + ( LSC * (avance + 1) ), SEEK_SET); // Se coloca
fwrite(&Comp1, LSC, 1, Comp); // Y escribe
avance--;
};
// Comp1_inx.Fin = Comp1_inx.Fin + 1;
Comp1_inx.Fin++;
fseek(Comp, (long)LSJ, SEEK_SET);
fwrite(&Comp1_inx, LSI, 1, Comp); // Acualiza n§ de registros
Current_Struct_to_Zero_Compras();
fseek(Comp, (long)LSJ + LSI + ( LSC * ( CurrTopLineComp + CurrRowComp1 - 1) ), SEEK_SET); // Se coloca
fwrite(&Comp1, LSC, 1, Comp); // Y escribe
CurrRowComp1++;
if (CurrRowComp1>/*28*/26) { CurrTopLineComp++; CurrRowComp1--; }
PrintWholeScreenComp();
GetLineComp();
EditCursorComp(0);
// PrintLineComp();
}
}
void PutLineComp(void){
int LSJ = sizeof(struct JD);
int LSI = sizeof(struct Comp_inx);
int LSC = sizeof(struct Compras);
int CurrRecord = CurrTopLineComp + CurrRowComp1 - 1;
fseek(Comp, (long)LSJ + LSI + ( LSC * CurrRecord ) - LSC, SEEK_SET); // Se coloca
fwrite(&Comp1, LSC, 1, Comp); // Y escribe
}
void GetLineComp(void){
int LSJ = sizeof(struct JD);
int LSI = sizeof(struct Comp_inx);
int LSC = sizeof(struct Compras);
int CurrRecord = CurrTopLineComp + CurrRowComp1 - 1;
fseek(Comp, (long)LSJ + LSI + ( LSC * CurrRecord ) - LSC, SEEK_SET); // Se coloca
fread(&Comp1, LSC, 1, Comp); // Y lee
BuscaReferencia(Comp1.Ref);
}
void Current_Struct_to_Zero_Compras(void){
cabecera.esc = 27; strcpy(cabecera.color, "[31;40m");
strcpy(cabecera.prog, "Jos David Guilln Dominguez");
cabecera.nl = 13; cabecera.rt = 10;
strcpy(cabecera.autor, " 6 / Mayo / 1995 ");
cabecera.pt = 7; cabecera.ef = 26;
getdate( &Comp1.Fecha );
Comp1.Fecha.da_year = Comp1.Fecha.da_year - ( ( Comp1.Fecha.da_year / 100 ) * 100 );
Comp1.Ref=0;
Comp1.Und=0;
Comp1.Cod=1;
}
void Imprimir_Compras_Menu(void){
int Where_Ask = 1;
int fins_print= 0, key_print, bpush;
int Desde, Hasta;
void far *ptr;
unsigned size;
struct boton pregunta[3];
size = imagesize(198, 138, 372, 257);
/* get byte size of image */
if ( (ptr = farmalloc(size)) != NULL) {
getimage(198, 138, 372, 257, ptr);
pregunta[0].up = 140; pregunta[0].down = 255;
pregunta[0].left= 200; pregunta[0].right= 370;
ImprimeBoton (1, ROJO, GRIS_C, BLANCO, pregunta[0]);
pregunta[0].up = 150; pregunta[0].down = 175;
pregunta[0].left= 210; pregunta[0].right= 360;
ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[0]);
pregunta[1].up = 185; pregunta[1].down = 210;
pregunta[1].left= 210; pregunta[1].right= 360;
ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[1]);
pregunta[2].up = 220; pregunta[2].down = 245;
pregunta[2].left= 210; pregunta[2].right= 360;
ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[2]);
Fuente(SMALL_FONT, 4);
} else {
Where_Ask = 0;
pregunta[0].up = 450; pregunta[0].down = 475;
pregunta[0].left= 5; pregunta[0].right= 152;
ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[0]);
pregunta[1].up = 450; pregunta[1].down = 475;
pregunta[1].left= 155; pregunta[1].right= 309;
ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[1]);
pregunta[2].up = 450; pregunta[2].down = 475;
pregunta[2].left= 312; pregunta[2].right= 549;
ImprimeBoton (1, GRIS_C, BLANCO, GRIS_O, pregunta[2]);
Fuente(SMALL_FONT, 4);
}
Letra_Boton
outtextxy(pregunta[0].left+2, pregunta[0].up+2, "F3 Codigos 1");
outtextxy(pregunta[1].left+2, pregunta[1].up+2, "F2 Codigos 0");
outtextxy(pregunta[2].left+2, pregunta[2].up+2, "F1 CANCELAR IMPRESION");
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
do{
if(raton!=0) activa_raton();
Espera_Tecla_o_Raton();
if(raton!=0) desactiva_raton();
if(kbhit()){
key_print = getch();
if( key_print == 0 ) {
switch( (key_print=getch()) ){
// F1 Cancelar
case 59:
fins_print = 1;
break;
// F3 Imprimir Ficha
case 61:
if(Where_Ask){
pregunta[0].up = 140; pregunta[0].down = 255;
pregunta[0].left= 200; pregunta[0].right= 370;
} else {
pregunta[0].up = 450; pregunta[0].down = 475;
pregunta[0].left= 5; pregunta[0].right= 549;
}
ImprimeBoton (1, GRIS_O, GRIS_C, BLANCO, pregunta[0]);
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
if(Comprueba_Impresora()) {
Letra_Boton
if( Desde_Hasta( &Desde, &Hasta) != -1 ) {
if(Where_Ask){ outtextxy(210,150, "Imprimiendo.");
outtextxy(210,170, "Por Favor, espere...");
} else outtextxy(10,452, "Imprimiendo. Por Favor, espere...");
Imprimir_Compras(Desde, Hasta, 1);
}
} else {
Letra_Boton
if(Where_Ask){ outtextxy(210,150, "Impresora no preparada.");
outtextxy(210,170, "Impresion Cancelada");
} else { outtextxy(10,452, "Impresora no preparada. Impresi¢n Cancelada."); }
Espera_Tecla_o_Raton();
}
fins_print = 1;
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
break;
// F2 Imprimir lista r pida
case 60:
if(Where_Ask){
pregunta[0].up = 140; pregunta[0].down = 255;
pregunta[0].left= 200; pregunta[0].right= 370;
} else {
pregunta[0].up = 450; pregunta[0].down = 475;
pregunta[0].left= 5; pregunta[0].right= 549;
}
ImprimeBoton (1, GRIS_O, GRIS_C, BLANCO, pregunta[0]);
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
if(Comprueba_Impresora()) {
Letra_Boton
if( Desde_Hasta( &Desde, &Hasta) != -1 ) {
if(Where_Ask){ outtextxy(210,150, "Imprimiendo.");
outtextxy(210,170, "Por Favor, espere...");
} else outtextxy(10,452, "Imprimiendo. Por Favor, espere...");
Imprimir_Compras(Desde, Hasta, 0);
}
} else {
Letra_Boton
if(Where_Ask){ outtextxy(210,150, "Impresora no preparada.");
outtextxy(210,170, "Impresion Cancelada");
} else { outtextxy(10,452, "Impresora no preparada. Impresi¢n Cancelada."); }
Espera_Tecla_o_Raton();
}
fins_print = 1;
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
break;
default:
fins_print = 1;
}
}
} else
if(raton!=0 && boton_izq==1 || boton_der==1) {
if( (bpush = CheckButon( 3, pregunta))>0 ) {
if(Where_Ask){
pregunta[0].up = 140; pregunta[0].down = 255;
pregunta[0].left= 200; pregunta[0].right= 370;
} else {
pregunta[0].up = 450; pregunta[0].down = 475;
pregunta[0].left= 5; pregunta[0].right= 549;
}
ImprimeBoton (1, GRIS_O, GRIS_C, BLANCO, pregunta[0]);
switch(bpush){
// Imprimir Ficha
case 1:
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
if(Comprueba_Impresora()) {
Letra_Boton
if( Desde_Hasta( &Desde, &Hasta) != -1 ) {
if(Where_Ask){ outtextxy(210,150, "Imprimiendo.");
outtextxy(210,170, "Por Favor, espere...");
} else outtextxy(10,452, "Imprimiendo. Por Favor, espere...");
Imprimir_Compras(Desde, Hasta, 1);
}
} else {
Letra_Boton
if(Where_Ask){ outtextxy(210,150, "Impresora no preparada.");
outtextxy(210,170, "Impresion Cancelada");
} else { outtextxy(10,452, "Impresora no preparada. Impresi¢n Cancelada."); }
Espera_Tecla_o_Raton();
}
fins_print = 1;
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
break;
// Imprime Lista R pida
case 2:
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
if(Comprueba_Impresora()) {
Letra_Boton
if( Desde_Hasta( &Desde, &Hasta) != -1 ) {
if(Where_Ask){ outtextxy(210,150, "Imprimiendo.");
outtextxy(210,170, "Por Favor, espere...");
} else outtextxy(10,452, "Imprimiendo. Por Favor, espere...");
Imprimir_Compras(Desde, Hasta, 0);
}
} else {
Letra_Boton
if(Where_Ask){ outtextxy(210,150, "Impresora no preparada.");
outtextxy(210,170, "Impresion Cancelada");
} else { outtextxy(10,452, "Impresora no preparada. Impresi¢n Cancelada."); }
Espera_Tecla_o_Raton();
}
fins_print = 1;
//ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
break;
// Cancelar
case 3:
fins_print=1;
break;
default:
fins_print = 1;
}
}
}
}while(!fins_print);
//ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
if(Where_Ask == 1) {
putimage(198, 138, ptr, COPY_PUT);
farfree(ptr);
} else {
struct boton help;
help.up = 450; help.down = 475;
help.left = 5; help.right = 549;
ImprimeBoton (1, GRIS_C, GRIS_O, BLANCO, help);
}
Fuente(SMALL_FONT, 5);
}
void Imprimir_Compras(int desde, int hasta, int codigos){
int LSJ = sizeof(struct JD);
int LSI = sizeof(struct Comp_inx);
int LSC = sizeof(struct Compras);
int lprint = 3, day, mon, cod, Curr_Comp = 0;
long total;
float Total_Compras = 0;
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");
fprintf( stdprn, "Informe de compras\n\r");
fprintf( stdprn, " Fecha Ref Concepto Cod Unds. P_Und. TOTAL\n\r");
fprintf( stdprn, "ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù\n\r");
while( (Curr_Comp <= Comp1_inx.Fin) ){
fseek(Comp, (long)LSJ + LSI + ( LSC * Curr_Comp ), SEEK_SET); // Se coloca
fread(&Comp1, LSC, 1, Comp); // Y lee
mon = Comp1.Fecha.da_mon;
if( mon>=desde && mon<=hasta ){
BuscaReferencia(Comp1.Ref);
day= Comp1.Fecha.da_day;
cod = Comp1.Cod;
if(cod==1)
total = ( ((Ref1.P_und * Ref1.P1)/100) + Ref1.P_und );
else
total = ( Ref1.P_und );
if(codigos==2) {
fprintf( stdprn, "%02d/%02d%02d", day, mon, Comp1.Fecha.da_year );
fprintf( stdprn, " % 4d %-20s % 1d % 4d % 7ld % 11lu\n\r",
Comp1.Ref, Ref1.Concepto, cod, Comp1.Und, total, ( Comp1.Und * total ) );
Total_Compras += ( Comp1.Und * total );
}
if(codigos==1 && cod==1) {
fprintf( stdprn, "%02d/%02d/%02d", day, mon, Comp1.Fecha.da_year );
fprintf( stdprn, " % 4d %-20s %1d % 4d % 7ld % 11lu\n\r",
Comp1.Ref, Ref1.Concepto, cod, Comp1.Und, total, ( Comp1.Und * total ) );
Total_Compras += ( Comp1.Und * total );
}
if(codigos==0 && cod==0) {
fprintf( stdprn, "%02d/%02d/%02d", day, mon, Comp1.Fecha.da_year );
fprintf( stdprn, " % 4d %-20s %1d % 4d % 7ld % 11lu\n\r",
Comp1.Ref, Ref1.Concepto, cod, Comp1.Und, total, ( Comp1.Und * total ) );
Total_Compras += ( Comp1.Und * total );
}
lprint++;
if (lprint==55) { lprint = 3;
fputc(12, stdprn);
fprintf( stdprn, " Fecha Ref Concepto Cod Unds. P_Und. TOTAL\n\r");
fprintf( stdprn, "ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù\n\r");
}
}
Curr_Comp++;
}
fprintf( stdprn, "\n\r");
fprintf( stdprn, "\n\r");
fprintf( stdprn, "ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù\n\r");
fprintf( stdprn, " Total de las compras entre los meses %s a %s\n\r", mes[desde-1], mes[hasta-1]);
fprintf( stdprn, "ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù\n\r");
fprintf( stdprn, "--------------> %e <--------------\n\r", Total_Compras);
fputc(12, stdprn);
}
void CompruebaLineasComp(void){
// Check una pulsacion sobre un campo, y se situa, si es posible
int ok_p=0, inc=0, md=0;
int oldr, oldc;
// Anclar_Raton();
do{
inc++;
if(x_raton >= (PC[(inc)-1].left+2) && x_raton <= (PC[inc-1].right-2) ) { ok_p=1; md = 1;
oldc=inc; }
if(inc==5) ok_p=1;
}while(!ok_p);
if(md==1){
inc=0; ok_p=0; md = 0;
do{
inc++;
if( (y_raton >= (PC[(oldc)-1].up+4+(inc-1)*15+2)) && (y_raton <= (PC[oldc-1].up+4+(inc-1)*15+16)) ) { ok_p=1; oldr=inc; md = 1;}
if(inc==26) ok_p=1;
}while(!ok_p);
}
int newc;
switch(oldc){
case 1:
case 2: newc = oldc; break;
case 4:
case 5: newc = (oldc - 1); break;
default:
break;
}
if( (md==1) && ((CurrColComp1!=newc) || (CurrRowComp1!=oldr)) )
{
if( (CurrTopLineComp + oldr - 2 )<= Comp1_inx.Fin ){
EditCursorComp(1);
switch(oldc){
case 1:
case 2:
CurrColComp1 = oldc;
CurrRowComp1 = oldr;
break;
case 4:
case 5:
CurrColComp1 = (oldc-1);
CurrRowComp1 = oldr;
break;
default:
EditCursorComp(0);
break;
}
GetLineComp();
}
}
}