FUNCTION UnInv()
  screen clear box 1 1 sch scw 0 0 no-border
  progress(fgp,bgp," Deleting old Uninvoiced indices on"&ipath|"ÿ",0)
  file unload all
  vloadif(dpath|"cust_ord.vws")
  for i = 1 to #branches
    order change physical
    $branch = group($branches,i)
    remove(ipath|$branch|"_uninv.idx")
    NewIndex()
  end for
  vunloadif("cust_ord.vws")
END FUNCTION ' UnInv()


FUNCTION NewIndex()
  progress(fgp,bgp," Creating new Uninvoiced indices on"&ipath|"ÿ",0)
  progtag(fgi,bgi," Creating index for"&$branch)
  data query execute "cofsales.dfq" index "despat_1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [SalesAnalysis]=$branch
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
'     messboxwait(" No uninvoiced orders ",0,0,1)
    return (-1)
  end if
  data query execute "despat_2.dfq" index ipath|$branch|"_uninv.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Inv_Nr]=blank
'   and
'   not (deleted)
'   and
'   [SalesAnalysis]<>"X"
'   and
'   [SalesAnalysis]<>"P"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
'     messboxwait(" No uninvoiced orders ",0,0,1)
    return (-1)
  end if
  error on
END FUNCTION ' NewIndex()
