PROCEDURE PRIN_BILL

*** CHANGE DONE ON 24/04/98 FOR PRINTING MULTIPLE BILLS/SALE LETTER


PRIVATE lcOnError
lcOnError = ON('ERROR')
ON ERROR 
PRIVATE SALE_REC,RESP,LCBILL_AMT,LCBILL_AMT2,LNCREDIT_AMT,LNNET_AMT,LNDEBIT_AMT,LCREPNAM
PRIVATE LCRECPT1,LCRECPT2,LCRECPT3,LCRECPT4,LCRECPT5,LCSCHEME,LCJRECPT1,LCJRECPT2
PRIVATE LNOPBAL,LNRECPT_AMT,LNJVDRAMT,LNJVCRAMT,LCCLIENTNO,LNBALANCE,LCAGENT,LCSHORTAGENTNAME
PRIVATE LNDAYS1,LNDAYS2,LNDAYS3,LNDAYS4,LNDAYS5,LNDAYS6, ;
	LNKMS1,LNKMS2,LNKMS3,LNKMS4,LNKMS5,LNKMS6,LDDATE1,LDDATE2,LDDATE3,LDDATE4,LDDATE5,LDDATE6,LCCUSTTINNO, ;
	LCFROMBILLNO,LCTOBILLNO 

= wget_pnam("SALES INVOICE")
	
STORE 0000 TO LNDAYS1,LNDAYS2,LNDAYS3,LNDAYS4,LNDAYS5,LNDAYS6,LNKMS1,LNKMS2,LNKMS3,LNKMS4,LNKMS5,LNKMS6
STORE {} TO LDDATE1,LDDATE2,LDDATE3,LDDATE4,LDDATE5,LDDATE6
STORE SPACE(LEN(SALEMAST.BILL_NO)) TO LCFROMBILLNO,LCTOBILLNO

STORE 0.00 TO LNOPBAL,LNRECPT_AMT,LNJVDRAMT,LNJVCRAMT,LNBALANCE,LNNET_AMT
STORE ' ' TO LCRECPT1,LCRECPT2,LCRECPT3,LCRECrPT4,LCRECPT5,LCSCHEME,LCCLIENTNO,LCJRECPT1,;
	LCJRECPT2,LCAGENT,LCSHORTAGENTNAME,LCCUSTTINNO


IF ! EMPT(SALEMAST.PRININVFLG)
	RESP = 1
	DO ALERT WITH 'BILL WAS ALREADY PRINTED SUCCESSFULLY;;DO YOU WANT TO REPRINT THIS BILL ?',1,'\<NO;\<YES',RESP
	IF RESP = 1
		ON ERROR &lcOnError
		RETU .F.
	ENDIF
ENDIF 

IF ! SEEK(salemast.ref_no,'VEHICLE','REF_NO')
	DO ERR_MSG WITH 'VEHICLE INFORMATION NOT FOUND IN VEHICLE TABLE FOR ' + CHR(13) + 'REF_NO : ' + salemast.ref_no + CHR(13) + 'SALE BILL WILL NOT BE PRINTED'
	RETURN 
ENDIF
IF ! SEEK(salemast.client_no,'CLIENT','CLIENT_NO')
	DO ERR_MSG WITH 'CLIENT INFORMATION NOT FOUND IN CLIENT TABLE FOR ' + CHR(13) + 'CLIENT_NO : ' + salemast.client_no + CHR(13) + 'SALE BILL WILL NOT BE PRINTED'
	ON ERROR &lcOnError
	RETURN 
ENDIF

LCCLIENTNO = SALEMAST.CLIENT_NO
IF SEEK(LCCLIENTNO,'CLIOPBAL','CLIENT_NO')
	LNOPBAL = CLIOPBAL.OP_BAL
ENDIF  

SELE SALEMAST
LNCREDIT_AMT = CLICRAMT(CLIENT_NO)
= CLI_CR_DR_AMT(LCCLIENTNO,LNJVCRAMT,LNJVDRAMT,LNNET_AMT,LCJRECPT1,LCJRECPT2)
IF LNNET_AMT < 0
	IF 'S' $ maccess_flg
		DO err_msg WITH 'PAYMENT DUE FROM CLIENT IS : ' + CHR(13) + ALLTRIM(STR(-LNNET_AMT,10,2)) 
	ELSE 
		DO err_msg WITH 'PAYMENT DUE FROM CLIENT IS : ' + CHR(13) + ALLTRIM(STR(-LNNET_AMT,10,2)) + CHR(13) + 'YOU CAN NOT PRINT BILL'
		SELECT saleMast
		ON ERROR &lcOnError
		RETURN
	ENDIF 
