FUNCTION get_it

PARAMETERS mitem_no,mitem,mbalance,mrate,mitemtype,sele_criteria,pcGodownNo

PRIVATE malias,lcbarcodeflg,lcGodownNo
STORE ' ' TO lcGodownNo
 
&& if godownNo is passed assign value to lcGodownNo
&& it may be possible that godown no is not passed
&& if it is passed, Location should be displayed from godown location

IF PARAMETERS() = 6
	lcGodownNo = ' '
ELSE
	lcGodownNo = pcGodownNo
ENDIF 

lcbarcodeflg = 'N'
malias = alia()
IF empt(mitem_no)
	mitem = ''
	RETURN  
ENDIF 

PUSH KEY 
DO assignMasterKeys 

SELECT itemmast
SET orde to item_no
mitem_no = padr(alltrim(mitem_no),len(item_no))

IF ! EMPTY(gcItemSeperator)
	if ALLTRIM(gcItemSeperator) $ mitem_no
		mitem_no = LEFT(ALLTRIM(mitem_no),AT(gcItemSeperator,mitem_no) - 1)
		mitem_no = padr(alltrim(mitem_no),len(item_no))
		lcbarcodeflg = 'Y'
	ENDIF 
ENDIF 
IF LEFT(mitem_no,1) = '*'
	mitem_no = PADR(SUBSTR(ALLTRIM(mitem_no),2),LEN(itemmast.item))
	if seek(mitem_no,'ITEMMAST','ITEM')
		IF (! itemtype $ sele_criteria) and ! empt(sele_criteria)
			DO err_beep
			DO err_beep
			DO alert with '!!! ATTENTION !!!;Item type of given Item No. is not a valid Item Type'
		ELSE 	
			IF itemmast.lock_flg = "Y"
				DO ALERT WITH "THIS ITEM IS LOCKED SO YOU CAN NOT SELECT IT.."
				SELECT (malias)
				RETURN .F.
			ENDIF
			mitem = itemmast.item
			mitem_no = itemmast.item_no
			mbalance = itemmast.balance
			mrate = itemmast.salerate
			mitemtype = itemmast.ITEMTYPE
			
			IF gcvat_flg = "Y" 
				IF EMPTY(itemmast.st_rt) AND INLIST(itemmast.itemtype,'S','C') AND (itemMast.taxFreeFlg) <> 'Y'
					DO alert WITH "Blank VAT% Found in Item Master" + CHR(13) + "Please check and try again.."
					SELECT itemmast
					BROWSE FIELDS ITEM_NO :H= 'ITEM NO.' :r,ITEM :H= 'ITEM NAME' :r,ST_RT :H= ' VAT.%' FOR EMPTY(itemmast.st_rt) AND INLIST(itemmast.itemtype,'S','C')
					RETURN .f.
				ENDIF 
			ENDIF
			IF gcaddivatflg = "Y"
				IF EMPTY(itemmast.addivatrt) AND INLIST(itemmast.itemtype,'S','C') AND (itemMast.taxFreeFlg) <> 'Y'
					DO alert WITH "Blank ADDITIONAL VAT% Found in Item Master" + CHR(13) + "Please check and try again.."
					SELECT itemmast
					BROWSE FIELDS ITEM_NO :H= 'ITEM NO.' :r,ITEM :H= 'ITEM NAME' :r,ADDIVATRT :H= 'ADDI.VAT.%'  FOR EMPTY(itemmast.addivatrt) AND INLIST(itemmast.itemtype,'S','C')
					RETURN .f.
				ENDIF 
			ENDIF
					
			SELECT (malias)
			IF lcbarcodeflg = 'Y'
				REPLACE qty WITH 0
			ENDIF 
			RETURN 
		ENDIF 	
	ELSE 
		IF  ! seek(allt(mitem_no),'ITEMMAST','ITEM')
			DO beep with 'Item Not Found !!! Press Ctrl+A to add new one',1
		ENDIF 	
	ENDIF
	SET ORDER TO item
	sele_rec = .f.
	do while not sele_rec
		private lcon_enter,lctrl_m
		lcon_enter = on('KEY','ENTER')
		lctrl_m = ON('KEY','CTRL+M')
		&& Modified on 29/04/12 by priten
		&& If godown No is passed , godown location should be displayed
		IF ! EMPTY(lcGodownNo)
			SET ORDER TO godoItem IN godown_i
			SET RELATION TO lcGodownNo + item_no INTO godown_i
		ENDIF
		if ! empt(sele_criteria)
			ON key labe enter do sele_rec
			ON KEY LABEL CTRL+M MESSAGEBOX("Pressed key has no meaning here ..","AUTOSOFT",0+64)
			IF gcmaterialissuemethod = 'WITH REQUISITION'
				BROWSE FIELDS itemmast.item :25 :r,itemmast.item_no :r :h='Item No' :17, ;
					itemmast.balance :h= 'Stock' :r,itemmast.Location,itemmast.salerate,g01Bal :h= 'G1',;
					g02Bal :h= 'G2',;
					itemmast.in_qty :h= 'IN QTY.', ;
					itemmast.out_qty :H='OUT QTY.',itemmast.salerate, ;
					itemmast.labour_rt :h='Lab Rt',itemmast.unit :r,g03Bal :h= 'G3',g04Bal :h= 'G4',g05Bal :h= 'G5',;
					g06Bal :h= 'G6',g07Bal :h= 'G7',;
					g08Bal :h= 'G8',g09Bal :h= 'G9',g10Bal :h= 'G10' ;
					wind itembr &gcview_clr ;
					NOAPPEND NODELETE   ;
					title 'Ctrl+A Add | Ctrl+S Search | Ctrl+F10 Zoom | Enter to Select Item' ;
					REST ;
					FOR  itemtype $ sele_criteria 
			ELSE
				BROWSE FIELDS itemmast.item :25 :r,itemmast.item_no :r :h='Item No' :17, ;
					itemmast.balance :h= 'Stock' :r,godown_i.gLocation,itemmast.salerate,g01Bal :h= 'G1',;
					g02Bal :h= 'G2',;
					itemmast.in_qty :h= 'IN QTY.', ;
					itemmast.out_qty :H='OUT QTY.',itemmast.salerate, ;
					itemmast.labour_rt :h='Lab Rt',itemmast.unit :r,g03Bal :h= 'G3',g04Bal :h= 'G4',g05Bal :h= 'G5',;
					g06Bal :h= 'G6',g07Bal :h= 'G7',;
					g08Bal :h= 'G8',g09Bal :h= 'G9',g10Bal :h= 'G10' ;
					wind itembr &gcview_clr ;
					NOAPPEND NODELETE   ;
					title 'Ctrl+A Add | Ctrl+S Search | Ctrl+F10 Zoom | Enter to Select Item' ;
					REST ;
					FOR  itemtype $ sele_criteria 
			ENDIF 
			ON key LABEL enter &lcon_enter			
			ON KEY LABEL ctrl+m &lctrl_m
		ELSE
			ON key LABEL enter do sele_rec	
			ON KEY LABEL CTRL+M MESSAGEBOX("Pressed key has no meaning here ..","AUTOSOFT",0+64)
			IF gcmaterialissuemethod = 'WITH REQUISITION'
				BROWSE  fiel itemmast.item :25 :r,itemmast.item_no :r :h='Item No' :17, ;
					itemmast.balance :h= 'Stock' :r,itemmast.Location,itemmast.salerate,g01Bal :h= 'G1',;
					itemmast.in_qty :h= 'IN QTY.', ;
					itemmast.out_qty :H='OUT QTY.',itemmast.unit :r,g02Bal :h= 'G2',g03Bal :h= 'G3',g04Bal :h= 'G4',;
					g05Bal :h= 'G5',g06Bal :h= 'G6',g07Bal :h= 'G7',;
					g08Bal :h= 'G8',g09Bal :h= 'G9',g10Bal :h= 'G10' ;
	 				wind itembr &gcview_clr  ;
					NOAPPEND NODELETE  ;
					TITLE  'Ctrl+A Add | Ctrl+S Search | Ctrl+F10 Zoom | Enter to Select Item' ;
					REST  
			ELSE
				BROWSE  fiel itemmast.item :25 :r,itemmast.item_no :r :h='Item No' :17, ;
					itemmast.balance :h= 'Stock' :r,godown_i.gLocation,itemmast.salerate,g01Bal :h= 'G1',;
					itemmast.in_qty :h= 'IN QTY.', ;
					itemmast.out_qty :H='OUT QTY.',itemmast.unit :r,g02Bal :h= 'G2',g03Bal :h= 'G3',g04Bal :h= 'G4',;
					g05Bal :h= 'G5',g06Bal :h= 'G6',g07Bal :h= 'G7',;
					g08Bal :h= 'G8',g09Bal :h= 'G9',g10Bal :h= 'G10' ;
	 				wind itembr &gcview_clr  ;
					NOAPPEND NODELETE  ;
					TITLE  'Ctrl+A Add | Ctrl+S Search | Ctrl+F10 Zoom | Enter to Select Item' ;
					REST  
			ENDIF		
			ON key labe enter &lcon_enter
			ON KEY LABEL ctrl+m &lctrl_m
		ENDIF 
		SET RELATION OFF INTO godown_i
		IF sele_rec
			IF itemmast.lock_flg = "Y"
				DO ALERT WITH "THIS ITEM IS LOCKED SO YOU CAN NOT SELECT IT.."
				sele (malias)
				RETURN .F.
			ENDIF
			mitem = itemmast.item
			mitem_no = itemmast.item_no
			mbalance = itemmast.balance
			mrate = itemmast.salerate
			mitemtype = itemmast.ITEMTYPE

			IF gcvat_flg = "Y" 
				IF EMPTY(itemmast.st_rt) AND INLIST(itemmast.itemtype,'S','C') AND (itemMast.taxFreeFlg) <> 'Y'
					DO alert WITH "Blank VAT% Found in Item Master" + CHR(13) + "Please check and try again.."
					SELECT itemmast
					BROWSE FIELDS ITEM_NO :H= 'ITEM NO.' :r,ITEM :H= 'ITEM NAME' :r,ST_RT :H= ' VAT.%' FOR EMPTY(itemmast.st_rt) AND INLIST(itemmast.itemtype,'S','C')
					RETURN .f.
				ENDIF 
			ENDIF
			IF gcaddivatflg = "Y"
				IF EMPTY(itemmast.addivatrt) AND INLIST(itemmast.itemtype,'S','C') AND (itemMast.taxFreeFlg) <> 'Y'
					DO alert WITH "Blank ADDITIONAL VAT% Found in Item Master" + CHR(13) + "Please check and try again.."
					SELECT ITEMMAST
					BROWSE FIELDS ITEM_NO :H= 'ITEM NO.' :r,ITEM :H= 'ITEM NAME' :r,ADDIVATRT :H= 'ADDI.VAT.%'  FOR EMPTY(itemmast.addivatrt) AND INLIST(itemmast.itemtype,'S','C')
					RETURN .f.
				ENDIF 
			ENDIF

			
			sele (malias)
		ELSE 
			private resp
			resp = 1
			do alert with "It is must to select Item;But You haven't selected any item;What Should I Do ?",1,'\<Try again;\<Cancel',resp
			if resp = 2
				mitem = ' '
				mitem_no = ' '
				mrate = 0.00
				do err_beep
				do err_beep
				sele_rec = .T.
			endif			
		endif
	ENDDO
