'CHK_ORDR - check for stock on order

external  dpath vloadif() Background() cpath ipath fgp bbd bpopdb() sch scw
external  entryline() messline() bgp strcount() delstr() colpopup()
external  findcolpop() progress() messbox()

public    ptstr ptval dsa prodcode

global    x ChooseItemType() Title_A() ReturnToMenu() y2 #prodrec i
global    ShowOrders() keyf keyb #ordwidth y Chk_Unalloc()
global    maxwidth #nritems strtrow upd_new $popstr prodMRC strtcol $popcol
global    #bline y1 y3


MAIN
single-step off
  Background()
  file unload all
  keyf = 7
  keyb = 0

  while true
    x = ChooseItemType()
    if x = -1
      exit while
    else
      ShowOrders()
    end if
  end while

  ReturnToMenu()

END MAIN


FUNCTION ShowOrders()
  Background()
  repaint off
  prodMRC = [Product_MRC]
  while true
    progress(15,10," Finding O/S orders for"&prodMRC|" ",0)
    vloadif(dpath|"purchord.vws")
    order change key "[Product_Code]"
    data query execute "uniqcode.dfq" index "x.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Product_Code] = prodcode
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messbox(" No outstanding orders for"&prodMRC,0,0,1)
      screen clear box 1 1 sch scw 0 0 no-border
      return (1)
    else
      data query execute "chk_ordr.dfq" index "chk_ordr.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Order_Status] = "P"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
      if cerror
        messbox(" No outstanding orders for"&prodMRC,0,0,1)
        screen clear box 1 1 sch scw 0 0 no-border
        return (1)
      else
        while true
          screen clear box 1 1 sch scw 0 0 no-border
          repaint off
          vloadif(dpath|"chk_ordr.vw")
          order change index "chk_ordr.idx"
          if records > 12
            #bline = 22
          else
            #bline = 10 + records
          end if
          y1 = format("Deliveries awaited for"&prodMRC,"M78")
          y2 = format(" (* = incomplete order) - {Esc} to quit ","M80")
          y3 = format("  ÿÿDate   Product                    Colour        Length  Width Delivery","L80")
          screen clear box 4 1 6 scw 15 1
          screen print 5 2 fgp bgp y1
          screen print 7 1 fgp bgp y3
          screen print #bline 1 fgp bgp y2
          vloadif(dpath|"chk_ordr.vw")
          x = bpopdb("chk_ordr",6,"","[Search_Supplier]","L78","[Supplier_Code]","L6","[Order_Nr]",8,1,21,80,"",0)
          if x = 0
            Chk_Unalloc()
          elseif x = -1
            screen clear box 1 1 sch scw 0 0 no-border
            repaint off
            order change physical
            return (1)
          end if
        end while
      end if
      screen clear box 1 1 sch scw 0 0 no-border
      repaint off
    end if
  end while
END FUNCTION '  ShowOrders()



FUNCTION ReturnToMenu()
  Background()
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION ChooseItemType()
local z #deflen $wrongprod f1 f2 f3 nr_reqns nr_index
  Title_A()
  repaint off
  ptval=0
  while true
    prodcode = ""
    x = inchar                         'message "x is:"&str(x)
    if x = 316                     ' F2 - Stock Carpet - IT = "A"
      while true
        vloadif(dpath|"cus_ent4.vw")
        error off
        vloadif(dpath|"prodselA.vw")
        order change index ipath|"stckcarp.idx"
        if prodcode = ""
          y2 = format(" Scroll to find & press {Enter} - {Esc} to leave ","M72")
          screen print 21 5 fgp bbd y2
          x = bpopdb("prodselA",4,"","[Prod_Back]","L35","[abbrv]","L4","[Product_Code]",7,43,20,80,"",0)
        else
          data goto record record-number #prodrec
          y2 = format(" Scroll to find & press {Enter} - {Esc} to leave ","M72")
          screen print 21 5 fgp bbd y2
          x = bpopdb("prodselA",4,"","[Prod_Back]","L35","[abbrv]","L4","[Product_Code]",7,43,20,80,"",0)
        end if
        if x = -1
          return (-1)
        end if
        #prodrec = record
        prodcode = ptstr               ' message "prodcode -L1430- is:"&str(prodcode)
        return (prodcode)
      end while

    elseif x = 317                 ' F3 - Bespoke Carpet - IT = "B"
      continue while

    elseif x = 318                 ' F4 - Stock Ancl - IT = "A"
      continue while

    elseif x = 319                 ' F5 - Bespoke Ancl - IT = "A"
      continue while

    elseif x = 320                 ' F6 - Vinyl - IT = "V or W"
      continue while

    elseif x = 321                     ' F7 - Tiles - IT = "S or T"
      continue while

    elseif x = 322                     ' F8 - Fitting - IT = "F"
      continue while

    elseif x = 315                     ' F1
      continue while

    elseif x = 323                     ' F9 - reservations
      continue while

    elseif x = 324                     ' F10 -
      continue while

    elseif x = 763                     ' {Esc}
      return (-1)
    end if
  end while
  data goto record last
  return (0)
END FUNCTION 'ChooseItemType()


FUNCTION  Title_A()
local y1 y3 f1 f2 f3
  y2 = format("Select requisition type or {Esc} to exit","M72")
  screen print 21 5 fgp bbd y2
  repaint off
  f1 = format("    F2   ³     F3    ³     F4    ³     F5    ³     F6    ³     F7    ³    F8   ","L80")
  f2 = format("  Stock  ³ ÿÿÿÿÿÿÿÿ  ³   ÿÿÿÿÿ   ³ÿÿÿÿÿÿÿÿÿ  ³   Vinyls  ³   Tiles   ³  ÿÿÿÿÿÿ ","L80")
  f3 = format("  Carpet ³   ÿÿÿÿÿÿ  ³ ÿÿÿÿÿÿÿÿ  ³ ÿÿÿÿÿÿÿÿ  ³           ³           ³         ","L80")
  screen print 22 1 keyf keyb f1
  screen print 23 1 keyf keyb f2
  screen print 24 1 keyf keyb f3
END FUNCTION   'Title_A()


FUNCTION Chk_Unalloc()
local $stock desMRC prodcode #ordwidth $ccwcode
  screen shortrestore dsa
'   vloadif(dpath|"colours.vws")
  desMRC=[Carpet_Color]
  prodcode=[Product_Code]
  #ordwidth=[Width]
' message "prodcode is:"&str(prodcode)
' message "desMRC is:"&str(desMRC)
' message "#ordwidth is:"&str(#ordwidth)
  $stock = left(prodcode|"ÿ"|desMRC|"ÿ"|"Y"|"ÿ"|str(fixed(#ordwidth,2))|repeat("ÿ",36),36)
' message "$stock is:"&str($stock)
'   error off
  $ccwcode = filelookup([Colours.CodeColourWidth],[Colours.CCW_Code],$stock)
' message "$ccwcode is:"&str($ccwcode)

END FUNCTION   'Chk_Unalloc()

