

FUNCTION AddReqn()
local z #deflen $wrongprod f1 f2 f3 nr_reqns nr_index
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ Show current requsn's                                              ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  upd_new = "NEW"
  vloadif(dpath|"cus_ent4.vw")
  order change key "[Job_Nr]"
  data query execute "job_reqn.dfq" index "current.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'     [Job_Nr] = jobnr
'     and
'     not(deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    makeidx("requsn","current.idx","0",1)
    order change index "current.idx"
  end
  error off
  data goto record last

  Title_A() ' show list of F numbers and await selection of Itemtype
  repaint off
  ptval=0
  while true
    tempcode="N"
    clear prodcode
    lastsuppcode=suppcode
'     clear suppcode
    clear prodMRC
    clear #unitcost
    clear $seltype
    clear $itemtype
    clear #ordwidth
    clear $backing
    clear desMRC
    clear $unit
    clear $keypress
    prodcode = ""

    x = inchar                         'message "x is:"&str(x)
    if x = 316                         ' F2 - Stock Carpet - IT = "A"
      tempcode="N"
      clear prodMRC
      clear #unitcost
      clear $seltype
      clear $itemtype
      clear #ordwidth
      clear $backing
      clear desMRC
      clear $unit
      $prodend ="A"
      ProcessChoice("stckcarp.idx")

    elseif x = 315                 ' F1 - Remnant
      tempcode="N"
      clear suppcode
      clear prodMRC
      clear #unitcost
      clear $seltype
      clear $itemtype
      clear #ordwidth
      clear $backing
      clear desMRC
      clear $unit
