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
32 #use C4::Interface::CGI::Output;
41 my $time = $input->param('time');
42 my $time2 = $input->param('time2');
43 my $op = $input->param('submit');
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
47 template_name
=> "reports/stats_screen.tmpl",
51 flagsrequired
=> { borrowers
=> 1 },
56 ( $time = "today" ) if !$time;
57 ( $time2 = "tomorrow" ) if !$time2;
59 my $date = ParseDate
($time);
60 my $date2 = ParseDate
($time2);
61 $date = UnixDate
( $date, '%Y-%m-%d' );
62 $date2 = UnixDate
( $date2, '%Y-%m-%d' );
63 warn "MASON: TIME: $time, $time2";
64 warn "MASON: DATE: $date, $date2";
66 # get a list of every payment
67 my @payments = TotalPaid
( $date, $date2 );
69 my $count = @payments;
71 warn "MASON: number of payments=$count\n";
81 # lets get a a list of all individual item charges paid for by that payment
83 foreach my $payment (@payments) {
86 if ( $payment->{'type'} ne 'writeoff' ) {
88 @charges = getcharges
(
89 $payment->{'borrowernumber'},
90 $payment->{'timestamp'},
91 $payment->{'proccode'}
96 # getting each of the charges and putting them into a array to be printed out
97 #this loops per charge per person
98 for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) {
99 my $hour = substr( $payment->{'timestamp'}, 8, 2 );
100 my $min = substr( $payment->{'timestamp'}, 10, 2 );
101 my $sec = substr( $payment->{'timestamp'}, 12, 2 );
102 my $time = "$hour:$min:$sec";
103 my $time2 = "$payment->{'date'}";
105 # my $branch=Getpaidbranch($time2,$payment->{'borrowernumber'});
106 my $branch = $payment->{'branch'};
108 # lets build up a row
111 datetime
=> $payment->{'datetime'},
112 surname
=> $payment->{'surname'},
113 firstname
=> $payment->{'firstname'},
114 description
=> $charges[$i2]->{'description'},
115 accounttype
=> $charges[$i2]->{'accounttype'},
116 amount
=> sprintf( "%.2f", $charges[$i2]->{'amount'} )
117 , # rounding amounts to 2dp
118 type
=> $payment->{'type'},
119 value
=> sprintf( "%.2f", $payment->{'value'} )
120 ); # rounding amounts to 2dp
122 push( @loop1, \
%rows1 );
125 $totalpaid = $totalpaid + $payment->{'value'};
126 warn "totalpaid = $totalpaid";
134 #get credits and append to the bottom of payments
135 my @credits = getcredits
( $date, $date2 );
137 my $count = @credits;
140 while ( $i < $count ) {
143 creditbranch
=> $credits[$i]->{'branchcode'},
144 creditdate
=> $credits[$i]->{'date'},
145 creditsurname
=> $credits[$i]->{'surname'},
146 creditfirstname
=> $credits[$i]->{'firstname'},
147 creditdescription
=> $credits[$i]->{'description'},
148 creditaccounttype
=> $credits[$i]->{'accounttype'},
149 creditamount
=> sprintf( "%.2f", $credits[$i]->{'amount'} )
152 push( @loop2, \
%rows2 );
153 $totalcredits = $totalcredits + $credits[$i]->{'amount'};
154 $i++; #increment the while loop
157 #takes off first char minus sign "-100.00"
158 $totalcredits = substr( $totalcredits, 1 );
160 my $totalrefunds = 0;
162 my @refunds = getrefunds
( $date, $date2 );
166 while ( $i < $count ) {
169 refundbranch
=> $refunds[$i]->{'branchcode'},
170 refunddate
=> $refunds[$i]->{'datetime'},
171 refundsurname
=> $refunds[$i]->{'surname'},
172 refundfirstname
=> $refunds[$i]->{'firstname'},
173 refunddescription
=> $refunds[$i]->{'description'},
174 refundaccounttype
=> $refunds[$i]->{'accounttype'},
175 refundamount
=> sprintf( "%.2f", $refunds[$i]->{'amount'} )
178 push( @loop3, \
%rows3 );
179 $totalrefunds = $totalrefunds + $refunds[$i]->{'amount'};
180 $i++; #increment the while loop
183 my $totalcash = $totalpaid - $totalrefunds;
185 if ( $op eq 'To Excel' ) {
187 my $csv = Text
::CSV_XS
->new(
190 'escape_char' => '"',
196 print $input->header(
197 -type
=> 'application/vnd.ms-excel',
198 -attachment
=> "stats.csv",
201 "Branch, Datetime, Surname, Firstnames, Description, Type, Invoice amount, Payment type, Payment Amount\n";
205 for my $row (@loop1) {
207 $row->{'branch'}, $row->{'datetime'},
208 $row->{'surname'}, $row->{'firstname'},
209 $row->{'description'}, $row->{'accounttype'},
210 $row->{'amount'}, $row->{'type'},
214 $csv->combine(@array);
215 my $string = $csv->string(@array);
220 "Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n";
222 for my $row (@loop2) {
225 $row->{'creditbranch'}, $row->{'creditdate'},
226 $row->{'creditsurname'}, $row->{'creditfirstname'},
227 $row->{'creditdescription'}, $row->{'creditaccounttype'},
228 $row->{'creditamount'}
231 $csv->combine(@array);
232 my $string = $csv->string(@array);
237 "Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n";
239 for my $row (@loop3) {
241 $row->{'refundbranch'}, $row->{'refunddate'},
242 $row->{'refundsurname'}, $row->{'refundfirstname'},
243 $row->{'refunddescription'}, $row->{'refundaccounttype'},
244 $row->{'refundamount'}
247 $csv->combine(@array);
248 my $string = $csv->string(@array);
255 print ",,Total Amount Paid, $totalpaid\n";
256 print ",,Total Number Written, $totalwritten\n";
257 print ",,Total Amount Credits, $totalcredits\n";
258 print ",,Total Amount Refunds, $totalrefunds\n";
267 totalpaid
=> $totalpaid,
268 totalcredits
=> $totalcredits,
269 totalwritten
=> $totalwritten,
270 totalrefund
=> $totalrefunds,
271 totalcash
=> $totalcash
273 output_html_with_http_headers
$input, $cookie, $template->output;