'REQN_IDX - rebuild indices for REQUSN's for each job

external   messbox() ipath remove() progress() progtag() fgp bgp vloadif()
external   dpath fgi bgi sch scw cpath reqnpath

public     ptstr $itemtype psa jobnr

global     ReturnToMenu() #prec $reqnidx Orders() jobidx #rem

MAIN
single-step off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
'   messbox(" Rebuild indices for all current job records? (y/n) ",1,1,1)
'   if ptstr == "n"
'     ReturnToMenu()
'   end if

  Orders()

' ReturnToMenu()

END MAIN


FUNCTION Orders()
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ create new indices for Customer orders                             ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  progress(fgp,bgp," Deleting old indices on"&reqnpath|"ÿ",0)
  file unload all
  remove(reqnpath|"*.idx")                'delete old indices
  screen shortrestore psa
  vloadif(dpath|"cust_ord.vws")
  data goto record first

  messbox(" No filter - all CUST_ORD records included ",0,1,1)
  progress(fgp,bgp," ÿÿÿÿBuilding new index filesÿÿÿÿ ",1)
  while precord <= precords
    if (deleted)
      data goto record next
      continue while
    end if

    jobnr = [Job_Nr]
    jobidx = jobnr|".idx"

' temp filter
    if round([Balance_Due],0) = 0 and days([Fitting_Date]) < days(today)
      data goto record next
      continue while         ' if Despatched go to next record
    end if

' permanent filter
'     if [Order_Status] = "D"
'       data goto record next
'       continue while         ' if Despatched go to next record
'     end if
    #prec = precord
    #rem = precords - #prec            ' message "#rem is:"&str(#rem)
    progtag(fgi,bgi,jobidx&"-"&fixed(#rem,0)&"jobs to go")
    vloadif(dpath|"requsn.vws")
    order change key "[Job_Nr]"
    data query execute "job_reqn.dfq" index reqnpath|jobidx
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Job_Nr] = jobnr
'   and
'   not(deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      vloadif(dpath|"cust_ord.vws")
      data goto record next
      continue while
    end if
    vloadif(dpath|"cust_ord.vws")
'     order change physical
'     data goto record record-number #prec
    if #prec = precords
      exit while
    end if
    data goto record next
  end while
END FUNCTION 'Orders()


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()
