#include #include #include #include #include #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_REF 15 extern BDatos BRef; // Base de datos de Referencias extern INFO_PRODUCTOS SRef; // Estructura de referencias // Empresa a la que se le realizan las gestiones extern char EmpresaActual[9]; /*************************************\ | | | Parte Principal del M¢dulo | | | \*************************************/ void MuestraDatosRef2( long RowStart ); void MuestraAyudaRef2( char columna ); void MuestraRef2( char columna, int linea, char como ); void ObtenCoordenadasRef2( char columna, char linea, int *X0, int *Y0, int *X1, int *Y1 ); /*************************************\ | | | Parte Secundaria del M¢dulo | | | | Secci¢n de Busqueda de Productos | | | \*************************************/ extern void ObtenCoordenadasMatch( char Row, int *X0, int *Y0, int *X1, int *Y1 ); extern int BuscaRef( char TipoBusqueda, char *CurrRow, long *CurrRef ); extern void MatchDrawRef( char Row, INFO_PRODUCTOS MRef, char como ); extern int Match_Ref( INFO_PRODUCTOS A, INFO_PRODUCTOS B ); extern void EditMatchRef( char Row, INFO_PRODUCTOS * MRef ); extern int ObtenMatchRef( INFO_PRODUCTOS *MRef ); /*************************************\ | | | Parte Tercera del M¢dulo | | | | Secci¢n para la impresi¢n | | | \*************************************/ void ImprimeStockActual(); int MuestraOrdenaciones( void ); int Ordenar( const void *A, const void *B ); char TIPO_ORDENACION; // ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß // Û Parte principal del m¢dulo Û // ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ /**************************************************************************\ |* *| |* InfoProducto *| |* *| |* Descripci¢n: *| |* Controla la introduccion de datos y muestreo asi como todo *| |* el interfaz de usuario... *| |* *| |* Entradas: (ninguna) *| |* Salidas: (ninguna) *| |* *| \**************************************************************************/ void InfoStock(void) { char buffer[100], ok = 0; char buffer1[40]; int BPush; char oldCol = -1; char CurrRow; // Linea sobre la que estamos char CurrCol; // Columna sobre la que estamos long CurrRef; // Producto sobre el que estamos posicionados a golpes unsigned long BenefTt,// Beneficio total ( de todos los productos ) -1- CostoTt,// Costo total -2- TtBruto;// Total bruto -3- char SumaMostrar = 1;// ----------- Suma a mostrar, de las anteriores. // Rellenamos la pantalla con un fondo atractivo... setfillstyle( Config.FillBgS, Config.FillBgC ); bar( 0, 0, 640, 480 ); Imprime_Estaticos( 23, "systm\\Tpv.img"); // Imprime botones estaticos 'Seccion 1' sprintf( buffer, "datos\\%s\\info_ref.dbf", NEmpresa ); if ( BRef.AbrirReg( buffer, sizeof( INFO_PRODUCTOS ) ) == ERROR ) Error( 1, BRef.cError); // Si no hay registros, creamos uno almenos. if ( BRef.Registros() == 0 ) { Optar( 0, "Atencion !!!", "No existen referencias", "por lo tanto, no hay", "stock que evaluar...", NULL ); return; } // Recopilamos los datos sobre el Total de Beneficio, Costo, Bruto BenefTt = CostoTt = TtBruto = 0; for ( CurrRef = 0; CurrRef < BRef.Registros(); CurrRef++ ) { if ( BRef.LeeReg( (void *)&SRef, CurrRef ) == ERROR ) break; if ( !SRef.Combinado ) { BenefTt += (long)( ( SRef.PrecioVenta[0] - SRef.PrecioCosto ) * SRef.Stock ); CostoTt += (long)( ( SRef.PrecioCosto ) * SRef.Stock ); TtBruto += (long)( ( SRef.PrecioVenta[0] ) * SRef.Stock ); } else { if ( SRef.CantUnitaria != 0 ) { BenefTt += (long)( (float)( ( SRef.PrecioVenta[0] - SRef.PrecioCosto ) * ( (float)SRef.Stock / (float)SRef.CantUnitaria ) ) ); CostoTt += (long)( (float)( ( SRef.PrecioCosto ) * ( (float)SRef.Stock / (float)SRef.CantUnitaria ) ) ); TtBruto += (long)( (float)( ( SRef.PrecioVenta[0] ) * ( (float)SRef.Stock / (float)SRef.CantUnitaria ) ) ); } } } // Mostramos los datos anteriormente recopilados setfillstyle( SOLID_FILL, Config.TxtBgN ); setcolor( Config.TxtFgN ); bar( 506, 456, 634, 474 ); formatea_u_long( BenefTt, buffer1); sprintf( buffer, "Benef: %13s", buffer1); settextstyle( SMALL_FONT, HORIZ_DIR, 4 ); outtextxy( 510, 458, buffer ); settextstyle( SMALL_FONT, HORIZ_DIR, 5 ); CurrRef = 0; CurrRow = 0; // Mostramos datos hasta que se nos acabe la pantalla MuestraDatosRef2( CurrRow + CurrRef ); if ( BRef.LeeReg( (void *)&SRef, 0 ) == ERROR ) Error( 1, BRef.cError); CurrCol = 0; do { if ( CurrCol != oldCol || CurrCol == 2 ) { oldCol = CurrCol; MuestraAyudaRef2( CurrCol ); } MuestraRef2( CurrCol, CurrRow, INTENSO ); BPush = Comprueba_Secuencia( 2, NULL ); MuestraRef2( CurrCol, 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: CurrCol++; if ( CurrCol > 4 ) CurrCol = 0; break; // Flecha Arriba case 72: if ( (CurrRow + CurrRef) > 0 ) { if ( ( CurrRow ) <= 0 ) { CurrRow = NLINEAS_REF - 1; CurrRef -= NLINEAS_REF; if ( CurrRef < 0 ) CurrRef = 0; while( ( CurrRow + CurrRef ) >= BRef.Registros() && CurrRow > 0 ) CurrRow--; while( ( CurrRow + CurrRef ) >= BRef.Registros() && CurrRef > 0 ) CurrRef++; // Mostramos datos hasta que se nos acabe la pantalla MuestraDatosRef2( CurrRef ); } else { CurrRow --; if ( CurrRow < 0 ) CurrRow = 0; } } if ( BRef.LeeReg( (void *)&SRef, (CurrRef + CurrRow) ) == ERROR ) Error( 1, BRef.cError); break; // Flecha Abajo case 80: if ( ( CurrRow + CurrRef ) < BRef.Registros() - 1 ) { if ( ( CurrRow ) >= NLINEAS_REF - 1 ) { CurrRow = 0; CurrRef += NLINEAS_REF; while ( (CurrRef + CurrRow) >= BRef.Registros() ) CurrRef--; // Mostramos datos hasta que se nos acabe la pantalla MuestraDatosRef2( CurrRef ); } else CurrRow++; } if ( BRef.LeeReg( (void *)&SRef, (CurrRef + CurrRow) ) == ERROR ) Error( 1, BRef.cError); break; // Inicio case 71: CurrRow = 0; if ( CurrRef != 0 ) { CurrRef = 0; // Mostramos datos hasta que se nos acabe la pantalla MuestraDatosRef2( CurrRef ); } if ( BRef.LeeReg( (void *)&SRef, (CurrRef + CurrRow) ) == ERROR ) Error( 1, BRef.cError); break; // Fin case 79: CurrRow = 0; if ( CurrRef != BRef.Registros() - NLINEAS_REF ) { CurrRef = BRef.Registros() - NLINEAS_REF; if ( CurrRef < 0 ) { CurrRef = 0; CurrRow = BRef.Registros()-1; } // Mostramos datos hasta que se nos acabe la pantalla MuestraDatosRef2( CurrRef ); } if ( BRef.LeeReg( (void *)&SRef, (CurrRef + CurrRow) ) == ERROR ) Error( 1, BRef.cError); break; } break; // Imprimir Referencias case 1: #ifndef DEMOSTRACION ImprimeStockActual(); #else Optar( 0, "VERSION DEMOSTRACION", "En esta versi¢n no se", "permite imprimir el Stock.", NULL ); #endif break; // Menu Principal case 2: ok = 1; break; // Eliminar case 3: break; // Insertar case 4: break; // Retroceso R pido case 5: #ifndef DEMOSTRACION CurrRow = NLINEAS_REF - 1; CurrRef -= NLINEAS_REF; if ( CurrRef < 0 ) CurrRef = 0; while( ( CurrRow + CurrRef ) >= BRef.Registros() && CurrRow > 0 ) CurrRow--; while( ( CurrRow + CurrRef ) >= BRef.Registros() && CurrRef > 0 ) CurrRef++; // Mostramos datos hasta que se nos acabe la pantalla MuestraDatosRef2( CurrRef ); if ( BRef.LeeReg( (void *)&SRef, (CurrRef + CurrRow) ) == ERROR ) Error( 1, BRef.cError); #endif break; // Busqueda Atras case 6: if ( BuscaRef( ATRAS, &CurrRow, &CurrRef ) == OK ) { // Mostramos datos hasta que se nos acabe la pantalla MuestraDatosRef2( CurrRow + CurrRef ); if ( BRef.LeeReg( (void *)&SRef, (CurrRow + CurrRef) ) == ERROR ) Error( 1, BRef.cError); } else { if ( BRef.LeeReg( (void *)&SRef, (CurrRow + CurrRef) ) == ERROR ) Error( 1, BRef.cError); } break; // Buscar case 7: if ( BuscaRef( NUEVA_BUSQUEDA, &CurrRow, &CurrRef ) == OK ) { // Mostramos datos hasta que se nos acabe la pantalla MuestraDatosRef2( CurrRow + CurrRef ); if ( BRef.LeeReg( (void *)&SRef, (CurrRow + CurrRef) ) == ERROR ) Error( 1, BRef.cError); } else { if ( BRef.LeeReg( (void *)&SRef, (CurrRow + CurrRef) ) == ERROR ) Error( 1, BRef.cError); } break; // Busqueda Adelante case 8: if ( BuscaRef( ADELANTE, &CurrRow, &CurrRef ) == OK ) { // Mostramos datos hasta que se nos acabe la pantalla MuestraDatosRef2( CurrRow + CurrRef ); if ( BRef.LeeReg( (void *)&SRef, (CurrRow + CurrRef) ) == ERROR ) Error( 1, BRef.cError); } else { if ( BRef.LeeReg( (void *)&SRef, (CurrRow + CurrRef) ) == ERROR ) Error( 1, BRef.cError); } break; // AvanceR pido case 9: #ifndef DEMOSTRACION CurrRow = 0; CurrRef += NLINEAS_REF; while ( (CurrRef + CurrRow) >= BRef.Registros() ) CurrRef--; // Mostramos datos hasta que se nos acabe la pantalla MuestraDatosRef2( CurrRef ); if ( BRef.LeeReg( (void *)&SRef, (CurrRef + CurrRow) ) == ERROR ) Error( 1, BRef.cError); #endif break; // Boton de uso general 1: ( ORDENACIONES ) case 10: if ( MuestraOrdenaciones() == OK ) { // Mostramos datos hasta que se nos acabe la pantalla MuestraDatosRef2( CurrRef ); if ( BRef.LeeReg( (void *)&SRef, (CurrRef + CurrRow) ) == ERROR ) Error( 1, BRef.cError); } break; // Boton de uso general 2: ( SUMA BENEFICIOS, BRUTO, COSTO ) case 11: SumaMostrar = (SumaMostrar++)%3; // Borramos y mostramos lo deseado setfillstyle( SOLID_FILL, Config.TxtBgN ); setcolor( Config.TxtFgN ); bar( 506, 456, 634, 474 ); switch( SumaMostrar ) { case 1: formatea_u_long( BenefTt, buffer1 ); sprintf( buffer, "Benef: %13s", buffer1 ); break; case 2: formatea_u_long( CostoTt, buffer1 ); sprintf( buffer, "Costo: %13s", buffer1 ); break; case 3: formatea_u_long( TtBruto, buffer1 ); sprintf( buffer, "Bruto: %13s", buffer1 ); break; } settextstyle( SMALL_FONT, HORIZ_DIR, 4 ); outtextxy( 510, 458, buffer ); settextstyle( SMALL_FONT, HORIZ_DIR, 5 ); break; default: break; } } while( !ok ); BRef.CerrarReg(); } /**************************************************************************\ |* *| |* MuestraOrdenaciones *| |* *| |* Descripci¢n: *| |* Despliega un cuadro con las distintas posibilidades de ordenaci¢n *| |* *| |* Entradas: (ninguna) *| |* Salidas: (ninguna) *| |* *| \**************************************************************************/ int MuestraOrdenaciones( void ) { void far *fondo; struct textsettingstype texttypeinfo; char ok, dev; if ( ( fondo = farmalloc ( JD_imagesize( 170, 165, 470, 315 ) ) ) != NULL ) { gettextsettings( &texttypeinfo ); getimage( 170, 165, 470, 315, fondo ); Imprime_Estaticos( 25, "systm\\tpv.img" ); settextstyle( texttypeinfo.font, texttypeinfo.direction, texttypeinfo.charsize ); ok = 0; do { switch( Comprueba_Secuencia( 3, NULL ) ) { case 0: case -1: case -2: while( kbhit() ) getch(); break; // Cancelar case 1: dev = 0; ok = 1; break; // Listado r pido case 2: dev = 1; ok = 1; break; // Listado completo case 3: dev = 2; ok = 1; break; // Codigos de barra case 4: dev = 3; ok = 1; break; } } while( !ok ); putimage( 170, 165, fondo, COPY_PUT ); farfree( fondo ); if ( dev != 0 ) { TIPO_ORDENACION = dev -1; BRef.SortReg( Ordenar ); return OK; } } return ERROR; } int Ordenar( const void *A, const void *B ) { switch( TIPO_ORDENACION ) { case 0: if ( (( INFO_PRODUCTOS *)A)->CodigoR > (( INFO_PRODUCTOS *)B)->CodigoR ) return 1; if ( (( INFO_PRODUCTOS *)A)->CodigoR < (( INFO_PRODUCTOS *)B)->CodigoR ) return -1; return 0; break; case 1: return ( strcmp( (( INFO_PRODUCTOS *)A)->Descripcion, (( INFO_PRODUCTOS *)B)->Descripcion ) ); break; case 2: if ( (( INFO_PRODUCTOS *)A)->Stock > (( INFO_PRODUCTOS *)B)->Stock ) return 1; if ( (( INFO_PRODUCTOS *)A)->Stock < (( INFO_PRODUCTOS *)B)->Stock ) return -1; return 0; break; } return 0; } /**************************************************************************\ |* *| |* MuestraDatosRef2 *| |* *| |* 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 MuestraDatosRef2( long RowStart ) { int linea, campo; char dev; int X0, Y0, X1, Y1; // Imprimo la NLINEAS_REF que caben en la pantalla dev = OK; for ( linea=0; linea < NLINEAS_REF && dev == OK; linea++ ) { dev = BRef.LeeReg( (void *)&SRef, RowStart + linea ); if ( dev == OK ) // Por cada linea hay 5 campos, ehhh!!! for ( campo=0; campo < 5; campo++ ) MuestraRef2( campo, linea, NORMAL ); } // Ahora limpio los restantes huecos si los hay if ( dev != OK ) { linea--; setfillstyle( SOLID_FILL, Config.TxtBgN ); for ( ; linea < NLINEAS_REF; linea++ ) for ( campo=0; campo < 5; campo++ ) { ObtenCoordenadasRef2( campo, linea, &X0, &Y0, &X1, &Y1 ); bar( X0, Y0, X1, Y1 ); } } } /**************************************************************************\ |* *| |* MuestraRef2 *| |* *| |* Descripci¢n: *| |* Reescribe el campo dado, seg£n la fila, y la intensidad *| |* *| |* Entradas: *| |* columna campo ha mostar *| |* linea linea en la que nos encontramos *| |* como intensidad del texto (NORMAL/INTENSO) *| |* *| |* Salidas: (ninguna) *| |* *| \**************************************************************************/ void MuestraRef2( char columna, int linea, char como ) { char buffer[80], font; char buffer1[80], buffer2[80]; int X0, Y0, X1, Y1; ObtenCoordenadasRef2( columna, linea, &X0, &Y0, &X1, &Y1 ); if ( SRef.CantUnitaria == 0 ) SRef.CantUnitaria = 1; font = 1; switch( columna ) { // Codigo Real case 0: sprintf ( buffer, " %09lu", SRef.CodigoR ); break; // Nombre del producto case 1: sprintf ( buffer, "%30s", SRef.Descripcion ); break; // Stock Actual ( Cant Und ) case 2: if ( SRef.CantUnitaria == 1 ) { formatea_long( (long)( SRef.Stock ), buffer1 ); sprintf ( buffer, "%9s", buffer1 ); } else { formatea_long( (long)( SRef.Stock / SRef.CantUnitaria ), buffer1 ); formatea_long( (long)( SRef.Stock % SRef.CantUnitaria ), buffer2 ); sprintf ( buffer, "%6s %6s", buffer1, buffer2 ); font = 0; } break; // Valoracion del Stock case 3: if ( !SRef.Combinado ) formatea_long( (long)( SRef.PrecioCosto * SRef.Stock ), buffer1 ); else formatea_long( (long)( (float)( SRef.PrecioCosto * ( (float)SRef.Stock / (float)SRef.CantUnitaria ) ) ), buffer1 ); sprintf ( buffer, "%12s", buffer1 ); font = 0; break; // Beneficio estimado case 4: if ( !SRef.Combinado ) formatea_long( (long)( ( SRef.PrecioVenta[0] - SRef.PrecioCosto ) * SRef.Stock ), buffer1 ); else formatea_long( (long)( (float)( ( SRef.PrecioVenta[0] - SRef.PrecioCosto ) * ( (float)SRef.Stock / (float)SRef.CantUnitaria ) ) ), buffer1 ); sprintf ( buffer, "%12s", buffer1 ); font = 0; break; } if ( columna <= 6 && SRef.Categoria == 99 && SRef.PrecioCosto == 0 && SRef.PrecioVenta[0] == 0 ) if ( como == NORMAL ) como = INTENSO; else como = NORMAL; setfillstyle( SOLID_FILL, ( como == NORMAL ) ? Config.TxtBgN : Config.TxtBgI ); bar( X0, Y0, X1, Y1 ); setcolor ( ( como == NORMAL ) ? Config.TxtFgN : Config.TxtFgI ); if ( font == 0 ) settextstyle( SMALL_FONT, HORIZ_DIR, 4 ); outtextxy( X0+2, Y0, buffer ); if ( font == 0 ) settextstyle( SMALL_FONT, HORIZ_DIR, 5 ); } /**************************************************************************\ |* *| |* MuestraAyudaRef2 *| |* *| |* Descripci¢n: *| |* Muestra una peque¤a descripcion del contenido para el campo *| |* *| |* Entradas: *| |* columna campo ha mostar su ayuda *| |* *| |* Salidas: (ninguna) *| |* *| \**************************************************************************/ void MuestraAyudaRef2( char columna ) { char buffer1[80]; switch( columna ) { // Codigo Real case 0: sprintf ( buffer1, "C¢digo del Producto" ); break; // Nombre del producto case 1: sprintf ( buffer1, "Nombre del producto" ); break; // Stock Actual ( desglosado ) case 2: // sprintf ( buffer1, "Stock Actual ( desglosado en Cajas y Unds )" ); sprintf ( buffer1, "Stock Actual ( 1 Caja = %d Unidades )", SRef.CantUnitaria ); break; // Valor aproximado case 3: sprintf ( buffer1, "Valor aproximado del stock" ); break; // Beneficio Estimado case 4: sprintf ( buffer1, "Beneficio estimado del stock actual" ); break; } // Ayuda reducida setfillstyle( SOLID_FILL, EGA_BLACK ); bar( 7, 457, 498, 473 ); // Imprime la ayudita setcolor( EGA_WHITE ); outtextxy( 7, 457, buffer1 ); } /**************************************************************************\ |* *| |* ObtenCoordenadasRef2 *| |* *| |* Descripci¢n: *| |* Obtiene las coordenadas de acotacion para el campo pedido *| |* *| |* Entradas: *| |* columna campo del que obtener las coordenadas *| |* linea linea en la que nos encontramos *| |* X0 Y0 X1 Y1 Punteros para devolver las coordenadas *| |* *| |* Salidas: (ninguna) *| |* *| \**************************************************************************/ void ObtenCoordenadasRef2( char columna, char linea, int *X0, int *Y0, int *X1, int *Y1 ) { // Calculamos la Y0, Y1 para la linea dada ( SOLO columna < 6 ) *Y0 = 164 + 19*linea; *Y1 = *Y0 + 17; switch( columna ) { case 0: *X0 = 7; *X1 = 98; break; case 1: *X0 = 107; *X1 = 358; break; case 2: *X0 = 367; *X1 = 450; break; case 3: *X0 = 459; *X1 = 541; break; case 4: *X0 = 550; *X1 = 633; break; } *X0 += 2; *X1 -= 2; } // ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß // Û Parte secundaria del m¢dulo Û // Û Û // Û Secci¢n de Busqueda de refecencias Û // ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ #ifndef DEMOSTRACION /**************************************************************************\ |* *| |* ImprimeStockActual *| |* *| |* Descripci¢n: *| |* Imprime todas las referencias seg£n se le indique *| |* *| |* Entradas: *| |* Como imprimir las referencias *| |* *| |* Salidas: (ninguna) *| |* *| \**************************************************************************/ void ImprimeStockActual(void) { long i, old_reg; char buffer[80]; char buffer1[80]; char buffer2[80]; FILE *file_out; old_reg = BRef.RegActual(); if ( !Config.Impresora.Printer ) { if ( ( file_out = fopen( Config.Impresora.PrintTo, "w" ) ) == NULL ) return; } else file_out = stdprn; fprintf( file_out, "C¢digo Descripci¢n Stock Valoraci¢n Beneficio\n\r" ); for ( i=0; i