*   *************  INVMENU COMMAND FILE  ******************
* Functions are selected by the menu.  This procedure works with two data
* files, BILLINGS and INVOICES.  BILLINGS keeps track of the amount
* billed to a client by individual job number, while INVOICES is a 
* summary of the total billed on any given invoice.  This latter file can
* be used to set up an accounts receivable system, as it has fields for
* storing how much has been received in payment against an invoice and
* when that amount was received (filled in by the Deposits.CMD file).
**************************************************************************

ERASE
STORE T TO Invoicing
DO WHILE Invoicing
   @  5,20 SAY '   1> BILL CLIENTS BY JOB'
   @  7,20 SAY '   2> EDIT INVOICES and BILLINGS'
   @  9,20 SAY '   3> REVIEW/PRINT INVOICES and BILLINGS'
   @ 12,20 SAY '        <RETURN>'
   WAIT TO Action

   IF Action = '1'
      DO Invoices
   ELSE
      IF Action = '2'
         STORE 'Y' TO Changing
         DO WHILE !(Changing) = 'Y'
            ERASE
            ? '         J to edit individual job billings.'
            ? '      <Return> to edit the summary invoices.'
            WAIT TO Which
            IF !(Which) = 'J'
               STORE 'Billings' TO Database
            ELSE
               STORE 'Invoices' TO Database
            ENDIF

            USE B:&Database
            STORE Inv:Nmbr TO First
            GO BOTTOM
            STORE Inv:Nmbr TO Last
            ERASE
            @  3,10 SAY 'EDITING '+!(Database)
            @  3,35 SAY First+'thru '+Last
            @  5,10 SAY '^W to SAVE, ^Q to CANCEL changes you make.'
            @  6,10 SAY '^R for PREVIOUS, ^C for NEXT record.'
            @  8,10 SAY 'Which INVOICE NUMBER do you want to EDIT?'
            IF !(Which) = 'J'
               @  9,10 SAY 'This takes you to the FIRST ENTRY for that number.'
               @ 10,10 SAY 'Use ^C to look at the rest of them.'
            ENDIF
            ACCEPT TO Invoice

            USE B:&Database INDEX B:&Database
            FIND &Invoice
            IF # = 0
               ?
               ?
               ? 'That invoice number is not in the file.'
               ? 'Do you want to continue (Y or N)?'
               WAIT TO Changing
            ELSE
               STORE STR(#,5) TO Number
               EDIT &Number
               REPLACE Sales:Tax WITH 0.06*Taxable
               REPLACE Client WITH !(Client)
               IF !(Which) = 'J'
                  REPLACE Descrip WITH !(Descrip),PO:Nmbr WITH !(PO:Nmbr)
               ENDIF
               ?
               ? 'Do you want to edit any other invoices (Y or N)?'
               WAIT TO Changing
            ENDIF
         ENDDO Changing
         RELEASE All
      ELSE
         IF Action = '3'
            ERASE
            @ 4, 0 SAY ' '
            ? '        J to see individual job billings,'
            ? '     <Return> to see the summary invoices.'
            WAIT TO Which
            IF !(Which) = 'j'
               STORE 'Billings' TO Database
            ELSE
               STORE 'Invoices' TO Database
            ENDIF

            USE B:&Database
            STORE 'Y' TO Reviewing
            DO WHILE !(Reviewing)='Y'
               GO BOTTOM
               STORE STR(#,5) TO Last
               ERASE
               @ 5,10 SAY 'The '+!(Database)+' file has '-Last-' entries.'
               @ 7,10 SAY '<Return> to see the entire file, or'
               @ 8,10 SAY 'enter the record number to start on.'
               ACCEPT TO Number

               ? 'Do you want to print the file now (Y or N)?'
               WAIT TO Output

               IF !(Output) = 'Y'
                  SET PRINT ON
               ENDIF

               STORE CHR(0) TO Condition
               DO Printout
               ?
               SET PRINT OFF
               ? 'Do you want to see it again (Y or N)?'
               WAIT TO Reviewing
               ERASE
            ENDDO Reviewing
            RELEASE All
         ELSE
            RELEASE All
            RETURN
         ENDIF 3
      ENDIF 2
   ENDIF 1
   ERASE
   STORE T TO Invoicing
ENDDO Invoicing