'       clear $keypress
      $prodend = "B"
      while true
        vloadif(dpath|"cus_ent4.vw")
        error off
        #refnr = filemax([#refnr])         'message "#refnr) is:"&str(#refnr)
        if cerror
          #refnr = 0
        end if
        refcode = jobnr|"-"|str(right("00"|str(#refnr+1),2))'
        clearvar()
        #prodrec = record
        prodcode = ptstr
        screen shortrestore dsa
        ProcessRemnant()
        vloadif(dpath|"cus_ent4.vw")
        order change index "current.idx"
        data goto record last
        Title_A()
        exit while
      end while

    elseif x = 317                 ' F3 - Bespoke Carpet - IT = "B"
      tempcode="N"
'       clear prodcode
      clear suppcode
      clear prodMRC
      clear #unitcost
      clear $seltype
      clear $itemtype
      clear #ordwidth
      clear $backing
      clear desMRC
      clear $unit
'       clear $keypress
      $prodend = "B"
      $cat = "B"
      $keypress = "F3"
      ProcessChoice("bespcarp.idx")

    elseif x = 318                ' F4 - Stock Ancl - IT = "A"
      tempcode="N"
'       clear prodcode
      clear suppcode
      clear prodMRC
      clear #unitcost
      clear $seltype
      clear $itemtype
      clear #ordwidth
      clear $backing
      clear desMRC
      clear $unit
      $prodend = "A"
      ProcessChoice("stckancl.idx")

    elseif x = 319                     ' F5 - Bespoke Ancl - IT = "J"
      tempcode="N"
'       clear prodcode
'       clear suppcode
      clear prodMRC
      clear #unitcost
      clear $seltype
      clear $itemtype
      clear #ordwidth
      clear $backing
      clear desMRC
      clear $unit
'       clear $keypress
      $prodend = "B"
      $cat = "J"
      $keypress = "F5"
      ProcessChoice("bespancl.idx")

    elseif x = 320                 ' F6 - Vinyl - IT = "V or W"
      tempcode="N"
'       clear prodcode
      clear suppcode
      clear prodMRC
      clear #unitcost
      clear $seltype
      clear $itemtype
      clear #ordwidth
      clear $backing
      clear desMRC
      clear $unit
'       clear $keypress
      $prodend = "B"
      $cat = "W"
      $keypress = "F6"
      ProcessChoice("vinyl.idx")

    elseif x = 321                     ' F7 - Tiles - IT = "S or T"
      $prodend = "B"
      $cat = "T"
'       $keypress = "F7"
'       ProcessChoice("vinyl.idx")
      while true
        tempcode="N"
'       clear prodcode
        clear suppcode
        clear prodMRC
        clear #unitcost
        clear $seltype
        clear $itemtype
        clear #ordwidth
        clear $backing
        clear desMRC
        clear $unit
'         clear $keypress
        vloadif(dpath|"cus_ent4.vw")
        error off
        #refnr = filemax([#refnr])         'message "#refnr) is:"&str(#refnr)
        if cerror
          #refnr = 0
        end if
        refcode = jobnr|"-"|str(right("00"|str(#refnr+1),2))'
        clearvar()
        vloadif(dpath|"prodsel"|$prodend|".vw")
        x = popuplist(20,59,25,"Stock Bespoke","",1,0)
        if ptstr = "Stock"
          order change index ipath|"stk_tile.idx"  ' bpop must show MRC ??????????????
        else
          $keypress = "F7"
          order change index ipath|"bsp_tile.idx"  ' bpop must show MRC ??????????????
        end if
        if prodcode = ""
          y2 = format("Enter first 4 letters of description or {Esc} to scroll","M72")
          screen print 21 5 fgp bbd y2
          x = bpopdb("prodsel"|$prodend,4,"fi","[Prod_Back]","L42","[abbrv]","L4","[Product_Code]",7,36,20,80,"",0)
        else
          data goto record record-number #prodrec
          y2 = format(" Scroll or press {F3} to search - {Esc} to leave ","M72")
          screen print 21 5 fgp bbd y2
          x = bpopdb("prodsel"|$prodend,4,"i","[Prod_Back]","L42","[abbrv]","L4","[Product_Code]",7,36,20,80,"",0)
        end if
        if x = -1
          repaint off
          vloadif(dpath|"cus_ent4.vw")
          order change index "current.idx"
          y2 = format("Select requisition type or {F10} to exit","M72")
          screen print 21 5 fgp bbd y2
          vloadif(dpath|"prodsel"|$prodend|".vw")
          exit while
        end if
        #prodrec = record
        prodcode = ptstr
        if [Note]="Y"
          CheckSupplier()
        end if
        $uos     = [Unit_Of_Sale]
        $backing = [Backing]
        screen shortrestore dsa
' message "892//$backing is:"&str($backing)
        x = Entries()
        if x = -1
          screen clear box 5 5 22 77 0 0 no-border
          screen shortrestore s_shwreq
          repaint off
          Title_C()
          continue while
        elseif x = 0
          vloadif(dpath|"cus_ent4.vw")
          order change index "current.idx"
          data goto record last
          Title_A()
          vloadif(dpath|"prodsel"|$prodend|".vw")
          continue while
        end if
      end while

    elseif x = 322                     ' F8 - Fitting - IT = "F"
'       if left(jobnr,1)="T"
'         messboxwait(" Cannot enter Fitting req'ns on Trade Orders ",0,0,1)
'         continue while
'       end if
      $prodend = "A"
      ProcessChoice("labour.idx")

    elseif x = 323                     ' F9 - reservations
      x = ConfirmReservations()
      if x = -1
        continue while
      else
        screen clear box 1 1 sch scw 0 0 no-border
        vloadif(dpath|"cus_ent4.vw")
        order change index "current.idx"
        data goto record last
        Title_A()
        continue while
      end if

    elseif x = 324                     ' F10 -
      order change physical
      vloadif(dpath|"cus_ent4.vw")
      if records > 0
        if $increqn ="Y"
          x = CheckFutureAppts()
        end if
        screen clear box 22 1 sch scw 0 0 no-border
        return (0)
      else                             ' no reqns entered OR active
        return (2)
      end if
      screen clear box 22 1 sch scw 0 0 no-border
      return (0)
    elseif x = 763                     ' {Esc}
      return (2)
    end if
  end while
  data goto record last
  return (0)
END FUNCTION ' AddReqn()
