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
34 my $time = $input->param('time');
35 my $time2 = $input->param('time2');
36 my $op = $input->param('submit');
38 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
40 template_name
=> "reports/stats_screen.tmpl",
44 flagsrequired
=> { borrowers
=> 1 },
49 ( $time = "today" ) if !$time;
50 ( $time2 = "tomorrow" ) if !$time2;
52 my $date = ParseDate
($time);
53 my $date2 = ParseDate
($time2);
54 $date = UnixDate
( $date, '%Y-%m-%d' );
55 $date2 = UnixDate
( $date2, '%Y-%m-%d' );
56 $debug and warn "MASON: TIME: $time, $time2";
57 $debug and warn "MASON: DATE: $date, $date2";
59 # get a list of every payment
60 my @payments = TotalPaid
( $date, $date2 );
62 my $count = @payments;
64 $debug and warn "MASON: number of payments=$count\n";
74 # lets get a a list of all individual item charges paid for by that payment
76 foreach my $payment (@payments) {
79 if ( $payment->{'type'} ne 'writeoff' ) {
81 @charges = getcharges
(
82 $payment->{'borrowernumber'},
83 $payment->{'timestamp'},
84 $payment->{'proccode'}
89 # getting each of the charges and putting them into a array to be printed out
90 #this loops per charge per person
91 for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) {
92 my $hour = substr( $payment->{'timestamp'}, 8, 2 );
93 my $min = substr( $payment->{'timestamp'}, 10, 2 );
94 my $sec = substr( $payment->{'timestamp'}, 12, 2 );
95 my $time = "$hour:$min:$sec";
96 my $time2 = "$payment->{'date'}";
98 # my $branch=Getpaidbranch($time2,$payment->{'borrowernumber'});
99 my $branch = $payment->{'branch'};
101 # lets build up a row
104 datetime
=> $payment->{'datetime'},
105 surname
=> $payment->{'surname'},
106 firstname
=> $payment->{'firstname'},
107 description
=> $charges[$i2]->{'description'},
108 accounttype
=> $charges[$i2]->{'accounttype'},
109 amount
=> sprintf( "%.2f", $charges[$i2]->{'amount'} )
110 , # rounding amounts to 2dp
111 type
=> $payment->{'type'},
112 value
=> sprintf( "%.2f", $payment->{'value'} )
113 ); # rounding amounts to 2dp
115 push( @loop1, \
%rows1 );
118 $totalpaid = $totalpaid + $payment->{'value'};
119 $debug and warn "totalpaid = $totalpaid";
127 #get credits and append to the bottom of payments
128 my @credits = getcredits
( $date, $date2 );
130 my $count = @credits;
133 while ( $i < $count ) {
136 creditbranch
=> $credits[$i]->{'branchcode'},
137 creditdate
=> $credits[$i]->{'date'},
138 creditsurname
=> $credits[$i]->{'surname'},
139 creditfirstname
=> $credits[$i]->{'firstname'},
140 creditdescription
=> $credits[$i]->{'description'},
141 creditaccounttype
=> $credits[$i]->{'accounttype'},
142 creditamount
=> sprintf( "%.2f", $credits[$i]->{'amount'} )
145 push( @loop2, \
%rows2 );
146 $totalcredits = $totalcredits + $credits[$i]->{'amount'};
147 $i++; #increment the while loop
150 #takes off first char minus sign "-100.00"
151 $totalcredits = substr( $totalcredits, 1 );
153 my $totalrefunds = 0;
155 my @refunds = getrefunds
( $date, $date2 );
159 while ( $i < $count ) {
162 refundbranch
=> $refunds[$i]->{'branchcode'},
163 refunddate
=> $refunds[$i]->{'datetime'},
164 refundsurname
=> $refunds[$i]->{'surname'},
165 refundfirstname
=> $refunds[$i]->{'firstname'},
166 refunddescription
=> $refunds[$i]->{'description'},
167 refundaccounttype
=> $refunds[$i]->{'accounttype'},
168 refundamount
=> sprintf( "%.2f", $refunds[$i]->{'amount'} )
171 push( @loop3, \
%rows3 );
172 $totalrefunds = $totalrefunds + $refunds[$i]->{'amount'};
173 $i++; #increment the while loop
176 my $totalcash = $totalpaid - $totalrefunds;
178 if ( $op eq 'To Excel' ) {
180 my $csv = Text
::CSV_XS
->new(
183 'escape_char' => '"',
189 print $input->header(
190 -type
=> 'application/vnd.ms-excel',
191 -attachment
=> "stats.csv",
194 "Branch, Datetime, Surname, Firstnames, Description, Type, Invoice amount, Payment type, Payment Amount\n";
198 for my $row (@loop1) {
200 $row->{'branch'}, $row->{'datetime'},
201 $row->{'surname'}, $row->{'firstname'},
202 $row->{'description'}, $row->{'accounttype'},
203 $row->{'amount'}, $row->{'type'},
207 $csv->combine(@array);
208 my $string = $csv->string(@array);
213 "Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n";
215 for my $row (@loop2) {
218 $row->{'creditbranch'}, $row->{'creditdate'},
219 $row->{'creditsurname'}, $row->{'creditfirstname'},
220 $row->{'creditdescription'}, $row->{'creditaccounttype'},
221 $row->{'creditamount'}
224 $csv->combine(@array);
225 my $string = $csv->string(@array);
230 "Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n";
232 for my $row (@loop3) {
234 $row->{'refundbranch'}, $row->{'refunddate'},
235 $row->{'refundsurname'}, $row->{'refundfirstname'},
236 $row->{'refunddescription'}, $row->{'refundaccounttype'},
237 $row->{'refundamount'}
240 $csv->combine(@array);
241 my $string = $csv->string(@array);
248 print ",,Total Amount Paid, $totalpaid\n";
249 print ",,Total Number Written, $totalwritten\n";
250 print ",,Total Amount Credits, $totalcredits\n";
251 print ",,Total Amount Refunds, $totalrefunds\n";
260 totalpaid
=> $totalpaid,
261 totalcredits
=> $totalcredits,
262 totalwritten
=> $totalwritten,
263 totalrefund
=> $totalrefunds,
264 totalcash
=> $totalcash,
265 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
267 output_html_with_http_headers
$input, $cookie, $template->output;