'PERDREPS - reports of Cash, Orders & Sales for chosen period

external  vloadif() dpath fentrybox() chkdate() messbox() sch scw cpath findpopup() cplpath
external  PrintReport() remove() progress() Background() shopstring shoplist vatrate
external  messboxwait() vunloadif() X_path _SWIP_Crystal() Xreppath
'     x = popuplist(5,53,13,"ByÿItemtype/ProductCode ByÿAge","",1,0)

public    ptstr $title $itemtype mthname $stktype	#perdsal #perdord #perdcsh #prdare1 #prdare2
public    $shop_name $shop $key briefmonth end_date strt_date #totdrs #totuninv #total_val
public 	#stkcarp_val #bspcarp_val #stkancl_val fname fdate ftime

global    x Date() $init_title m0 m1 m2 y0 y1 i $ch_branch $init_branch	' #stkcarp_val #bspcarp_val #stkancl_val
global	PeriodCash() PeriodOrders() PeriodSales() PeriodAreas() AgedDrs() Uninvoiced()
global	Stk_Bals() StkValns() Stk_Ancls() Bsp_Bals() Stk_Lstg()


MAIN
single-step off
	Background()
  	file unload all
  	x = Date()
  	if x = -1
		Background()
	     file unload all
    		exit main
  	end if
' message "PERDREPS"
    	PeriodCash()     ' show keybox() listing each shop (& ALL)

   	PeriodOrders()

    	PeriodSales()

	PeriodAreas()

	AgedDrs()

	Uninvoiced()

	StkValns()

	Background()

' message "Cash rec'd"&str(#perdcsh)
' message "NET Orders taken"&str(#perdord)
' message "NET sales"&str(#perdsal)
' message "#total_val) is:"&str(#total_val)
' message "#bspcarp_val is:"&str(#bspcarp_val)
' message "#stkcarp_val is:"&str(#stkcarp_val)
' message "#stkancl_val is:"&str(#stkancl_val)

  	vloadif(dpath|"perdtot1.vw")
	data query execute "perdtot1.dfq" index "onlyone.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ precord=1
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    	vunloadif("Xperdtot.vws")
    	remove(X_path|"Xperdtot.*")
data query execute "not_del.dfq" Smart4 X_path|"Xperdtot" fields "[Receipt_Nr;perdsal;perdord;perdcsh;prdare1;prdare2;prdaged;prduninv;start;end;stkcarp;stkancl;bspcarp]"
    	vunloadif("Xperdtot.vws")
    	_SWIP_Crystal(Xreppath|"perdtots","S",0,1,"") ' draft report

   	messbox(" Print details? (y/n) ",1,1,1)
   	if ptstr == "y"
     		if x = 0
 	   		_SWIP_Crystal(Xreppath|"perdcsh1","S",0,1,"") ' draft report
 		  	_SWIP_Crystal(Xreppath|"perdsal1","S",0,1,"")
   			_SWIP_Crystal(Xreppath|"perdord1","S",0,1,"")
 		   	_SWIP_Crystal(Xreppath|"perdare1","S",0,1,"")
 ' 			_SWIP_Crystal(Xreppath|"perdare2","S",0,1,"")
     		elseif x = -1
      		return (-1)
     		end if
   	end if

    	Stk_Lstg()

   	file unload all

END MAIN


FUNCTION Date()
local y mth ld last_m_e
	strt_date="01"|right(date2(days(today)-30),8)		' message "strt_date) is:"&str(strt_date)
  	while true
    		x = fentrybox(" Enter START Date for Summary ",10,"##\/##\/####",strt_date)
    		if x = 0
      		strt_date = ptstr
      		if chkdate(strt_date,1) = -1
        			messbox(" Incorrect date - re-enter ",0,0,1)
        			continue while
      		end if
    		elseif x = -1
     		return (-1)
    		end if
  		mth = right(date2(strt_date),7)
  		for ld = 31 to 28 step -1
    			last_m_e = str(ld)|"/"|mth         'message "last_m_e is:"&str(last_m_e)
    			if chkdate(last_m_e,1) = -1
      			continue for
    			else
      			exit for
    			end if
  		end for
 		end_date=last_m_e
		mthname=monthname(strt_date)
		x = fentrybox(" Enter END Date for Summary ",10,"##\/##\/####",end_date)
    		if x = 0
      		end_date = ptstr
      		if chkdate(end_date,1) = -1
        			messbox(" Incorrect date - re-enter ",0,0,1)
        			continue while
      		end if
      		exit while
    		elseif x = -1
      		return (-1)
    		end if
  	end while
END FUNCTION 'Date()


FUNCTION AgedDrs()
  	Background()
    	progress(15,10," Please wait ... looking for aged debtors ",0)
	vloadif(dpath|"ageddr1.vw")
    	data query execute "perdtot2.dfq" INDEX "first.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' days([Invoice_Date])<=days(end_date) and
