'MESSAGES - for shops to read messages

external   vloadif() lpath dpath navrecs() wraptext() sch scw PrintReport()
external   cpath base messbox()

public     ptstr dsa ptval psa

global     x Titles() ViewUnread() DelRead() PrintAll() ReadExceptions()
global     y1 y2 y3 y4 $findcat S_poplist $popcat ReturnToMenu()

MAIN
  messbox(" Not yet operational ",0,0,1)
  file unload all
  transfer "pm_menu.psl" in-memory
'   ChangeAllocn()
' message "base is:"&str(base)
'   ReadExceptions()
'
'   ReturnToMenu()

END MAIN


FUNCTION ReturnToMenu()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION ReadExceptions()
'   $deld = "N"
  vloadif("oldpurch.vws")
  load lpath|"wraptext.rf3" in-memory
  vloadif(dpath|"unread1.vw")
  while true
'     x = CatPopup()
'     if x = -1
'       return (0)
'     end if
    screen shortrestore dsa
    Titles()
    ptval=0
    while ptval <> {Esc}
       ptval = navrecs()
       if ptval = {Enter}
          ViewUnread()
          screen shortrestore psa
          continue while
       elseif ptval = {D} or ptval = {d}
          DelRead()
          Titles()
          continue while
       elseif ptval = {P} or ptval = {p}
          PrintAll()
          exit while
      end if
    end while
    repaint off
  end while
END FUNCTION ' ReadExceptions()


FUNCTION ViewUnread()
local x
'   load "wraptext.rf3" in-memory
  x = left(format([Time_Created],"T2"),5)&":"&[message]
  wraptext(8,20,15,60,15,12,x,"L",1,0,1)
'   unload "wraptext.rf3"
END FUNCTION ' ViewUnread()


FUNCTION DelRead()
  if not(deleted)
    data delete record
    lock-record
      [Del] = "D"
    write-record
  '   $deld = "Y"
  else
    data delete record
    lock-record
      [Del] = ""
    write-record
  end if
END FUNCTION ' DelRead()


FUNCTION Titles()
  y1 = format(" Outstanding Exception messages","M33")
  y2 = format("{E}nter to view - {D}elete ","M36")
  y3 = format("{P}rint all - {Esc} to exit","M36")
'   y4 = format(" Category:"&$findcat,"M36")
  repaint on
  repaint
  screen shortrestore S_poplist
  screen clear box 4 33 6 68 15 12
  screen print 5 35 15 12 y1
'   screen print 7 33 15 1  y4
  screen print 17 33 15 1  y2
  screen print 18 33 15 1  y3
END FUNCTION ' Titles


FUNCTION PrintAll()
local repdef p2 p3 p4 p5 p6
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  repdef = "exceptn1.dfr"
  p2 = "Messages"
  p3 = 1
  p4 = 1
  p5 = 3
  p6 = 1
  PrintReport(repdef,p2,p3,p4,p5,p6)
' p1 = report definition ("ord_stck.dfr")
' p2 = title at top of choice popup ("LABEL")
' p3 = printer to be used (1=HPIII_QC; 2=GEN_EPSN etc)
' p4 = printer port to use (1,2 etc - network set to use 2=LASER; 3=LABEL)
' p5 = choose VIEW/PRINT 1=PRINT; 2=VIEW; 3=CHOOSE
' p6 = nr of copies
END FUNCTION ' PrintCategory()
