4 #use warnings; FIXME - Bug 2505
13 &Date_Init
("DateFormat=non-US"); # set non-USA date, eg:19/08/2005
15 my $csv = Text
::CSV_XS
->new(
25 my $time=$input->param('time');
26 my $time2=$input->param('time2');
32 if ($time eq 'yesterday'){
33 $date=ParseDate
('yesterday');
34 $date2=ParseDate
('today');
36 if ($time eq 'today'){
37 $date=ParseDate
('today');
38 $date2=ParseDate
('tomorrow');
40 if ($time eq 'daybefore'){
41 $date=ParseDate
('2 days ago');
42 $date2=ParseDate
('yesterday');
44 if ($time eq 'month') {
45 $date = ParseDate
('1 month ago');
46 $date2 = ParseDate
('today');
50 $date=ParseDate
($time);
51 $date2=ParseDateDelta
('+ 1 day');
52 $date2=DateCalc
($date,$date2);
56 $date=ParseDate
('today');
57 $date2=ParseDate
('tomorrow');
61 $date=ParseDate
($time);
62 $date2=ParseDate
($time2);
65 my $date=UnixDate
($date,'%Y-%m-%d');
66 my $date2=UnixDate
($date2,'%Y-%m-%d');
68 #warn "MASON: DATE: $date, $date2";
70 #get a list of every payment
71 my @payments=TotalPaid
($date,$date2);
74 # print "MASON: number of payments=$count\n";
82 # lets get a a list of all individual item charges paid for by that payment
88 if ($payments[$i]{'type'} ne 'writeoff'){ # lets ignore writeoff payments!.
89 @charges=getcharges
($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'});
93 # getting each of the charges and putting them into a array to be printed out
94 #this loops per charge per person
95 for (my $i2=0;$i2<$count;$i2++){
97 my $hour=substr($payments[$i]{'timestamp'},8,2);
98 my $min=substr($payments[$i]{'timestamp'},10,2);
99 my $sec=substr($payments[$i]{'timestamp'},12,2);
100 my $time="$hour:$min:$sec";
101 my $time2="$payments[$i]{'date'}";
102 # my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
103 my $branch=$payments[$i]{'branch'};
105 my @rows1 = ($branch, # lets build up a row
106 $payments[$i]->{'datetime'},
107 $payments[$i]->{'surname'},
108 $payments[$i]->{'firstname'},
109 $charges[$i2]->{'description'},
110 $charges[$i2]->{'accounttype'},
111 # rounding amounts to 2dp and adding dollar sign to make excel read it as currency format
112 "\$".sprintf("%.2f", $charges[$i2]->{'amount'}),
113 $payments[$i]->{'type'},
114 "\$".$payments[$i]->{'value'});
116 push (@loop1, \
@rows1);
117 $totalpaid = $totalpaid + $payments[$i]->{'value'};
123 $i++; #increment the while loop
126 #get credits and append to the bottom of payments
127 my @credits=getcredits
($date,$date2);
134 my @rows2 = ($credits[$i]->{'branchcode'},
135 $credits[$i]->{'date'},
136 $credits[$i]->{'surname'},
137 $credits[$i]->{'firstname'},
138 $credits[$i]->{'description'},
139 $credits[$i]->{'accounttype'},
140 "\$".$credits[$i]->{'amount'});
142 push (@loop2, \
@rows2);
143 $totalcredits = $totalcredits + $credits[$i]->{'amount'};
147 #takes off first char minus sign "-100.00"
148 $totalcredits = substr($totalcredits, 1);
150 print $input->header(
151 -type
=> 'application/vnd.ms-excel',
152 -attachment
=> "stats.csv",
154 print "Branch, Datetime, Surname, Firstnames, Description, Type, Invoice amount, Payment type, Payment Amount\n";
157 for my $row ( @loop1 ) {
159 $csv->combine(@
$row);
160 my $string = $csv->string;
166 for my $row ( @loop2 ) {
168 $csv->combine(@
$row);
169 my $string = $csv->string;
175 print ",,Total Amount Paid, $totalpaid\n";
176 print ",,Total Number Written, $totalwritten\n";
177 print ",,Total Amount Credits, $totalcredits\n";