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
42 my $time=$input->param('time');
\r
44 my ($template, $loggedinuser, $cookie)
\r
45 = get_template_and_user({template_name => "stats.screen.tmpl",
\r
48 authnotrequired => 1,
\r
49 flagsrequired => {borrowers => 1},
\r
55 #my $time=$input->param('time');
\r
61 if ($time eq 'yesterday'){
\r
62 $date=ParseDate('yesterday');
\r
63 $date2=ParseDate('today');
\r
65 if ($time eq 'today'){
\r
66 $date=ParseDate('today');
\r
67 $date2=ParseDate('tomorrow');
\r
69 if ($time eq 'daybefore'){
\r
70 $date=ParseDate('2 days ago');
\r
71 $date2=ParseDate('yesterday');
\r
73 if ($time eq 'month') {
\r
74 $date = ParseDate('1 month ago');
\r
75 $date2 = ParseDate('today');
\r
79 $date=ParseDate($time);
\r
80 $date2=ParseDateDelta('+ 1 day');
\r
81 $date2=DateCalc($date,$date2);
\r
84 #my $date=UnixDate($date,'%Y-%m-%d');
\r
85 #my $date2=UnixDate($date2,'%Y-%m-%d');
\r
87 my $date="2005-08-19";
\r
88 my $date2="2005-08-20";
\r
90 #my $date="2005-01-05";
\r
91 #my $date2="2005-01-06";
\r
93 #get a list of every payment
\r
94 my @payments=TotalPaid($date,$date2);
\r
96 my $count=@payments;
\r
97 # print "MASON: number of payments=$count\n";
\r
100 my $totalcharges=0;
\r
101 my $totalcredits=0;
\r
103 my $totalwritten=0;
\r
105 # lets get a a list of all individual item charges paid for by that payment
\r
106 while ($i<$count ){
\r
111 if ($payments[$i]{'type'} ne 'writeoff'){ # lets ignore writeoff payments!.
\r
112 @charges=getcharges($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'});
\r
115 # getting each of the charges and putting them into a array to be printed out
\r
116 #this loops per charge per person
\r
117 for (my $i2=0;$i2<$count;$i2++){
\r
118 my $hour=substr($payments[$i]{'timestamp'},8,2);
\r
119 my $min=substr($payments[$i]{'timestamp'},10,2);
\r
120 my $sec=substr($payments[$i]{'timestamp'},12,2);
\r
121 my $time="$hour:$min:$sec";
\r
122 my $time2="$payments[$i]{'date'}";
\r
123 my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
\r
126 my $fullname = join ' ', $payments[$i]->{'firstname'}, $payments[$i]->{'surname'};
\r
128 # lets build up a row
\r
129 my %rows1 = (branch => $branch,
\r
130 datetime => $payments[$i]->{'datetime'},
\r
131 surname => $payments[$i]->{'surname'},
\r
132 firstname => $payments[$i]->{'firstname'},
\r
133 description => $charges[$i2]->{'description'},
\r
134 accounttype => $charges[$i2]->{'accounttype'},
\r
135 amount => sprintf("%.2f", $charges[$i2]->{'amount'}), # rounding amounts to 2dp
\r
136 type => $payments[$i]->{'type'},
\r
137 value => sprintf("%.2f", $charges[$i2]->{'type'})); # rounding amounts to 2dp
\r
139 push (@loop1, \%rows1);
\r
144 $i++; #increment the while loop
\r
145 $totalpaid = $totalpaid + $payments[$i]->{'value'};
\r
150 #get credits and append to the bottom of payments
\r
151 my @credits=getcredits($date,$date2);
\r
153 #print Dumper(@credits);
\r
155 my $count=@credits;
\r
158 while ($i<$count ){
\r
160 my %rows2 = (creditbranch => $credits[$i]->{'branchcode'},
\r
161 creditdate => $credits[$i]->{'date'},
\r
162 creditsurname => $credits[$i]->{'surname'},
\r
163 creditfirstname => $credits[$i]->{'firstname'},
\r
164 creditdescription => $credits[$i]->{'description'},
\r
165 creditaccounttype => $credits[$i]->{'accounttype'},
\r
166 creditamount => $credits[$i]->{'amount'});
\r
168 push (@loop2, \%rows2);
\r
169 $i++; #increment the while loop
\r
170 $totalcredits = $totalcredits + $credits[$i]->{'amount'};
\r
174 #takes off first char minus sign "-100.00"
\r
177 $totalcredits = substr($totalcredits, 1);
\r
179 $template->param( loop1 => \@loop1,
\r
181 totalpaid => $totalpaid,
\r
182 totalcredits => $totalcredits,
\r
183 totalwritten => $totalwritten );
\r
185 output_html_with_http_headers $input, $cookie, $template->output;
\r