Added some FIXME comments.
[koha.git] / stats2.pl
1 #!/usr/bin/perl
2
3 #written 14/1/2000
4 #script to display reports
5
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 use C4::Context;
26 use C4::Stats;
27 use Date::Manip;
28 use CGI;
29 use C4::Output;
30 use DBI;
31
32 my $input=new CGI;
33 my $time=$input->param('time');
34 print $input->header;
35
36 print startpage;
37 print startmenu('report');
38 print center;
39
40 my $date;
41 my $date2;
42 if ($time eq 'yesterday'){
43   $date=ParseDate('yesterday');
44   $date2=ParseDate('today');
45 }
46 if ($time eq 'today'){
47   $date=ParseDate('today');
48   $date2=ParseDate('tomorrow');
49 }
50 if ($time eq 'daybefore'){
51   $date=ParseDate('2 days ago');
52   $date2=ParseDate('yesterday');
53 }
54 if ($time=~ /\//){
55   $date=ParseDate($time);
56   $date2=ParseDateDelta('+ 1 day');
57   $date2=DateCalc($date,$date2);
58 }
59 $date=UnixDate($date,'%Y-%m-%d');
60 $date2=UnixDate($date2,'%Y-%m-%d');
61
62 my $dbh = C4::Context->dbh;
63 my $query="select * 
64 from accountlines,accountoffsets,borrowers where
65 accountlines.borrowernumber=accountoffsets.borrowernumber and
66 (accountlines.accountno=accountoffsets.accountno or accountlines.accountno
67 =accountoffsets.offsetaccount) and accountlines.timestamp >=20000621000000 
68 and borrowers.borrowernumber=accountlines.borrowernumber
69 group by accountlines.borrowernumber,accountlines.accountno";
70 my $sth=$dbh->prepare($query);
71 $sth->execute;
72
73
74
75 print mktablehdr;
76 while (my $data=$sth->fetchrow_hashref){
77   print "<TR><Td>$data->{'surname'}</td><td>$data->{'description'}</td><td>$data->{'amount'}
78   </td>";
79   if ($data->{'accountype'}='Pay'){     # FIXME - This should be "==", not "=", right?
80     my $branch=Getpaidbranch($data->{'timestamp'});
81     print "<td>$branch</td>";
82   }
83   print "</tr>";
84
85 }
86
87
88 print mktableft;
89 print endcenter;
90 #print "<p><b>$total</b>";
91
92
93
94 print endmenu('report');
95 print endpage;
96 $sth->finish;