10 ' ============ ::::::::   ADAAJR :::::::: ==============================
   '
   ' :::::::  ESTADISTICA DE VENTAS
   '
   ' SISTEMAS SIERRA SA DE CV                    ACUMULA DIAS ANTERIORES
   ' 22-May-2006 1008  creaci¢n inicial del programa
   ' ======================================================================
   
    ' $INCLUDE: 'EDITAL.BAS'
      DIM SHARED V1%(2000),V2%(2000),V3%(2000)
      ON ERROR GOTO ErrorHandler
      WIDTH LPRINT 150                                     ' asigna impresor

     CAR$="C"
     NDIR$="ORDERS"
     GOSUB 350                                             ' VENTAS POR DIA
     CLOSE                                                 ' cierra archivos
     END

350                                                        ' ACUMULA DIAS ANTERIORES
     GOSUB 10016                                           ' cuadro pantalla
     SISTEMA$="ANALISIS DE VENTAS":LG=79                   ' titulo
     MENU$="Acum d¡as anteriores"                             
     GOSUB 8300                                            ' encabezado
     COLOR 7,0                                             ' intensidad media
     PR=07:PC=12:NR=02:NC=04:GOSUB 9981
     PR=07:PC=20:NR=06:NC=33:GOSUB 9981
     PR=11:PC=14:NR=01:NC=02:GOSUB 9981
     PR=14:PC=10:NR=01:NC=06:GOSUB 9981

     COLOR 0,7
        LOCATE 08,03:PRINT "Fecha de"
        LOCATE 09,03:PRINT "Fecha a"
        LOCATE 12,03:PRINT "Valida a¤o"
        LOCATE 15,03:PRINT "\Direc"
     COLOR 15,7
        LOCATE 08,21:PRINT "El sistema calcula el an lisis de"
        LOCATE 09,21:PRINT "la venta de los d¡as indicados.  "
        LOCATE 10,21:PRINT "Lee los archivos de venta del    "
        LOCATE 11,21:PRINT "directorio \ORDERS, calcula, y   "
        LOCATE 12,21:PRINT "graba el an lisis de la venta en "
        LOCATE 13,21:PRINT "la base de datos AJR.            "
     COLOR 4,7
        LOCATE 11,32:PRINT "\";NDIR$
        LOCATE 13,38:PRINT "AJR"
        

900  GOSUB 902:GOSUB 904:GOSUB 906:GOSUB 908:GOTO 950
902  COLOR 15,07:LOCATE 08,13:PRINT "mmdd":RETURN          ' fecha de
904  COLOR 15,07:LOCATE 09,13:PRINT "mmdd":RETURN          ' fecha a
906  COLOR 15,07:LOCATE 12,15:PRINT "  "  :RETURN          ' valida a¤o    
908  COLOR 15,07:LOCATE 15,11:PRINT NDIR$ :RETURN          ' directorio

950  FECD$="mmdd":FECA$="mmdd":VA$=SPACE$(2)

1000 MENSAJE$=" Calcula desde fecha.  mm=mes, dd=dia.  Enter=0101.  ESC=terminar.":GOSUB 15710
     COLOR 16,15:LOCATE 24,42:PRINT "Enter";
                 LOCATE 24,55:PRINT "Esc";
     LOCATE 23,2:PRINT "":COLOR 7,0
     IF FECD$=SPACE$(4) THEN S$="" ELSE S$=FECD$
     COLOR 15,1:W=08:Z=13:L=4:T=1:keypressed = edit(z,w,l,S$) ' FECHA DE
     IF KEYPRESSED=ESCAPE OR KEYPRESSED=UPARROW THEN RETURN
        FECD$=S$
        IF FECD$=SPACE$(4) OR FECD$="mmdd" THEN FECD$="0101"
        IF MID$(FECD$,1,2)<"01" OR MID$(FECD$,1,2)>"12" THEN GOSUB 7600:GOTO 1000
        IF MID$(FECD$,3,2)<"01" OR MID$(FECD$,3,2)>"31" THEN GOSUB 7600:GOTO 1000
           COLOR 15,7:LOCATE 8,13:PRINT FECD$

1010 MENSAJE$=" Calcula hasta fecha.  mm=mes, dd=dia.  Enter=1231.":GOSUB 15710
     COLOR 16,15:LOCATE 24,42:PRINT "Enter";
     LOCATE 23,2:PRINT "":COLOR 7,0
     IF FECA$=SPACE$(4) THEN S$="" ELSE S$=FECA$
     COLOR 15,1:W=09:Z=13:L=4:T=1:keypressed = edit(z,w,l,S$) ' FECHA A
     IF KEYPRESSED=ESCAPE OR KEYPRESSED=UPARROW THEN 900   
        FECA$=S$
        IF FECA$=SPACE$(4) OR FECA$="mmdd" THEN FECA$="1231"
        IF MID$(FECA$,1,2)<"01" OR MID$(FECA$,1,2)>"12" THEN GOSUB 7600:GOTO 1010
        IF MID$(FECA$,3,2)<"01" OR MID$(FECA$,3,2)>"31" THEN GOSUB 7600:GOTO 1010
        IF FECA$<FECD$ THEN GOSUB 7600:GOTO 1010
           COLOR 15,7:LOCATE 9,13:PRINT FECA$

