FUNCTION EnterSupplier()
local bpop_ret
  vloadif(dpath|"new_supp.vw")
  order change physical
  order sort now dictionary "suppname" fields "[Name]" ascending
'   screen print 19 10 fgi bgi (format("Choose Supplier or {Esc} to enter new","M45"))
  screen print 19 10 fgi bgi (format("Choose Supplier (existing suppliers only) ","M45"))
  bpop_ret = bpopdb("new_supp",6,"","[Name]","L35","[Supplier_Code]","L6","[New_Code]",8,10,18,54,"Choose Supplier",0)
  if bpop_ret = 0
    newcode = ptstr
    suppcode = [Supplier_Code]
    suppname = [Name]
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
'    progress(fgp,bgp," Calculating possible Product Code ",0)
  elseif bpop_ret = -1
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    return (-1)
  end if
' if present {Enter} will return [Supplier_Code] or {Esc} will branch
' to entry screen for new SUPPLIER record
' message "suppcode is:"&str(suppcode)
' message "suppname is:"&str(suppname)
END FUNCTION ' EnterSupplier()


FUNCTION EnterDetails() ' entered on PRODUCTS.DB
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  vloadif(dpath|"prodent1.vw")

  while true
    EnterSupplier()                      'message "suppcode is:"&str(suppcode)
    while true
      x = fentrybox(" Enter Product name ",30,"",prodmrc)
      if x = 0
        prodmrc = ptstr
        x = messbox(" Confirm name is"&prodMRC|"? (y/n) ",1,1,1)
        if ptstr=="n"
          continue while
        end if
        exit while
      end if
    end while

    SelectUnit()  'message "6159/$unit is:"&str($unit)

    while true
