Category : Dbase (Clipper, FoxBase, etc) Languages Source Code
Archive   : SBBILL.ZIP
Filename : CHKACCNT.PRG

 
Output of file : CHKACCNT.PRG contained in archive : SBBILL.ZIP

* --- CHKACCNT.PRG
* this routine goes through the CLIENT.DBF and, for each client, checks
* the ACCOUNT.DBF and readds the current balance, compares the values
* and fixes any errors.

clear
SELECT CLIENT
GO TOP
DO WHILE .NOT. eof()

? 'Checking client '+trim(first)+' '+trim(last)

* --- save the pertinent data, clientno and balance
old_bal = balance
key = str(clientno,4)

* --- check for the clients ledger
select Account
seek key

* --- if no ledger is found, go to next patient
if eof()
?? ' No ledger.'
select CLIENT
skip
loop
endif

* --- initialize memvars to record charges and payments
mpaid = 0.00
mcost = 0.00

* --- go through the clients ledger and recalculate
do while account->clientno=client->clientno .and. .not. eof()
mcost = charge + mcost
mpaid = paid + mpaid
skip
enddo

* --- calculate actual balance according to ledger
new_bal = mcost - mpaid

* --- if they match, go to next client
if old_bal = new_bal
?? ' Balance correct.'
select client
skip
loop
endif

* --- if they do not match, update the client database with new bal
* and go to the next client
?? ' Updating current balance.'
select client
replace balance with new_bal
?? ' Done.'
skip

enddo
inkey(3)
return