          ************ COSTBILLS COMMAND FILE **************
* This file accepts inputs for supplier bills.
*
* A temporary file called GetBills (also used in USETAX.CMD) is used for data
* entry because the operator can decide to quit on an incomplete entry, which
* is marked for deletion.
* When the data is APPENDed to the PostFile, these entries are eliminated (the
* APPEND command does not transfer records marked for deletion).  An entry must
* include (the name of a supplier <and> the amount of the bill). If these
* are not both supplied, the entry is flagged for correction or deletion.
***************************************************************************

ERASE
@ 5,20 SAY 'SUPPLIER BILLS'
USE B:PostFile
COPY STRUCTURE TO GetBills

USE GetBills
STORE 'Y' TO Bills
DO WHILE !(BILLS) <> 'F'
   APPEND BLANK
   STORE STR(#,5) TO Number

   STORE T TO Entering
   DO WHILE Entering
      ERASE
      @ 1,0 SAY '   RECORD NUMBER: ' - Number
      @ 3,0 SAY '          CLIENT' GET Client
      @ 4,0 SAY '      JOB NUMBER' GET Job:Nmbr
      @ 5,0 SAY '          AMOUNT' GET Amount
      @ 6,0 SAY '     BILL NUMBER' GET Bill:Nmbr
      @ 7,0 SAY '       BILL DATE' GET Bill:Date
      @ 8,0 SAY '   SUPPLIER NAME' GET Name
      @ 9,0 SAY '     DESCRIPTION' GET Descrip
      READ
      REPLACE Client WITH !(Client), Name WITH !(Name), Descrip;
              WITH !(Descrip), Bill:Nmbr WITH !(Bill:Nmbr)
      @ 3,17 SAY Client
      @ 8,17 SAY Name
      @ 9,17 SAY Descrip

      STORE ' ' TO Getting
      IF $(Client,1,1) = ' ' .OR. $(Client,2,1) = ' ' .OR. $(Client,3,1) = ' ';
            .OR. Job:Nmbr <=0
         @ 12,0
         ? '      CLIENT or JOB NUMBER wrong.'
         ? '      F if FINISHED,'
         ACCEPT '   <RETURN> to change.' TO Getting
      ELSE
         IF Amount = 0 .OR. Name <= '    '
            ?
            ?
            ? '        AMOUNT or NAME missing.'
            ?
            ? '        F if FINISHED,'
            ACCEPT '     <RETURN> to change.' TO Getting
         ELSE
            @ 12,5 SAY '   C to CHANGE,'
            @ 13,5 SAY '   F if FINISHED,'
            ACCEPT '     <Return> to continue.' TO Bills

            IF !(BILLS) = 'C'
               STORE T TO Entering
            ELSE
               STORE F TO Entering
            ENDIF
         ENDIF  amount or name
      ENDIF client or job number

      IF !(Getting) = 'F'
         DELETE RECORD &Number
         STORE F TO Entering
         STORE 'F' TO Bills
      ENDIF
   ENDDO Entering
ENDDO Bills

COUNT FOR .NOT. * TO Any
IF Any = 0
   ? 'No entries to add to the Cost Base.'
   ? '<Return> to the menu.'
   USE
   WAIT
ELSE

   RESTORE FROM B:Constant
   STORE 'Bill:Date' TO Date
   DO DateTest

   * Checks names against a list of suppliers to catch spelling and
   * abbreviation inconsistencies.
   DO NameTest

   ERASE
   @ 3,25 SAY ' *** DO NOT INTERRUPT ***'
   @ 5,25 SAY ' UPDATING THE POSTING FILE'
   USE B:PostFile
   APPEND FROM GetBills
ENDIF

USE
DELETE FILE GetBills
RELEASE All
RETURN

