'FRANROUT - end-of-day routines at franchises; replaces (& includes) DLY_CASH

external   vkeybox() sch scw progress() messbox() vloadif() cpath PrintReport()
external   vunloadif() dpath fentrybox() chkdate() remove() areas greeting
external   base findpopup() Background() messboxwait() addidxrec() makeidx()

public     ptstr choice sum_date br_name psa dsa $branch

global     x DailyCash() ReturnToMenu() p1 p2 p3 p4 p5 p6 $place
global     Gds_Rcvd() $prec ChooseShop()


MAIN
single-step off
  Background()
  file unload all
  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

  ChooseShop()
  br_name = $place
  choice = left(br_name,1)             'message "choice is:"&str(choice)
  $branch = choice

  x = DailyCash()
  if x = -1
    ReturnToMenu()
  end if

  x = Gds_Rcvd()

  ReturnToMenu()

END MAIN


FUNCTION ChooseShop()
  case base
    when "P"
      choice = "P"
      $place = "Putney"

    otherwise
      messboxwait(" Shop not recognised ",0,0,1)
      return (-1)
  end case
END FUNCTION ' ChooseShop()


FUNCTION DailyCash()     ' show keybox() listing each shop (& ALL)
  vloadif(dpath|"franrcv1.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 "totcash.dfq" index "totcash2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Date_Of_Receipt] = days(sum_date) and [Branch] = choice
'   and
'   [Abbrv_M] <> "O"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messbox(" No Cash Received today ",0,0,1)
      exit function
    end if
    order sort execute dictionary "totcash.dfs" index "totcash.idx"
    p1 = "totcash.dfr"
    PrintReport(p1,p2,p3,p4,p5,p6)
  else
    messbox(greeting|", you do not have access rights for this report ",0,0,1)
  end if
  screen clear box 1 1 sch scw 0 0 no-border
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 Gds_Rcvd()
  p1 = "dly_gds1.dfr"          ' p1 = report definition ("ord_stck.dfr")
  vloadif(dpath|"dlygoods.vw")
  progress(15,10," Please wait ... preparing report ",0)
  remove("goods1.idx")
  makeidx("gds_rcvd","goods1.idx","0",1)
  data goto record last
  while true
    if days([Date_Received])=days(sum_date)
      $prec = str(precord)
      x=addidxrec("goods1.idx",$prec,7)  'message "x is:"&str(x)
      if x<>0
        messboxwait(" not added to index ",0,0,1)
      end if
    elseif (deleted)
    elseif days([Date_Received])<days(sum_date)
      exit while
    end if
    data goto record previous
  end while
  order change index "goods1.idx"
  data query execute "dly_gds1.dfq" index "goods2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Branch]=$branch
'   OR
'   [Branch]="X"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" No Goods Received to list ",0,0,1)
    return (0)
  end if

  data query execute "dly_gds3.dfq" index "goods4.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Branch]=$branch
'   OR
'   [Item_Type]="C"
'   OR
'   [Item_Type]="S"
'   OR
'   [Item_Type]="V"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" No Goods Received to list ",0,0,1)
    return (0)
  end if
  order sort now dictionary "dlygoods.idx" fields "[Order_Nr]" ascending
'   order sort execute dictionary "dlygoods.dfs" index "dlygoods.idx"
  p6 = 1    ' p6 = nr of copies
  PrintReport(p1,p2,p3,p4,p5,p6)
END FUNCTION 'Gds_Rcvd()
