database engdb end

define
  variable open_old  integer
  variable open_new  integer
  variable analz_old  integer
  variable analz_new  integer
  variable fdbck_old  integer
  variable fdbck_new  integer
  variable suspd_old  integer
  variable suspd_new  integer
  variable closed_old integer
  variable closed_new integer
  variable total_old  integer
  variable total_new  integer
  variable week_str   char(9)
end

output
  page length 66
  top margin 5
  bottom margin 3
  left margin 0
end

select 
  asof, open, analyzed, suspended, feedback, closed, total ptotal
from history
where 
      asof >= (today - interval (13) day to day)
order by asof
end

format
  page header

    print column 1, "*** GNATS SUMMARY as of ", date, " ***",
          column 56, "Page", pageno
    skip 2 lines
    print 
          column  1, "Date",
          column 15, "Open", 
          column 25, "Analyzed",
          column 35, "Feedback",
          column 45, "Closed",
          column 55, "Suspended",
          column 65, "Total"
    skip 1 line

    let open_new = 0
    let analz_new = 0
    let fdbck_new = 0
    let suspd_new = 0
    let closed_new = 0
    let total_new = 0

  on every row 

    let week_str="Change   "

    let open_old = open_new
    let analz_old = analz_new
    let fdbck_old = fdbck_new
    let closed_old = closed_new
    let suspd_old = suspd_new
    let total_old = total_new

    let open_new = open
    let analz_new = analyzed 
    let fdbck_new = feedback
    let closed_new = closed
    let suspd_new = suspended
    let total_new = ptotal

    print 
          column  1, asof using "yy-mm-dd",
          column 13, open using "###,###", 
          column 23, analyzed using "###,###",
          column 33, feedback using "###,###",
          column 43, closed using "###,###",
          column 53, suspended using "###,###",
          column 63, ptotal using "###,###"


  on last row

    let open_old = open_new - open_old
    let analz_old = analz_new - analz_old
    let fdbck_old = fdbck_new - fdbck_old
    let closed_old = closed_new - closed_old
    let suspd_old = suspd_new - suspd_old
    let total_old = total_new - total_old


    skip 2 lines
    print "Change",
          column 13, open_old using "----###", 
          column 23, analz_old using "----###",
          column 33, fdbck_old using "----###",
          column 43, closed_old using "----###",
          column 53, suspd_old using "----###",
          column 63, total_old using "----###"
end

