'CHNGLOCN - change listed location of carpet in Warehouse

external   messbox() fentrybox() dpath vloadif() sch scw messboxwait()
external   rollmask mess4() vunloadif() colpopup()

public     ptstr ptval $rollnr

global     EnterRolls() x ReturnToMenu() #old_bal prodcode desMRC #width m4 i
global     $backing prodMRC a1 a2 a3 a4 #old_PHYS locn Location()


MAIN
single-step off
' quiet off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  error off
  while true
    x = EnterRolls()                ' show unallocated REQUSN's to move and select REQUSN.
    if x = -1
      exit while
    end if
  end while

  ReturnToMenu()                        ' unload screens

END MAIN


FUNCTION EnterRolls()
local l
  while true
    x = colpopup(14,31,19,"Stock Bespoke","",1,0,14,11,0,15)
    l = left(str(ptstr),1)
' message "l is:"&str(l)
    x = fentrybox(" Enter Roll Nr to adjust - {Esc} to finish ",8,rollmask,"")
    if x = 0
      $rollnr = ptstr
      vloadif(dpath|"products.vws")
      if l="S"
        vloadif(dpath|"STK_CARP.vws")
      elseif l="B"
        vloadif(dpath|"STK_BESP.vws")
      end if
      order change key "[RollNr]"
      data find "[RollNr]" equal $rollnr options "gw"
      if cerror
        messbox(" Roll Nr not found - re-enter ",0,0,1)
        return (0)
      else
        if l="S"
          if [Active]="N"
            messboxwait(" Marked as INACTIVE - inform office before proceeding ",0,0,1)
            return (0)
          end if
        end if
'         #old_BAR = [BAR]               'message "#old_BAR is:"&str(#old_BAR)
        #old_PHYS= [PhysicalBalance]   'message "#old_PHYS is:"&str(#old_PHYS)
        #old_bal = [Balance]           'message "#old_bal is:"&str(#old_bal)
        prodcode = [Product_Code]
        desMRC   = [Description_MRC]
        #width   = [Width]
        locn     = [Location]

        $backing = filelookup([products.Product_Code],[products.Backing],prodcode)
        prodMRC  = filelookup([products.Product_Code],[products.Product_MRC],prodcode)

        a1 = format("Code:"&prodcode&left(prodMRC,30),"M46") 'message "len(a1)) is:"&str(len(a1))
        a2 = format(desMRC&"("|$backing|")","M46")
        a3 = format("Balance shown in stock:"&fixed(#old_PHYS,2)|"m","M46")
        a4 = format("Current location is:"&locn,"M46")
        m4 = " Correct Roll? (y/n) "
        x = mess4(a1,a2,a3,a4,m4,"")
        if x = 0
          if ptstr == "y"
            vunloadif("PRODUCTS.vws")
            Location()
          else
            continue while
          end if
        else
          message "MESS4 failed in SHRTMEAS - inform David Guyan"
          return (-1)                        ' unload screens
        end if
      end if
    elseif x = -1
      return (-1)
    else
      message "FENTRY Error:"&str(x)
      screen clear box 1 1 sch scw 0 0 no-border
      repaint off
      return (-1)
    end if
  end while
END FUNCTION ' EnterRolls()


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 ' ReturnToMenu()


FUNCTION Location()
  while true
'     messbox(" Is the carpet being returned to the same location? (y/n) ",1,1,1)
'     if ptstr == "y"
'       exit while
'     end if

    repaint off
    x = colpopup(4,1,19,"Whse Shop Site","",1,0,14,11,0,15)
    locn      = str(ptstr)
'|
    if locn="Whse"
      while true
        x = colpopup(4,10,19,"Unit˙19 Unit˙32 Showroom","",1,0,14,11,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,11,0,15)
          x = colpopup(4,21,19,"A B C D E F G H J K","",1,0,14,11,0,15)
          locn="19"|str(ptstr)
          x = colpopup(4,26,19,"1 2 3 4","Level",1,0,14,11,0,15)
          locn=locn|str(ptstr)
          messbox(" Is location -"&locn&"- correct? (y/n) ",1,1,1)
          if ptstr=="y"
            lock-record
              [Location]=locn
            write-record
            return (0)
          else
            continue while
          end if
        elseif locn="Unit˙32"
          x = colpopup(4,21,19,"L M N P Q R S T U V W X Y Z ANCL SMPL","",1,0,14,11,0,15)
          if ptstr="ANCL" or ptstr="SMPL"
            locn=ptstr
            x=messbox(" Is location -"&locn&"- correct? (y/n) ",1,1,1)
            if ptstr=="y"
              lock-record
                [Location]=locn
              write-record
              return (0)
            else
              continue while
            end if
          end if
          locn="32"|str(ptstr)
          x = colpopup(4,26,19,"1 2 3 4","Level",1,0,14,11,0,15)
          locn=locn|str(ptstr)
          x=messbox(" Is location -"&locn&"- correct? (y/n) ",1,1,1)
          if ptstr=="y"
            lock-record
              [Location]=locn
            write-record
            return (0)
          end if
        elseif locn="Showroom"
          x=messbox(" Is location -"&locn&"- correct? (y/n) ",1,1,1)
          if ptstr=="y"
            lock-record
              [Location]="SHOW"
            write-record
            return (0)
          else
            continue while
          end if
        end if
      end while
    end if
  end while
END FUNCTION 'Location()

