FUNCTION CarpetStockRecord()
  repaint off
  x = colpopup(4,1,19,"Warehouse Shop Site Cadogan","",1,0,14,1,0,15)
  locn      = str(ptstr)
  prodcode  = [Product_Code]
  #width    = [Width]
  $itemtype = [Item_Type]
'|
  if locn="Warehouse"
    while true
      x = colpopup(4,10,19,"Unit˙19 Unit˙32 Showroom Container","",1,0,14,1,0,15)
      locn      = str(ptstr)
      if locn="Unit˙19"
        x = colpopup(4,21,19,"A B C D E F G H J K L M N O P","",1,0,14,1,0,15)
        locn="19"|str(ptstr)
        x = colpopup(4,26,19,"1 2 3 4","Level",1,0,14,1,0,15)
        locn=locn|str(ptstr)
        messbox(" Is location -"&locn&"- correct? (y/n) ",1,1,1)
        if ptstr=="y"
          exit while
        end if
      elseif locn="Unit˙32"
        x = colpopup(4,21,19,"T U V W X Y Z ANCL SMPL","",1,0,14,1,0,15)
        if ptstr="ANCL" or ptstr="SMPL"
          locn=ptstr
          messbox(" Is location -"&locn&"- correct? (y/n) ",1,1,1)
          if ptstr=="y"
            exit while
          else
            continue while
          end if
        end if
        locn="32"|str(ptstr)
        x = colpopup(4,26,19,"1 2 3 4","Level",1,0,14,1,0,15)
        locn=locn|str(ptstr)
        messbox(" Is location -"&locn&"- correct? (y/n) ",1,1,1)
        if ptstr=="y"
          exit while
        end if
      elseif locn="Showroom"
        x=messbox(" Is location -"&locn&"- correct? (y/n) ",1,1,1)
        if ptstr=="y"
          locn="SHOW"
          exit while
        end if
      elseif locn="Container"
        x=messbox(" Is location -"&locn&"- correct? (y/n) ",1,1,1)
        if ptstr=="y"
          locn="CNTR"
          exit while
        end if
      end if
    end while

  elseif locn="Cadogan"
'     x=messbox(" Is location -"&locn&"- correct? (y/n) ",1,1,1)
'     if ptstr=="y"
    locn="CDGN"
' message "Enter Cadogan roll nr"
    entryline(" Enter Cadogan's roll reference ",50,"*50{X}",$comment_P,#bline,1,80)
    $comment_P = ptstr
'     exit while
' a    end if
  end if

  $ccwcode = ""
  case $itemtype

    when "B"
      p1 = "gdsrcv_B.dfr"
      $carp = "besp"
      FindCustomer()
      vloadif(dpath|"stk_besp.vws")

    when "J"
      p1 = "gdsrcv_B.dfr"
      $carp = "besp"
      FindCustomer()
      vloadif(dpath|"stk_besp.vws")

    when "W"
      p1 = "gdsrcv_B.dfr"
      $carp = "besp"
      FindCustomer()
      vloadif(dpath|"stk_besp.vws")

    when "T"
      p1 = "gdsrcv_B.dfr"
      $carp = "besp"
      FindCustomer()
      vloadif(dpath|"stk_besp.vws")

    when "C"
      Check_CCW()
      p1 = "gdsrcv_S.dfr"
      $carp = "carp"
      vloadif(dpath|"stk_carp.vws")

    when "S"
      Check_CCW()
      p1 = "gdsrcv_S.dfr"
      $carp = "carp"
      vloadif(dpath|"stk_carp.vws")

    when "V"
      Check_CCW()
      p1 = "gdsrcv_S.dfr"
      $carp = "carp"
      vloadif(dpath|"stk_carp.vws")

    when "O"
      p1 = "gdsrcv_S.dfr"
      $carp = "carp"
      vloadif(dpath|"stk_carp.vws")
  end case

  AllocateRollNr()                    ' generate unique Roll Nr
  $rollreserve="R"|$rollnr		'message "$rollreserve is:"&str($rollreserve)
  data enter lock                 '
    [DateRecd]        = datercvd
    [Product_Code]    = prodcode
    [Description_MRC] = desMRC
    [RollNr]          = $rollnr
    [Width]           = #width
    [Location]        = locn
    [StockOrder]      = ordernr
    [Stock_Delivered] = #lengthrcvd
    [Balance]         = #lengthrcvd
    [PhysicalBalance] = #lengthrcvd
    [BAR]             = #lengthrcvd
    [Active]          = "Y"
    [CCW_Code]        = $ccwcode
    [Unit_Cost]       = #unitcost
    [Comments]        = $comment_P
    [RollReserve]     = $rollreserve	
  write-record

  case $itemtype
    when "B"
      lock-record
        [Balance]         = 0
        [BAR]             = 0
        [Active]          = "N"
      write-record
    when "J"
      lock-record
        [Balance]         = 0
        [BAR]             = 0
        [Active]          = "N"
      write-record
    when "W"
      lock-record
        [Balance]         = 0
        [BAR]             = 0
        [Active]          = "N"
      write-record
    when "T"
      lock-record
        [Balance]         = 0
        [BAR]             = 0
        [Active]          = "N"
      write-record
  end case

  $ccwidx = $ccwcode|".idx"
  #prec = precord
  if bckg_del <> "OVER"
    x = PrintAcceptLabel()
    if x = -1
      ShowLabel()                        ' message "Show label details"
    end if
  end if
  RecordReceipt()
  case $itemtype
    when "B"
      AllocateBespoke()
    when "J"
      AllocateBespoke()
    when "W"
      AllocateBespoke()
    when "T"
      AllocateBespoke()
    when "O"
      AllocateBespoke()
    when "C"
      x = AllocateStock()
      if x = 0                           ' if not alloc'd
        return (0)                       ' do not add to index of ???
      else
        return (1)                       ' add to index to ???
      end if

    when "S"
      x = AllocateStock()
      if x = 0                           ' if not alloc'd
        return (0)                       ' do not add to index of ???
      else
        return (1)                       ' add to index to ???
      end if

  end case
END FUNCTION ' CarpetStockRecord()


FUNCTION AllocateRollNr()
local datenumber
  datenumber = left(date2(datercvd),2)|mid(date2(datercvd),4,2)
  while true
    increment(dpath|"rollnr.dat",1)
    $rollnr = str(datenumber)|right(date2(datercvd),1)|"/"|right("00"|str(ptval),2)
    order change key "[RollNr]"
    data find "[RollNr]" equal $rollnr options ""
    if cerror                               '   if none - then return
      exit while
    end if
  end while
  messboxwait(" Roll Nr assigned is"&str($rollnr)|" ",0,2,1)
END FUNCTION 'AllocateRollNr()
