function sbillcli

parameter pcclient,pcclient_no,pcclistatus

private lctmp_wind,lcalias,lcbooking_ord

lctmp_wind = sys(2015)
lcalias = alia()
PUSH KEY 
DO assignMasterKeys
IF VAL(pcclient) > 0 
	PRIVATE tmpclient_no
	tmpclient_no = PADL(ALLTRIM(pcclient),len(client.client_no),'0')
	IF SEEK(tmpclient_no,'BOOKING','CLIENT_NO')
		IF booking.status <> pcclistatus
			DO CASE 
				CASE pcclistatus = '*'		&& All Clients
					pcclient = booking.client
					pcclient_no = booking.client_no
					RETURN 
				CASE booking.status = ' '		&& Clients whose Booking is not done'
					DO attention WITH 'DC has not been prepared for this Client' + CHR(13) + 'You can not select this Client'
					RETURN .F.
				CASE booking.status = 'D'		&& Clients whose Booking is not done'
					DO attention WITH 'DC has been prepared & Bill is not prepared for this Client' + CHR(13) + 'You can not select this Client'
					RETURN .F.
				CASE booking.status = 'B'		&& Clients whose Bills have prepared'
					DO attention WITH 'Bill has been prepared for this Client' + CHR(13) + 'You can not select this Client'
					RETURN .F.
				CASE booking.status = 'C'		&& Clients whose Bills have prepared'
					DO attention WITH 'BOOKING IS CANCLED' + CHR(13) + 'You can not select this Client'
					RETURN .F.
			ENDCASE 
		ELSE
			pcclient = booking.client
			pcclient_no = booking.client_no
			RETURN 
		ENDIF 
	ENDIF 
	SELE BOOKING
	SET ORDER TO CLIENT_NO IN BOOKING
	lcbooking_ord = orde()
	SET ORDER TO BOOKING_NO IN salemast
	SET RELATION TO booking_no INTO salemast addi
	SET ORDER TO client_no IN client
	SET rela TO client_no into client addi  
	defi wind (lctmp_wind) from 15,30 to 40,130 &gcview_clr 
	on key labe enter do sele_rec

	private sele_rec
	sele_rec = .F.
	do while ! sele_rec
		on key labe enter do sele_rec
		IF GCMBFLG = "Y" and gcHoFlg <> "Y"		
			IF pcclistatus <> '*'
				set filt to status = pcclistatus
				brow fiel CLIENT_NO :R :h= 'CLIENT NO',client :r :H= 'CLIENT',salemast.dc_no :h = 'DC NO',client.chasis_no :h= 'CHASIS NO',client_no :h= 'CLI. CODE',modelcolno :r :H= 'MODELCOL',;
					booking_dt :H= 'BOOKING DT.',add1 :H= 'ADDRESS1 ';
					noap nodel nomo ;
					wind (lctmp_wind) for booking.ibranchId = giBranchId
				set filt to
			ELSE 
				brow fiel client :r :H= 'CLIENT',client_no :h= 'CLI. CODE',modelcolno :r :H= 'MODELCOL',;
					booking_dt :H= 'BOOKING DT.',add1 :H= 'ADDRESS1 ';
					noap nodel nomo ;
					wind (lctmp_wind) for booking.ibranchId = giBranchId
			ENDIF 
		ELSE
			IF pcclistatus <> '*'
				set filt to status = pcclistatus
				brow fiel CLIENT_NO :R :h= 'CLIENT NO',client :r :H= 'CLIENT',salemast.dc_no :h = 'DC NO',client.chasis_no :h= 'CHASIS NO',client_no :h= 'CLI. CODE',modelcolno :r :H= 'MODELCOL',;
					booking_dt :H= 'BOOKING DT.',add1 :H= 'ADDRESS1 ';
					noap nodel nomo ;
					wind (lctmp_wind)
				set filt to
			ELSE 
				brow fiel client :r :H= 'CLIENT',client_no :h= 'CLI. CODE',modelcolno :r :H= 'MODELCOL',;
					booking_dt :H= 'BOOKING DT.',add1 :H= 'ADDRESS1 ';
					noap nodel nomo ;
					wind (lctmp_wind)
			ENDIF 
		ENDIF
		on key labe enter 
		if sele_rec
			pcclient = booking.client
			pcclient_no = booking.client_no
		else
			private lnresp
			lnresp = 1
			do alert with 'No Client has been selected' + 'What do you want to Do ?',1,'Continue;Cancel',lnresp
			if lnresp = 2
				sele_rec = .T.
				pcclient_no = ' '
				pcclient = ' '
			ENDIF 
		ENDIF  
	ENDDO
	SET RELATION OFF INTO SALEMAST
	SET RELATION OFF INTO client
	RETURN 
