PROCEDURE impitem

PRIVATE lctmp_file,lcitem,lcimp_billno,lctmp_wind
lcitem = ''
lctmp_file = SYS(2015)
lctmp_wind = SYS(2015)
lcimp_billno = ' '
DO ATTENTION WITH 'PLEASE SELECT DATABASE FILE FROM WHICH YOU WANT TO IMPORT' IN vfplib
lctmp_file= GETFILE('DBF')
IF EMPTY(lctmp_file)
	DO err_msg WITH 'NO DATA FILE WAS SELECTED' IN vfplib
	RETURN .F.
ELSE
	USE (lctmp_file) IN 0 ALIAS tmppurit
	SELECT tmppurit
	DEFINE WINDOW (lctmp_wind) FROM 0,0 TO 8,70
	ACTIVATE WINDOW (lctmp_wind)
	MOVE WINDOW (lctmp_wind) CENTER 
	lcimp_billno = tmppurit.invoice_no
	@ 2,2 say 'Invoice No. in Import File ' get lcimp_billno defa tmppurit.invoice_no size 1,LEN(tmppurit.invoice_no)
	READ 
	RELEASE WINDOWS (lctmp_wind)
	LOCATE FOR invoice_no = lcimp_billno
	IF FOUND() 
		GO TOP IN tmpissue
		SELECT tmppurit
		SCAN FOR ! EMPTY(part_no) AND invoice_no = lcimp_billno
			IF ! SEEK(PADR(ALLTRIM(tmppurit.part_no),LEN(itemmast.item_no)),'ITEMMAST','ITEM_NO')
				lcitem = ' '
			ELSE 
				lcitem = itemmast.item
			ENDIF 
			REPLACE tmpissue.item_no WITH tmppurit.part_no ;
				tmpissue.item WITH lcitem ;
				tmpissue.qty WITH tmppurit.qty ;
				tmpissue.rate WITH tmppurit.unit_price ;
				tmpissue.amount WITH tmppurit.qty*tmppurit.unit_price
			SKIP IN tmpissue
		ENDSCAN 
		USE IN tmppurit
		DO ok_msg WITH 'Import of Purchase Items completed Successfully'
		RETURN .T.
	ELSE 
		USE IN tmppurit
		DO err_msg WITH 'Given Invoice No. not found' + CHR(13) + 'Try again'
		RETURN .F.
	ENDIF 
ENDIF
RETURN .F.
