5 #script to display reports
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
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
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.
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
33 my $time = $input->param('time');
35 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37 template_name => "circ/stats.tmpl",
41 flagsrequired => { reports => 1 },
49 $template->param(notime => '1');
50 output_html_with_http_headers $input, $cookie, $template->output;
53 if ( $time eq 'yesterday' ) {
54 $date = ParseDate('yesterday');
55 $date2 = ParseDate('today');
57 if ( $time eq 'today' ) {
58 $date = ParseDate('today');
59 $date2 = ParseDate('tomorrow');
61 if ( $time eq 'daybefore' ) {
62 $date = ParseDate('2 days ago');
63 $date2 = ParseDate('yesterday');
65 if ( $time eq 'month' ) {
66 $date = ParseDate('1 month ago');
67 $date2 = ParseDate('today');
68 warn "d : $date // d2 : $date2";
70 if ( $time =~ /\// ) {
71 $date = ParseDate($time);
72 $date2 = ParseDateDelta('+ 1 day');
73 $date2 = DateCalc( $date, $date2 );
75 $date = UnixDate( $date, '%Y-%m-%d' );
76 $date2 = UnixDate( $date2, '%Y-%m-%d' );
77 warn "d : $date // d2 : $date2";
78 my @payments = TotalPaid( $date, $date2 );
79 my $count = @payments;
87 while ( $i < $count ) {
88 warn " pay : " . $payments[$i]{'timestamp'};
89 my $time = $payments[$i]{'datetime'};
90 my $payments = $payments[$i]{'value'};
92 my @temp = split( / /, $payments[$i]{'datetime'} );
95 getcharges( $payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'} );
100 my $temptotalren = 0;
103 for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) {
104 $charge += $charges[$i2]->{'amount'};
106 name => $charges[$i2]->{'description'},
107 type => $charges[$i2]->{'accounttype'},
108 time => $charges[$i2]->{'timestamp'},
109 amount => $charges[$i2]->{'amount'},
110 branch => $charges[$i2]->{'amountoutstanding'}
112 push( @loop, \%row );
113 if ( $payments[$i]{'accountytpe'} ne 'W' ) {
114 if ( $charges[$i2]->{'accounttype'} eq 'Rent' ) {
116 $charges[$i2]->{'amount'} -
117 $charges[$i2]->{'amountoutstanding'};
119 if ( $charges[$i2]->{'accounttype'} eq 'F'
120 || $charges[$i2]->{'accounttype'} eq 'FU'
121 || $charges[$i2]->{'accounttype'} eq 'FN' )
124 $charges[$i2]->{'amount'} -
125 $charges[$i2]->{'amountoutstanding'};
127 if ( $charges[$i2]->{'accounttype'} eq 'Res' ) {
129 $charges[$i2]->{'amount'} -
130 $charges[$i2]->{'amountoutstanding'};
132 if ( $charges[$i2]->{'accounttype'} eq 'R' ) {
134 $charges[$i2]->{'amount'} -
135 $charges[$i2]->{'amountoutstanding'};
139 my $hour = substr( $payments[$i]{'timestamp'}, 8, 2 );
140 my $min = substr( $payments[$i]{'timestamp'}, 10, 2 );
141 my $sec = substr( $payments[$i]{'timestamp'}, 12, 2 );
142 my $time = "$hour:$min:$sec";
143 my $time2 = "$payments[$i]{'date'}";
144 my $branch = Getpaidbranch( $time2, $payments[$i]{'borrowernumber'} );
145 my $borrowernumber = $payments[$i]{'borrowernumber'};
146 my $oldtime = $payments[$i]{'timestamp'};
147 my $oldtype = $payments[$i]{'accounttype'};
149 while ($borrowernumber eq $payments[$i]{'borrowernumber'}
150 && $oldtype == $payments[$i]{'accounttype'}
151 && $oldtime eq $payments[$i]{'timestamp'} )
153 my $hour = substr( $payments[$i]{'timestamp'}, 8, 2 );
154 my $min = substr( $payments[$i]{'timestamp'}, 10, 2 );
155 my $sec = substr( $payments[$i]{'timestamp'}, 12, 2 );
156 my $time = "$hour:$min:$sec";
157 my $time2 = "$payments[$i]{'date'}";
158 my $branch = Getpaidbranch( $time2, $payments[$i]{'borrowernumber'} );
159 if ( $payments[$i]{'accounttype'} eq 'W' ) {
160 $totalw += $payments[$i]{'amount'};
163 $payments[$i]{'amount'} = $payments[$i]{'amount'} * -1;
164 $total += $payments[$i]{'amount'};
169 . $payments[$i]{'firstname'}
170 . $payments[$i]{'surname'} . "</b>",
171 type => $payments[$i]{'accounttype'},
172 time => $payments[$i]{'date'},
173 amount => $payments[$i]{'amount'},
176 push( @loop, \%row );
177 $oldtype = $payments[$i]{'accounttype'};
178 $oldtime = $payments[$i]{'timestamp'};
179 $borrowernumber = $payments[$i]{'borrowernumber'};
190 output_html_with_http_headers $input, $cookie, $template->output;