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
19 #use warnings; FIXME - Bug 2505
30 my $time = $input->param('time');
31 my $time2 = $input->param('time2');
32 my $op = $input->param('submit');
34 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
36 template_name
=> "reports/stats_screen.tmpl",
40 flagsrequired
=> { reports
=> '*' },
45 ( $time = "today" ) if !$time;
46 ( $time2 = "tomorrow" ) if !$time2;
48 my $date = ParseDate
($time);
49 my $date2 = ParseDate
($time2);
50 $date = UnixDate
( $date, '%Y-%m-%d' );
51 $date2 = UnixDate
( $date2, '%Y-%m-%d' );
52 $debug and warn "MASON: TIME: $time, $time2";
53 $debug and warn "MASON: DATE: $date, $date2";
55 # get a list of every payment
56 my @payments = TotalPaid
( $date, $date2 );
58 my $count = @payments;
60 $debug and warn "MASON: number of payments=$count\n";
70 # lets get a a list of all individual item charges paid for by that payment
72 foreach my $payment (@payments) {
75 if ( $payment->{'type'} ne 'writeoff' ) {
77 @charges = getcharges
(
78 $payment->{'borrowernumber'},
79 $payment->{'timestamp'},
80 $payment->{'proccode'}
85 # getting each of the charges and putting them into a array to be printed out
86 #this loops per charge per person
87 for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) {
88 my $hour = substr( $payment->{'timestamp'}, 8, 2 );
89 my $min = substr( $payment->{'timestamp'}, 10, 2 );
90 my $sec = substr( $payment->{'timestamp'}, 12, 2 );
91 my $time = "$hour:$min:$sec";
92 my $time2 = "$payment->{'date'}";
94 # my $branch=Getpaidbranch($time2,$payment->{'borrowernumber'});
95 my $branch = $payment->{'branch'};
100 datetime
=> $payment->{'datetime'},
101 surname
=> $payment->{'surname'},
102 firstname
=> $payment->{'firstname'},
103 description
=> $charges[$i2]->{'description'},
104 accounttype
=> $charges[$i2]->{'accounttype'},
105 amount
=> sprintf( "%.2f", $charges[$i2]->{'amount'} )
106 , # rounding amounts to 2dp
107 type
=> $payment->{'type'},
108 value
=> sprintf( "%.2f", $payment->{'value'} )
109 ); # rounding amounts to 2dp
111 push( @loop1, \
%rows1 );
114 $totalpaid = $totalpaid + $payment->{'value'};
115 $debug and warn "totalpaid = $totalpaid";
123 #get credits and append to the bottom of payments
124 my @credits = getcredits
( $date, $date2 );
126 my $count = @credits;
129 while ( $i < $count ) {
132 creditbranch
=> $credits[$i]->{'branchcode'},
133 creditdate
=> $credits[$i]->{'date'},
134 creditsurname
=> $credits[$i]->{'surname'},
135 creditfirstname
=> $credits[$i]->{'firstname'},
136 creditdescription
=> $credits[$i]->{'description'},
137 creditaccounttype
=> $credits[$i]->{'accounttype'},
138 creditamount
=> sprintf( "%.2f", $credits[$i]->{'amount'} )
141 push( @loop2, \
%rows2 );
142 $totalcredits = $totalcredits + $credits[$i]->{'amount'};
143 $i++; #increment the while loop
146 #takes off first char minus sign "-100.00"
147 $totalcredits = substr( $totalcredits, 1 );
149 my $totalrefunds = 0;
151 my @refunds = getrefunds
( $date, $date2 );
155 while ( $i < $count ) {
158 refundbranch
=> $refunds[$i]->{'branchcode'},
159 refunddate
=> $refunds[$i]->{'datetime'},
160 refundsurname
=> $refunds[$i]->{'surname'},
161 refundfirstname
=> $refunds[$i]->{'firstname'},
162 refunddescription
=> $refunds[$i]->{'description'},
163 refundaccounttype
=> $refunds[$i]->{'accounttype'},
164 refundamount
=> sprintf( "%.2f", $refunds[$i]->{'amount'} )
167 push( @loop3, \
%rows3 );
168 $totalrefunds = $totalrefunds + $refunds[$i]->{'amount'};
169 $i++; #increment the while loop
172 my $totalcash = $totalpaid - $totalrefunds;
174 if ( $op eq 'To Excel' ) {
176 my $csv = Text
::CSV_XS
->new(
179 'escape_char' => '"',
185 print $input->header(
186 -type
=> 'application/vnd.ms-excel',
187 -attachment
=> "stats.csv",
190 "Branch, Datetime, Surname, Firstnames, Description, Type, Invoice amount, Payment type, Payment Amount\n";
194 for my $row (@loop1) {
196 $row->{'branch'}, $row->{'datetime'},
197 $row->{'surname'}, $row->{'firstname'},
198 $row->{'description'}, $row->{'accounttype'},
199 $row->{'amount'}, $row->{'type'},
203 $csv->combine(@array);
204 my $string = $csv->string(@array);
209 "Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n";
211 for my $row (@loop2) {
214 $row->{'creditbranch'}, $row->{'creditdate'},
215 $row->{'creditsurname'}, $row->{'creditfirstname'},
216 $row->{'creditdescription'}, $row->{'creditaccounttype'},
217 $row->{'creditamount'}
220 $csv->combine(@array);
221 my $string = $csv->string(@array);
226 "Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n";
228 for my $row (@loop3) {
230 $row->{'refundbranch'}, $row->{'refunddate'},
231 $row->{'refundsurname'}, $row->{'refundfirstname'},
232 $row->{'refunddescription'}, $row->{'refundaccounttype'},
233 $row->{'refundamount'}
236 $csv->combine(@array);
237 my $string = $csv->string(@array);
244 print ",,Total Amount Paid, $totalpaid\n";
245 print ",,Total Number Written, $totalwritten\n";
246 print ",,Total Amount Credits, $totalcredits\n";
247 print ",,Total Amount Refunds, $totalrefunds\n";
256 totalpaid
=> $totalpaid,
257 totalcredits
=> $totalcredits,
258 totalwritten
=> $totalwritten,
259 totalrefund
=> $totalrefunds,
260 totalcash
=> $totalcash,
261 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
263 output_html_with_http_headers
$input, $cookie, $template->output;