C
C         VEHICLE MAINTENANCE PRGM        by Bruce W. Roeckel
C       *--------------------------*                         
C           OPTION #2 - REPAIRS   
C
C
$STORAGE:2
C
C
      SUBROUTINE REPAIR
C
      COMMON/MONTHS/ IMON
      CHARACTER*4 IMON(13)
C
      COMMON/MAIN1/ NAME,IDNUM,DATE,RFILE,MFILE
      CHARACTER NAME(25)*20,IDNUM(25)*20,DATE(2,25)*8
      CHARACTER RFILE(25)*11,MFILE(25)*11
C
      COMMON/MAIN2/ COST,ODOM,VNUM
      INTEGER VNUM
      REAL COST(2,25),ODOM(2,25)
C
      COMMON/REPAR1/ RDESC,RDATE
      CHARACTER RDESC(500)*25,RDATE(500)*8
C
      COMMON/REPAR2/ RCODE,RCOST,RODOM,RNUM
      INTEGER RCODE(500),RNUM
      REAL RCOST(500),RODOM(500)
C
      INTEGER SEL,ICODE,TYPE,OLD
      CHARACTER TEST*8,OPTION*25,RAMDSK*80,CHOICE(2)*1
      REAL GALS
C
C           LIST ALL CARS, SELECT ONE TO WORK WITH
C
      SEL=0
      TYPE=1
      OPTION='Update Repair Log   '
      CALL HEADER(OPTION)
      CALL LISTEM(TYPE,SEL)
      IF(SEL.EQ.0) RETURN
      CALL RDREPS(SEL)
C
C           DISPLAY SELECTED CAR                        
C
   25 CONTINUE
      CALL HEADER(OPTION)
      CALL DNAME(SEL)
C
C           DRAW A SOLID LINE
C
      CALL MOVEIT(1,21)
      CALL BOLD
      CALL ULINE
         WRITE(*,'(80X)')
      CALL OFF
