IF EMPT(M.BILL_NO)
	IF FILE('gatepass.frx')
		PRIVATE lnjob_rec
		lnjob_rec = RECNO('JOB_MAST')
		SELECT job_mast
		_PADVANCE = 'LINEFEED'
		= get_OPRIN('PRINT GATE PASS')
		REPORT FORM gatepass NEXT 1 TO (OUT_FILE) NOCO
		DO out_repo 
		_PADVANCE = 'FORMFEED'
		GO (lnjob_rec) IN job_mast
	ENDIF
	IF FILE('wgatepass.frx')
		PRIVATE lnjob_rec
		lnjob_rec = RECNO('JOB_MAST')
		SELECT job_mast
		_PADVANCE = 'LINEFEED'
		REPORT FORM wgatepass NEXT 1 TO print NOCO
		_PADVANCE = 'FORMFEED'
		GO (lnjob_rec) IN job_mast
	ENDIF	 
	RETU
ENDIF

WAIT WIND '!!! WAIT !!! GENERATING REPORT ...' NOWA
SELE JOB_BODY
SET ORDE TO ITEM_NO IN ITEMMAST
SET RELA TO ITEM_NO INTO ITEMMAST ADDI
SELE JOB_MAST
PRIVATE lnjob_rec
lnjob_rec = RECNO('JOB_MAST')
SET ORDE TO BILL_NO
SET ORDE TO CLIENT_NO IN CLIENT
SET RELA TO CLIENT_NO INTO CLIENT ADDI
SET ORDE TO JOBCARD_NO IN JOB_BODY
SET RELA TO JOBCARD_NO INTO JOB_BODY ADDI
SET SKIP TO JOB_BODY
= SEEK(JOB_MAST.MECHANICNO,'MECHANIC','MECHANICNO')
IF gcJbilname <> '*' 
	= GET_OPRIN('JOB BILL PRINTING')
ENDIF 
_PADVANCE = 'LINEFEED'

IF SEEK(M.BILL_NO,'JOB_MAST','BILL_NO')
	IF ! '.FRX' $ UPPER(gcJbilname)
		lcrepnam = gcJbilname + '.FRX'
	ELSE 
		lcrepnam = gcJbilname 
	ENDIF
	IF lcrepnam = '*'
		lcrepnam = SUBSTR(lcrepnam,2)
	ENDIF 
	IF GCVAT_FLG = 'Y'
		IF EMPTY(gcjbilname)
*			IF gcjbilname = '*'
*				REPO REST FORM subs(gcJbilname,2) WHILE BILL_NO = M.BILL_NO TO PRINTER NOCO
*			ELSE 
				REPO REST FORM VJOBBILL WHILE BILL_NO = M.BILL_NO TO (OUT_FILE) NOCO
*			ENDIF 
		ELSE 
			IF ! FILE(lcrepnam)			
				DO err_msg WITH "Please copy REPORT file "+ lcrepnam + " and try again ..."
			ELSE 			
				IF gcjbilname = '*'			
					REPORT FORM subs(gcJbilname,2) TO PRINTER WHILE BILL_NO = M.BILL_NO NOCO
*					REPORT FORM subs(gcJbilname,2) WHILE BILL_NO = M.BILL_NO PREVIEW NOCO
				ELSE 
					REPORT FORM &gcjbilname WHILE BILL_NO = M.BILL_NO TO (OUT_FILE) NOCO
				ENDIF 				
			ENDIF 			
		ENDIF
	ELSE 
		IF EMPTY(gcjbilname)
			REPO REST FORM JOB_BILL WHILE BILL_NO = M.BILL_NO TO (OUT_FILE) NOCO
		ELSE 
			IF ! FILE(lcrepnam)			
				DO err_msg WITH "Please copy REPORT file "+ lcrepnam + " and try again ..."
			ELSE 			
				IF gcjbilname = '*'		
*					REPORT FORM subs(gcJbilname,2) WHILE BILL_NO = M.BILL_NO TO PRINTER NOCO
					REPORT FORM subs(gcJbilname,2) WHILE BILL_NO = M.BILL_NO PREVIEW NOCO
				ELSE 
					REPORT FORM &gcjbilname WHILE BILL_NO = M.BILL_NO TO (OUT_FILE) NOCO
				ENDIF
			ENDIF 			
		ENDIF
	ENDIF 	
	DO OUT_REPO
ELSE
	DO ERR_BEEP 
	DO ALERT WITH '!!! ERROR !!!;THERE WAS PROBLEM IN GETTING BILL NO;WHILE PRINTING BILL'
ENDIF
SET SKIP TO
SET RELA OFF INTO JOB_BODY
SET RELA OFF INTO CLIENT
SELE JOB_BODY
SET RELA OFF INTO ITEMMAST
SELECT job_mast
GO (lnjob_rec) IN job_mast
IF FILE('gatepass.frx')
	= get_OPRIN('PRINT GATE PASS')
	= SEEK(JOB_MAST.CLIENT_NO,'CLIENT','CLIENT_NO')
	REPORT FORM gatepass NEXT 1 TO (OUT_FILE) NOCO
	DO out_repo 
ENDIF 
IF FILE('wgatepass.frx')
	= SEEK(JOB_MAST.CLIENT_NO,'CLIENT','CLIENT_NO')
	REPORT FORM wgatepass NEXT 1 TO prin noco 
ENDIF 
_PADVANCE = 'FORMFEED'