'POINTS - report of req'ns for Points System

external  fentrybox() messbox() vloadif() messboxwait() Background() progress()
external  PrintReport()

public     entry $drive ptstr $screen ver count base #startdate #enddate dpath
public     #strtdate

global     x waitmsg ListPoints() p1 p2 p3 p4 p5 p6 PrintDuePoints() ProcessPoints()


MAIN
  single-step off
  file unload all
  Background()
  error off

  while true
    x=ListPoints()
    if x = 1
      exit while
    end if

    PrintDuePoints()

    x=ProcessPoints()
    if x = 1
      exit while
    end if
  end while

  Background()

  file unload all

END MAIN


FUNCTION ListPoints()
  vloadif(dpath|"points.vw")
'   while true
    #enddate  =today
    while true			
      x = fentrybox(" Enter End date ",10,"##\/##\/####",#enddate)
      if x=-1
        return (1)
      end if
      if x = 0
        #enddate = ptstr
        exit while
      end if
    end while
    progress(15,10," Please wait ...... selecting requisitions ",0)
'     progtag(fgi,bgi," Selecting previous appointments ")

    data query execute "points1.dfq" index "points1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' days(date2([Date_Requisitioned]))<=days(date2(#enddate))
' and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
    end if

    while true			
      x = fentrybox(" Enter Start date ",10,"##\/##\/####",#strtdate)
      if x=-1
        return (1)
      end if
      if x = 0
        #strtdate = ptstr
        exit while
      end if
    end while
    progress(15,10," Please wait ...... selecting requisitions ",0)

    data query execute "points0.dfq" index "points0.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' days(date2([Date_Requisitioned]))>=days(date2(#strtdate))
' and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
    end if

    data query execute "points2.dfq" index "points2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [PointsProcessed]=blank
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messboxwait(" No 'unprocessed points' requ'ns ",0,0,1)
      return(1)
    end if
    data query execute "points3.dfq" index "points3.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [CarpetPoints]<>blank
' or
' [CarpetPoints]<>0
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messboxwait(" No 'unprocessed points' requ'ns ",0,0,1)
      return(1)
    end if
    order sort now dictionary "points4.idx" fields "[Job_Nr]" ascending
    return (0)
'   end while
END FUNCTION' ListPoints()


FUNCTION PrintDuePoints()
  repaint off

  p1 = "points1.dfr"    ' p1 = report definition ("ord_stck.dfr")
  p2 = ""               ' 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

  PrintReport(p1,p2,p3,p4,p5,p6)
END FUNCTION ' PrintDuePoints()


FUNCTION ProcessPoints()
  messbox(" Do you want to process these Points and mark them off? (y/n) ",1,1,1)
  if ptstr == "n"
'       messboxwait(" Amend the payments and run this program again ",0,0,1)
    return (1)
  end if

  p1 = "points2.dfr"    ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)
  messbox(" Has the Processed Points List printed correctly? (y/n) ",1,1,1)
  if ptstr == "n"
    messboxwait(" Resolve problem and run this program again ",0,0,1)
    return (0)
'   else
'     return (1)
  end if

'transact points
  data query execute "points5.dfq" index "points4.idx"
  data query execute "points6.dfq" index "points5.idx"
  return (1)

END FUNCTION ' ProcessPoints()