C
C           ASK FOR DATA
C
   50 CONTINUE
      LM=RNUM
      CALL UPTOP (1,10) 
      CALL OFF
         WRITE(*,100)
  100    FORMAT(//,18X,'1. Oil Change w/Filter      6. Alignment     ',
     A           /,18X,'2. Lubrication              7. Front Brakes  ',
     B           /,18X,'3. Air Filter               8. Rear Brakes   ',
     C           /,18X,'4. Dist. Points             9. Tire Rotation ',
     D           /,18X,'5. Spark Plugs             98. Special Repair',
     E           /,18X,'                                             ',
     F         ///,18X,'                                             ')
  150 CONTINUE
      CALL MOVEIT(1,23) 
         CALL BOLD
         WRITE(*,'(9X,A33,\)') 'Enter Choice (H=Help, Q=Quit) : '
         READ(*,'(2A1)',ERR=150) (CHOICE(K),K=1,2)
         CALL OFF
         IF(CHOICE(1).EQ.'Q' .OR. CHOICE(1).EQ.'q') THEN
            CALL WRREPS(SEL)
            GOTO 900
         ELSEIF(CHOICE(1).EQ.'H' .OR. CHOICE(1).EQ.'h') THEN
            CHOICE(1)='2'
            IUNIT=15
            CALL HELP(CHOICE(1),IUNIT)
            GOTO 25
         ELSEIF(CHOICE(1).EQ.'1' .OR. CHOICE(1).EQ.'2' .OR.
     A          CHOICE(1).EQ.'3' .OR. CHOICE(1).EQ.'4' .OR.
     B          CHOICE(1).EQ.'5' .OR. CHOICE(1).EQ.'6' .OR.
     C          CHOICE(1).EQ.'7' .OR. CHOICE(1).EQ.'8' .OR.
     D          CHOICE(1).EQ.'9') THEN
            WRITE(RAMDSK,'(A1)') CHOICE(1)
            READ(RAMDSK,'(I1)') ICODE
            LM=RNUM+1
C
C              IF CATAGORY 1 THRU 9, THEN UPDATE THAT ENTRY WITH DATA
C
            IF(CHOICE(2).EQ.' ') THEN
               DO 155 JL=1,RNUM
               IF(RCODE(JL).EQ.ICODE) LM=JL
  155          CONTINUE
            ELSEIF(CHOICE(1).EQ.'9' .AND. CHOICE(2).EQ.'8') THEN
               ICODE = 98
            ELSE
               CALL BELL
               GOTO 150
            ENDIF
C
C              POINT TO SELECTION, PROMPT FOR ALL DATA
C
            RCODE(LM)=ICODE
            IF(ICODE.LE.5) THEN
               LH=16
               LV=11+ICODE
            ELSEIF(ICODE.EQ.98) THEN
               LH=43
               LV=16
            ELSE
               LH=44
               LV=11+(ICODE-5)
            ENDIF
            CALL UPTOP(LH,LV)
            CALL BOLD
            CALL BLINK
            WRITE(*,'(A3)') '==>'
            CALL OFF
C
C              REPAIR DATE
C
  160       CONTINUE
            CALL MOVEIT(1,23) 
            CALL BOLD
            WRITE(*,'(5X,A30,\)') ' Date Repaired ? (MM/DD/YY) : '
            CALL OFF
            TEST=' '
            CALL EDATE(38,23,TEST)
            IF(TEST.EQ.' ') THEN
               GOTO 50
            ELSE
               RDATE(LM)=TEST 
            ENDIF
C
C               NOW ASK FOR A DESCRIPTION IF SPECIAL TYPE
C
            IF(ICODE.EQ.98) THEN
  175          CALL MOVEIT(1,23) 
               CALL BOLD
               WRITE(*,'(5X,A30,\)') 'Enter Description of Repair : '
               CALL OFF
               RAMDSK=' '
               CALL EDCHR(38,23,RAMDSK,25)
               RDESC(LM)=RAMDSK
            ELSE
  180          CALL MOVEIT(1,23) 
               CALL BOLD
               WRITE(*,'(5X,A30,\)') '   Any Notes About Repair ? : '
               CALL OFF
               RAMDSK=' '
               CALL EDCHR(38,23,RAMDSK,25)
               RDESC(LM)=RAMDSK
            ENDIF
C
C               NOW THE COST
C
            ITRY=0
  200       CONTINUE
            CALL MOVEIT(1,23) 
            CALL BOLD
            WRITE(*,'(5X,A30,\)') '       Cost of the Repair ? : '
            CALL OFF
            GALS=0.0
            CALL EDREL(38,23,GALS,8)
            IF(GALS.LE.0.0 .AND. ITRY.EQ.0) THEN
               ITRY=1
               CALL BELL
               GOTO 200
            ENDIF
            IF(LM.LE.RNUM) THEN
               RCOST(LM)=RCOST(LM) + GALS
            ELSE
               RCOST(LM)=GALS 
            ENDIF
C
C               AND LAST, THE ODOMETER READING
C
  300       CONTINUE
            CALL MOVEIT(1,23) 
            CALL BOLD
            WRITE(*,'(5X,A30,\)') '           Odometer Reading : '
            CALL OFF
            GALS=0.0
            CALL EDREL(38,23,GALS,8)
            IF(GALS.LE.0.0) THEN
               CALL BELL
               GOTO 300
            ENDIF
            IF(DATE(2,SEL).EQ.' ') GALS=GALS+ODOM(2,SEL)
            RODOM(LM)=GALS 
C
C              INCREMENT COUNTER, CREATE FILE NAME IF NECESSARY
C
            IF(LM.GT.RNUM) RNUM=RNUM+1
            IF(RNUM.EQ.1) THEN
               WRITE(RAMDSK,'(A5,I2.2,A4)') 'VEHIC',SEL,'.REP'
               READ(RAMDSK,'(A11)') RFILE(SEL)
            ENDIF
         ELSE
            CALL BELL
            GOTO 150
         ENDIF
         GOTO 50
  900 CONTINUE
      RETURN
      END
