'OS_PURCH - list o/s purchases for BESPOKE & "X" purchase orders.

external   dpath vloadif() sch scw bpopdb() vunloadif() scr fgp bgp progress()
external   popuplist() PrintReport() messboxwait() messbox()

public     ptstr ptval $rollnr prodMRC dsa

global     ReturnToMenu() Titles() ListOrders() x ChooseType() OS_Bespoke()
global     p1 p2 p3 p4 p5 p6 ShowDetails()


MAIN
  single-step off
'   quiet off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  p1 = "os_purcA.dfr"   ' p1 = report definition ("ord_stck.dfr")
  p2 = "Bespoke Orders" ' p2 = title at top of choice popup ("LABEL")
  p3 = 1                ' p3 = printer to be used (1=HPIII_QC; 2=GEN_EPSN etc)
  p4 = 1                ' p4 = printer port to use (1,2 etc - network set to use 2=LASER; 3=LABEL)
  p5 = 3                ' p5 = choose VIEW/PRINT 1=PRINT; 2=VIEW; 3=CHOOSE
  p6 = 1                ' p6 = nr of copies

  ChooseType()

  ReturnToMenu()                        ' unload screens

END MAIN


FUNCTION ShowDetails()
local r1 r2 c1 c2 cl1 cl2 y1 y2 y3 y4 y5 delquot ordref ordnr suppname
  r1 = 1
  r2 = r1+5
  c1 = 19
  c2 = c1+41
  cl1 = 15
  cl2 = 10
  screen clear box r1 c1 r2 c2 cl1 cl2
  delquot = [Delivery_Quoted]
  ordnr   = [Order_Nr]
  ordref  = [Order_Reference]
  suppname= [Name]

  y1 = format(suppname,"M39")
  y2 = format("Order Nr:˙˙˙˙˙˙˙˙˙"&ordnr,"L39")
  y3 = format("Delivery:˙˙˙˙˙˙˙˙˙"&delquot,"L39")
  y4 = format("Their ref:˙˙˙˙˙˙˙˙"&ordref,"L39")
  screen print r1+1 c1+2 cl1 cl2 y1
  screen print r1+2 c1+2 cl1 cl2 y2
  screen print r1+3 c1+2 cl1 cl2 y3
  screen print r1+4 c1+2 cl1 cl2 y4
  screen print r2 c1+10 cl1 cl2 " ... press any key to continue"
  inchar
END FUNCTION ' ShowDetails()


FUNCTION ChooseType()
local y1 y2
' choose Stock to view or Bespoke to print
  y1 = "˙˙˙˙˙˙Stock˙˙˙˙˙"
  y2 = "˙˙˙˙˙Bespoke˙˙˙˙"
  screen print 9 30 15 1 (format("  Goods not rec'd ","M20"))
  x = popuplist(10,30,13,y1&y2," Search for?",1,0)
  if ptstr = y1
    screen clear box 1 1 sch scw 0 0 no-border
    ListOrders()
  elseif ptstr = y2
    screen clear box 1 1 sch scw 0 0 no-border
    OS_Bespoke()
  end if
  return (1)
END FUNCTION ' ChooseType()


FUNCTION OS_Bespoke()
  screen clear box 1 1 sch scw 0 0 no-border
  progress(fgp,bgp," Preparing file ... please wait ",0)
  vloadif(dpath|"os_purcA.vw")
  order change key "[Product_Code]"
  data query execute "os_purcA.dfq" index "x.idx"
' ŚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄæ
'   left([Order_Nr],1) <> "X"
'   and
'   [Order_Status] = "P"
' ĄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŁ
  if cerror
    messbox(" No outstanding deliveries for Bespoke items ",0,0,1)
  end if
  order sort execute dictionary "os_purcA.dfs" index "os_purcA"
  if records > 100
    messboxwait(" WARNING! More than 100 records to print - suggest VIEW only ",0,0,1)
  end if
  screen clear box 1 1 sch scw 0 0 no-border
  PrintReport(p1,p2,p3,p4,p5,p6)
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  vunloadif("os_purcA.vw")
  return (1)
END FUNCTION ' OS_Bespoke()


FUNCTION ListOrders()
  progress(fgp,bgp," Preparing file ... please wait ",0)
  vloadif(dpath|"os_purch.vw")
  order change key "[Product_Code]"
  data query execute "os_purch.dfq" index "x.idx"
' ŚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄæ
'   left([Order_Nr],1) = "X"
'   and
'   [Order_Status] = "P"
' ĄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŁ
  if cerror
    messbox(" No outstanding deliveries for Stock ",0,0,1)
  end if
  order sort execute dictionary "os_purch.dfs" index "os_purch"
  while true
    Titles()
    x = bpopdb("os_purch",8,"","[Date_Supplier]","L21","[Product_Quant]","L60","[Product_Code]",7,1,22,79,"",0)
    screen shortrestore dsa
    if x = -1
      exit while
    end if
    ShowDetails()
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
  end while
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
END FUNCTION ' ListOrders()


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


FUNCTION Titles()
local a2 a3
  a2 = format(" Ordered  Supp'r Bckg   Description               Colour               Length","M79")
  screen print 6 1 15 1 a2
END FUNCTION

