6 #script to display reports
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
34 my $time = $input->param('time');
36 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38 template_name => "circ/stats.tmpl",
42 flagsrequired => { reports => 1 },
50 $template->param(notime => '1');
51 output_html_with_http_headers $input, $cookie, $template->output;
54 if ( $time eq 'yesterday' ) {
55 $date = ParseDate('yesterday');
56 $date2 = ParseDate('today');
58 if ( $time eq 'today' ) {
59 $date = ParseDate('today');
60 $date2 = ParseDate('tomorrow');
62 if ( $time eq 'daybefore' ) {
63 $date = ParseDate('2 days ago');
64 $date2 = ParseDate('yesterday');
66 if ( $time eq 'month' ) {
67 $date = ParseDate('1 month ago');
68 $date2 = ParseDate('today');
69 warn "d : $date // d2 : $date2";
71 if ( $time =~ /\// ) {
72 $date = ParseDate($time);
73 $date2 = ParseDateDelta('+ 1 day');
74 $date2 = DateCalc( $date, $date2 );
76 $date = UnixDate( $date, '%Y-%m-%d' );
77 $date2 = UnixDate( $date2, '%Y-%m-%d' );
78 warn "d : $date // d2 : $date2";
79 my @payments = TotalPaid( $date, $date2 );
80 my $count = @payments;
88 while ( $i < $count ) {
89 warn " pay : " . $payments[$i]{'timestamp'};
90 my $time = $payments[$i]{'datetime'};
91 my $payments = $payments[$i]{'value'};
93 my @temp = split( / /, $payments[$i]{'datetime'} );
96 getcharges( $payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'} );
100 my $temptotalres = 0;
101 my $temptotalren = 0;
104 for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) {
105 $charge += $charges[$i2]->{'amount'};
107 name => $charges[$i2]->{'description'},
108 type => $charges[$i2]->{'accounttype'},
109 time => $charges[$i2]->{'timestamp'},
110 amount => $charges[$i2]->{'amount'},
111 branch => $charges[$i2]->{'amountoutstanding'}
113 push( @loop, \%row );
114 if ( $payments[$i]{'accountytpe'} ne 'W' ) {
115 if ( $charges[$i2]->{'accounttype'} eq 'Rent' ) {
117 $charges[$i2]->{'amount'} -
118 $charges[$i2]->{'amountoutstanding'};
120 if ( $charges[$i2]->{'accounttype'} eq 'F'
121 || $charges[$i2]->{'accounttype'} eq 'FU'
122 || $charges[$i2]->{'accounttype'} eq 'FN' )
125 $charges[$i2]->{'amount'} -
126 $charges[$i2]->{'amountoutstanding'};
128 if ( $charges[$i2]->{'accounttype'} eq 'Res' ) {
130 $charges[$i2]->{'amount'} -
131 $charges[$i2]->{'amountoutstanding'};
133 if ( $charges[$i2]->{'accounttype'} eq 'R' ) {
135 $charges[$i2]->{'amount'} -
136 $charges[$i2]->{'amountoutstanding'};
140 my $hour = substr( $payments[$i]{'timestamp'}, 8, 2 );
141 my $min = substr( $payments[$i]{'timestamp'}, 10, 2 );
142 my $sec = substr( $payments[$i]{'timestamp'}, 12, 2 );
143 my $time = "$hour:$min:$sec";
144 my $time2 = "$payments[$i]{'date'}";
145 my $branch = Getpaidbranch( $time2, $payments[$i]{'borrowernumber'} );
146 my $borrowernumber = $payments[$i]{'borrowernumber'};
147 my $oldtime = $payments[$i]{'timestamp'};
148 my $oldtype = $payments[$i]{'accounttype'};
150 while ($borrowernumber eq $payments[$i]{'borrowernumber'}
151 && $oldtype == $payments[$i]{'accounttype'}
152 && $oldtime eq $payments[$i]{'timestamp'} )
154 my $hour = substr( $payments[$i]{'timestamp'}, 8, 2 );
155 my $min = substr( $payments[$i]{'timestamp'}, 10, 2 );
156 my $sec = substr( $payments[$i]{'timestamp'}, 12, 2 );
157 my $time = "$hour:$min:$sec";
158 my $time2 = "$payments[$i]{'date'}";
159 my $branch = Getpaidbranch( $time2, $payments[$i]{'borrowernumber'} );
160 if ( $payments[$i]{'accounttype'} eq 'W' ) {
161 $totalw += $payments[$i]{'amount'};
164 $payments[$i]{'amount'} = $payments[$i]{'amount'} * -1;
165 $total += $payments[$i]{'amount'};
170 . $payments[$i]{'firstname'}
171 . $payments[$i]{'surname'} . "</b>",
172 type => $payments[$i]{'accounttype'},
173 time => $payments[$i]{'date'},
174 amount => $payments[$i]{'amount'},
177 push( @loop, \%row );
178 $oldtype = $payments[$i]{'accounttype'};
179 $oldtime = $payments[$i]{'timestamp'};
180 $borrowernumber = $payments[$i]{'borrowernumber'};
191 output_html_with_http_headers $input, $cookie, $template->output;