PROCEDURE prin_letr


PRIVATE sale_rec,lndebit_amt,lncredit_amt,lcbill_amt2,lnnet_amt,lcShortAgent
store 0 to lndebit_amt,lncredit_amt,lnnet_amt
STORE ' ' TO lcShortAgent
if empt(salemast.letter_no)
	do err_beep
	do alert with '!!! ERROR !!!;Sale Letter has not been prepared;Prepare it first and try again'
	retu
endif
= get_oprin('SALE LETTER Printing')
SELE salemast
IF EMPT(SALEMAST.REF_NO)
	DO ERR_MSG WITH 'VEHICLE REF. NO. IS BLANK' + CHR(13) +  'SALE LETER WILL NOT BE PRINTED'
	RETU .F.
ENDIF 
IF ! SEEK(SALEMAST.REF_NO,'VEHICLE','REF_NO')
	DO ERR_MSG WITH 'VEHICLE INFORMATION NOT FOUND' + CHR(13) +  'SALE LETER WILL NOT BE PRINTED'
	RETU .F.
ENDIF
SET ORDE TO model_no IN model
SET RELA TO vehicle.model_no INTO model ADDI
SET ORDE TO modelcolno IN modelcol
SET RELA TO vehicle.modelcolno INTO modelcol ADDI
IF ! seek(salemast.client_no,'BOOKING','CLIENT_NO')
	DO err_msg WITH 'CLIENT INFO. NOT FOUND IN BOOKING INFORMATION' + CHR(13) + "SALE LETTER CAN NOT BE PRINTED"
	RETURN .F.
ENDIF
IF ! seek(salemast.client_no,'CLIENT','CLIENT_NO')
	DO err_msg WITH 'CLIENT INFO. NOT FOUND IN CLIENT MASTER' + CHR(13) + "SALE LETTER CAN NOT BE PRINTED"
	RETURN .F.
ENDIF
IF ! EMPTY(booking.agent_no)
	IF SEEK(booking.agent_no,'agent','agent_no')
		lcShortAgent = agent.shortagent
	ELSE 
		DO err_msg WITH 'AGENT/NETWORK INFORMATION WAS NOT WAS FOUND'
	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
SELECT salemast
GO (sale_rec)
lndebit_amt = (salemast.basic_amt - salemast.disc_rs) + salemast.st_amt + 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
lncredit_amt = clicramt(client_no)
lcbill_amt2 = rupeewrd(abs(lndebit_amt - lncredit_amt))
lnnet_amt = lndebit_amt - lncredit_amt

IF lnnet_amt > 0
	IF ! "S" $ MACCESS_FLG
		do alert with "PAYMENT DUE FROM CUSTOMER IS RS. : " + ALLT(STR(lnnet_amt,12,2)) + CHR(13) + " SO SALE LETTER CAN NOT BE PRINTED "
		RETU .F.
	ELSE 
		do alert with "PAYMENT DUE FROM CUSTOMER IS RS. : " + ALLT(STR(lnnet_amt,12,2))
	ENDIF
ENDIF

if empt(salemast.letter_dt)
	ldletter_dt = date()
else
	ldletter_dt = salemast.letter_dt
endif
DEFI WIND prin_letr FROM 0,0 TO 7,60 PANEL
ACTI WIND prin_letr
MOVE WIND prin_letr CENT
@ 2,3 SAY '      Sale Letter No : ' GET salemast.letter_no
@ 4,3 SAY 'New Sale Letter Date : ' GET ldletter_dt VALID valid_dt(ldletter_dt) AND ldletter_dt >= bill_dt DEFA DATE()
READ
RELE WIND prin_letr
IF RLOC('SALEMAST')
	REPL letter_dt WITH ldletter_dt
	UNLO IN salemast
ENDIF
IF print_flg = 'Y'
	IF GcSalLetrFlg <> 'Y' AND ! ('S' $ maccess_flg)
		DO alert WITH '!!! ATTENTION !!!;Sale Letter No : ' + letter_no + ' has already been printed'
		SET RELA OFF INTO model
		SET RELA OFF INTO modelcol
		RETURN .f.
	ENDIF 	
	PRIVATE lnresp
	lnresp = 1
	DO alert WITH '!!! ATTENTION !!!;Sale Letter No : ' + letter_no + ' has already been printed;Continue any way ?',1,'\<No;\<Yes',lnresp
	IF lnresp = 1
		SET RELA OFF INTO model
		SET RELA OFF INTO modelcol
		RETU
	ENDIF
ENDIF
IF EMPTY(gcsletrnam)
	DO prinrepo WITH 'WSALELET','SALELETR','','',1
ELSE
   PRIVATE lcrepnam
   STORE '' TO lcrepnam
		lcrepnam = gcsletrnam + '.FRX'
		IF ! FILE(lcrepnam)			
			MESSAGEBOX("Please copy REPORT file and try again ...","AUTOSOFT",0+64)
		ELSE 			
			DO prinrepo WITH '',gcsletrnam,'','',1
		ENDIF 			
endif
SET RELA OFF INTO model
SET RELA OFF INTO modelcol
IF RLOC('SALEMAST')
	REPL salemast.print_flg WITH 'Y'
	UNLO IN salemast
ENDIF