1020 MENSAJE$=" Validar el a¤o al calcular.  aa=a¤o.  Enter=No valida.":GOSUB 15710
     COLOR 16,15:LOCATE 24,41:PRINT "Enter";
     LOCATE 23,2:PRINT "":COLOR 7,0
     IF VA$=SPACE$(2) THEN S$="" ELSE S$=VA$
     COLOR 15,1:W=12:Z=15:L=2:T=1:keypressed = edit(z,w,l,S$) ' VALIDA A¥O
     IF KEYPRESSED=ESCAPE OR KEYPRESSED=UPARROW THEN COLOR 15,7:LOCATE 12,15:PRINT VA$:GOTO 1010   
        VA$=SPACE$(2-LEN(S$))+S$
        IF VA$=SPACE$(2) THEN 1022
        IF VA$<"00" OR VA$>"99" THEN GOSUB 7600:GOTO 1020
1022       COLOR 15,7:LOCATE 12,15:PRINT VA$

1030 MENSAJE$=" Directorio donde se encuentran los ORDERS. Enter=no modifica. Default=ORDERS.":GOSUB 15710
     COLOR 16,15:LOCATE 24,46:PRINT "Enter";
     LOCATE 23,2:PRINT "":COLOR 7,0
     IF NDIR$=SPACE$(6) THEN S$="" ELSE S$=NDIR$
     COLOR 15,1:W=15:Z=11:L=6:T=3:keypressed = edit(z,w,l,S$) ' DIRECTORIO
     IF KEYPRESSED=ESCAPE OR KEYPRESSED=UPARROW THEN COLOR 15,7:LOCATE 15,11:PRINT NDIR$:GOTO 1020   
        NDIR$=S$
        IF LEN(NDIR$)<>6 THEN GOSUB 7600:GOTO 1030
           COLOR 15,7:LOCATE 15,11:PRINT NDIR$

1100 GOSUB 7500                                            ' GRABAR
     IF KEYPRESSED=ESCAPE OR KEYPRESSED=UPARROW THEN 1030
     IF KEYPRESSED=FF1 OR S$="1" THEN 1200
     IF KEYPRESSED=FF2 OR S$="C" OR S$="c" THEN 900
        GOSUB 7600:GOTO 1100

1200 MESI=VAL(MID$(FECD$,1,2))                             ' mes inicial
     MESF=VAL(MID$(FECA$,1,2))                             ' mes final
     DIAI=VAL(MID$(FECD$,3,2))                             ' dia inicial
     DIAF=VAL(MID$(FECA$,3,2))                             ' dia final

     COLOR 7,0                                             ' intensidad media
     CLS
     PR=07:PC=28:NR=05:NC=21:GOSUB 9981
     COLOR 0,7
        LOCATE PR+1,PC+2:PRINT "INTERFASE DE VENTAS"
        COLOR 15,7
           LOCATE PR+2,PC+2:PRINT "Acumula estad¡stica"
        COLOR 0,7
           LOCATE PR+4,PC+3:PRINT "Venta  "
           LOCATE PR+5,PC+3:PRINT "Avance"

     PRI=31*(MESI-1)+DIAI                                  ' primero
     ULT=31*(MESF-1)+DIAF                                  ' ultimo
     FOR R=PRI TO ULT
         M=INT((R+31)/31)                                  ' mes
         D=R MOD 31                                        ' dia
         IF D=0 THEN
            D=31
            IF M<>1 THEN
               M=M-1
            ENDIF
         ENDIF
         M$=MID$(STR$(M),2)
         M$=STRING$(2-LEN(M$),"0")+M$
         D$=MID$(STR$(D),2)
         D$=STRING$(2-LEN(D$),"0")+D$
         MD$=M$+D$
         ORDE$="ORDE"+MD$
         C1$="UNZ -O \"+NDIR$+"\"+ORDE$+" "+ORDE$+".QUE"
         C2$="COPY "+ORDE$+".QUE ORDER1.QUE"
         C3$="DEL "+ORDE$+".QUE"
         C4$="DEL ORDER1.QUE"
         C5$="UNZ -O \"+NDIR$+"\"+ORDE$+" "+"POS-B.*"
         AP1%=VARPTR(V1%(1)):CALL SAVESCRN(1,AP1%)     ' salva ventana
             LOCATE 12,2:PRINT ""
             SHELL C4$
             LOCATE 12,2:PRINT ""
             SHELL C1$
             LOCATE 13,2:PRINT ""
             SHELL C2$
             LOCATE 13,2:PRINT ""
             SHELL C3$
             LOCATE 13,2:PRINT ""
             ' SHELL C5$
             CALL RESTSCRN(1,AP1%)                         ' restaura ventana
             SHELL "\SIEAJR\AEEAJR"
             COLOR 15,7:LOCATE PR+4,PC+10:PRINT MID$(ORDE$,5,4)
     NEXT R

     BEEP
     RETURN

6999 ' $INCLUDE: 'R50GRL.BAS'
     ' $INCLUDE: 'VERSFT.BAS'

ErrorHandler:
      IF ERR=70 THEN LOCATE 24,01:COLOR 16,15:PRINT "pd...";:LOCATE 23,2:PRINT "":RESUME
      IF ERR=24 OR ERR=25 OR ERR=27 THEN GOSUB 7510:RESUME
      COLOR 16,15:LOCATE 24,01:PRINT "Error en los datos ";ERR;" Linea ";ERL;". Llame a SIERRA.";:LOCATE 23,2:PRINT "":W$=INPUT$(1):CLOSE:END
