'NO_ftgdt - list Goods Rec'd but w/o Ftg_Date; excludes SUPPLY/DELIVERY ONLY
'           and Order Date less than 90 days old

'          list of Jobs as above BUT Goods O/S AND No FtgDAte

external   dpath vloadif() sch scw bpopdb() vunloadif() scr fgp bgp progress()
external   popuplist() PrintReport() messboxwait() messbox() addidxrec()
external   remove() makeidx() getidxrecs() progtag() fgi bgi

public     ptstr ptval $rollnr prodMRC jobnr

global     ReturnToMenu() x p1 p2 p3 p4 p5 p6 CheckInStock()
global     $type Unbooked_GoodsIn()

MAIN
single-step off
'   quiet off
  file unload all
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  p2 = "No Fitting Date" ' 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)
  p5 = 1                 ' p5 = choose VIEW/PRINT 1=PRINT; 2=VIEW; 3=CHOOSE
  p6 = 1                 ' p6 = nr of copies

  remove("stocked.idx")
  makeidx("cust_ord","stocked.idx","0",5)
  remove("notstckd.idx")
  makeidx("cust_ord","notstckd.idx","0",5)

  x = Unbooked_GoodsIn()

'   messbox(" Check for Goods NOT In AND without Fitting Date? (y/n) ",1,1,1)
'   if ptstr == "y"
'     x = Unbooked_NoGoods()
'   end if

  ReturnToMenu()                        ' unload screens

END MAIN


FUNCTION Unbooked_GoodsIn()
'select all jobs which do not have a fitting date
local i1
  progress(15,10," Please wait ... searching for items received or allocated ",0)
  vloadif(dpath|"no_ftg_A.vw")
  order change key "[Order_Status]"
  data query execute "no_ftgdt.dfq" index "x1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Order_Status] = "P"
'   and
'   [Fitting_Date] = blank
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror                               '   if none - then return
    messboxwait(" No Jobs PASSED but WITHOUT Fitting Date ",0,0,1)
    return (0)
  end if
  order sort execute dictionary "no_ftgdt.dfs" index "no_ftgdt"

  progress(15,10," Please wait ... searching for items received or allocated ",0)
  data goto record first
  for i1 = 1 to records                   ' check each job
    jobnr = [Job_Nr]                      ' message "This job to be checked"&jobnr
    progtag(fgi,bgi,jobnr&"checking"&str(record)&"out of"&str(records))

' check within last 90 days
    if (days([Date_Of_Order])+90) < days(today)
      data goto record next
      continue for
    end if

' check for supply/delivery only
    if left([Description],6) = "Supply"
      data goto record next
      continue for
    end if
    if left([Description],8) = "Delivery"
      data goto record next
      continue for
    end if
    x = CheckInStock()
    data goto record next
  end for

  getidxrecs("stocked.idx",2)
  if ptval = 0
    messboxwait(" NO jobs complete and ready to book ",0,0,1)
  else
    vloadif(dpath|"no_ftg_B.vw")
    order change index "stocked.idx"
'     order sort execute dictionary "stocked.dfs" index "no_ftgdt"
    if records > 100
      messboxwait(" WARNING! More than 100 records to print - suggest VIEW only ",0,0,1)
    end if
    screen clear box 1 1 sch scw 0 0 no-border
    p1 = "no_ftgdt.dfr"
    PrintReport(p1,p2,p3,p4,p5,p6)
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
  end if

  messbox(" Check for Goods NOT In AND without Fitting Date? (y/n) ",1,1,1)
  if ptstr == "y"
    getidxrecs("notstckd.idx",2)
    if ptval = 0
      return (0)
    else
      vloadif(dpath|"no_ftg_B.vw")
      order change index "notstckd.idx"
      if records > 100
        messboxwait(" WARNING! More than 100 records to print - suggest VIEW only ",0,0,1)
      end if
      screen clear box 1 1 sch scw 0 0 no-border
      p1 = "notstckd.dfr"    ' p1 = report definition ("ord_stck.dfr")
      PrintReport(p1,p2,p3,p4,p5,p6)
      screen clear box 1 1 sch scw 0 0 no-border
      repaint off
    end if
  end if
END FUNCTION ' Unbooked_GoodsIn()


FUNCTION CheckInStock()
' search each job for req'ns then check each req'n to check that BESPOKE &
' STOCK are in stock - all Requsn's must have RollNr
local i4
  vloadif(dpath|"cplprep2.vw")
  order change key "[Job_Nr]"
  data query execute "job_reqn.dfq" index "chk_reqn.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ QUERY is:  [Job_Nr] = jobnr                                        ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror                               '   if none - then return
    vloadif(dpath|"no_ftg_A.vw")
    return (0)
  end if

  for i4 = 1 to records  ' check in stock ie. for types BJTW RollNr <> BESPOK & types CSV <> 000/00
    $type = [Item_Type]
    if $type = "B" or $type = "J" or $type = "T" or $type = "W"
      if [RollNr] = "BESPOK"
        vloadif(dpath|"no_ftg_A.vw")
        x=addidxrec("notstckd.idx",precord,6)   ' add to list of ACTIVE jobs
        return (1)
      end if
    elseif $type = "C" or $type = "S" or $type = "V"
      if [RollNr] = "00000/00"
        vloadif(dpath|"no_ftg_A.vw")
        x=addidxrec("notstckd.idx",precord,6)   ' add to list of ACTIVE jobs
        return (1)
      end if
    end if
    data goto record next
  end for
' if exit from FOR loop, then ALL STOCK & BESPOKE in stock
  vloadif(dpath|"no_ftg_A.vw")
  x=addidxrec("stocked.idx",precord,6)   ' add to list of ACTIVE jobs
  return (0)
END FUNCTION ' CheckInStock()


FUNCTION ReturnToMenu()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  transfer "pm_menu.psl" in-memory
END FUNCTION

