'SUPP_IDX - rebuild index for o/s PURCHORD records for selected supplier
'           to be used when GDS_RCV1 program has to show req'ns entered
'           since the previous automatic rebuild

external   dpath vloadif() prpath sch scw progress() fgp bgp remove()
external   progtag() bgi fgi makeidx() bpopdb() pipath messbox() cpath
external   messboxwait()

public     ptstr suppcode dsa

global     x i suppname FindSupplier() ReturnToMenu() y1 #bline Suppliers()
global     y2 y3 supp_idx


MAIN
single-step off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off

  while true
    vloadif(dpath|"supplier.vws")
    order change physical
    order sort now dictionary "suppname" fields "[Name]" ascending
    repaint off
    x = FindSupplier()
    if x = -1
      exit while
    end if
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
' message "supp_idx is:"&str(supp_idx)
    file unload all
    x = remove(supp_idx)
    if x = -1
      messboxwait(" Index for"&suppname&"is in use - cannot rebuild ",0,0,1)
'       continue while
    end if
    Suppliers()

  end while

  ReturnToMenu()

END MAIN


FUNCTION FindSupplier()
  vloadif(dpath|"supplier.vws")
  while true
    y1 = format(" Choose Supplier and press {Enter} ","M38")
    screen print 7 21 15 1 y1
    screen print 20 21 15 1 (format(" {Enter} views orders - {Esc} exits ","M38"))
    x = bpopdb("supplier",6,"","[Name]","l35","[Supplier_Code]","L6","[Supplier_Code]",8,21,19,58,"",0)
    if x = 0
      exit while
    elseif x = -1
      screen clear box 1 1 sch scw 0 0 no-border
      return (-1)
    end if
  end while
  suppcode = ptstr
  suppname = [Name]
  supp_idx = pipath|"P_"|suppcode|".idx"
END FUNCTION 'FindSupplier()


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 Suppliers()
  progress(fgp,bgp," ˙˙˙˙Building new index files for O/S goods ˙˙˙˙",1)
  progtag(fgi,bgi," Re-indexing"&suppname|" ")
  vloadif(dpath|"purchord.vws")
  order change key "[Supplier_Code]"
  data query execute "ospurchB.dfq" index pipath|"P_"|suppcode|".idx"
' ŚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄæ
' ³ [Supplier_Code] = suppcode and [Order_Status] = "P"                ³
' ĄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŁ
  if cerror
    x=makeidx("purchord",pipath|"P_"|suppcode|".idx","0",5)
  end if
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
END FUNCTION ' Suppliers()