' not (deleted)
' and
' days([Invoice_Date]) > 0
' and
' abs([Balance_Due]) > 0.009
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    	if cerror
      	messboxwait(" No outstanding debtors at"&$shop_name|" ",0,0,1)
    	else
		#totdrs=filesum([Balance_Due])
' message "#totdrs is:"&str(#totdrs)
	end if
END FUNCTION 'AgedDrs()


FUNCTION Uninvoiced()
' 	vloadif(dpath|"ageddr1.vw")

    	progress(15,10," Please wait ... looking for uninvoiced orders ",0)
    	order change physical
    	data query execute "perdtot3.dfq" INDEX "second.idx"   ' choose o/s balances
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   days([Invoice_Date]) = 0 and
'   days([Date_Of_Order])<=days(end_date) and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	if cerror
     	messboxwait(" No uninvoiced orders for"&$shop_name|" ",0,0,1)
    	else
'       	order sort now "ageddrs5" fields "[Date_Of_Order]" ascending
'       	screen clear box 1 1 sch scw 0 0 no-border
      	vunloadif("X_mrdrs5.vws")
      	remove(X_path|"X_mrdrs5.*")
	     data query execute "not_del.dfq" Smart4 X_path|"X_mrdrs5" fields "[Job_Nr;Date_Of_Order;Customer_Name;Invoice_Total;Bal_OS;TotalCosts;Br_KA;repdate]"
		#totuninv=filesum([Invoice_Total])
' message "#totuninv is:"&str(#totuninv)
' 	     _SWIP_Crystal(Xreppath|"X_drs6","S",0,1,"")
	end if
END FUNCTION 'Uninvoiced()


FUNCTION PeriodCash()     ' show keybox() listing each shop (& ALL)
local br_dir repdate cashrep

  	vloadif(dpath|"cshrcvd1.vw")
    	progress(15,10," Please wait ... preparing report ",0)
 	data query execute "totcash4.dfq" index "preplst2"
 ' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
 ' days([Date_Of_Receipt])>=days(strt_date)
 ' and
 ' days([Date_Of_Receipt])<=days(end_date)
 ' and
 ' not (deleted)
 ' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	if cerror
		messboxwait(" No cash received in this period ",0,0,1)
		return (-1)
	end if
    	order sort execute dictionary "totcash.dfs" index "totcash.idx"
	#perdcsh=filesum([Amount_Received])
    	vunloadif("X_cshrcd.vws")
    	remove(X_path|"X_cshrcd.*")
    	data query execute "not_del.dfq" Smart4 X_path|"X_cshrcd" fields "[Customer_Code|Br_KA]"
    	vunloadif("X_cshrcd.vws")
'     	_SWIP_Crystal(Xreppath|"perdcsh1","S",0,1,"") ' draft report

    	vunloadif("cshrcvd1.vw")

END FUNCTION ' PeriodCash()


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 PeriodSales()     ' show keybox() listing each shop (& ALL)
local br_dir repdate cashrep

  	vloadif(dpath|"sal_rep3.vw")
    	progress(15,10," Please wait ... preparing report ",0)
 	data query execute "totsales.dfq" index "preplst2"
 ' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
 ' days([Invoice_Date])>=days(strt_date)
 ' and
 ' days([Invoice_Date])<=days(end_date)
 ' and
 ' not (deleted)
 ' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	if cerror
		messboxwait(" No orders invoiced in this period ",0,0,1)
		return (-1)
	end if

	#perdsal=filesum([Net_Invoice])
  	vunloadif("X_mth_s.vws")
  	remove(X_path|"X_mth_s.*")
  	data query execute "not_del.dfq" Smart4 X_path|"X_mth_s" fields\
  "[Inv_Nr;Job_Nr;Invoice_Date;CustOrd_Name;Delivery_Address_1;Net_Invoice;shop;Date_To;SalesAnalysis]"

'   	_SWIP_Crystal(Xreppath|"perdsal1","P",0,1,"")
  	vunloadif("sal_rep3.vw")

END FUNCTION ' PeriodSales()


FUNCTION PeriodOrders()     ' show keybox() listing each shop (& ALL)
local br_dir repdate cashrep
  	vloadif(dpath|"ord_rep1.vw")
  	order change key "[Var_Nr]"
    	progress(15,10," Please wait ... preparing report ",0)
 	data query execute "totordrs.dfq" index "preplst2"
 ' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
 ' days([Date])>=days(strt_date)
 ' and
 ' days([Date])<=days(end_date)
 ' and
 ' not (deleted)
 ' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	if cerror
		messboxwait(" No orders received in this period ",0,0,1)
		return (-1)
	end if
' message "vatrate is:"&str(vatrate)
  	vunloadif("X_mth_o.vws")
  	remove(X_path|"X_mth_o.*")
	#perdord=filesum([Amount_Gross])/(1+(vatrate/100))
  	data query execute "not_del.dfq" Smart4 X_path|"X_mth_o" fields "[Var_Nr;Date;CustOrd_Name;Amount_Gross;shop;Date_To;SalesAnalysis]"

