'LISTDESP ' list jobs from Goodsout file which have been despatched 3 days ago

external  dpath Background() progress() vloadif() messbox() chkstr() strcount()
external  makeidx() addidxrec() vunloadif() ipath sch scw remove()

public    jobnr ptstr ftgdate ptval

global    x ListJobs() $jobnrs i FittedDate()


MAIN
single-step off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  x = remove(ipath|"listdesp.idx")     'message "remove is:"&str(x)

  FittedDate()                        'message "ftgdate) is:"&date2(ftgdate)
  ListJobs()

  file unload all

END MAIN


FUNCTION  ListJobs()
local  #jobnrs $jobnrs
  vloadif(dpath|"goodsout.vws")
  progress(15,10," Please wait .... finding records ",0)
  order change key "[Date_Out]"
  data query execute "listdsp1.dfq" index "listdsp1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' days([Date_Out])=days(ftgdate)
' and
' [Itemtype]="F"
' and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" No jobs to list ",0,0,1)
    x = makeidx("cust_ord",ipath|"listdesp","0",3)     'message "makeidx is:"&str(x)
    return (0)
  end if
  order sort now dictionary "listdsp2.idx" fields "[Job_Nr]" ascending

  data goto record first
  $jobnrs = [Job_Nr]
  data goto record next
  for i = 2 to records                 'create text string of Job Nrs
    x = chkstr([Job_Nr],$jobnrs)
    if x = -1
      $jobnrs = $jobnrs&[Job_Nr]
    end if
    data goto record next
  end for
  vunloadif("goodsout.vws")
' message "$jobnrs) is:"&str($jobnrs)
'create index of CUST_ORD by stepping thro' text string and using ADDIDXRECS
  x=strcount($jobnrs)                  ' message "x is:"&str(x)
  #jobnrs = ptval
' message "#jobnrs) is:"&str(#jobnrs)
  vloadif(dpath|"cust_ord.vws")
  order change key "[Job_Nr]"
  x = makeidx("cust_ord",ipath|"listdesp","0",3)     'message "x is:"&str(x)
  for i = 1 to #jobnrs
    jobnr = group($jobnrs,i)
    data find "[Job_Nr]" equal jobnr options ""
'     if [Balance_Due]>.01
    x = addidxrec(ipath|"listdesp.idx",precord,7)    'message "x is:"&str(x)
'     end if
  end for
  vunloadif("cust_ord.vws")
END FUNCTION ' ListJobs()


FUNCTION FittedDate()
  if dayname(today)="Monday"
    ftgdate=date2(days(today)-3)
  else
    ftgdate=date2(days(today)-2)
  end if
END FUNCTION ' Ftgdate()

