'STKLIST - produces list of Stock Carpet

external  dpath sch scw Background() vloadif() remove() PrintReport()
external  fentrybox() chkdate() messbox() progress() vunloadif() cplpath
external  messboxwait() makeidx() addidxrec() popuplist() X_path _SWIP_Crystal() Xreppath

public    ptstr sum_date ptval $wiptitle fdate fname ftime

global    WIP_Date() x ReturnToMenu() Stk_Bals() #total
' global    p1 p2 p3 p4 p5 p6 Bsp_Bals() BespokeSummaries() NrCopies() AgedStock()
' global    CheckDocRef() CheckCtgRef() InvdUndeld1() InvdUndeld2()


' STOCK   "wip_1.vw" - "stk1.dfw" - file "wip_sum1" - "wip_1.dfr"
' ANCL    "wip_2.vw" - print "wip_2.dfr"
' BESPOKE   cross-tab "wip_3.dfw" - file "wip_sum3" - print "wip_3.dfr"
' WIP       cross-tab "wip_4.dfw" - file "wip_sum4" - print "wip_4.dfr"
' PT Gds    cross-tab "wip_4.dfw" - file "wip_sum5" - print "wip_5.dfr"
' PT Rqns   cross-tab "wip_5.dfw" - file "wip_sum6" - print "wip_6.dfr"


MAIN
single-step off
' 	message "SL 1615Z"
	Background()
  	file unload all

	WIP_Date()

	Stk_Bals()

	ReturnToMenu()

END MAIN


FUNCTION ReturnToMenu()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
'   transfer cpath|"pm_menu.psl" in-memory
END FUNCTION 'ReturnToMenu()


FUNCTION WIP_Date()
	sum_date=today
END FUNCTION 'WIP_Date()


FUNCTION Stk_Bals()
'ALL undeleted records in STK_CARP.DB with positive [PhysicalBalance]
  	progress(15,10," Please wait .... searching stock list ",0)
  	vloadif(dpath|"WIP_1.vw")
  	data query execute "WIP1.dfq" index "wip0.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'  [PhysicalBalance]>0.1 and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  	if cerror
    		messboxwait(" No Stock Carpets held ",0,0,1)
    		return (1)
  	end if
  	data utilities recalc-all

  	data query execute "liststck.dfq" index "wip1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Item_Type]="C" or [Item_Type]="S" or [Item_Type]="V"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  	if cerror
    		messboxwait(" No Stock Carpets held ",0,0,1)
    		return (1)
  	end if

     order sort now dictionary "wip_1a.idx" fields "[Item_Type;Product_MRC;Description_MRC;DateRecd]" ascending
     remove("WIPstk_c.*")
     file export 3-dbase "[Product_Code;Description_MRC;Product_MRC;RollNr;Width;Unit_Cost;PhysicalBalance;Balance_Value;Location]" file "WIPstk_c"

   	messbox(" Export List of Stock Carpets for Excel? (y/n) ",1,1,1)
   	if ptstr == "y"
    		order sort now dictionary "wip_xl.idx" fields "[Item_Type;Product_MRC;Description_MRC;DateRecd]" ascending
		fdate=left(date2(today),2)|mid(date2(today),4,2)|left(time24,2)|mid(time24,4,2) ' message "fdate is:"&str(fdate)
' fname="stkcarp_list_at_"|fdate
' 		ftime=str(left(time24,2)|mid(time24,4,2))			' message "ftime) is:"&str(ftime)
' 		fname="stkcarp list on"&str(left(date2(today),2)|mid(date2(today),4,2)|right(date2(today),2))&"at"&ftime
' message "fname is:"&str(fname)
		fname=fdate|".dbf"
' message "fname is:"&str(fname)
' message "cplpath) is:"&str(cplpath)
file export 3-dbase "[Product_Code;Description_MRC;Product_MRC;RollNr;Width;ChckMeas;Unit_Cost;Balance;Location]" file cplpath|fname
' file export 3-dbase "[Product_Code;Description_MRC;Product_MRC;RollNr;Width;Unit_Cost;PhysicalBalance;Balance_Value;Location]" file cplpath|"stkcarp_list_at_"|str(left(date2(today),2)|mid(date2(today),4,2)|right(date2(today),2))
		messboxwait(" File -"&fname&"stored in"&cplpath,0,1,1)
   	end if
	Background()
  	vunloadif("wip_sum1.vws")
' x=process_create("excel.exe",fname)
' "S:\all_work\mrc\accounts\sales and order summary.xls")

	remove(X_path|"X_stk_c.*")
    	order sort now dictionary "wip_2.idx" fields "[Product_MRC;Description_MRC;DateRecd]" ascending
    	data query execute "not_del.dfq" Smart4 X_path|"X_stk_c" fields "[Product_Code|ChckMeas]"
	_SWIP_Crystal(Xreppath|"XstkcptX","S",0,1,"")

	messbox(" This is a LONG report, continue and print? (y/n) ",1,1,1)
	if ptstr == "y"
	 	_SWIP_Crystal(Xreppath|"XstkcptX","P",0,1,"")
	end if
END FUNCTION ' Stk_Bals()

