'BSPSTCK1 - calculates & prints Bespoke Stock list of items held at Unit 19/32 WHETHER invoiced or not

external  dpath sch scw Background() vloadif() remove() X_path _SWIP_Crystal() Xreppath

external  fentrybox() chkdate() messbox() progress() vunloadif()
external  messboxwait() makeidx() addidxrec() popuplist()

public    ptstr strt_date ptval $wiptitle

global    WIP_Date() x ReturnToMenu() #total Bsp_Bals() BespokeSummaries()

' BESPOKE   cross-tab "wip_3.dfw" - file "wip_sum3" - print "wip_3.dfr"


MAIN
'(str,str,str,int,int,int)
single-step off
  	file unload all
  	Background()
  	remove(dpath|"WIP_SUM?.*")
  	remove("WIPstk_A.*")

  	while true
    		WIP_Date()
    		if x = -1
      		exit while
    		end if
		Bsp_Bals()
    		exit while
  	end while

  	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()
  while true
    x = fentrybox(" Confirm Date for oldest Bespoke Carpet to be listed ",10,"##\/##\/####","")
    if x = 0
      strt_date = ptstr
      if chkdate(strt_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 'WIP_Date()



FUNCTION Bsp_Bals()
' ALL undeleted records in STK_BESP.DB with positive [PhysicalBalance] whether or not the CUST_ORD record
'  has been invoiced - mark in the report those which have been marked as despatched (inc date).

  	progress(15,10," Please wait .... searching bespoke list ",0)
  	remove(dpath|"bespstk1.*")
'   	remove(dpath|"bespstk?.vws")
  	vloadif(dpath|"WIP_3.vw")

' SEARCH FOR ITEMS WITH A POSITIVE BALANCE IN STK_BESP.DB
     data query execute "wip1.dfq" index "WIP_invd.idx" ' find NOT inv'd to customer
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [PhysicalBalance]>0.1 and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

  	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
'   messbox(" List Bespoke Carpets in Stock but NOT invoiced? (y/n) ",1,0,1)
'   if ptstr == "y"
'     PrintInStockButInvd()
'     if cerror
'       messboxwait(" No invoiced Bespoke items in stock ",0,0,1)
'       return (1)
'     end if
'     BespokeSummaries()
'   end if

' single-step off

  	vloadif(dpath|"bespstk3.vw") ' show
message "strt_date is:"&date2(strt_date)
repaint on
repaint
single-step on
'   order change physical
	data query execute "bsp_init.dfq" index "WIP2.idx" ' find NOT inv'd to customer
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' days([DateRecd])>=days(strt_date)
' and
' [Item_Type]="B"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
   	if cerror
    		messboxwait(" No Bespoke items in stock ",0,0,1)
    		return (1)
   	end if

    	remove(X_path|"X_bsp_c.*")
    	data query execute "not_del.dfq" Smart4 X_path|"X_bsp_c" fields\
   "[JobNr;StockOrder;PhysicalBalance;Balance_Value;Width;Unit_Cost;DateRecd;Item_Type;fromdate;Product_Code;Product_MRC;Description_MRC;Location;RollNr;Inv_Nr;Invoice_Date]"

' message "create report"
    _SWIP_Crystal(Xreppath|"Xall_bsp","S",0,1,"")
'   vloadif(dpath|"bespstk3.vw") ' show
'   order change index "WIP2.idx"
'   data cross-tab execute "wip_3.dfw" Smart4 dpath|"wip_sum3"
  vunloadif("stk_sum3.vw")
  vunloadif("WIP_3.vw")
END FUNCTION ' Bsp_Bals()


FUNCTION BespokeSummaries()
'in "bespstk3.vw" index "WIP2.idx"
  order sort now dictionary "WIP_3f.idx" fields "[JobNr]" ascending
'   p6 = NrCopies()
'   p1 = "WIP_3F.dfr"        ' p1 = report definition ("ord_stck.dfr")
'   PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report
  return (0)
END FUNCTION ' BespokeSummaries()

'   remove(X_path|"X_mth_o.*")
'
'   vunloadif("X_inv_a.vws")
'   ClearHardSpaces()
'   data query execute "not_del.dfq" data-file X_path|"X_mth_o" fields\
'   "[Var_Nr;Date;CustOrd_Name;Amount_Gross;shop;Date_To;Nr_Orders;Avg_Order;Tot_Order_Net;Tot_Order_Gross]"
'   _SWIP_Crystal(Xreppath|"$inv_1","P",0,1,"")
'   _SWIP_Crystal(Xreppath|"$inv_1","EP",0,1,invpath|$nextinvnr|".pdf")
' ' '