ENDIF 		
SELE SALEMAST
= SEEK(SALEMAST.CLIENT_NO,'BOOKING','CLIENT_NO')
= SEEK(SALEMAST.CLIENT_NO,'CLIENT','CLIENT_NO')


IF ! EMPTY(BOOKING.SCHEME_NO)
	IF SEEK(BOOKING.SCHEME_NO,'SCHEMEMAST','SCHEME_NO')
		LCSCHEME = SCHEMEMAST.SCHEME
	ENDIF 
ENDIF 
SALE_REC = RECN()
SELECT BOOKING
IF EMPTY(BOOKING.HPA_NAME) AND ! EMPTY(BOOKING.HPA_NO)
	IF SEEK(BOOKING.HPA_NO,'HPAMAST','HPA_NO')
		REPLACE BOOKING.HPA_NAME WITH HPAMAST.HPA_NAME
	ENDIF
ENDIF
IF ! EMPTY(BOOKING.AGENT_NO)
	IF SEEK(BOOKING.AGENT_NO,'AGENT','AGENT_NO')
		LCAGENT = AGENT.AGENT
		LCSHORTAGENTNAME = AGENT.SHORTAGENT
	ENDIF 
ENDIF
SELECT SALEMAST
GO (SALE_REC)
SET ORDE TO REF_NO IN VEHICLE
LNDEBIT_AMT = SALEMAST.BASIC_AMT + SALEMAST.ST_AMT + SALEMAST.VEHAVATAMT + SALEMAST.ST_SC_AMT + SALEMAST.INSURANCE+SALEMAST.RTO_CUST +  SALEMAST.OCTROI + SALEMAST.ROAD_TAX + SALEMAST.CRTM_AMT + SALEMAST.ACCESSORY + SALEMAST.OTHER + SALEMAST.HPA_RTO + SALEMAST.OPTICALAMT + SALEMAST.SPL_NOAMT
LCBILL_AMT2 = RWRD(ABS(LNDEBIT_AMT - LNCREDIT_AMT))

&& Getting Receipt No. We have defined fined 5 variables for recipt no,date,amount,cheque no 
&& So that it can be printed if required

IF SEEK(SALEMAST.CLIENT_NO,'RECEIPT','CLIENT_NO')
	SELECT RECEIPT
	SET ORDER TO CLIENT_NO 
	PRIVATE LNI 
	LNI = 1
	SCAN REST WHILE CLIENT_NO = SALEMAST.CLIENT_NO
		DO CASE 
			CASE LNI = 1
				LCRECPT1 = '1' + SPACE(2) + RECEIPT.RECEIPT_NO + SPACE(2) + DTOC(RECEIPT.RECEIPT_DT) + SPACE(1) + STR(RECEIPT.AMOUNT,10,2) + SPACE(5) + RECEIPT.PAY_MODE
				LNRECPT_AMT = LNRECPT_AMT + RECEIPT.AMOUNT
			CASE LNI = 2
				LCRECPT2 = '2' + SPACE(2) + RECEIPT.RECEIPT_NO + SPACE(2) + DTOC(RECEIPT.RECEIPT_DT) + SPACE(1) + STR(RECEIPT.AMOUNT,10,2) + SPACE(5) + RECEIPT.PAY_MODE
				LNRECPT_AMT = LNRECPT_AMT + RECEIPT.AMOUNT
			CASE LNI = 3
				LCRECPT3 = '3' + SPACE(2) + RECEIPT.RECEIPT_NO + SPACE(2) + DTOC(RECEIPT.RECEIPT_DT) + SPACE(1) + STR(RECEIPT.AMOUNT,10,2) + SPACE(5) + RECEIPT.PAY_MODE
				LNRECPT_AMT = LNRECPT_AMT + RECEIPT.AMOUNT
			CASE LNI = 4
				LCRECPT4 = '4' + SPACE(2) + RECEIPT.RECEIPT_NO + SPACE(2) + DTOC(RECEIPT.RECEIPT_DT) + SPACE(1) + STR(RECEIPT.AMOUNT,10,2) + SPACE(5) + RECEIPT.PAY_MODE
			CASE LNI = 5
				LNRECPT_AMT = LNRECPT_AMT + RECEIPT.AMOUNT
				LCRECPT5 = '5' + SPACE(2) + RECEIPT.RECEIPT_NO + SPACE(2) + DTOC(RECEIPT.RECEIPT_DT) + SPACE(1) + STR(RECEIPT.AMOUNT,10,2) + SPACE(5) + RECEIPT.PAY_MODE
				LNRECPT_AMT = LNRECPT_AMT + RECEIPT.AMOUNT
		ENDCASE 
		LNI = LNI + 1
	ENDSCAN 
	SELECT SALEMAST
