'DLY_ROUT - end-of-day routines at Shops; 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_Paid() $place
global     Jobs2Inv() Gds_Rcvd() $prec


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)
  p5 = 1    ' p5 = choose VIEW/PRINT 1=PRINT; 2=VIEW; 3=CHOOSE
  p6 = 1    ' p6 = nr of copies

  p4 = 1
'   case base              ' p4 = printer port to use (1,2 etc - network set to use 2=LASER; 3=LABEL)
'     when "O"
'       p4 = 2
'     when "W"
'       p4 = 2
'     otherwise
'       p4 = 1
'   end case

  x = Place_Paid()
  if x = -1
    return (-1)
  end if

  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()
'
'   x = Jobs2Inv()

  ReturnToMenu()

END MAIN


FUNCTION DailyCash()     ' show keybox() listing each shop (& ALL)
  vloadif(dpath|"cshrcvd1.vw")
  order change physical
  if areas ! upper(choice)
    while true
      x = fentrybox(" Confirm Date for Cash Summary ",8,"##\/##\/##",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
  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
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
      p1 = "cshrcvd3.dfr"
      PrintReport(p1,p2,p3,p4,p5,p6)
    else
      p1 = "cshrcvd2.dfr"
      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()


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)-1)
      $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
    else
      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_gds2.dfq" index "goods3.idx"
' ' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' '   days([Date_Received])=days(today)
' ' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
'   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 execute dictionary "dlygoods.dfs" index "dlygoods.idx"
  PrintReport(p1,p2,p3,p4,p5,p6)
END FUNCTION 'Gds_Rcvd()


FUNCTION Jobs2Inv()
' list & print jobs which have a ftg date but not yet invoiced
  vloadif(dpath|"jobs2inv.vw")
  order change key "[Branch]"
  progress(15,10," Please wait ... preparing report ",0)
  data query execute "job2inv1.dfq" index "job2inv1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Branch]=$branch
'   and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" No Jobs to Invoice ",0,0,1)
    return (0)
  end if
  data query execute "job2inv2.dfq" index "job2inv2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Fitting_Date]<>blank
'   AND
'   days([Fitting_Date])<days(today)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" No Jobs to Invoice ",0,0,1)
    return (0)
  end if

'   data query execute "dly_gds3.dfq" index "goods3.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 "job2inv3.idx" fields "[Job_Nr]" ascending
  p1 = "jobs2inv.dfr"          ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)

'   order change index "job2inv1.idx"
'   data query execute "job2inv3.dfq" index "job2inv3.idx"
' ' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' '   [Fitting_Date]=blank
' ' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
'   if cerror
'     messbox(" No Jobs w/o fitting date ",0,0,1)
'     return (0)
'   end if
'   p1 = "noftgdt1.dfr"          ' p1 = report definition ("ord_stck.dfr")
'   PrintReport(p1,p2,p3,p4,p5,p6)
END FUNCTION 'Jobs2Inv()


