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
29 my $time = $input->param('time');
30 my $time2 = $input->param('time2');
31 my $op = $input->param('submit');
33 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
35 template_name
=> "reports/stats_screen.tmpl",
39 flagsrequired
=> { reports
=> 1 },
44 ( $time = "today" ) if !$time;
45 ( $time2 = "tomorrow" ) if !$time2;
47 my $date = ParseDate
($time);
48 my $date2 = ParseDate
($time2);
49 $date = UnixDate
( $date, '%Y-%m-%d' );
50 $date2 = UnixDate
( $date2, '%Y-%m-%d' );
51 $debug and warn "MASON: TIME: $time, $time2";
52 $debug and warn "MASON: DATE: $date, $date2";
54 # get a list of every payment
55 my @payments = TotalPaid
( $date, $date2 );
57 my $count = @payments;
59 $debug and warn "MASON: number of payments=$count\n";
69 # lets get a a list of all individual item charges paid for by that payment
71 foreach my $payment (@payments) {
74 if ( $payment->{'type'} ne 'writeoff' ) {
76 @charges = getcharges
(
77 $payment->{'borrowernumber'},
78 $payment->{'timestamp'},
79 $payment->{'proccode'}
84 # getting each of the charges and putting them into a array to be printed out
85 #this loops per charge per person
86 for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) {
87 my $hour = substr( $payment->{'timestamp'}, 8, 2 );
88 my $min = substr( $payment->{'timestamp'}, 10, 2 );
89 my $sec = substr( $payment->{'timestamp'}, 12, 2 );
90 my $time = "$hour:$min:$sec";
91 my $time2 = "$payment->{'date'}";
93 # my $branch=Getpaidbranch($time2,$payment->{'borrowernumber'});
94 my $branch = $payment->{'branch'};
99 datetime
=> $payment->{'datetime'},
100 surname
=> $payment->{'surname'},
101 firstname
=> $payment->{'firstname'},
102 description
=> $charges[$i2]->{'description'},
103 accounttype
=> $charges[$i2]->{'accounttype'},
104 amount
=> sprintf( "%.2f", $charges[$i2]->{'amount'} )
105 , # rounding amounts to 2dp
106 type
=> $payment->{'type'},
107 value
=> sprintf( "%.2f", $payment->{'value'} )
108 ); # rounding amounts to 2dp
110 push( @loop1, \
%rows1 );
113 $totalpaid = $totalpaid + $payment->{'value'};
114 $debug and warn "totalpaid = $totalpaid";
122 #get credits and append to the bottom of payments
123 my @credits = getcredits
( $date, $date2 );
125 my $count = @credits;
128 while ( $i < $count ) {
131 creditbranch
=> $credits[$i]->{'branchcode'},
132 creditdate
=> $credits[$i]->{'date'},
133 creditsurname
=> $credits[$i]->{'surname'},
134 creditfirstname
=> $credits[$i]->{'firstname'},
135 creditdescription
=> $credits[$i]->{'description'},
136 creditaccounttype
=> $credits[$i]->{'accounttype'},
137 creditamount
=> sprintf( "%.2f", $credits[$i]->{'amount'} )
140 push( @loop2, \
%rows2 );
141 $totalcredits = $totalcredits + $credits[$i]->{'amount'};
142 $i++; #increment the while loop
145 #takes off first char minus sign "-100.00"
146 $totalcredits = substr( $totalcredits, 1 );
148 my $totalrefunds = 0;
150 my @refunds = getrefunds
( $date, $date2 );
154 while ( $i < $count ) {
157 refundbranch
=> $refunds[$i]->{'branchcode'},
158 refunddate
=> $refunds[$i]->{'datetime'},
159 refundsurname
=> $refunds[$i]->{'surname'},
160 refundfirstname
=> $refunds[$i]->{'firstname'},
161 refunddescription
=> $refunds[$i]->{'description'},
162 refundaccounttype
=> $refunds[$i]->{'accounttype'},
163 refundamount
=> sprintf( "%.2f", $refunds[$i]->{'amount'} )
166 push( @loop3, \
%rows3 );
167 $totalrefunds = $totalrefunds + $refunds[$i]->{'amount'};
168 $i++; #increment the while loop
171 my $totalcash = $totalpaid - $totalrefunds;
173 if ( $op eq 'To Excel' ) {
175 my $csv = Text
::CSV_XS
->new(
178 'escape_char' => '"',
184 print $input->header(
185 -type
=> 'application/vnd.ms-excel',
186 -attachment
=> "stats.csv",
189 "Branch, Datetime, Surname, Firstnames, Description, Type, Invoice amount, Payment type, Payment Amount\n";
193 for my $row (@loop1) {
195 $row->{'branch'}, $row->{'datetime'},
196 $row->{'surname'}, $row->{'firstname'},
197 $row->{'description'}, $row->{'accounttype'},
198 $row->{'amount'}, $row->{'type'},
202 $csv->combine(@array);
203 my $string = $csv->string(@array);
208 "Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n";
210 for my $row (@loop2) {
213 $row->{'creditbranch'}, $row->{'creditdate'},
214 $row->{'creditsurname'}, $row->{'creditfirstname'},
215 $row->{'creditdescription'}, $row->{'creditaccounttype'},
216 $row->{'creditamount'}
219 $csv->combine(@array);
220 my $string = $csv->string(@array);
225 "Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n";
227 for my $row (@loop3) {
229 $row->{'refundbranch'}, $row->{'refunddate'},
230 $row->{'refundsurname'}, $row->{'refundfirstname'},
231 $row->{'refunddescription'}, $row->{'refundaccounttype'},
232 $row->{'refundamount'}
235 $csv->combine(@array);
236 my $string = $csv->string(@array);
243 print ",,Total Amount Paid, $totalpaid\n";
244 print ",,Total Number Written, $totalwritten\n";
245 print ",,Total Amount Credits, $totalcredits\n";
246 print ",,Total Amount Refunds, $totalrefunds\n";
255 totalpaid
=> $totalpaid,
256 totalcredits
=> $totalcredits,
257 totalwritten
=> $totalwritten,
258 totalrefund
=> $totalrefunds,
259 totalcash
=> $totalcash,
260 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
262 output_html_with_http_headers
$input, $cookie, $template->output;