Viewing contents of file '../idllib/deutsch/local/tethyslog.pro'

;+
; NAME:
;   TETHYSLOG
; PURPOSE:
;   This program manages the accounting for the printer tethys.
; CALLING SEQEUNCE:
;   .run tethyslog
;-


  openr,1,'/usr/local/tethys/uselog'
  lin=''
  while (strmid(lin,0,3) ne '---') do readf,1,lin

  media=['letter','trans']
  mediacost=[0.63,1.50]
  mediaamounts=[0.0,0.0]

  xfer=['B&W','3clr','4clr']
  xfercost=[1.00,1.85,2.45]
  xferamounts=[0.0,0.0,0.0]

  budgetnumbers=strarr(1000) & budgetamounts=fltarr(1000)
  budgetprints=strarr(1000)  & budgetusers=strarr(1000)
  budgetptr=0

 print,'  FOS $   HPCC $ MACHO $  Oth $  FOS# HPC# MCH# Oth# B&W 3cl 4cl papr trns
 print,' ------- ------- ------- ------- ---- ---- ---- ---- --- --- --- ---- ----
;print,' 1118.46 1629.58 1120.29 1120.29 1137 1196 1196 1118  29  17  98 9151 9990

  while not EOF(1) do begin
    readf,1,lin
    if (strn(lin) eq '') then goto,DONE
    if (strmid(lin,0,4) eq ' New') then begin
      print,lin
      rib=strn(strmid(lin,13,10))
      xferi=where(rib eq xfer)
      xferamounts(xferi)=0
      print,' ------- ------- ------- ------- ---- ----'
      goto,SKIP1
      endif
    nprints=float(strmid(lin,10,3))
    medium=strn(strmid(lin,14,6))
    roll=strn(strmid(lin,22,4))
    user=strn(strmid(lin,28,9))
    budget=strn(strmid(lin,39,7))

    mediumi=where(medium eq media)
    xferi=where(roll eq xfer)

    xferamounts(xferi)=xferamounts(xferi)+nprints
    mediaamounts(mediumi)=mediaamounts(mediumi)+nprints

    match=-1
    for i1=0,budgetptr-1>0 do if (user eq budgetnumbers(i1)) then match=i1
    if (match eq -1) then begin
      budgetnumbers(budgetptr)=budget
      budgetusers(budgetptr)='('
      match=budgetptr & budgetptr=budgetptr+1
      endif
    budgetprints(match)=budgetprints(match)+nprints
    budgetamounts(match)=budgetamounts(match)+mediacost(mediumi)*nprints+ $
      xfercost(xferi)*nprints
    if (strpos(budgetusers(match),user) lt 1) then begin
      if (strlen(budgetusers(match)) eq 1) then $
        budgetusers(match)=budgetusers(match)+user $
      else $
        budgetusers(match)=budgetusers(match)+'+'+user
      endif

SKIP1:

    endwhile

DONE:
  close,/all


  print,''
  print,'Usage:'

  tot=0.0
  for i1=0,budgetptr-1>0 do begin
    print,budgetamounts(i1),budgetnumbers(i1),budgetusers(i1)+')', $
      format='(f10.2,a10,2x,a)'
    tot=tot+budgetamounts(i1)
    endfor

  print,'------------------------------------------'
  print,tot,'   Total',format='(f10.2,a)'
  print,''
  print,''



;-------------------------------------------------------------------------------

  openr,1,'/host/dione/usr/local/tethys/acctlog'
  acctnumbers=strarr(100)
  acctpaids=fltarr(100)
  acctflags=fltarr(100)
  lin='' & pp=0
  while (not EOF(1)) do begin
    readf,1,lin
    if (strn(lin) ne '') then begin
      acctnumbers(pp)=strn(strmid(lin,0,8))
      acctpaids(pp)=float(strmid(lin,9,10))
      pp=pp+1
      endif
    endwhile
  close,1
  acctnumbers=acctnumbers(0:pp-1)
  acctpaids=acctpaids(0:pp-1)
  naccts=pp

;-------------------------------------------------------------------------------

  print,'  Budget #  Incurred      Paid      Owes'
  print,'----------  --------  --------   -------'
; print,'    hammer    458.52 -  606.00 = -147.48


  tot=0.0 & otot=0.0 & ptot=0.0
  for i1=0,budgetptr-1>0 do begin
    paidamt=0.0
    for pp=0,naccts-1 do begin
      if (budgetnumbers(i1) eq acctnumbers(pp)) then begin
        paidamt=acctpaids(pp)
        acctflags(pp)=1
        endif
      endfor
    print,budgetnumbers(i1),budgetamounts(i1),paidamt,budgetamounts(i1)-paidamt, $
      format='(a10,f10.2," - ",f7.2," = ",f7.2)'
    tot=tot+budgetamounts(i1)
    ptot=ptot+paidamt
    otot=otot+(budgetamounts(i1)-paidamt)
    endfor


  for i1=0,naccts-1>0 do begin
    if (acctflags(i1) eq 0) then begin
      print,acctnumbers(i1),0.0,acctpaids(i1),0.0-acctpaids(i1), $
        format='(a10,f10.2," - ",f7.2," = ",f7.2)'
      ptot=ptot+acctpaids(i1)
      otot=otot+(0.0-acctpaids(i1))
      endif
    endfor


  print,'            ----------------------------'
  print,'other tot:',tot,ptot,otot, $
    format='(a10,f10.2," - ",f7.2," = ",f7.2)'


end