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