'CARPCOST - enter cost of goods received - v1.0

' 171300A MAY

external   vloadif() vunloadif() navrecs() sch scw fgp bgp dpath
external   entryline() messline() delidxrec() progress() cpath

public     ptstr ptval

global     FindStock() EnterCost() x LoadScreens() #cost y Title()
global     ReturnToMenu()

MAIN
  single-step off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
'   quiet off

  LoadScreens()

  while true
    x = FindStock()
    if x = -1
      exit while
    end if
  end while

  while true
    error off
    window close
    if cerror
      exit while
    end if
  end while

  ReturnToMenu()

END MAIN


FUNCTION LoadScreens()
  vloadif(dpath|"products.vws")
  vloadif(dpath|"purchord.vws")
  vloadif(dpath|"supplier.vws")
  window split horizontal 19
  vloadif(dpath|"carpcst1.vw")
  data goto window 2
  vloadif(dpath|"carpcst2.vw")
  data goto window 1
  window link "[Product_Code]" "carpcst2.vw" "[Product_Code]"
END FUNCTION 'LoadScreens()


FUNCTION FindStock()
  progress(fgp,bgp," Please wait ... selecting unpriced stock carpets ",0)
  data query execute "carpcost.dfq" index "x.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ QUERY is:  [Cost_Price] = ""                                       ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    x = messline(" All deliveries are priced ",0,1,1,19,11,59)
    return (-1)
  end if
  order sort now dictionary "carpcost" fields "[DateDelvd]" ascending

  repaint on
  repaint
  Title()

  ptval=0
  while ptval <> {Esc}
    ptval = navrecs()
    if ptval = {Enter}
      x = EnterCost()
      if x = -1
        return (-1)
      end if
      x = delidxrec("carpcost.idx",record,1)
      if x <> 0
        repaint off
        data query execute "carpcost.dfq" index "x.idx"
        if cerror
          x = messline(" All deliveries are priced ",0,1,1,19,11,59)
          return (-1)
        end if
        order sort now dictionary "carpcost" fields "[DateDelvd]" ascending
        repaint on
        repaint
      end if
      if records = 0
        x = messline(" All deliveries are priced ",0,1,1,19,11,59)
        return (-1)
      end if
      order change index "carpcost.idx"
      repaint on
      repaint
      Title()
    end if
  end while
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  return (-1)
END FUNCTION ' FindStock()

FUNCTION EnterCost()
local y1 y2 y3 #width #length
'   #width =
'   #length =
  repaint off
  while true
    x = entryline(" Enter Cost price ",5,"","",20,11,60)
    screen clear box 20 1 21 80 0 0 no-border
    if x = -1
      return (-1)
    else
      #cost = round(value(ptstr),2)
    end if
    y1 = currency(#cost)    	'
    y2 = currency(#cost/([Width]*[Stock_Delivered]))
    y3 = currency(filelookup([products.Product_Code],[products.SM_List_Rolls],[Product_Code]))
    x = messline(" Confirm "|y1|"("|y2|"sqm)? MRC roll price is"&y3|"(y/n)",1,1,1,19,11,59)
    if ptstr == "y"
      exit while
    end if
    repaint on
    repaint
  end while

  lock-record             		' assign cost to field
    [Cost_Price] = #cost
  write-record

END FUNCTION  'EnterCost()

FUNCTION Title()
  y = format(" {Enter} to enter price - {Esc} to finish ","M60")
  screen print 20 11 fgp bgp y
END FUNCTION ' Title()

FUNCTION ReturnToMenu()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  vunloadif("carpcst1.vw")
  vunloadif("carpcst2.vw")
  vunloadif("products.vws")
  vunloadif("purchord.vws")
  vunloadif("supplier.vws")
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()



