5 # First sort by branch
\r
6 #Then sort by surname
\r
8 #_Branch_: Could we have Levin displaying as L, please, not C__
\r
12 #*Total written off*
\r
13 #*Total credits (which will include manual credits and credits for lost books returned*
\r
20 use C4::Interface::CGI::Output;
\r
28 my $csv = Text::CSV_XS->new(
\r
30 'quote_char' => '"',
\r
31 'escape_char' => '"',
\r
34 'always_quote' => 1,
\r
40 #my $time=$input->param('time');
\r
46 if ($time eq 'yesterday'){
\r
47 $date=ParseDate('yesterday');
\r
48 $date2=ParseDate('today');
\r
50 if ($time eq 'today'){
\r
51 $date=ParseDate('today');
\r
52 $date2=ParseDate('tomorrow');
\r
54 if ($time eq 'daybefore'){
\r
55 $date=ParseDate('2 days ago');
\r
56 $date2=ParseDate('yesterday');
\r
58 if ($time eq 'month') {
\r
59 $date = ParseDate('1 month ago');
\r
60 $date2 = ParseDate('today');
\r
64 $date=ParseDate($time);
\r
65 $date2=ParseDateDelta('+ 1 day');
\r
66 $date2=DateCalc($date,$date2);
\r
69 #my $date=UnixDate($date,'%Y-%m-%d');
\r
70 #my $date2=UnixDate($date2,'%Y-%m-%d');
\r
72 my $date="2005-08-19";
\r
73 my $date2="2005-08-20";
\r
75 #my $date="2005-01-05";
\r
76 #my $date2="2005-01-06";
\r
78 #get a list of every payment
\r
79 my @payments=TotalPaid($date,$date2);
\r
81 my $count=@payments;
\r
82 # print "MASON: number of payments=$count\n";
\r
90 # lets get a a list of all individual item charges paid for by that payment
\r
96 if ($payments[$i]{'type'} ne 'writeoff'){ # lets ignore writeoff payments!.
\r
97 @charges=getcharges($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'});
\r
100 # getting each of the charges and putting them into a array to be printed out
\r
101 #this loops per charge per person
\r
102 for (my $i2=0;$i2<$count;$i2++){
\r
103 my $hour=substr($payments[$i]{'timestamp'},8,2);
\r
104 my $min=substr($payments[$i]{'timestamp'},10,2);
\r
105 my $sec=substr($payments[$i]{'timestamp'},12,2);
\r
106 my $time="$hour:$min:$sec";
\r
107 my $time2="$payments[$i]{'date'}";
\r
108 my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
\r
109 my @rows1 = ($branch, # lets build up a row
\r
110 $payments[$i]->{'datetime'},
\r
111 $payments[$i]->{'surname'},
\r
112 $payments[$i]->{'firstname'},
\r
113 $charges[$i2]->{'description'},
\r
114 $charges[$i2]->{'accounttype'},
\r
115 sprintf("%.2f", $charges[$i2]->{'amount'}), # rounding amounts to 2dp
\r
116 $payments[$i]->{'type'},
\r
117 $payments[$i]->{'value'});
\r
118 push (@loop1, \@rows1);
\r
123 $i++; #increment the while loop
\r
124 $totalpaid = $totalpaid + $payments[$i]->{'value'};
\r
129 #get credits and append to the bottom of payments
\r
130 my @credits=getcredits($date,$date2);
\r
132 #print Dumper(@credits);
\r
134 my $count=@credits;
\r
137 while ($i<$count ){
\r
139 my @rows2 = ($credits[$i]->{'branchcode'},
\r
140 $credits[$i]->{'date'},
\r
141 $credits[$i]->{'surname'},
\r
142 $credits[$i]->{'firstname'},
\r
143 $credits[$i]->{'description'},
\r
144 $credits[$i]->{'accounttype'},
\r
145 $credits[$i]->{'amount'});
\r
147 push (@loop2, \@rows2);
\r
148 $i++; #increment the while loop
\r
149 $totalcredits = $totalcredits + $credits[$i]->{'amount'};
\r
153 #takes off first char minus sign "-100.00"
\r
156 $totalcredits = substr($totalcredits, 1);
\r
159 print $input->header(
\r
160 -type => 'application/vnd.ms-excel',
\r
161 -attachment => "moo.csv",
\r
163 print "Branch, Datetime, Surame, Firstnames, Description, Type, Invoice amount, Payment type, Payment Amount\n";
\r
166 for my $row ( @loop1 ) {
\r
168 $csv->combine(@$row);
\r
169 my $string = $csv->string;
\r
170 print $string, "\n";
\r
175 for my $row ( @loop2 ) {
\r
177 $csv->combine(@$row);
\r
178 my $string = $csv->string;
\r
179 print $string, "\n";
\r
184 print ",,Total Amount Paid, $totalpaid\n";
\r
185 print ",,Total Number Written, $totalwritten\n";
\r
186 print ",,Total Amount Credits, $totalcredits\n";
\r