'PRN_FTRS - print fitters' payments sheets for W'house Mgr to check off

external  dpath cpath vloadif() bpopdb() vunloadif() Background() fentrybox()
external  chkdate() messbox() messboxwait() progress() popuplist() messline()
external  increment() userid PrintReport()

public    ptstr dsa ftgdate datecode ftrcode psa ptval $nickname

global    x ChooseFitter() ReturnToMenu() ProcessFitter() i
global    addr ppl CheckJobs2Date() jobnr reqref p1 p2 p3 p4 p5 p6


MAIN
single-step off
  Background()
  file unload all

messboxwait(" Program not currently in use ",0,0,1)

	ReturnToMenu()

  x = CheckJobs2Date()
  if x = -1
    ReturnToMenu()
  end if

  while true
    x = popuplist(10,31,13,"Activeÿfitters ÿAllÿFittersÿ","Select by",1,0)
    if x = 0
      ppl = ptstr
      while true
        if ppl = "Activeÿfitters"
          x = ChooseFitter("v")
          if x = -1
            exit while
          end if
        else
          x = ChooseFitter("a")
          if x = -1
            exit while
          end if
        end if
      end while
    else
      ReturnToMenu()
    end if
  end while
END MAIN


FUNCTION ChooseFitter(t)
  vloadif(dpath|"ftr_list.vws")
  if t = "v"                           'active fitters
    data query execute "actv_ftr.dfq" index "actv_ftr.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Active]="YES"
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  end if
  order sort now dictionary "nickname" fields "[Nickname]" ascending
  while true
    x = bpopdb("ftr_list",5,"","[Nickname]","L8","[Fitter_Name]","L0","[Fitter_Code]",5,35,21,45,"",0)
    if x = -1
      repaint off
      vunloadif("ftr_list.vws")
      return(-1)
    else
      ftrcode   = ptstr                      'message "ptstr is:"&str(ptstr)
      $nickname = [Nickname]
      ProcessFitter()
      Background()
      vloadif(dpath|"ftr_list.vws")
    end if
  end while
  repaint off
  screen shortrestore dsa
  vunloadif("ftr_list.vws")
  return (-1)
END FUNCTION  ' ChooseFitter()


FUNCTION ReturnToMenu()
  Background()
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION ProcessFitter() 'find all unprocessed records (ie. those without docref)
local recnr jobseq ord bl m1
  Background()
  progress(15,10," Please wait .... finding records ",0)
  repaint off
  vloadif(dpath|"chkpayt1.vw")
  order change key "[FtrCode]"
  data query execute "dateout2.dfq" index "da2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [FtrCode]=ftrcode
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No records found for for"&$nickname,0,0,1)
    vloadif(dpath|"ftr_list.vws")
    return (1)
  end if
  data query execute "dateout3.dfq" index "da3.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   left([Job_Nr],1)<>"P"
'   and
'   [Itemtype]="F"
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No records found for for"&$nickname,0,0,1)
    vloadif(dpath|"ftr_list.vws")
    return (1)
  end if
  data query execute "dateout4.dfq" index "da4.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ len([Document]) = 0
'   and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No fittings to be checked for for"&$nickname,0,0,1)
    return (1)
  end if
  data query execute "dateout5.dfq" index "dateout4.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ days([[Date_Out]) >= days(ftgdate)
'   and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No fitting records for"&date2(ftgdate),0,0,1)
    return (1)
  end if
  order change physical

  vloadif(dpath|"chkpayt2.vw")
  order change index "dateout4.idx"
  order sort now dictionary "chkpayt2.idx" fields "[ViewDesc]" ascending
repaint on
repaint
single-step on


' messboxwait(" DEMO!! change printer settings @ L130 ",0,0,1)



  p1 = "chkpayt2.dfr"   ' p1 = report definition ("ord_stck.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                ' p4 = printer port to use (1,2 etc - network set to use 2=LASER; 3=LABEL)
'   p4 = 1                ' p4 = printer port to use (1,2 etc - network set to use 2=LASER; 3=LABEL)
  p5 = 1                ' p5 = choose VIEW/PRINT 1=PRINT; 2=VIEW; 3=CHOOSE
  p6 = 1                ' p6 = nr of copies
  PrintReport(p1,p2,p3,p4,p5,p6)
END FUNCTION ' ProcessFitter()


FUNCTION CheckJobs2Date()
  while true
    ftgdate = days(today) - 1
    if dayname(date2(today)) == "Monday"
      ftgdate = days(today) - 2
    end if
'     if dayname(date2(ftgdate)) == "Sunday"
'       ftgdate = days(today) + 2
'     end if
    x = fentrybox(" Date for checking Job Lists upto ",10,"##\/##\/####",date2(ftgdate))
    if x = -1
      return (-1)
    end if
    ftgdate = ptstr
    if chkdate(ftgdate,1) = -1
      messbox(" Incorrect date - re-enter ",0,0,1)
      continue while
    end if
    exit while
  end while
END FUNCTION ' CheckFitDate()
