PRIVATE LNREPO
STORE 0 TO LNREPO

DO SET_MENU

DO ALERT WITH "GENERATE REPORT ? ",1,"\<PAYMENT DETAIL;\<DUE PAYMENT DETAIL",LNREPO
IF LNREPO = 2
	= GET_PNAM('SUPPLIER WISE PAYMENT DETAIL')
	WAIT WIND '!!! WAIT !!! GATHERING DATA USING SQL ...' NOWA	
	SELECT VEHICLE.CHASIS_NO,VEHICLE.ENGINE_NO,VEHICLE.IN_DATE,VEHICLE.IN_RATE, ;
		VEHICLE.MODELCOLNO,VEHICLE.BRKPAIDDUE,VEHICLE.REF_NO,LEDGER.ACCOUNT ;
	FROM VEHICLE,LEDGER;
	WHERE VEHICLE.SUPPLIER_N = LEDGER.ACCOUNT_NO ;
		AND VEHICLE.BRKPAIDDUE <> 0 ;
	ORDER BY LEDGER.ACCOUNT ;			
	INTO CURSOR QUERY
ELSE
	= GET_PDT('SUPPLIER WISE PAYMENT DETAIL')
	WAIT WINDOW "!!! WAIT !!! Gathering data Using SQL CLEAR PAYMENT ... " NOWA	
	SELECT SUPLPAYBDY.REF_NO,SUPLPAYBDY.AMOUNT AS PAYMENT, ;
		SUPLPAY.ENTRY_NO,SUPLPAY.BILL_AMT,SUPLPAY.CHEQUE_NO,SUPLPAY.ENTRY_DT, ;
		VEHICLE.CHASIS_NO,VEHICLE.ENGINE_NO,VEHICLE.IN_DATE,VEHICLE.IN_RATE, ;
		VEHICLE.MODELCOLNO,VEHICLE.BRKPAIDDUE,LEDGER.ACCOUNT ;
	FROM VEHICLE,LEDGER,SUPLPAYBDY,SUPLPAY ;
	WHERE SUPLPAYBDY.ENTRY_NO = SUPLPAY.ENTRY_NO ;
		AND SUPLPAYBDY.REF_NO = VEHICLE.REF_NO ;	
		AND VEHICLE.SUPPLIER_N = LEDGER.ACCOUNT_NO ;
		AND VEHICLE.BRKPAIDAMT > VEHICLE.BRKPAIDDUE ;
		AND BETWEEN(SUPLPAY.ENTRY_DT,DATE1,DATE2) ;
	ORDER BY SUPLPAY.ENTRY_NO,SUPLPAYBDY.REF_NO ;
	INTO CURSOR QUERY
ENDIF 
SELECT QUERY

IF RECCOUNT('QUERY') > 0
	WAIT WINDOW 'GENERATING REPORT.........' NOWAIT
	IF LNREPO = 1	
		DO PRINREPO WITH 'WSUPPAYD','SUPPAYDT','','',0,.F.
	ELSE		
		DO PRINREPO WITH 'WSUPPAYD','SUPPNDDT','','',0,.F.
	ENDIF			
ENDIF
USE IN QUERY
DO CLS_MENU