' message "6265//#unitcost is:"&str(#unitcost)
      x = fentrybox(" Enter Supplier's net price per"&$unit,8,"*8{[1234567890.]}",#unitcost)
      if x = 0
        #unitcost = val(ptstr)
        x = messbox(" Confirm net price is"&str(currency(#unitcost))|"? (y/n) ",1,1,1)
        if ptstr=="n"
          continue while
        end if
        exit while
      end if
    end while

' message "6151//#### $cat is:"&str($cat)

' message "$seltype is:"&str($seltype)
' message "$keypress is:"&str($keypress)
  if $keypress="F5"
    $seltype="P"
    $backing="NONE"
    desMRC="NONE"
  else
    SelectType()             '########## select product type from options in [Group]
    SelectBacking()             '########## select product type from options in [Group]
' message "6262//$backing is:"&str($backing)
    while true
      x = fentrybox(" Enter Colour ",20,"",desMRC)
      if x = 0
        desMRC=ptstr
        x = messbox(" Confirm colour is"&desMRC&"? (y/n) ",1,1,1)
        if ptstr=="n"
          continue while
        end if
        exit while
      end if
    end while
  end if

    while true
      x = fentrybox(" Enter WIDTH (enter 1 if Width not applicable)",6,nr6,"1")
      if x = 0
        if value(ptstr) = 0
          continue while
        else
          #ordwidth = value(ptstr)
          x = messbox(" Confirm width"&fixed(#ordwidth,2)|"? (y/n) ",1,1,1)
          if ptstr=="n"
            continue while
          else
            exit while
          end if
        end if
      end if
    end while
    $itemtype=$cat

' message "prodcode is:"&str(prodcode)
' message "suppcode is:"&str(suppcode)
' message "prodMRC is:"&str(prodMRC)
' message "#unitcost is:"&str(#unitcost)
' message "$seltype is:"&str($seltype)
' message "$itemtype is:"&str($cat)
' message "#ordwidth is:"&str(#ordwidth)
' message "6301//$backing is:"&str($backing)
' message "desMRC is:"&str(desMRC)
' message "$unit is:"&str($unit)

    vloadif(dpath|"prodent1.vw")
    data enter lock
      [Product_Code]        = prodcode
      [Supplier_Code]       = suppcode
      [Product_MRC]         = prodmrc
      [Prod_Cust]           = prodmrc
      [Prev_SMLC]           = #unitcost
      [SM_List_Cuts]        = #unitcost
      [Prev_SMLR]           = #unitcost
      [SM_List_Rolls]       = #unitcost
      [Discount_%]          = 0
      [Effect_Date]         = today
      [Item_Type]           = $cat
      [Initial_Code]        = left(prodcode,1)
      [Type]                = $seltype
      [Rebranded]           = "N"
      [Markup_Code]         = "M3"
'       [Group]               = "N"
      [Product_Supplier]    = prodMRC
      [Backing]             = $backing
      [Widths_Available]    = #ordwidth
      [Unit_Of_Sale]        = "U2"       ' width is 1 even for quantities
'       [Unit_Desc]           = "Sq metres"
      [Unit_Desc]           = $unit
      [Re_Order_Level]      = 0
      [Comments]            = ""
      [Last_Update]         = today
      [Updated_By]          = userid
      [Updated_On]          = today
      [Colours]             = desMRC
      [Temporary]           = "Y"
    write-record
    tempcode="Y"
    exit while
  end while
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
END FUNCTION ' EnterDetails()


FUNCTION SelectUnit()
local d1 d2 d3 d4 d5
  while true
    d1="Quantity"
'     d2="Units"
'     d3="Metres"
    d4="Lin˙Metre"
'     d4="Lin Metre"
    d5="Sq˙Metre"
'     d5="Sq Metre"
    x = popuplist(10,39,25,d5&d4&d1,"Select Units",1,0)
    $unit = ptstr
    messbox(" Confirm Unit Description is"&$unit&"? (y/n) ",1,1,1)
'     $unit = ptstr
    if ptstr == "y"
      exit while
    else
      continue while
    end if
  end while
END FUNCTION ' SelectUnit()


FUNCTION SelectType()
local t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11
  while true
    t1="Twist"
    t2="Velvet"
    t3="Natural"
    t4="Saxony"
    t5="Wood"
    t6="Lino"
    t7="Domestic Vinyl"
    t8="Rugs"
    t9="Other"
    t10="N/A"
    t11="Pattern"
'     x = popuplist(10,39,25,t1&t2&t3&t4&t5&t6&t7&t8&t9&t10&t11,"Select Type",1,0)
    x = popuplist(10,39,25,t1&t2&t3&t4&t8&t9&t11,"Select Type",1,0)
    $seltype=ptstr
    messbox(" Confirm Product Category is"&$seltype&"? (y/n) ",1,1,1)
    if ptstr == "n"
      continue while
    end if
    if $seltype=t1
      $seltype="Z"
    elseif $seltype=t2
      $seltype="Y"
    elseif $seltype=t3
      $seltype="X"
    elseif $seltype=t4
      $seltype="W"
    elseif $seltype=t5
      $seltype="V"
    elseif $seltype=t6
      $seltype="U"
    elseif $seltype=t7
      $seltype="T"
    elseif $seltype=t8
      $seltype="S"
    elseif $seltype=t9
      $seltype="R"
    elseif $seltype=t10
      $seltype="P"
    elseif $seltype=t11
      $seltype="N"
    end if
    exit while
  end while
END FUNCTION ' SelectType()


FUNCTION SelectBacking()
  while true
    while true
      x = popuplist(10,55,21,"JUTE FOAM GELL IMPV FELT VINY WAFF LATX STND OVER NONE","Backing",1,0)
' message "x is:"&str(x)
      if x = 0
        $backing = ptstr
        exit while
      elseif x = -1
        continue while
      end if
    end while
    messbox(" Confirm Backing is"&$backing&"? (y/n) ",1,1,1)
    if ptstr == "y"
      exit while
    else
      continue while
    end if
  end while
END FUNCTION ' SelectBacking()
