'ANCLSTCK - prints out lists of Gds Recvd and Goodsout for chosen STKANCL over given period

external	dpath Background() vloadif() cpath bpopdb() messboxwait() vunloadif() X_path _SWIP_Crystal() Xreppath
external  messbox() fentrybox() chkdate() remove() popuplist() progress()

public	ptstr periodstart periodend prodcode totrecvd psa

global	x VolumeReports() ChooseDate() ReturnToMenu() ChooseAncl() prodname GdsInRpt() GdsOutRpt()
global	ShowResults() BoxText() totdespd y2 y2a y2b y2c y2d


MAIN
	single-step off
	repaint off
	Background()

	x = ChooseDate()
	if x = -1
		ReturnToMenu()
	end if

	while true
		file unload all
		x = VolumeReports()
		if x = -1
			exit while
		end if
'     exit while
	end while
  ReturnToMenu()


END MAIN


FUNCTION ReturnToMenu()
	Background()
	file unload all
	transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION ChooseAncl()
local y1
	vloadif(dpath|"products.vws")
	data query execute "chs_ancl.dfq" index "chsancl1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ [Item_Type] = "A" and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	order sort now dictionary "chsancl2.idx" fields "[Product_MRC]" ascending
	repaint off
	while true
		y1 = format(" Choose Product to List ","M30")
' 		screen print 6 36 15 1 y1
		x = bpopdb("products",6,"","[Product_MRC]","L42","[Product_Code]","L6","[Product_Code]",7,30,20,64,"",0)
		if x = 0
			exit while
		elseif x = -1
			Background()
			return (-1)
		end if
	end while
	prodcode = ptstr
	prodname = [Product_MRC]
	repaint off
     progress(15,1," Searching for"&prodname,0)
' message "prodcode is:"&str(prodcode)
' message "prodname is:"&str(prodname)
END FUNCTION ' ChooseAncl()


FUNCTION ChooseDate()
local y ld
  while true
    periodstart = right(date2(days(today)-30),10)
    x = fentrybox(" Enter Start date for report ",10,"*2#\/*2#\/*4#",periodstart)
    if x = 0
		periodstart = ptstr
	     x = chkdate(periodstart,1) 'message "x is:"&str(x)
      if x = 0
        exit while
      else
        messbox(" Incorrect date - re-enter ",0,0,1)
      end if
    else
      return (-1)
    end if
  end while
  while true
     periodend = right(date2(today),10)
     x = fentrybox(" Enter End date for report ",10,"*2#\/*2#\/*4#",periodend)
	if x = 0
		periodend = ptstr
	     if x = 0
       		exit while
	     else
       		messbox(" Incorrect date - re-enter ",0,0,1)
      end if
    else
      return (-1)
    end if
  end while
END FUNCTION 'Date()


FUNCTION GdsInRpt()
	vloadif(dpath|"anclstk1.vw")
	data query execute "chsanclI.dfq" INDEX "gdsin1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' days([Date_Received])>=days(periodstart)
' and
' days([Date_Received])<=days(periodend)
' and
' [Product_Code]=prodcode
' and
' not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	if cerror
		messboxwait(" No Receipts in this period for"&prodname|" ",0,0,1)
	     return (1)
	end if
	totrecvd=filesum([Length_Received])	'message "totrecvd is:"&str(totrecvd)
	vunloadif("X_ANCL1.vws")
	remove(X_path|"X_ANCL1.*")
	data query execute "not_del.dfq" Smart4 X_path|"X_ANCL1" fields "[Date_Received;Product_Supplier;Supplier_Code;Length_Received;datefrom;dateto]"
     progress(15,10," Searching for"&prodname,1)
END FUNCTION ' GdsInRpt()


FUNCTION GdsOutRpt()
	vloadif(dpath|"anclstk2.vw")
 	order change key "[Date_Out]"
	data query execute "chsanclO.dfq" INDEX "gdsout1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' days([Date_Out])>=days(periodstart)
' and
' days([Date_Out])<=days(periodend)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	if cerror
		messboxwait(" No Goods Out in this period for"&prodname|" ",0,0,1)
	     return (1)
	end if
	data query execute "chsanclb.dfq" INDEX "gdsout2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Product_Code]=prodcode
' and
' not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	if cerror
		messboxwait(" No Goods Out in this period for"&prodname|" ",0,0,1)
	     return (1)
	end if
	totdespd=filesum([QuantOut])	'message "totrecvd is:"&str(totrecvd)
	vunloadif("X_ANCL2.vws")
	remove(X_path|"X_ANCL2.*")
	data query execute "not_del.dfq" Smart4 X_path|"X_ANCL2" fields "[Date_Out;Product_MRC;Document;Date_Out;CPL_Ref;QuantOut]"
END FUNCTION ' GdsOutRpt()


FUNCTION VolumeReports()
while true
	x=ChooseAncl()
     if x = -1
		return (-1)
'        exit while
     end if

	GdsInRpt()

	if GdsOutRpt()=1
		exit while
	end if

	ShowResults()

end while
END FUNCTION ' VolumeReports()


FUNCTION ShowResults()
local fmt m1 m2
	fmt="L64"
'show on screen/print out
     m1="Showÿonÿscreen"
	m2="ÿÿPrintÿout"
	x=popuplist(12,39,16,m1&m2,"",1,0)
message "ptstr is:"&str(ptstr)
	if ptstr=m1
  		y2 = format("Period from"&date2(periodstart)&"to"&date2(periodend),fmt)
message "y2 is:"&str(y2)
          y2a = format(mid(prodcode&prodname,66),fmt)
message "y2a is:"&str(y2a)
        	y2b = format(left("Received:"&totrecvd,64),fmt)   'message "len(y2a) is:"&str(len(y2a))
message "y2b is:"&str(y2b)
        	y2c = format(left("Despatched:"&totrecvd,64),fmt)   'message "len(y2a) is:"&str(len(y2a))
message "y2c is:"&str(y2c)
'         	y2d = format(left("Deliver to:"&dld,66),fmt)   'message "y2d is:"&str(len(y2a))
'       col1 = 1
    end if
    if BoxText(10,7,7,73,1,5,"L",1,0,0) = 0
      wait 7
      screen shortrestore psa
    end if

' 	else
' 	 	_SWIP_Crystal(Xreppath|"X_ANCL1","P",0,1,"")
' 	 	_SWIP_Crystal(Xreppath|"X_ANCL2","P",0,1,"")
'      end if
END FUNCTION ' ShowResults()


FUNCTION BoxText(r1,c1,r2,c2,fg,bg,jst,sprn,sml,pg)
local dr a b $line fmt
  b = dr
  clear psa
message "r1 is:"&str(r1)
message "c1 is:"&str(c1)
message "r2 is:"&str(r2)
message "c2 is:"&str(c2)

  screen save r1 c1 r2 c2 psa
  screen clear box r1 c1 r2 c2 fg bg
  screen print (r1+1) c1+2 fg bg format fmt y2
  screen print (r1+2) c1+2 fg bg format fmt y2a
  screen print (r1+3) c1+2 fg bg format fmt y2c
  screen print (r1+4) c1+2 fg bg format fmt y2b
'   screen print (r1+5) c1+2 fg bg format fmt y2d
'   screen save r1 c1 r2 c2 dsa
'   redimension ptary[1]
'   ptval = a
  return (0)
END FUNCTION   'BoxText(r1,c1,r2,c2,fg,bg,ts,jst,sprn,sml,pg)

