3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
22 use C4::Interface::CGI::Output;
27 &Date_Init("DateFormat=non-US"); # set non-USA date, eg:19/08/2005
30 my $time = $input->param('time');
31 my $time2 = $input->param('time2');
33 if ( $input->param('submit') eq "To Excel"
34 || $input->param('submit_x') eq "To Excel" )
36 print $input->redirect(
37 "/cgi-bin/koha/stats.print.pl?time=$time&time2=$time2");
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42 template_name => "stats_screen.tmpl",
46 flagsrequired => { reports => 1 },
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');
70 if ( $time =~ /\// ) {
71 $date = ParseDate($time);
72 $date2 = ParseDateDelta('+ 1 day');
73 $date2 = DateCalc( $date, $date2 );
78 $date = ParseDate('today');
79 $date2 = ParseDate('tomorrow');
82 # if script is called with a start and finsh date range...
83 if ( $time ne '' && $time2 ne '' ) {
84 $date = ParseDate($time);
85 $date2 = ParseDate($time2);
88 my $date = UnixDate( $date, '%Y-%m-%d' );
89 my $date2 = UnixDate( $date2, '%Y-%m-%d' );
91 # warn "MASON: TIME: $time, $time2";
92 # warn "MASON: DATE: $date, $date2";
94 # get a list of every payment
95 my @payments = TotalPaid( $date, $date2, 0 );
97 my $count = @payments;
99 # print "MASON: number of payments=$count\n";
102 my $totalcharges = 0;
103 my $totalcredits = 0;
105 my $totalwritten = 0;
109 # lets get a a list of all individual item charges paid for by that payment
110 while ( $i < $count ) {
115 if ( $payments[$i]{'type'} ne 'writeoff' ) {
117 @charges = getcharges(
118 $payments[$i]{'borrowernumber'},
119 $payments[$i]{'timestamp'},
120 $payments[$i]{'proccode'}
125 # getting each of the charges and putting them into a array to be printed out
126 #this loops per charge per person
127 for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) {
128 my $hour = substr( $payments[$i]{'timestamp'}, 8, 2 );
129 my $min = substr( $payments[$i]{'timestamp'}, 10, 2 );
130 my $sec = substr( $payments[$i]{'timestamp'}, 12, 2 );
131 my $time = "$hour:$min:$sec";
132 my $time2 = "$payments[$i]{'date'}";
134 # my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
135 my $branch = $payments[$i]{'branch'};
137 # if ($payments[$i]{'borrowernumber'} == 18265){
138 # warn "$payments[$i]{'branch'} $branch $payments[$i]{'borrowernumber'}";#
140 # lets build up a row
143 datetime => $payments[$i]->{'datetime'},
144 surname => $payments[$i]->{'surname'},
145 firstname => $payments[$i]->{'firstname'},
146 description => $charges[$i2]->{'description'},
147 accounttype => $charges[$i2]->{'accounttype'},
148 amount => sprintf( "%.2f", $charges[$i2]->{'amount'} )
149 , # rounding amounts to 2dp
150 type => $payments[$i]->{'type'},
151 value => sprintf( "%.2f", $payments[$i]->{'value'} )
152 ); # rounding amounts to 2dp
154 push( @loop1, \%rows1 );
155 $totalpaid = $totalpaid + $payments[$i]->{'value'};
162 $i++; #increment the while loop
165 #get credits and append to the bottom of payments
166 my @credits = getcredits( $date, $date2 );
168 my $count = @credits;
171 while ( $i < $count ) {
174 creditbranch => $credits[$i]->{'branchcode'},
175 creditdate => $credits[$i]->{'date'},
176 creditsurname => $credits[$i]->{'surname'},
177 creditfirstname => $credits[$i]->{'firstname'},
178 creditdescription => $credits[$i]->{'description'},
179 creditaccounttype => $credits[$i]->{'accounttype'},
180 creditamount => sprintf( "%.2f", $credits[$i]->{'amount'} )
183 push( @loop2, \%rows2 );
184 $totalcredits = $totalcredits + $credits[$i]->{'amount'};
185 $i++; #increment the while loop
188 #takes off first char minus sign "-100.00"
189 $totalcredits = substr( $totalcredits, 1 );
191 my $totalrefunds = 0;
193 my @refunds = getrefunds( $date, $date2 );
197 while ( $i < $count ) {
200 refundbranch => $refunds[$i]->{'branchcode'},
201 refunddate => $refunds[$i]->{'date'},
202 refundsurname => $refunds[$i]->{'surname'},
203 refundfirstname => $refunds[$i]->{'firstname'},
204 refunddescription => $refunds[$i]->{'description'},
205 refundaccounttype => $refunds[$i]->{'accounttype'},
206 refundamount => sprintf( "%.2f", $refunds[$i]->{'amount'} )
209 push( @loop3, \%rows2 );
210 $totalrefunds = $totalrefunds + $refunds[$i]->{'amount'};
211 $i++; #increment the while loop
214 my $totalcash = $totalpaid - $totalrefunds;
222 totalpaid => $totalpaid,
223 totalcredits => $totalcredits,
224 totalwritten => $totalwritten,
225 totalrefund => $totalrefunds,
226 totalcash => $totalcash
229 output_html_with_http_headers $input, $cookie, $template->output;