parameter pcjobcard_no,pcpay_mode,pddeli_dt

private lcdebit_ac,lccredit_ac,lnamount,lcsparetran,lclabourtran,lcoiltran,;
	lcpmcoiltran,lcpmclabtran,malias

store ' ' to lcdebit_ac,lccredit_ac,lcsparetran,lclabourtran,lcoiltran,;
	lcpmcoiltran,lcpmclabtran
store 0.00 to lnamount

if empt(pcjobcard_no)
	do err_beep
	do alert with '!!! ERROR !!!;Blank Job Card No. found while storing Delivery Information'
	retu
endif
if ! profseek(pcjobcard_no,'JOB_MAST','JOBCARD_NO')
	do err_beep
	do alert with '!!! ERROR !!!;Job Card No. : ' + pcjobcard_no + 'not found while storing Delivery Information'
	retu
endif
if empt(pcpay_mode)
	do err_beep
	do alert with '!!! ERROR !!!;Blank Payment mode found;while storing Delivery Information'
	retu
endif
do case
	case pcpay_mode = 'C'
		lcdebit_ac = gcworkcash_ac
	case pcpay_mode = 'R'
		lcdebit_ac = mclient_ac
	case pcpay_mode = 'R'
		lcdebit_ac = mcheque_ac
endc
if ! empt(job_mast.bill_no) and (gcworkpost = 'Y' or pcpay_mode <> 'C')
	PRIVATE lcac_no
	lcac_no = ' ' 
	IF SEEK(job_mast.client_no,'CLIENT','CLIENT_NO')
		lcac_no = client.dr_job_ac
	ENDIF 
	if job_mast.tot_spares - job_mast.sparedisc > 0
		lccredit_ac = spares_ac
		lnamount = job_mast.tot_spares - job_mast.sdisc_amt
		IF EMPTY(lcac_no)
			IF ! addtran(pddeli_dt,lcdebit_ac,lccredit_ac,lnamount,job_mast.bill_no,'','','Job Card No : ' + job_mast.jobcard_no,lcsparetran,'JBL',job_mast.client_no,'D')
				do err_beep
				do alert with '!!! ERROR !!!;There was problem in storing Spares Info....'
			ENDIF 
		ELSE 
			IF ! addtran(pddeli_dt,lcac_no,lccredit_ac,lnamount,job_mast.bill_no,'','','Job Card No : ' + job_mast.jobcard_no,lcsparetran,'JBL','','')
				do err_beep
				do alert with '!!! ERROR !!!;There was problem in storing Spares Info....'
			ENDIF 
		ENDIF 
	ENDIF 
	IF job_mast.tot_labour - job_mast.ldisc_amt + job_mast.labtaxamt > 0
		lccredit_ac = labour_ac
		lnamount = job_mast.tot_labour - job_mast.ldisc_amt + job_mast.labtaxamt
		IF EMPTY(lcac_no)
			if ! addtran(pddeli_dt,lcdebit_ac,lccredit_ac,lnamount,job_mast.bill_no,'','','Job Card No : ' + job_mast.jobcard_no,lclabourtran,'JBL',job_mast.client_no,'D')
				do err_beep
				do alert with '!!! ERROR !!!;There was problem in storing Labour Info....'
			ENDIF 
		ELSE 
			if ! addtran(pddeli_dt,lcac_no,lccredit_ac,lnamount,job_mast.bill_no,'','','Job Card No : ' + job_mast.jobcard_no,lclabourtran,'JBL','','')
				do err_beep
				do alert with '!!! ERROR !!!;There was problem in storing Labour Info....'
			ENDIF 
		ENDIF 
	ENDIF 
	IF job_mast.tot_oil > 0
		lccredit_ac = oil_ac
		lnamount = job_mast.tot_oil
		IF EMPTY(lcac_no)
			if ! addtran(pddeli_dt,lcdebit_ac,lccredit_ac,lnamount,job_mast.bill_no,'','','Job Card No : ' + job_mast.jobcard_no,lcoiltran,'JBL',job_mast.client_no,'D')
				do err_beep
				do alert with '!!! ERROR !!!;There was problem in storing Labour Info....'
			ENDIF 
		ELSE 
			IF ! addtran(pddeli_dt,lcac_no,lccredit_ac,lnamount,job_mast.bill_no,'','','Job Card No : ' + job_mast.jobcard_no,lcoiltran,'JBL','','')
				do err_beep
				do alert with '!!! ERROR !!!;There was problem in storing Labour Info....'
			ENDIF 
		ENDIF 
	ENDIF 
	IF job_mast.round_off <> 0
		IF ! EMPTY(gcroundoff_ac)
			IF EMPTY(lcac_no)
				if ! addtran(pddeli_dt,lcdebit_ac,lccredit_ac,job_mast.round_off,job_mast.bill_no,'','','Job Card No : ' + job_mast.jobcard_no,lcoiltran,'JBL',job_mast.client_no,'D')
					do err_beep
					do alert with '!!! ERROR !!!;There was problem in storing Labour Info....'
				ENDIF 
			ELSE 
				if ! addtran(pddeli_dt,lcac_no,gcroundoff_ac,job_mast.round_off,job_mast.bill_no,'','','Job Card No : ' + job_mast.jobcard_no,lcoiltran,'JBL','','')
					do err_beep
					do alert with '!!! ERROR !!!;There was problem in storing Labour Info....'
				ENDIF 
			ENDIF 
		ENDIF 
	ENDIF 
	sele job_mast
	if pcpay_mode = 'R'
		repl job_mast.amt_remain with job_mast.amt_remain + job_mast.bill_amt
	endif
