*      **********  DEPOSITS COMMAND FILE  *************
* This file records any money coming in , in a file called Deposits.  If the
* money is in payment of an invoice, the amount and date of payment are
* entered against that invoice in the Invoice file.
*      The checkbook balance is kept current for each entry.
*      At the end of the secession, deposits are printed out individually, then
* the total of the deposits plus the new checkbook balance are printed.
****************************************************************************

RESTORE FROM B:Constant

ERASE
@  5,20 SAY '  ENTERING INCOME'
@  7, 5 SAY 'The STARTING BALANCE is '+STR(MBalance,9,2)
?
? '   If this does not match the checkbook,'
? '   <Return> to the main menu to change.'
?
? '   C to CONTINUE.'
?
WAIT TO Continue
IF !(Continue) <> 'C'
   RELEASE ALL
   RETURN
ENDIF
RELEASE Continue

DO GetDate

SELECT PRIMARY
USE B:Deposits
COPY STRUCTURE TO GetDep

USE GetDep
STORE 'Y' TO Depositing
DO WHILE !(Depositing) <> 'F'
   APPEND BLANK
   STORE STR(#,5) TO Number
   REPLACE Dep:Date WITH Date

   ERASE
   * Next loop is used when there has been an error in the entry
   * (defined as no client or no rate).  The operator is shown the
   * previous entries and can make any changes required.
   STORE 'T' TO Incorrect
   DO WHILE !(Incorrect) <> 'F'
      @ 3, 0 SAY ' If a check covers more than one agency invoice,'
      @ 4, 0 SAY ' enter each invoice and amount separately.'
      ?
      @  6,0 SAY ' RECORD NUMBER: '-Number
      @  7,0 SAY '      HOW MUCH' GET Deposit
      @  8,0 SAY 'OUR INVOICE NO' GET Inv:Nmbr
      @  9,0 SAY '    CHECK FROM' GET Payer
      @ 10,0 SAY 'THEIR CHECK NO' GET Pay:Nmbr
      @ 11,0 SAY '      Comments' GET Comments
      ? CHR(7)
      READ

      REPLACE Payer WITH !(Payer), Comments WITH !(Comments)
      @  9,15 SAY Payer
      @ 11,15 SAY Comments

      IF Payer <> '   ' .AND. Deposit > 0
         @ 17,5 SAY '    C to CHANGE,'
         @ 18,5 SAY '<Return> to continue.'
         ?
         ? CHR(7)
         WAIT TO Depositing
         IF !(Depositing) = 'C'
            STORE 'T' TO Incorrect
            ERASE
         ELSE
            STORE (MBalance + Deposit) TO MBalance
            @ 17, 5 SAY '   F if FINISHED,'
            ?
            ? '                             '
            ? CHR(7)
            WAIT TO Depositing

            STORE 'F' TO Incorrect
         ENDIF
      ELSE 
         @ 15,5 SAY 'CHECK WRITER or AMOUNT missing.'
         ?
         ? '        F if FINISHED,'
         ? '     <Return> to correct the record.'
         ? CHR(7)
         WAIT TO Depositing
         ERASE
         IF !(Depositing)= 'F'
            DELETE RECORD &Number
            STORE 'F' TO Incorrect
         ELSE
            ERASE
            STORE 'T' TO Incorrect
         ENDIF
      ENDIF
   ENDDO Incorrect
ENDDO Depositing

RELEASE Change, Date, NoDate, Depositing, Number, Update, New, Incorrect
SAVE TO B:Constant

COUNT FOR .NOT. * TO Any
ERASE
IF Any = 0
   ? 'No deposits to add to the file.'
   ? 'Press any key to continue.'
   ? CHR(7)
   USE
   WAIT
ELSE
   DO DepPrint

   * The next portion of this program uses the Primary and Secondary work
   * areas to record payments received against agency invoices in the record
   * for that invoice in the Invoices file.  Both work areas are necessary so
   * that we can compare each record in the GetDep file against all of the
   * records in the Invoices file.
   DO DepTrans
   USE B:Deposits
   APPEND FROM GetDep
ENDIF there are deposits to add to the file

DELETE FILE GetDep
RELEASE ALL
RETURN