ENDIF
IF ! SEEK(SALEMAST.REF_NO,'VEHICLE','REF_NO')
	DO ERR_MSG WITH 'VEHICLE DETAIL WAS NOT FOUND WHILE PRINTING'
	RETURN .F.
ELSE 
	IF ! SEEK(VEHICLE.MODELCOLNO,'MODELCOL','MODELCOLNO')
		DO ERR_MSG WITH 'MODEL COLOUR DETAIL WAS NOT FOUND WHILE PRINTING'
		ON ERROR &lcOnError
		RETURN .F.		
	ENDIF 		
	IF ! SEEK(VEHICLE.MODEL_NO,'MODEL','MODEL_NO')
		DO ERR_MSG WITH 'MODEL DETAIL WAS NOT FOUND WHILE PRINTING'
		ON ERROR &lcOnError
		RETURN .F.		
	ENDIF 
ENDIF
IF GCVAT_FLG = 'Y'
	IF EMPTY(GCSBILNAME)
		DO PRINREPO WITH 'WVSALBILL','VSALBILL','','',1
	ELSE
		LCREPNAM = GCSBILNAME + '.FRX'
		IF LCREPNAM = '*' 
			LCREPNAM = SUBSTR(LCREPNAM,2)
			IF lcRepNam == '.FRX'	&& Name is not defined and only * is given
				lcRepNam = 'wVSalBill.frx'
			ENDIF
		ENDIF
		IF ! FILE(LCREPNAM)			
			MESSAGEBOX("PLEASE COPY REPORT FILE " + CHR(13) + LCREPNAM + "AND TRY AGAIN ...","AUTOSOFT",0+64)
		ELSE 
			IF GCSBILNAME = '*'	
				PRIVATE LCTMP_WIND,LNCOPIRS,LNSALE_REC
				LNCOPIRS = 1 
				IF ';' $ GCSBILNAME		&& Ask for Multiple copies
					LCTMP_WIND = SYS(2015)
					DEFINE WINDOW (LCTMP_WIND) FROM 0,0 TO 10,30
					ACTIVATE WINDOW (LCTMP_WIND)
					MOVE WINDOW (LCTMP_WIND) CENT
					@ 2,2 SAY 'NO OF COPIES : ' GET LNCOPIRS PICT '##' VALID LNCOPIRS <= 1
					READ 
					RELEASE WINDOWS (LCTMP_WIND)
				ENDIF
				LNSALE_REC = RECNO('SALEMAST')
				FOR I = 1 TO (LNCOPIRS)
					GO (LNSALE_REC) IN SALEMAST
					REPORT FORM (lcRepNam) NEXT 1 TO PRINTER NOCONSOLE 
					GO (LNSALE_REC) IN SALEMAST
				ENDFOR 
			ELSE 
				DO PRINREPO WITH GCSBILNAME,GCSBILNAME,'','',1
			ENDIF 
		ENDIF 			
	ENDIF
ELSE 
	IF EMPTY(GCSBILNAME)
		DO PRINREPO WITH 'WSALEBILL','SALEBILL','','',1
	ELSE
		LCREPNAM = GCSBILNAME + '.FRX'
		IF LCREPNAM = '*' 
			LCREPNAM = SUBSTR(LCREPNAM,2)
		ENDIF 
		IF ! FILE(LCREPNAM)			
			MESSAGEBOX("PLEASE COPY REPORT FILE AND TRY AGAIN ...","AUTOSOFT",0+64)
		ELSE 			
			IF GCSBILNAME = '*'			
				REPORT FORM SUBSTR(GCSBILNAME,2) NEXT 1 TO PRINTER NOCONSOLE 
			ELSE 
				DO PRINREPO WITH GCSBILNAME,GCSBILNAME,'','',1
			ENDIF 
		ENDIF 			
	ENDIF
ENDIF 
GO (SALE_REC)

IF RLOC('SALEMAST')
	IF OUT_TYP = 'PRINT (DOS)' OR OUT_TYP = 'MODIFY & PRINT' OR OUT_TYP = 'PRINT (WIN)' OR GCSBILNAME = '*'
		REPLACE SALEMAST.PRININVFLG WITH 'Y'
	ENDIF
	UNLO IN SALEMAST
ENDIF
ON ERROR &lcOnError
