'SAL_SUMM - sales summary

external   dpath PrintReport() sch scw vloadif() progress() progtag() fgi bgi
external   vatrate remove() makeidx() fentrybox() chkdate() messbox() cpath
external   nr8 messboxwait() dly_pstgpath vunloadif()

public     ptstr rel_date from_date chk_cb end_date strt_date
public     totsal                      ' daily sales - calc'd from data
public     sal_FG                      ' Fulham sales - calc'd from data GROSS
public     sal_PG                      ' Putney   "   - calc'd from data GROSS
public     sal_RG                      ' Raynes   "   - calc'd from data GROSS
public     sal_SG                      ' Sheen    "   - calc'd from data GROSS
public     sal_TG                      ' Trade    "   - calc'd from data GROSS
public     sal_WG                      ' W'hse    "   - calc'd from data GROSS
public     sal_YG                      ' sundry   "   - calc'd from data GROSS
public     sal_XG                      ' Clapham orders etc

global     x Sales() SelectDates()
global     ReturnToMenu() #chk #chk1

MAIN
single-step off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all

  SelectDates()

  progress(15,10," Preparing data for Sales Summary ",1)

  x = Sales()

END MAIN


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 "sal_pstg.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   days([Date_Of_Order]) <= days(end_date) and
'   days([Date_Of_Order]) >= days(strt_date)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    sal_FG = 0
    sal_PG = 0
    sal_RG = 0
    sal_SG = 0
    sal_WG = 0
    sal_TG = 0
    sal_YG = 0
    return(0)
  end if

  sal_FG = filesum([Invoice_Total],[SalesAnalysis]="F") 'message "sal_FG is:"&str(sal_FG)

  sal_PG = filesum([Invoice_Total],[SalesAnalysis]="P") 'message "sal_PG is:"&str(sal_FG)

  sal_RG = filesum([Invoice_Total],[SalesAnalysis]="R") 'message "sal_RG is:"&str(sal_RG)

  sal_SG = filesum([Invoice_Total],[SalesAnalysis]="S") 'message "sal_SG is:"&str(sal_SG)

  sal_TG = filesum([Invoice_Total],[SalesAnalysis]="T") 'message "sal_TG is:"&str(sal_TG)

  sal_WG = filesum([Invoice_Total],[SalesAnalysis]="W") 'message "sal_WG is:"&str(sal_WG)

  sal_YG = filesum([Invoice_Total],[SalesAnalysis]="Y") 'message "sal_YG is:"&str(sal_YG)

  sal_XG = filesum([Invoice_Total],[SalesAnalysis]="X") 'message "sal_XG is:"&str(sal_XG)

  totsal = sal_FG+sal_RG+sal_SG+sal_WG+sal_YG+sal_TG    'message "totsal:"&str(totsal)

  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  messboxwait(" Gross Sales from"&date2(strt_date)&"to"&date2(end_date)&"is"&currency(totsal)|"ÿ",0,1,1)

END FUNCTION ' Sales()


FUNCTION ReturnToMenu()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  clear public
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


