rel_3_0 moved to HEAD
[koha_fer] / reports / stats.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 CGI;
28 use C4::Output;
29 use C4::Auth;
30 use C4::Interface::CGI::Output;
31 use C4::Context;
32 use Date::Manip;
33 use C4::Stats;
34
35 my $input=new CGI;
36 my $time=$input->param('time');
37 my $date=$input->param('from');
38 my $date2=$input->param('to');
39 my ($template, $loggedinuser, $cookie)
40     = get_template_and_user({template_name => "stats.tmpl",
41                              query => $input,
42                              type => "intranet",
43                              authnotrequired => 0,
44                              flagsrequired => {borrowers => 1},
45                              debug => 1,
46                              });
47
48
49
50 my @payments=TotalPaid($date,$date2);
51 my $count=@payments;
52 my $total=0;
53 my $oldtime;
54 my $totalw=0;
55 my @loop;
56 my %row;
57 my $i=0;
58 while ($i<$count){
59 #       warn " pay : ".$payments[$i]{'timestamp'};
60         my $time=$payments[$i]{'datetime'};
61         my $payments=$payments[$i]{'value'};
62         my $charge=0;
63         my @temp=split(/ /,$payments[$i]{'datetime'});
64         my $date=$payments[$i]{'date'};
65
66         my @charges=getcharges($payments[$i]{'borrowernumber'},$payments[$i]{'date'});
67         my $count2=@charges;
68 warn "$count2";
69         my $temptotalf=0;
70         my $temptotalr=0;
71         my $temptotalres=0;
72         my $temptotalren=0;
73         my $temptotalw=0;
74         for (my $i2=0;$i2<$count2;$i2++){
75                 $charge+=$charges[$i2]->{'amount'};
76                 %row = ( name   => $charges[$i2]->{'description'},
77                                         type   => $charges[$i2]->{'accounttype'},
78                                         time   => $charges[$i2]->{'timestamp'},
79                                         amount => $charges[$i2]->{'amount'},
80                                         branch => $charges[$i2]->{'amountoutstanding'} );
81                 push(@loop, \%row);
82                 if ($payments[$i]{'accountytpe'} ne 'W'){
83                         if ($charges[$i2]->{'accounttype'} eq 'Rent'){
84                                 $temptotalr+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
85                         }
86                         if ($charges[$i2]->{'accounttype'} eq 'F' || $charges[$i2]->{'accounttype'} eq 'FU' || $charges[$i2]->{'accounttype'} eq 'FN' ){
87                                 $temptotalf+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
88                         }
89                         if ($charges[$i2]->{'accounttype'} eq 'Res'){
90                                 $temptotalres+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
91                         }
92                         if ($charges[$i2]->{'accounttype'} eq 'R'){
93                         $temptotalren+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
94                         }
95                 }
96         }
97         my $hour=substr($payments[$i]{'timestamp'},8,2);
98         my  $min=substr($payments[$i]{'timestamp'},10,2);
99         my $sec=substr($payments[$i]{'timestamp'},12,2);
100         my $time="$hour:$min:$sec";
101         my $time2="$payments[$i]{'date'}";
102         my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
103         my $bornum=$payments[$i]{'borrowernumber'};
104         my $oldtime=$payments[$i]{'timestamp'};
105         my $oldtype=$payments[$i]{'accounttype'};
106         while ($bornum eq $payments[$i]{'borrowernumber'} && $oldtype == $payments[$i]{'accounttype'}  && $oldtime eq $payments[$i]{'timestamp'}){
107                 my $hour=substr($payments[$i]{'timestamp'},8,2);
108                 my  $min=substr($payments[$i]{'timestamp'},10,2);
109                 my $sec=substr($payments[$i]{'timestamp'},12,2);
110                 my $time="$hour:$min:$sec";
111                 my $time2="$payments[$i]{'date'}";
112                 my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
113                 if ($payments[$i]{'accounttype'} eq 'W'){
114                         $totalw+=$payments[$i]{'amount'};
115                 } else {
116                         $payments[$i]{'amount'}=$payments[$i]{'amount'}*-1;
117                         $total+=$payments[$i]{'amount'};
118                 }
119
120                 %row = ( name   => "<b>".$payments[$i]{'firstname'}.$payments[$i]{'surname'} . "</b>",
121                                         type   => $payments[$i]{'accounttype'}, time   => $payments[$i]{'date'},
122                                         amount => $payments[$i]{'amount'}, branch => $branch );
123                 push(@loop, \%row);
124                 $oldtype=$payments[$i]{'accounttype'};
125                 $oldtime=$payments[$i]{'timestamp'};
126                 $bornum=$payments[$i]{'borrowernumber'};
127                 $i++;
128         }
129
130 }
131
132 $template->param( loop1   => \@loop,
133                   totalw => $totalw,
134                   total  => $total );
135
136 output_html_with_http_headers $input, $cookie, $template->output;
137
138