'CARPLST4 - report showing Stock materials dispatched in chosen period. Similar to Prep Lists in
'		  CPL_PREP - for DG

external  vloadif() dpath fentrybox() chkdate() messbox() sch scw cpath
external  PrintReport() remove() progress() Background() shopstring shoplist
external  messboxwait() vunloadif()
external   X_path _SWIP_Crystal() Xreppath

public    ptstr $title $itemtype mthname $stktype
public    $shop_name $shop $key briefmonth end_date strt_date

global    x Date() $init_title m0 m1 m2 y0 y1 i
global	PreparationLists()
'     PrepareStockReport() PrepareBespokeReport()


MAIN
single-step off
	Background()
  	file unload all
  	x = Date()
  	if x = -1
		Background()
	     file unload all
    		exit main
  	end if

	PreparationLists()

   	Background()
   	file unload all
END MAIN


FUNCTION Date()
local y mth ld last_m_e
	strt_date="01"|right(date2(days(today)-60),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 PreparationLists()   '
local $datafile
	vloadif(dpath|"prepcpt1.vw")
	progress(15,10," Selecting dispatches for chosen period ",0)
 	data query execute "preplst3.dfq" index "preplst2"
 ' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
 ' days([Date_Out])>=days(strt_date)
 ' and
 ' days([Date_Out])<=days(end_date)
 ' and
 ' not (deleted)
 ' and
 ' [Document]<>""
 ' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
		if cerror
   			messboxwait(" No carpets delivered in this period ",0,0,1)
			return (-1)
		end if

	messbox(" Print list of dispatched STOCK carpet, tiles etc? (y/n) ",1,1,1)
  	if ptstr == "y"
 		$stktype="STOCK"
	  	progress(15,10," Selecting stock carpet etc. dispatches ",0)
		data query execute "ctglist1.dfq" index "list.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ [Itemtype] = "C"                                                   ³
' ³ or                                                                 ³
' ³ [Itemtype] = "S"                                                   ³
' ³ or                                                                 ³
' ³ [Itemtype] = "V"                                                   ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
		if cerror
   			messboxwait(" No carpets delivered in this period ",0,0,1)
		end if
		vunloadif("Xprpcpt1.vws")
		x=remove(X_path|"Xprpcpt1.*")				'message "x is:"&str(x)
		data query execute "not_del.dfq" Smart4 X_path|"Xprpcpt1" fields \
"[Reference_Nr;Product_Code;Product_MRC;Description_MRC;Width;Lst_Stck;Requsn_Nr;Date_Out;RollNr;QuantOut;Job_Nr;Itemtype;Cost;FtrCode;ViewDesc;Document;CPL_Ref;strtdate;enddate;stocktype]"
		_SWIP_Crystal(Xreppath|"Xprpcpt2","S",0,1,"")
	end if

	messbox(" Print list of dispatched BESPOKE carpet, tiles etc? (y/n) ",1,1,1)
  	if ptstr == "y"
 		$stktype="BESPOKE"
	  	progress(15,10," Selecting bespoke carpet etc. dispatches ",0)
		vloadif(dpath|"prepcpt1.vw")
	 	order change index "preplst2"
		data query execute "ctglist2.dfq" index "list.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ [Itemtype] = "B"                                                   ³
' ³ or                                                                 ³
' ³ [Itemtype] = "J"                                                   ³
' ³ or                                                                 ³
' ³ [Itemtype] = "T"                                                   ³
' ³ or                                                                 ³
' ³ [Itemtype] = "W"                                                   ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
		if cerror
   			messboxwait(" No carpets delivered in this period ",0,0,1)
		end if
		vunloadif("Xprpcpt1.vws")
		x=remove(X_path|"Xprpcpt1.*")				'message "x is:"&str(x)
		data query execute "not_del.dfq" Smart4 X_path|"Xprpcpt1" fields \
"[Reference_Nr;Product_Code;Product_MRC;Description_MRC;Width;Lst_Stck;Requsn_Nr;Date_Out;RollNr;QuantOut;Job_Nr;Itemtype;Cost;FtrCode;ViewDesc;Document;CPL_Ref;strtdate;enddate;stocktype]"
' "[Reference_Nr;Product_Code;Product_MRC;Description_MRC;Width;Lst_Stck;Requsn_Nr;Date_Out;RollNr;QuantOut;Job_Nr;Itemtype;Cost;FtrCode;ViewDesc;Document;CPL_Ref;strtdate;enddate]"
		_SWIP_Crystal(Xreppath|"Xprpcpt2","S",0,1,"")
  	end if

' 	vunloadif("Xprpcpt1.vws")
' 	x=remove(X_path|"Xprpcpt1.*")				'message "x is:"&str(x)
' 	data query execute "not_del.dfq" Smart4 X_path|"Xprpcpt1" fields \
' "[Reference_Nr;Product_Code;Product_MRC;Description_MRC;Width;Lst_Stck;Requsn_Nr;Date_Out;RollNr;QuantOut;Job_Nr;Itemtype;Cost;FtrCode;ViewDesc;Document;CPL_Ref;strtdate;enddate]"
' 	_SWIP_Crystal(Xreppath|"Xprpcpt2","S",0,1,"")

END FUNCTION ' PreparationLists()