endif	

if job_mast.servicetyp = 'P' 
	sele pmc_regi
	set orde to client_no desc
	if seek(job_mast.client_no,'PMC_REGI')
		lcpmcregi_no = pmc_regi.client_no
	endif
	set orde to client_no asce
	if ! empt(job_mast.pmc_labour)
		lcdebit_ac = gcpmc_ac
		lccredit_ac = gclabour_ac
		lnamount = job_mast.pmc_labour
		if ! add_tran(pddeli_dt,lcdebit_ac,lccredit_ac,lnamount,job_mast.jobcard_no,'','','Vehicle No :' + client.vehicle_no,lcpmclabtran,'JBL')
			do err_beep
			do alert with '!!! ERROR !!!;There was problem in storing Spares Info....'
		else
			do pmc_tran with lcpmclabtran,job_mast.client_no,pcjobcard_no,pddeli_dt,lnamount,'D',lccredit_ac,lcpmcregi_no
		endif
	endif			
	if ! empt(job_mast.pmc_oil) and job_mast.oil
		lcdebit_ac = gcpmc_ac
		lccredit_ac = gcoil_ac
		lnamount = job_mast.pmc_oil
		if ! add_tran(pddeli_dt,lcdebit_ac,lccredit_ac,lnamount,job_mast.jobcard_no,'','','Vehicle No :' + client.vehicle_no,lcpmcoiltran,'JBL')
			do err_beep
			do alert with '!!! ERROR !!!;There was problem in storing Spares Info....'
		else
			do pmc_tran with lcpmcoiltran,job_mast.client_no,pcjobcard_no,pddeli_dt,lnamount,'D',lccredit_ac,lcpmcregi_no
		endif
	endif			
	if job_mast.oil
		if profseek(job_mast.client_no,'CLIENT','CLIENT_NO')
			if rloc('CLIENT')
				repl client.pmcoilcnt with client.pmcoilcnt + 1
				unlo in client
			endif
		endif
	endif
endif
sele job_mast
if rloc('JOB_MAST')
	repl job_mast.status with 'D' ;
		job_mast.deli_dt with pddeli_dt ;
		job_mast.pay_mode with pcpay_mode ;
		job_mast.labourtran with lclabourtran ;
		job_mast.sparetran with lcsparetran ;
		job_mast.oiltran with lcoiltran ;
		job_mast.pmcoiltran with lcpmcoiltran ;
		job_mast.pmclabtran with lcpmclabtran 
		unlo in job_mast
	unlo in job_mast
endif

if profseek(job_mast.client_no,'CLIENT','CLIENT_NO')
	sele client
	if rloc('CLIENT')
		repl client.reminder1 with ' ' ;
			client.reminder2 with ' ' ;
			client.job_status with ' ' 
		if job_mast.SERVICETYP <> 'W'
			repl client.lstservedt with pddeli_dt ;
				client.last_kms with job_mast.kms
		endif
		unlo in client
	endif