ENDIF 
pcclient = PADR(ALLTRIM(pcclient),LEN(booking.client))
if seek(pcclient,'BOOKING','CLIENT')
	IF booking.status <> pcclistatus
		DO CASE 
			CASE pcclistatus = '*'		&& All Clients
			CASE pcclistatus = ' '		&& Clients whose Booking is not done'
				DO attention WITH 'DC has not been prepared for this Client' + CHR(13) + 'You can not select this Client'
				RETURN .F.
			CASE pcclistatus = 'D'		&& Clients whose Booking is not done'
				DO attention WITH 'DC has been prepared for this Client' + CHR(13) + 'You can not select this Client'
				RETURN .F.
			CASE pcclistatus = 'B'		&& Clients whose Bills have prepared'
				DO attention WITH 'Bill has been prepared for this Client' + CHR(13) + 'You can not select this Client'
				RETURN .F.
			CASE pcClientStatus = 'C'
				DO attention WITH 'Booking is already cancled'
				RETURN .F.
		ENDCASE 
	ENDIF 
	pcclient = booking.client
	pcclient_no = booking.client_no
ELSE 

ENDIF 
= seek(allt(pcclient),'BOOKING','CLIENT')
SELE BOOKING
SET ORDER TO CLIENT IN BOOKING
lcbooking_ord = orde()
SET ORDER TO BOOKING_NO IN salemast
SET RELATION TO booking_no INTO salemast addi
SET ORDER TO client_no IN client
SET rela TO client_no into client addi 
defi wind (lctmp_wind) from  15,30 to 40,130 &gcview_clr 
on key labe enter do sele_rec

private sele_rec
sele_rec = .F.
do while ! sele_rec
	on key labe enter do sele_rec
	IF GCMBFLG = "Y" and gcHoFlg <> "Y"		
		IF pcclistatus <> '*'
			set filt to status = pcclistatus
			brow fiel client :r :H= 'CLIENT',salemast.dc_no :h = 'DC NO',client.chasis_no :h= 'CHASIS NO',client_no :h= 'CLI. CODE',modelcolno :r :H= 'MODELCOL',;
				booking_dt :H= 'BOOKING DT.',add1 :H= 'ADDRESS1 ';
				noap nodel nomo ;
				wind (lctmp_wind) for booking.ibranchId = giBranchId
			set filt to
		ELSE 
			brow fiel client :r :H= 'CLIENT',client_no :h= 'CLI. CODE',modelcolno :r :H= 'MODELCOL',;
				booking_dt :H= 'BOOKING DT.',add1 :H= 'ADDRESS1 ';
				noap nodel nomo ;
				wind (lctmp_wind) for booking.ibranchId = giBranchId
		ENDIF 
	ELSE
		IF pcclistatus <> '*'
			set filt to status = pcclistatus
			brow fiel client :r :H= 'CLIENT',salemast.dc_no :h = 'DC NO',client.chasis_no :h= 'CHASIS NO',client_no :h= 'CLI. CODE',modelcolno :r :H= 'MODELCOL',;
				booking_dt :H= 'BOOKING DT.',add1 :H= 'ADDRESS1 ';
				noap nodel nomo ;
				wind (lctmp_wind)
			set filt to
		ELSE 
			brow fiel client :r :H= 'CLIENT',client_no :h= 'CLI. CODE',modelcolno :r :H= 'MODELCOL',;
				booking_dt :H= 'BOOKING DT.',add1 :H= 'ADDRESS1 ';
				noap nodel nomo ;
				wind (lctmp_wind)
		ENDIF 
	ENDIF
	
	on key labe enter 
	if sele_rec
		pcclient = booking.client
		pcclient_no = booking.client_no
	else
		private lnresp
		lnresp = 1
		do alert with 'No Client has been selected' + 'What do you want to Do ?',1,'Continue;Cancel',lnresp
		if lnresp = 2
			sele_rec = .T.
			pcclient_no = ' '
			pcclient = ' '
		ENDIF 
	ENDIF  
ENDDO 
SET RELATION OFF INTO SALEMAST
SET RELATION OFF INTO client

if ! empt(lcbooking_ord)
	set orde to (lcbooking_ord) in booking
endif 
if ! empt(lcalias)
	sele (lcalias)
endif
rele wind (lctmp_wind)
POP KEY