FUNCTION c_eff_due

PARAMETERS pcclient_no

PRIVATE lnbalance,lcalias,lctran_ord
lcalias = ALIAS()
lctran_ord = ORDER('TRANSECT')
lnbalance = 0

IF SEEK(pcclient_no,'BOOKING','CLIENT_NO')
	IF booking.status <> 'B'
		IF SEEK(pcclient_no,'CLIOPBAL','CLIENT_NO')
*!*				lnbalance = cliopbal.bookingdue - cliopbal.op_bal		Change By Priten on 15/06/11
			lnbalance = booking.total_amt - cliopbal.op_bal
		ELSE 
			do err_msg with 'CLIENT NO. : ' + pcclient_no + ' WAS NOT FOUND IN ' + CHR(13) + 'CLIENT OPENING BALANCE FILE' + CHR(13) + 'PL. RUN' + CHR(13) + 'CLIENT OP. BALANCE IN REPAIR DATA'
			INSERT INTO cliopbal ;
				(client_no,bookingdue) ;
			VALUES ;
				(pcclient_no,booking.total_amt)
			lnbalance = booking.total_amt
		ENDIF 
	ELSE 
		IF SEEK(pcclient_no,'CLIOPBAL','CLIENT_NO')
			lnbalance = -cliopbal.op_bal
		ELSE 
			do err_msg with 'CLIENT NO. : ' + pcclient_no + ' WAS NOT FOUND IN ' + CHR(13) + 'CLIENT OPENING BALANCE FILE' + CHR(13) + 'PL. RUN' + CHR(13) + 'CLIENT OP. BALANCE IN REPAIR DATA'
			INSERT INTO cliopbal ;
				(client_no,bookingdue) ;
			VALUES ;
				(pcclient_no,booking.total_amt)
			lnbalance = 0.00   && -booking.total_amt    Change By Priten on 15/06/11
		ENDIF 
	ENDIF 
ENDIF

SELECT transect
SET ORDER TO client_no
IF SEEK(pcclient_no)
	SCAN REST WHILE client_no = pcclient_no FOR transect.PREV_FLG <> 'Y'
		lnbalance = lnbalance + IIF(cli_dbcr = 'D',1,-1)*amount
	ENDSCAN 
ENDIF

IF EMPTY(lnbalance)
	SET ORDER TO 0
ELSE 
	SET orde to (lctran_ord)
ENDIF 

IF ! EMPTY(lcalias)
	SELECT (lcalias)
ENDIF 

RETURN lnbalance