'   	_SWIP_Crystal(Xreppath|"perdord1","S",0,1,"")

  	vunloadif("ord_rep1.vw")

END FUNCTION ' PeriodOrders()


FUNCTION PeriodAreas()
  	vloadif(dpath|"perdare1.vw")
    	progress(15,10," Please wait ... preparing report ",0)
 	data query execute "totares1.dfq" index "preplst2"
 ' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
 ' days([Date_Out])>=days(strt_date)
 ' and
 ' days([Date_Out])<=days(end_date)
 ' and
 ' not (deleted)
 ' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	if cerror
		messboxwait(" No GoodsOut in this period ",0,0,1)
		return (-1)
	end if

 	data query execute "perdare2.dfq" index "preplst3"
 ' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Itemtype]="C"
' or
' [Itemtype]="B"
 ' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	if cerror
		messboxwait(" No GoodsOut in this period ",0,0,1)
		return (-1)
	end if
	#prdare1=filesum([Area])

  	vunloadif("X_mth_a.vws")
  	remove(X_path|"X_mth_a.*")
  	data query execute "not_del.dfq" Smart4 X_path|"X_mth_a" fields "[Job_Nr;Product_MRC;Area;Date_Out;Itemtype]"
'    	_SWIP_Crystal(Xreppath|"perdare1","S",0,1,"")
  	vunloadif("perdare1.vw")

END FUNCTION '	PeriodAreas()


FUNCTION Stk_Bals()
'ALL undeleted records in STK_CARP.DB with positive [PhysicalBalance]
  	progress(15,10," Please wait ..... searching Stock Carpets ",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
	#stkcarp_val=filesum([Balance_Value])
' 	order change physical
END FUNCTION 'Stk_Bals()


FUNCTION StkValns()

 	Bsp_Bals()
' message "#bspcarp_val is:"&str(#bspcarp_val)
	Stk_Bals()
' message "PR L343 #stkcarp_val is:"&str(#stkcarp_val)
 	Stk_Ancls()
' message "#stkancl_val is:"&str(#stkancl_val)
	#total_val=#stkcarp_val+#stkancl_val+#bspcarp_val

END FUNCTION ' StkValns()


FUNCTION Stk_Ancls()
'ALL undeleted records in STK_ANCL.DB with positive [PhysicalBalance]
  	progress(15,10," Please wait - searching Stock Ancillaries ",0)
  	vloadif(dpath|"WIP_2.vw")
  	data query execute "WIP1.dfq" index "wip4.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'  [PhysicalBalance]>0.1 and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  	if cerror
    		messboxwait(" No Stock Ancillaries held ",0,0,1)
    		return (1)
  	end if
  	data utilities recalc-all
	#stkancl_val=filesum([Balance_Value])

END FUNCTION ' Stk_Ancls()


FUNCTION Bsp_Bals()
' ALL undeleted records in STK_BESP.DB with positive [PhysicalBalance] for which
' the CUST_ORD record has NOT been invoiced. Does not include PUTNEY/TRADE either.

  	progress(15,10," Please wait .... searching bespoke list ",0)
  	remove(dpath|"bespstk?.db")
  	remove(dpath|"bespstk?.vws")
  	vloadif(dpath|"WIP_3.vw")
  	data query execute "chk_wip7.dfq" Smart4 dpath|"bespstk1" fields\
 "[JobNr;StockOrder;PhysicalBalance;Balance_Value;Width;Unit_Cost;DateRecd;Item_Type;Product_Code;Product_MRC;Description_MRC;Location;RollNr]"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Balance_Value]>.01
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  	if cerror
    		messboxwait(" No Bespoke items in stock ",0,0,1)
    		return (1)
  	end if
  	data utilities recalc-all

  	vloadif(dpath|"bespstk3.vw") ' show
  	order change physical
  	data query execute "chk_wip2.dfq" index "WIP2.idx" ' find NOT inv'd to customer
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Inv_Nr]=blank
'   and
'   [Invoice_Total]>1
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  	if cerror
    		messboxwait(" No Bespoke items in stock ",0,0,1)
    		return (1)
  	end if
	#bspcarp_val=filesum([Balance_Value])
  	vunloadif("stk_sum3.vw")
  	vunloadif("WIP_3.vw")
END FUNCTION ' Bsp_Bals()


FUNCTION Stk_Lstg()
'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

   	messbox(" Export List of Stock Carpets for Excel? (y/n) ",1,1,1)
   	if ptstr == "y"
    		order sort now dictionary "wip_1a.idx" fields "[Item_Type;Product_MRC;Description_MRC;DateRecd]" ascending
		fdate=str(left(date2(today),2)|mid(date2(today),4,2)|right(date2(today),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)
' message "cplpath) is:"&str(cplpath)
file export 3-dbase "[Product_Code;Description_MRC;Product_MRC;RollNr;Width;Unit_Cost;PhysicalBalance;Balance_Value;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 on"&cplpath,0,1,1)
   	end if
	Background()
  	vunloadif("wip_sum1.vws")
END FUNCTION ' Stk_Lstg()

