'R_ABNORM - BOSSMENU item only for abnormal reports.

external   vkeybox() messbox() sch scw vloadif() dpath progress() PrintReport() Background()
external   progtag() fgi bgi vatrate remove() makeidx() fentrybox() chkdate() cpath
external   nr8 messboxwait() dly_pstgpath vunloadif()
external   X_path _SWIP_Crystal() Xreppath

public     ptstr rel_date from_date chk_cb end_date strt_date

global     x NegBal() Ftngs_OS() VATZeroRate() Timeline() BalanceRequest() DebtorsLetters()
global     Sales() SelectDates() p1 p2 p3 p4 p5 p6 #chk #chk1 InvoicingReports() OS_Bals()


MAIN
	while true
		Background()
' 		if vkeybox(13,38,"1Monies˙Due 1Timeline˙Reports 1PettyCash˙Entry 1Summarise˙PettyCash 1Fittings˙O/S 1Copy˙of˙Invoice 1VAT˙Zero˙rate","Press {Esc} to exit")=0
' 		if vkeybox(13,38,"1Monies˙Due 1Timeline˙Reports 1PettyCash˙Entry 1Summarise˙PettyCash 1Fittings˙O/S 1Copy˙of˙Invoice 1VAT˙Zero˙rate","Press {Esc} to exit")=0
		if vkeybox(13,38,"1Monies˙Due 1Bespoke˙Colours 1Timeline˙Reports 1PettyCash˙Entry 1Summarise˙PettyCash 1Fittings˙O/S 1Copy˙of˙Invoice 1VAT˙Zero˙rate","Press {Esc} to exit")=0
    			if ptstr == "t"
      			Timeline()
      			continue while

			elseif ptstr == "p"
			     execute "pcsh_ent.rf3" in-memory
			     continue while

			elseif ptstr == "c"
      			execute "despat_4.rf3" in-memory
      			continue while

    			elseif ptstr == "s"
      			execute "pcsh_prc.rf3" in-memory
      			continue while

    			elseif ptstr == "b"
      			execute "quikrept.rf3" in-memory
      			continue while

    			elseif ptstr == "m"
 				OS_Bals()
      			continue while

    			elseif ptstr == "n"
      			NegBal()
      			continue while

    			elseif ptstr == "v"
      			VATZeroRate()
      			continue while

    			elseif ptstr == "f"
      			Ftngs_OS()
      			continue while
    			end if
  		else
			x=vkeybox(8,28,"1Monies Due 1Timeline˙Reports 1PettyCash˙Entry 1Summarise˙PettyCash 1Fittings˙O/S 1Copy˙of˙Invoice 1VAT˙Zero˙rate","Press {Esc} to exit")
' message "x is:"&str(x)
    			exit while
  		end if
	end while
	transfer "pm_menu.psl" in-memory
END MAIN


FUNCTION OS_Bals()
single-step off
	Background()
  	progress(15,10," Please wait ... preparing report ",0)
  	vloadif(dpath|"cust_ord.vws")
    data query execute "posbal.dfq" index "os_bals2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŋ
' [Balance_Due]>.01
' ĀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŲ
	order sort now dictionary "osbals2.idx" fields "[Balance_Due]" descending
  	vunloadif("X_osbals.vws")
  	remove(X_path|"X_osbals.*")
'   	ClearHardSpaces()
  	data query execute "not_del.dfq" Smart4 X_path|"X_osbals" fields\
  	"[Job_Nr;CustOrd_Name;Delivery_Address_1;Invoice_Total;Balance_Due]"
  	_SWIP_Crystal(Xreppath|"X_osbals","S",0,1,"")
END FUNCTION ' OS_Bals()


FUNCTION NegBal()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  vloadif(dpath|"cust_ord.vws")
  order change physical
  progress(15,10," Please wait ... preparing report ",0)
  data query execute "neg_bal.dfq" index "x"
  PrintReport("neg_bal.dfr","",1,2,1,1)
'   print report execute "neg_bal.dfr" printer detail start 1 end 0 copies 1
  order change physical
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
END FUNCTION ' NegBal()


FUNCTION Ftngs_OS()		' list all Customer orders with o/s fittings
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  vloadif(dpath|"cust_ord.vws")
  order change physical
  progress(15,10," Please wait ... preparing report ",0)
  data query execute "ftngs_os.dfq" index "x"
  repaint on
  repaint
  PrintReport("ftngs_os.dfr","",1,2,1,1)
'   print report execute "ftngs_os.dfr" screen detail start 1 end 0 copies 1
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  order change physical
END FUNCTION 'Ftngs_OS()


FUNCTION VATZeroRate()
single-step off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  p1 = "zerorate.dfr"   ' p1 = report definition ("ord_stck.dfr")
  p2 = ""               ' p2 = title at top of choice popup ("LABEL")
  p3 = 1                ' p3 = printer to be used (1=HPIII_QC; 2=GEN_EPSN etc)
  p4 = 2                ' p4 = printer port to use (1,2 etc - network set to use 2=LASER; 3=LABEL)
  p5 = 1                ' p5 = choose VIEW/PRINT 1=PRINT; 2=VIEW; 3=CHOOSE
  p6 = 1                ' p6 = nr of copies

  SelectDates()

  progress(15,10," Preparing data for Sales Summary ",1)

  x = Sales()

  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all