endif
if job_mast.servicetyp = 'P'
	if profseek(job_mast.CLIENT_NO,'PMC_REGI','CLIENT_NO')
		repl pmc_regi.serviceseq with pmc_regi.serviceseq + 1
		if 	m.pmcoilseq <> 0
			repl pmc_regi.pmcoilcnt with pmc_regi.pmcoilcnt + 1
		endif
		if pmc_regi.serveseq = pmc_regi.tot_serve
			repl pmc_regi.clear_flg with 'Y'
		endif
	else
		do err_beep
		do alert with '!!! ERROR !!!;CLIENT DATA NOT FOUND IN PMC_REGI;Contact your system administrator/vendor'
	endif
endif
if inli(client.status,'P','F') and inli(job_mast.SERVICETYP,'F')
	if rloc('CLIENT')
		repl client.serviceseq with padl(ltrim(str(val(job_mast.serviceseq) )),len(client.serviceseq),'0')
		unlo in client
	endif
endif		
do case
	case client.status = 'P' and job_mast.servicetyp = 'P'
		if rloc('CLIENT')
			if val(client.pmcserveseq) >= client.tot_pmcserve
				do alert with '!!! ATTENTION !!!;All PMC Services of this client are completed;Convience him for PMC Renual;;Also as his all PMC services are completed;he would be considered as REGULAR CUSTOMER'
				repl client.pmcserveseq with 0 ;
					client.status with 'R' ;
					client.serviceseq with ' ' ;
					client.due_dt with pdDELI_DT + 45 ;
					client.exp_dt with {  /  /  } ;
					client.balance with 0
			else
				repl client.LSTSERVEDT with pdDELI_DT ;
					client.due_dt with pdDELI_DT + 45 ;
					client.exp_dt with {  /  /  }
			endif
			unlo in client
		endif
					
	case client.status = 'F' and job_mast.servicetyp = 'F'
		if val(client.serviceseq) >= client.tot_serve
			if client.adv_pmc = 'Y'
				do alert with '!!! ATTENTION !!!;This Client was ADVANCE PMC PAYER;So now he would be considered as PMC Client'
				if rloc('CLIENT')
					repl adv_pmc with ' '
					set orde to SCHEME_NO in pmcschem
					if seek(client.scheme_no,'PMCSCHEM')
						repl client.tot_serve with pmcschem.tot_serve ;
							client.serviceseq with  ' ' ;
							client.status with 'P'
					endif
					unlo in client
				endif	
			ELSE 
				do alert with '!!! ATTENTION !!!;All Company Free Services of this client are completed;Convience him for PMC'
			ENDIF 
		ELSE 
			set orde to modelcolno in modelcol
			if seek(client.modelcolno,'MODELCOL')
				private mfrm_kms,mto_kms,mfrm_days,mto_days
				store 0 to mfrm_kms,mto_kms
				store {  /  /  } to mfrm_days,mto_days
				IF !  nextfree(modelcol.model_no,client.serviceseq,mfrm_kms,mto_kms,mfrm_days,mto_days)
					DO alert with '!!! ERROR !!!;There was problem in Getting Next Free Service Info ...;So next free service due info. will not be updated'
				ELSE
					IF rloc('CLIENT')
						REPLACE client.due_dt with client.sale_dt + mfrm_days ;
							client.exp_dt with client.sale_dt + mto_days ;
							client.due_kms with mfrm_kms ;
							client.exp_kms with mto_kms
						unlo in client
					ENDIF 
				ENDIF 
			ELSE 
				DO alert with '!!! ERROR !!!;There was problem in getting MODEL COLOUR INFO.'
			ENDIF
		endif	
		if rloc('CLIENT')
			if val(client.serviceseq)  >= client.tot_serve
				do alert with '!!! ATTENTION !!!;As all the FREE Services for this clients are completed,;this client will be now treated as REGULAR SERVICE Customer'
				REPLACE client.serviceseq with ' ' ;
					client.status with 'R' ;
					client.due_dt with pdDELI_DT + 45 ;
					client.exp_dt with {  /  /  }
			ENDIF 
			unlo in client
		endif
	OTHERWISE 
		IF ! inli(job_mast.servicetyp,'A','W')
			REPLACE client.due_dt with pdDELI_DT + 45 ;
				client.exp_dt with {  /  /  }
			UNLOCK
		ENDIF
ENDCASE