
external   vkeybox() sch scw progress() messbox() vloadif() cpath PrintReport()
external   vunloadif() dpath fentrybox() chkdate() remove() areas greeting
external   base findpopup() messboxwait() $drive Background()

public     ptstr choice sum_date br_name psa dsa #banking

global     x DailyCash() ReturnToMenu() p1 p2 p3 p4 p5 p6 Place_Paid() $place i


MAIN
single-step off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
'   screen shortrestore dsa
  p1 = "totcash.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 = 1
  p5 = 1    ' p5 = choose VIEW/PRINT 1=PRINT; 2=VIEW; 3=CHOOSE
  p6 = 1    ' p6 = nr of copies

  DailyCash()

  Background()

  ReturnToMenu()

END MAIN


FUNCTION DailyCash()     ' show keybox() listing each shop (& ALL)
local br_dir repdate cashrep
  x = Place_Paid()
  if x = -1
    return (-1)
  end if

  br_name = $place
  choice = left(br_name,1)             'message "choice is:"&str(choice)
  vloadif(dpath|"cshrcvd1.vw")
  order change physical
  if areas ! upper(choice)
    while true
      x = fentrybox(" Confirm Date for Cash Summary ",10,"##\/##\/####",today)
      if x = 0
        sum_date = ptstr
        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
    progress(15,10," Please wait ... preparing report ",0)
    data query execute "totcash1.dfq" index "totcash2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Banked]=blank and [Branch] = choice
'   and
'   [Abbrv_M] <> "O"
'   and
'   [Method_Of_Payment]<>"PDQ"
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messboxwait(" No Cash/cheques to summarise/pay in ",0,0,1)
      return (1)
    end if
    messbox(" Do you want to include CASH in this banking? (y/n) ",1,1,1)
    if ptstr == "n"
      data query execute "totcash3.dfq" index "totcash3.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Method_Of_Payment]="Cheque"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
      if cerror
        messboxwait(" No cheques to pay in ",0,0,1)
        return (1)
      end if
    end if
    #banking=filesum([Amount_Received],[Abbrv_M]="C") 'message "#banking is:"&str(#banking)
    order sort execute dictionary "totcash.dfs" index "totcash.idx"
    p1 = "totcash.dfr"
    if base="F"
      p6 = 2    ' p6 = nr of copies
    else
      p6 = 1    ' p6 = nr of copies 'message " nr of copies"
    end if
    while true
      PrintReport(p1,p2,p3,p4,p5,p6)
      messbox(" Has the Cash Summary printed correctly? (y/n) ",1,1,1)
      if ptstr == "y"                      '  store file & exit
        for i = 1 to records
          lock-record                        ' update record with inv nr & date
            [Banked]=today
          write-record
          data goto record next
        end for
        repdate = left(sum_date,2)|mid(sum_date,4,2)|right(sum_date,2) 'message "repdate) is:"&str(repdate)
        br_dir=case br_name ("Sheen","SHEEN")("Fulham","FULHAM")("HeadÿOffice","HEAD") 'message "br_dir is:"&str(br_dir)
        cashrep = $drive|":\REPORTS\BANKINGS\"|br_dir|"\"|repdate|".BNK" 'message "cashrep) is:"&str(cashrep)
        print report execute p1 disk cashrep detail start 1 end 0 copies 1
        exit while
      else
        messbox(" Abandon and print later? (y/n) ",1,1,1)
        if ptstr == "y"                      '  store file & exit
          return (-1)
        else
          continue while
        end if
      end if
    end while
  else
    messbox(greeting|", you do not have access rights for this report ",0,0,1)
  end if
  if $place = "HeadÿOffice"
    data query execute "totcash2.dfq" index "totcash3.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Type_Branch]="H"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      data query execute "onlyone.dfq" index "totcash4.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'    record = 1
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
      if cerror
'         messbox(" No Cash Received today ",0,0,1)
'         exit function
      end if
      p1 = "cshrcvd3.dfr"
      PrintReport(p1,p2,p3,p4,p5,p6)
    else
      p1 = "cshrcvd2.dfr"
      messboxwait(" Reset printer ",0,0,1)
      PrintReport(p1,p2,p3,p4,p5,p6)
    end if
  end if
  screen clear box 1 1 sch scw 0 0 no-border
' if shop selection is not included in "areas" on oldpurch.vws refuse access
' if "areas" allow 2 areas, then only one report to be done at any one time (DG excepted)
' print report listing all cash rec'd for selected shop(s)
END FUNCTION ' DailyCash()


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 Place_Paid()
local s1 s2 s3 s4 s5 s6 $locn
  $locn = case base ("R","Raynes")("S","Sheen")("F","Fulham") else "HeadÿOffice"
  s1 = "Fulham"
  s2 = "HeadÿOffice"
  s3 = "Raynes"
  s4 = "Sheen"
  while true
    x = findpopup(8,60,15,s1&s2&s3&s4,$locn,"Place",1,0)
    if x = -1
      return (-1)
    end if
    $place = ptstr                     'message "$place is:"&str($place)
    return (0)
  end while
END FUNCTION 'Place_Paid()