END FUNCTION ' VATZeroRate()


FUNCTION SelectDates()
local mth ld

  while true
    x = fentrybox(" Enter Start Date for Sales 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
    end if
    exit while
  end while

  while true
    x = fentrybox(" Enter End Date for Sales 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
    end if
    exit while
  end while

END FUNCTION ' SelectDate()


FUNCTION Sales()
local q
  progtag(fgi,bgi," Selecting Sales Orders ")
  vloadif(dpath|"cust_ord.vws")
'   from_date = date2(filemax([Posted])+1)
'   from_date = @if(days(from_date)>=days(rel_date),rel_date,from_date)
  data query execute "sal_summ.dfq" index "z.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŋ
'   days([Date_Of_Order]) <= days(end_date) and
'   days([Date_Of_Order]) >= days(strt_date)
' ĀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŲ
  if cerror
    return(0)
  end if

  data query execute "zerorate.dfq" index "zerorate.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŋ
'   [Invoice_Total] = [Net_Invoice]
' ĀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŲ
  if cerror
    messboxwait(" No ZERO rated Sales in period from"&date2(strt_date)&"to"&date2(end_date)|"˙",0,1,1)
    return (1)
  end if

'print list
  PrintReport(p1,p2,p3,p4,p5,p6)

END FUNCTION ' Sales()


FUNCTION Timeline()
' ? print Balance Request letters
  while true
    file unload all
    if vkeybox(8,28,"1Balance˙Request˙Letters 1Invoicing˙Reports 1Debtors˙Letters 1ALL˙reports","Press {Esc} to exit") = 0
      if ptstr == "b"
        BalanceRequest()
        continue while
      elseif ptstr == "i"
        InvoicingReports()
        continue while
      elseif ptstr == "d"
        DebtorsLetters()
        continue while
      elseif ptstr == "a"
        BalanceRequest()
        InvoicingReports()
        DebtorsLetters()
        continue while
      end if
    else
      return (-1)
    end if
  end while
END FUNCTION ' Timeline()


FUNCTION BalanceRequest()
' BalanceRequest - select ALL orders > 40 days since Date_Of_Order
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  vloadif(dpath|"balreqs3.vw")
  order change physical
  progress(15,10," Please wait ... preparing report ",0)
  data query execute "bal_reqs.dfq" index "x"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŋ
' (days(today)-days([Date_Of_Order]))>40
' and
' days([Invoice_Date])=0
' and
' [Balance_Due]>.01
' and
' not (deleted)
' ĀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŲ
  if cerror
    return(0)
  end if
  order sort now dictionary "balreqs1.idx" fields "[ViewDesc;EnterDate]" ascending
  PrintReport("bal_reqs.dfr","",1,1,1,1)
END FUNCTION ' BalanceRequest()


FUNCTION InvoicingReports()
' Any order NOT invoiced which is over 1000 and over 60 days old
  vloadif(dpath|"balreqs3.vw")
  order change physical
  progress(15,10," Please wait ... preparing report ",0)
  data query execute "not_invd.dfq" index "x"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŋ
' (days(today)-days([Date_Of_Order]))>60
' and
' [Invoice_Total]>1000
' and
' days([Invoice_Date])=0
' and
' [Balance_Due]>.01
' and
' not (deleted)
' ĀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŲ
  if cerror
    return(0)
  end if
  order sort now dictionary "balreqs1.idx" fields "[ViewDesc;EnterDate]" ascending
  PrintReport("notinvd1.dfr","",1,1,1,1)

' Any order NOT invoiced under 1000 which is over 90 days
  order change physical
  progress(15,10," Please wait ... preparing report ",0)
  data query execute "notinvd1.dfq" index "x"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŋ
' (days(today)-days([Date_Of_Order]))>90
' and
' [Invoice_Total]>.01
' and
' [Invoice_Total]<1000
' and
' days([Invoice_Date])=0
' and
' [Balance_Due]>.01
' and
' not (deleted)
' ĀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŲ
  if cerror
    return(0)
  end if
'   order sort now dictionary "balreqs1.idx" fields "[Job_Nr]" ascending
  order sort now dictionary "balreqs1.idx" fields "[ViewDesc;EnterDate]" ascending
  PrintReport("notinvd2.dfr","",1,1,1,1)
END FUNCTION ' InvoicingReports()


FUNCTION DebtorsLetters()
' Debtors Letters - list of debtors
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  vloadif(dpath|"balreqs3.vw")
  order change physical
  progress(15,10," Please wait ... preparing report ",0)
  data query execute "balreqs4.dfq" index "x"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŋ
' abs([Balance_Due])>.01
' and
' days([Invoice_Date])>0
' and
' not (deleted)
' ĀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŲ
  if cerror
    return(0)
  end if
  order sort now dictionary "balreqs1.idx" fields "[ViewDesc2;DaysOld;EnterDate]" ascending
  PrintReport("os_drs.dfr","",1,1,1,1)
END FUNCTION ' DebtorsLetters()

