 *************** PAYFIND COMMAND FILE *************
* This file is called by the PAYBILLS command file after we have found at least
* one cost entry for the supplier that we are looking for.
* This file now looks for either the first unpaid bill for the supplier
* (if only the name was specified) or looks for a complete match (if more than
* the name was specified.
* If an unpaid bill meeting the criteria is found, Looking is
* set to False.  Otherwise it remains True.
* If only the name was used, at this point we are at the first
* unpaid bill for the supplier name.
*      If more than the name was specified for the search, we could be anywhere
* in the indexed list of records for this supplier.  If we do not want to pay
* this particular bill, or we want to pay more bills for this supplier, we use
* a short cut in the PAYBILLS command file so that we do not have to start at
* the first record for the name every time.  To do this, we store the record
* number that we start at to a variable called Start if we have more than the
* name to look for.  Otherwise, Start =0
******************************************************************************

STORE T TO Looking
IF MBill:Nmbr > ' ' .OR. MAmount > 0
   * If we have more than the name, we first check for the bill number.
   * If this is not found or if the bill has already been paid,
   * the confirming procedure is skipped (Looking set TRUE).
   * In this case, we may have entered the list of supplier bills in the
   * middle of the indexed list.  In a later procedure, we may need to go
   * back to the top and look at the names we skipped. To do this, if we
   * find a record here, we store its number to "Start".

   IF MBill:Nmbr > ' '
      DO WHILE Name=Key .AND. .NOT. EOF .AND. Looking
         IF Bill:Nmbr <> MBill:Nmbr
            SKIP
         ELSE
            STORE F TO Looking
         ENDIF
      ENDDO

      * If we're on a new name of the end of the file, looking is TRUE
      * because we have not found the supplierr we were looking for.
      * Otherwise, we have a matcing bill number to confirm.
      IF Looking
	 ? '   This BILL NUMBER is not in the CostBase.'
	 ? '<Return> to continue.'
	 WAIT
      ELSE
	 IF Check:Nmbr <> ' '
	    STORE T TO Looking
	    ? '   This bill paid on '+Check:Date+', check '+Check:Nmbr
	    ? '<Return> to continue.'
	    WAIT
	 ENDIF
      ENDIF
   ELSE

      * If no bill number, look for the amount and an unpaid bill.
      * If not found, skip the confirmation procedure.
      DO WHILE Name=Key .AND. .NOT. EOF .AND. Looking
         IF Amount <> MAmount .OR. Check:Nmbr <> ' '
	    SKIP
	 ELSE
	    STORE F TO Looking
	 ENDIF
      ENDDO
      * If we're on a new name or the end of the file, Looking is TRUE
      * Otherwise, we have an unpaid bill to confirm.
      IF Looking
	 ? '   No unpaid bill for this amount and this supplier.'
         ? '<Return> to continue.'
         WAIT
      ENDIF
   ENDIF

   * If we found a matching record, store its number to Start
   IF .NOT. Looking
      STORE # TO Start
   ENDIF

ELSE
   * If we have only the name, find the next unpaid bill
   DO WHILE Name=Key .AND. .NOT. EOF .AND. Looking
      IF Check:Nmbr <> ' '
	 SKIP
      ELSE
	 STORE F TO Looking
      ENDIF
   ENDDO

   * If we're on a new name or the end of the file, Looking is TRUE
   * because we did not find the supplier we were looking for.
   * Otherwise, we have an unpaid bill to confirm.
   IF Looking
      ? '   There are no unpaid bills for this supplier.'
      ? '<Return> to continue.'
      WAIT
   ENDIF
ENDIF

RETURN

   * find a record here, we store its number to "Start".

   IF MBill:Nmbr > ' '
      DO WHILE Name=Key .AND. .NOT. EOF .AND. Looking
	 IF Bill:Nmbr <> MBill:Nmbr
	    SKIP
	 ELSE
	    STORE F TO Looking
	 ENDIF
      ENDDO

      * If we're on a new name of the end of the file, looking is TRUE
      * because we have not found the supplierr we were looking for.
         ? '<Return> to continue.'
      WAIT
   ENDIF
ENDIF

RETURN

   * find a record here, we store its number to "Start".

   IF MBill:Nmbr > ' '
      DO WHILE Name=Key .AND. .NOT. EOF .AND. Looking
	 IF Bill:Nmbr <> MBill:Nmbr
	    SKIP
	 ELSE
	    STORE F TO Looking
	 ENDIF
      ENDDO

      * If we're on a new name of the end of the file, looking is TRUE
      * because we have not found the supplierr we were looking for.
   unpaid bill for the supplier name.
*      If more than the name was specified for the search, we could be anywhere
* in the indexed list of records for this supplier.  If we do not want to pay
* this particular bill, or we want to pay more bills for this supplier, we use
* a short cut in the PAYBILLS command file so that we do not have to start at
* the first record for the name every time.  To do this, we store the record
* number that we start at to a variable cal