PRIVATE LCFRM_NO,LCTO_NO
STORE SPACE(8) TO LCFRM_NO,LCTO_NO

DO SET_MENU

=GET_PNAM('MTR')

DEFINE WINDOW LWFRMTO FROM 0,0 TO 14,78 
ACTIVATE WINDOW LWFRMTO
MOVE WINDOW LWFRMTO CENT

@ 1,2 SAY "FROM REPORT NO. : " GET LCFRM_NO
@ 2,2 SAY "  TO REPORT NO. : " GET LCTO_NO 

LCFRM_NO = PADL(ALLTRIM(LCFRM_NO),8,'0')
LCTO_NO = PADL(ALLTRIM(LCTO_NO),8,'0')
READ
RELEASE WINDOWS LWFRMTO

IF LCFRM_NO > LCTO_NO
	DO err_msg WITH "TO NUMBER IS ALWAYS MORE THEN FROM NUMBER"
	DO CLS_MENU
	RETURN 
ENDIF
WAIT WIND '!!! WAIT !!! GATHERING DATA USING SQL ...' NOWA

IF ! EMPTY(LCFRM_NO) AND ! EMPTY(LCTO_NO)
	SELECT WARRANTY.REPORT_DT,WARRANTY.REPORT_NO,WARRANTY.SUB_TITLE,WARRANTY.MAIN_PART_NO, ;
		WARRANTY.MAIN_PART,WARRANTY.VENDOR,WARRANTY.MFG_CODE,CLIENT.MODEL_NO,CLIENT.MODELCOLNO, ;
		CLIENT.ENGINE_NO,CLIENT.CHASIS_NO,WARRANTY.MALF_DT,WARRANTY.MALF_KM,WARRANTY.DELIVERYDT, ;
		WARRANTY.REPAIR_KM,WARRANTY.MAIN_USAGE,WARRANTY.DIAGNOSIS,WARRANTY.FREE_01_KM,WARRANTY.FREE_02_KM, ;
		WARRANTY.FREE_03_KM,WARRANTY.FREE_04_KM,WARRANTY.FREE_05_KM,WARRANTY.FREE_06_KM, ;
		WARRANTY.FREE_01_DT,WARRANTY.FREE_02_DT,WARRANTY.FREE_03_DT,WARRANTY.FREE_04_DT, ;
		WARRANTY.FREE_05_DT,WARRANTY.FREE_06_DT,ITEMMAST.ITEM,WARRANTY.WR_IMAGE, ;
		MTR_BODY.ITEM_NO AS MTR_ITEMNO,MTR_BODY.SR_NO,VOR_ITEM.ITEM AS VOR_ITEM,MTR_BODY.QTY, ;
		MTR_BODY.VOR_NO,MTR_BODY.VOR_DT,MTR_BODY.ORD_QTY,WARRANTY.REPAIR_TYP ;
	FROM WARRANTY,MTR_BODY,ITEMMAST,ITEMMAST VOR_ITEM,CLIENT ;
	WHERE WARRANTY.CLAIM_NO = MTR_BODY.CLAIM_NO ;
		AND WARRANTY.CLIENT_NO = CLIENT.CLIENT_NO ;
		AND WARRANTY.ENGINE_OIL = ITEMMAST.ITEM_NO ;
		AND MTR_BODY.ITEM_NO = VOR_ITEM.ITEM_NO ;
		AND BETWEEN(WARRANTY.REPORT_NO,LCFRM_NO,LCTO_NO) ;
	ORDER BY WARRANTY.REPORT_NO ;
	INTO CURS QUERY
ELSE
	SELECT WARRANTY.REPORT_DT,WARRANTY.REPORT_NO,WARRANTY.SUB_TITLE,WARRANTY.MAIN_PART_NO, ;
		WARRANTY.MAIN_PART,WARRANTY.VENDOR,WARRANTY.MFG_CODE,CLIENT.MODEL_NO,CLIENT.MODELCOLNO, ;
		CLIENT.ENGINE_NO,CLIENT.CHASIS_NO,WARRANTY.MALF_DT,WARRANTY.MALF_KM,WARRANTY.DELIVERYDT, ;
		WARRANTY.REPAIR_KM,WARRANTY.MAIN_USAGE,WARRANTY.DIAGNOSIS,WARRANTY.FREE_01_KM,WARRANTY.FREE_02_KM, ;
		WARRANTY.FREE_03_KM,WARRANTY.FREE_04_KM,WARRANTY.FREE_05_KM,WARRANTY.FREE_06_KM, ;
		WARRANTY.FREE_01_DT,WARRANTY.FREE_02_DT,WARRANTY.FREE_03_DT,WARRANTY.FREE_04_DT, ;
		WARRANTY.FREE_05_DT,WARRANTY.FREE_06_DT,WARRANTY.WR_IMAGE,WARRANTY.ENGINE_OIL, ;
		MTR_BODY.ITEM_NO AS MTR_ITEMNO,MTR_BODY.SR_NO,MTR_BODY.QTY, ;
		MTR_BODY.VOR_NO,MTR_BODY.VOR_DT,MTR_BODY.ORD_QTY,WARRANTY.REPAIR_TYP ;
	FROM WARRANTY,MTR_BODY,CLIENT ;
	WHERE WARRANTY.CLAIM_NO = MTR_BODY.CLAIM_NO ;
		AND WARRANTY.CLIENT_NO = CLIENT.CLIENT_NO ;
		ORDER BY WARRANTY.REPORT_NO ;
	INTO CURS QUERY
	
	SELECT QUERY

	IF ! USEDBF(YEAR_PATH,'ITEMMAST','','VOR_ITEM',.T.,.T.,.F.,MPROG_PATH + '\YEARSTRU\',.F.)
		RETU .F.
	ENDIF

	INDEX ON MTR_ITEMNO TAG ITEM_NO  ADDITIVE 
	INDEX ON ENGINE_OIL TAG ENGINE_OIL  ADDITIVE 
	SET RELATION TO MTR_ITEMNO INTO ITEMMAST ADDITIVE 
	SET RELATION TO ENGINE_OIL INTO VOR_ITEM ADDITIVE 
	SELECT QUERY
	GO TOP 
	IF _TALLY > 0
		WAIT WINDOW 'GENERATING REPORT.........' NOWAIT
		DO PRINREPO WITH 'WMTR','MTR','','',0,.F.
	ENDIF
	USE IN QUERY
ENDIF
DO CLS_MENU