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
37 my $time = $input->param('time') || '';
39 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41 template_name => "circ/stats.tmpl",
45 flagsrequired => { reports => 1 },
52 if ( $time eq 'yesterday' ) {
53 $date = ParseDate('yesterday');
54 $date2 = ParseDate('today');
56 elsif ( $time eq 'today' ) {
57 $date = ParseDate('today');
58 $date2 = ParseDate('tomorrow');
60 elsif ( $time eq 'daybefore' ) {
61 $date = ParseDate('2 days ago');
62 $date2 = ParseDate('yesterday');
64 elsif ( $time eq 'month' ) {
65 $date = ParseDate('1 month ago');
66 $date2 = ParseDate('today');
68 elsif ( $time =~ /\// ) {
69 $date = ParseDate($time);
70 $date2 = ParseDateDelta('+ 1 day');
71 $date2 = DateCalc( $date, $date2 );
73 $template->param(notime => '1'); # TODO: add error feedback if time sent, but unrecognized
74 output_html_with_http_headers $input, $cookie, $template->output;
78 $debug and warn "d : $date // d2 : $date2";
79 $date = UnixDate( $date, '%Y-%m-%d' );
80 $date2 = UnixDate( $date2, '%Y-%m-%d' );
81 $debug and warn "d : $date // d2 : $date2";
82 my @payments = TotalPaid( $date, $date2 );
83 my $count = @payments;
91 while ( $i < $count ) {
92 $debug and warn " pay : " . $payments[$i]{'timestamp'};
93 my $time = $payments[$i]{'datetime'};
94 my $payments = $payments[$i]{'value'};
96 my @temp = split(/ /, $payments[$i]{'datetime'});
99 getcharges( $payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'} );
100 my $count = @charges;
103 my $temptotalres = 0;
104 my $temptotalren = 0;
107 # FIXME: way too much logic to live only here in a report script
108 for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) {
109 $charge += $charges[$i2]->{'amount'};
111 name => $charges[$i2]->{'description'},
112 type => $charges[$i2]->{'accounttype'},
113 time => $charges[$i2]->{'timestamp'},
114 amount => $charges[$i2]->{'amount'},
115 branch => $charges[$i2]->{'amountoutstanding'}
117 push( @loop, \%row );
118 if ( $payments[$i]{'accountytpe'} ne 'W' ) {
119 if ( $charges[$i2]->{'accounttype'} eq 'Rent' ) {
121 $charges[$i2]->{'amount'} -
122 $charges[$i2]->{'amountoutstanding'};
124 if ( $charges[$i2]->{'accounttype'} eq 'F'
125 || $charges[$i2]->{'accounttype'} eq 'FU'
126 || $charges[$i2]->{'accounttype'} eq 'FN' )
129 $charges[$i2]->{'amount'} -
130 $charges[$i2]->{'amountoutstanding'};
132 if ( $charges[$i2]->{'accounttype'} eq 'Res' ) {
134 $charges[$i2]->{'amount'} -
135 $charges[$i2]->{'amountoutstanding'};
137 if ( $charges[$i2]->{'accounttype'} eq 'R' ) {
139 $charges[$i2]->{'amount'} -
140 $charges[$i2]->{'amountoutstanding'};
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 $xtime2 = $payments[$i]{'date'};
155 my $branch = Getpaidbranch( $xtime2, $payments[$i]{'borrowernumber'} );
156 if ( $payments[$i]{'accounttype'} eq 'W' ) {
157 $totalw += $payments[$i]{'amount'};
160 $payments[$i]{'amount'} = $payments[$i]{'amount'} * -1;
161 $total += $payments[$i]{'amount'};
164 #FIXME: display layer HTML
167 . $payments[$i]{'firstname'}
168 . $payments[$i]{'surname'} . "</b>",
169 type => $payments[$i]{'accounttype'},
170 time => $payments[$i]{'date'},
171 amount => $payments[$i]{'amount'},
174 push( @loop, \%row );
175 $oldtype = $payments[$i]{'accounttype'};
176 $oldtime = $payments[$i]{'timestamp'};
177 $borrowernumber = $payments[$i]{'borrowernumber'};
188 output_html_with_http_headers $input, $cookie, $template->output;