'MR_SALES - Summary of Sales/Orders by shop, month etc

external   dpath sch scw vloadif() vunloadif() messbox() base progress()
external   cpath vkeybox() PrintReport() navrecs() progtag() fgi bgi
external   fentrybox() chkdate() popuplist() ChooseBranch() $menu
external   messboxwait() Background()

public     ptstr $shop value1 $REPORT_DATE $SHOP_NAME $MONTH_TXT $response
public     $branch ptval jobnr dsa orderdate

global     per9 per8 per7 per0 per1 $stat i ftgdate x ReturnToMenu()
global     ChooseShop() $check SelectDrs()
global     p1 p2 p3 p4 p5 p6 ChooseReportDate()


MAIN
single-step off
  quiet on
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  p2 = ""   ' p2 = title at top of choice popup ("LABEL")
  p3 = 1    ' p3 = printer to be used (1=HPIII_QC; 2=GEN_EPSN etc)
  p5 = 1    ' p5 = choose VIEW/PRINT 1=PRINT; 2=VIEW; 3=CHOOSE
'   p5 = 3    ' p5 = choose VIEW/PRINT/FILE;  1=PRINT; 2=VIEW; 3=CHOOSE
  p6 = 1    ' p6 = nr of copies

'   p4 = 1
'   vloadif(dpath|"aged_drs.vw")
'   order change key "[Job_Nr]"
'
'   ChooseReportDate()
'
'   x = ChooseShop()
'   if x = -1
'   else
'     SelectDrs()
'   end if

messboxwait(" Not yet in use ",0,0,1)

  ReturnToMenu()

END MAIN


FUNCTION ChooseReportDate()
  while true
    x = fentrybox(" Enter Date that the Report is being made upto ",10,"##\/##\/####",today)
    if x = 0
      orderdate = ptstr
      if chkdate(orderdate,1) = -1
        messbox(" Incorrect date - re-enter ",0,0,1)
        continue while
      end if
      exit while
    end if
  end while
  $report_date = date3(orderdate)
END FUNCTION ' ChooseDate()


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 ChooseShop()
  if $menu = "shop"              'message "base is:"&str(base)
    case base
      when "F"
        $SHOP = "F"
        $SHOP_NAME = "Fulham"
      when "P"
        $SHOP = "P"
        $SHOP_NAME = "Putney"
      when "R"
        $SHOP = "R"
        $SHOP_NAME = "Raynes"
      when "S"
        $SHOP = "S"
        $SHOP_NAME = "Sheen"
      when "T"
        $SHOP = "T"
        $SHOP_NAME = "Trade"
      when "W"
        $SHOP = "W"
        $SHOP_NAME = "Warehouse"
    end case
  else
    while true
      $shop_name = ChooseBranch(8,33,1)
      $shop      = upper(left($shop_name,1))
      if $shop_name = -1
        return (-1)
      end if
      screen shortrestore dsa
      vloadif(dpath|"aged_drs.vw")
      SelectDrs()
      screen clear box 1 1 sch scw 0 0 no-border
      repaint off
    end while
  end if
END FUNCTION ' ChooseShop()


FUNCTION SelectDrs()
  Background()
  $branch = $shop_name
  messbox(" Print Aged Drs list? (y/n) ",1,1,1)
  if ptstr == "y"
    Background()
    progress(15,10," Please wait ... looking for debtors ",0)
    order change key "[SalesAnalysis]"
    data query execute "mr_drs1.dfq" INDEX "first.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   days([Date_Of_Order])<=days(orderdate) and
'   [SalesAnalysis]=$shop
'   and
'   (days(today) - days([Invoice_Date]) >= value1
'   and
'   days([Invoice_Date]) > 0
'   and
'   [Balance_Due] > 0.009     ' 1p or more
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messboxwait(" No outstanding debtors at"&$shop_name|" ",0,0,1)
    else
      order sort now "aged_drs" fields "[Invoice_Date]" ascending
      screen clear box 1 1 sch scw 0 0 no-border
      PrintReport("mr_drs1.dfr","Aged Debtors",p3,p4,p5,p6)
    end if
  end if

  Background()
  messbox(" Print uninvoiced orders? (y/n) ",1,1,1)
  if ptstr == "y"
    progress(15,10," Please wait ... looking for uninvoiced orders ",0)
    order change physical
    data query execute "mr_drs2.dfq" INDEX "second.idx"   ' choose o/s balances
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   days([Invoice_Date]) = 0 and
'   days([Date_Of_Order])<=days(orderdate) and
'   [SalesAnalysis]=$shop
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messboxwait(" No uninvoiced orders for"&$shop_name|" ",0,0,1)
    else
      order sort now "aged_drs" fields "[Date_Of_Order]" ascending
      screen clear box 1 1 sch scw 0 0 no-border
      PrintReport("mr_drs2.dfr","Aged Debtors",p3,p4,p5,p6)
    end if
  end if
END FUNCTION ' SelectDrs()




