'M_Stkcpt   - stock balance reports for Mthly Mgrs meetings

external  dpath sch scw Background() vloadif() remove() PrintReport()
external  fentrybox() chkdate() messbox() progress() vunloadif()
external  messboxwait() makeidx() addidxrec() popuplist() X_path  _SWIP_Crystal() Xreppath

public    ptstr sum_date ptval $wiptitle

global    WIP_Date() x ReturnToMenu() Stk_Bals() #total
global    Bsp_Bals()


MAIN
single-step off
	file unload all
  	Background()

  	while true

    		WIP_Date()
    		if x = -1
      		exit while
    		end if

'     		messbox(" Print out Stock Balances? (y/n) ",1,0,1)
'     		if ptstr == "y"
	      	Stk_Bals()
'     		end if

'       	messbox(" Print out Bespoke Balances? (y/n) ",1,0,1)
'     		if ptstr == "y"
      		Bsp_Bals()
' 	     end if

    		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 Summary ",10,"##\/##\/####","")
'     if x = 0
'       sum_date = ptstr
sum_date = today
'       if chkdate(sum_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] 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

	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

	vunloadif("X_bsp_c.vws")
    	remove(X_path|"X_bsp_c.*")
	remove("E:\ALL_WORK\MRC\ACCOUNTS\Mgrs_mtg\Bespoke carpet.pdf")
	data query execute "not_del.dfq" Smart4 X_path|"X_bsp_c" fields\
"[JobNr;StockOrder;PhysicalBalance;Balance_Value;Width;Unit_Cost;DateRecd;Item_Type;Product_Code;Product_MRC;Description_MRC;Location;RollNr]"

     _SWIP_Crystal(Xreppath|"M_bspcpt","S",0,1,"")
' 	remove("E:\ALL_WORK\MRC\ACCOUNTS\Mgrs_mtg\Bespoke carpet.pdf")
     _SWIP_Crystal(Xreppath|"M_bspcpt","EP",0,1,"E:\ALL_WORK\MRC\ACCOUNTS\Mgrs_mtg\Bespoke carpet.pdf")

END FUNCTION ' Bsp_Bals()


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 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.*")
	vunloadif("X_stk_c.vws")

    	remove(X_path|"X_stk_c.*")
    	remove("E:\ALL_WORK\MRC\ACCOUNTS\Mgrs_mtg\Stock carpet.pdf")
    	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_MRC|Balance]"

     _SWIP_Crystal(Xreppath|"M_stkcpt","S",0,1,"")
     _SWIP_Crystal(Xreppath|"M_stkcpt","EP",0,1,"E:\ALL_WORK\MRC\ACCOUNTS\Mgrs_mtg\Stock carpet.pdf")

	vloadif(dpath|"WIP_1.vw")

END FUNCTION ' Stk_Bals()

' E:\ALL_WORK\MRC\ACCOUNTS\Managers' meetings