ELSE 
	if seek(mitem_no)
		if  (! itemtype $ sele_criteria) and ! empt(sele_criteria)
			do err_beep
			do err_beep
			do alert with '!!! ATTENTION !!!;Item type of given Item No. is not a valid Item Type'
		else	
			IF itemmast.lock_flg = "Y"
				DO ALERT WITH "THIS ITEM IS LOCKED SO YOU CAN NOT SELECT IT.."
				sele (malias)
				RETURN .F.
			ENDIF
			mitem = itemmast.item
			mitem_no = itemmast.item_no
			mbalance = itemmast.balance
			mrate = itemmast.salerate
			mitemtype = itemmast.ITEMTYPE

			IF gcvat_flg = "Y" 
				IF EMPTY(itemmast.st_rt) AND INLIST(itemmast.itemtype,'S','C') AND (itemMast.taxFreeFlg) <> 'Y'
					DO alert WITH "Blank VAT% Found in Item Master" + CHR(13) + "Please check and try again.."
					SELECT itemmast
					BROWSE FIELDS ITEM_NO :H= 'ITEM NO.' :r,ITEM :H= 'ITEM NAME' :r,ST_RT :H= ' VAT.%' FOR EMPTY(itemmast.st_rt) AND INLIST(itemmast.itemtype,'S','C')
					RETURN .f.
				ENDIF 
			ENDIF
			IF gcaddivatflg = "Y"
				IF EMPTY(itemmast.addivatrt) AND INLIST(itemmast.itemtype,'S','C') AND (itemMast.taxFreeFlg) <> 'Y'
					DO alert WITH "Blank ADDITIONAL VAT% Found in Item Master" + CHR(13) + "Please check and try again.."
					SELECT ITEMMAST
					BROWSE FIELDS ITEM_NO :H= 'ITEM NO.' :r,ITEM :H= 'ITEM NAME' :r,ADDIVATRT :H= 'ADDI.VAT.%'  FOR EMPTY(itemmast.addivatrt) AND INLIST(itemmast.itemtype,'S','C')
					RETURN .f.
				ENDIF 
			ENDIF
			
			sele (malias)
			IF lcbarcodeflg = 'Y'
				REPLACE qty WITH 0
			ENDIF 
			retu
		endif	
	else
		if ! seek(allt(mitem_no))
			do beep with 'Item Not Found !!! Press Ctrl+A to add new one',1
		endif	
	ENDIF
	sele_rec = .f.
	do while not sele_rec
		private lcon_enter,lctrl_m
		lcon_enter = on('KEY','ENTER')
		lctrl_m = ON('KEY','CTRL+M')
		&& Modified on 29/04/12 by priten
		&& If godown No is passed , godown location should be displayed
		IF ! EMPTY(lcGodownNo)
			SET ORDER TO godoItem IN godown_i
			SET RELATION TO lcGodownNo + item_no INTO godown_i
		ENDIF
		IF ! empt(sele_criteria)
			ON key labe enter do sele_rec
			ON KEY LABEL CTRL+M MESSAGEBOX("Pressed key has no meaning here ..","AUTOSOFT",0+64)
			IF gcmaterialissuemethod = 'WITH REQUISITION'			
				BROWSE fiel itemmast.item_no :r :h='Item No' :17,itemmast.item :25 :r, ;
					itemmast.balance :h= 'Stock' :r,itemmast.Location,itemmast.salerate,g01Bal :h= 'G1',;
					g02Bal :h= 'G2',g03Bal :h= 'G3',g04Bal :h= 'G4',g05Bal :h= 'G5',g06Bal :h= 'G6',g07Bal :h= 'G7',;
					g08Bal :h= 'G8',g09Bal :h= 'G9',g10Bal :h= 'G10' ,;
					itemmast.in_qty :h= 'IN QTY.', ;
					itemmast.out_qty :H='OUT QTY.',itemmast.salerate, ;
					itemmast.labour_rt :h='Lab Rt',itemmast.unit :r ;
					wind itembr &gcview_clr ;
					noap node  ;
					title 'Ctrl+A Add | Ctrl+S Search | Ctrl+F10 Zoom | Enter to Select Item' ;
					rest ;
					for itemtype $ sele_criteria 
			else
				BROWSE fiel itemmast.item_no :r :h='Item No' :17,itemmast.item :25 :r, ;
					itemmast.balance :h= 'Stock' :r,godown_i.gLocation,itemmast.salerate,g01Bal :h= 'G1',;
					g02Bal :h= 'G2',g03Bal :h= 'G3',g04Bal :h= 'G4',g05Bal :h= 'G5',g06Bal :h= 'G6',g07Bal :h= 'G7',;
					g08Bal :h= 'G8',g09Bal :h= 'G9',g10Bal :h= 'G10' ,;
					itemmast.in_qty :h= 'IN QTY.', ;
					itemmast.out_qty :H='OUT QTY.',itemmast.salerate, ;
					itemmast.labour_rt :h='Lab Rt',itemmast.unit :r ;
					wind itembr &gcview_clr ;
					noap node  ;
					title 'Ctrl+A Add | Ctrl+S Search | Ctrl+F10 Zoom | Enter to Select Item' ;
					rest ;
					for itemtype $ sele_criteria 
			endif 			
			on key labe enter &lcon_enter			
			ON KEY LABEL ctrl+m &lctrl_m
		ELSE
			on key labe enter do sele_rec	
			ON KEY LABEL CTRL+M MESSAGEBOX("Pressed key has no meaning here ..","AUTOSOFT",0+64)
			IF gcmaterialissuemethod = 'WITH REQUISITION'			
				brow fiel itemmast.item_no :r :h='Item No' :17,itemmast.item :25 :r, ;
					itemmast.balance :h= 'Stock' :r,itemmast.Location,itemmast.salerate,g01Bal :h= 'G1',;
					g02Bal :h= 'G2',g03Bal :h= 'G3',g04Bal :h= 'G4',g05Bal :h= 'G5',g06Bal :h= 'G6',g07Bal :h= 'G7',;
					g08Bal :h= 'G8',g09Bal :h= 'G9',g10Bal :h= 'G10' ,;
					itemmast.in_qty :h= 'IN QTY.', ;
					itemmast.out_qty :H='OUT QTY.',itemmast.unit :r ;
					wind itembr &gcview_clr  ;
					noap node ;
					title 'Ctrl+A Add | Ctrl+S Search | Ctrl+F10 Zoom | Enter to Select Item' ;
					rest 
			else
				brow fiel itemmast.item_no :r :h='Item No' :17,itemmast.item :25 :r, ;
					itemmast.balance :h= 'Stock' :r,godown_i.gLocation,itemmast.salerate,g01Bal :h= 'G1',;
					g02Bal :h= 'G2',g03Bal :h= 'G3',g04Bal :h= 'G4',g05Bal :h= 'G5',g06Bal :h= 'G6',g07Bal :h= 'G7',;
					g08Bal :h= 'G8',g09Bal :h= 'G9',g10Bal :h= 'G10' ,;
					itemmast.in_qty :h= 'IN QTY.', ;
					itemmast.out_qty :H='OUT QTY.',itemmast.unit :r ;
					wind itembr &gcview_clr  ;
					noap node ;
					title 'Ctrl+A Add | Ctrl+S Search | Ctrl+F10 Zoom | Enter to Select Item' ;
					rest 
			endif		
			on key labe enter &lcon_enter
			ON KEY LABEL ctrl+m &lctrl_m
		ENDIF 
		SET RELATION OFF INTO godown_i		
		if sele_rec
			IF itemmast.lock_flg = "Y"
				DO ALERT WITH "THIS ITEM IS LOCKED SO YOU CAN NOT SELECT IT.."
				sele (malias)
				RETURN .F.
			ENDIF
			mitem = itemmast.item
			mitem_no = itemmast.item_no
			mbalance = itemmast.balance
			mrate = itemmast.salerate
			mitemtype = itemmast.ITEMTYPE

			IF gcvat_flg = "Y" 
				IF EMPTY(itemmast.st_rt) AND INLIST(itemmast.itemtype,'S','C') AND (itemMast.taxFreeFlg) <> 'Y'
					DO alert WITH "Blank VAT% Found in Item Master" + CHR(13) + "Please check and try again.."
					SELECT itemmast
					BROWSE FIELDS ITEM_NO :H= 'ITEM NO.' :r,ITEM :H= 'ITEM NAME' :r,ST_RT :H= ' VAT.%' FOR EMPTY(itemmast.st_rt) AND INLIST(itemmast.itemtype,'S','C')
					RETURN .f.
				ENDIF 
			ENDIF
			IF gcaddivatflg = "Y"
				IF EMPTY(itemmast.addivatrt) AND INLIST(itemmast.itemtype,'S','C') AND (itemMast.taxFreeFlg) <> 'Y'
					DO alert WITH "Blank ADDITIONAL VAT% Found in Item Master" + CHR(13) + "Please check and try again.."
					SELECT ITEMMAST
					BROWSE FIELDS ITEM_NO :H= 'ITEM NO.' :r,ITEM :H= 'ITEM NAME' :r,ADDIVATRT :H= 'ADDI.VAT.%'  FOR EMPTY(itemmast.addivatrt) AND INLIST(itemmast.itemtype,'S','C')
					RETURN .f.
				ENDIF 
			ENDIF
			
			sele (malias)
		else
			private resp
			resp = 1
			do alert with "It is must to select Item;But You haven't selected any item;What Should I Do ?",1,'\<Try again;\<Cancel',resp
			if resp = 2
				mitem = ' '
				mitem_no = ' '
				mrate = 0.00
				do err_beep
				do err_beep
				sele_rec = .T.
			endif			
		endif
	ENDDO
ENDIF 

POP KEY

sele (malias)
RETURN