8 use C4::Interface::CGI::Output;
\r
12 &Date_Init("DateFormat=non-US"); # set non-USA date, eg:19/08/2005
\r
15 my $time=$input->param('time');
\r
17 my ($template, $loggedinuser, $cookie)
\r
18 = get_template_and_user({template_name => "stats.screen.tmpl",
\r
21 authnotrequired => 0,
\r
22 flagsrequired => {borrowers => 1},
\r
28 if ($time eq 'yesterday'){
\r
29 $date=ParseDate('yesterday');
\r
30 $date2=ParseDate('today');
\r
32 if ($time eq 'today'){
\r
33 $date=ParseDate('today');
\r
34 $date2=ParseDate('tomorrow');
\r
36 if ($time eq 'daybefore'){
\r
37 $date=ParseDate('2 days ago');
\r
38 $date2=ParseDate('yesterday');
\r
40 if ($time eq 'month') {
\r
41 $date = ParseDate('1 month ago');
\r
42 $date2 = ParseDate('today');
\r
46 $date=ParseDate($time);
\r
47 $date2=ParseDateDelta('+ 1 day');
\r
48 $date2=DateCalc($date,$date2);
\r
52 $date=ParseDate('today');
\r
53 $date2=ParseDate('tomorrow');
\r
58 my $date=UnixDate($date,'%Y-%m-%d');
\r
59 my $date2=UnixDate($date2,'%Y-%m-%d');
\r
61 #warn "MASON: DATE: $date, $date2";
\r
63 #get a list of every payment
\r
64 my @payments=TotalPaid($date,$date2);
\r
66 my $count=@payments;
\r
67 # print "MASON: number of payments=$count\n";
\r
78 # lets get a a list of all individual item charges paid for by that payment
\r
84 if ($payments[$i]{'type'} ne 'writeoff'){ # lets ignore writeoff payments!.
\r
85 @charges=getcharges($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'});
\r
89 # getting each of the charges and putting them into a array to be printed out
\r
90 #this loops per charge per person
\r
91 for (my $i2=0;$i2<$count;$i2++){
\r
92 my $hour=substr($payments[$i]{'timestamp'},8,2);
\r
93 my $min=substr($payments[$i]{'timestamp'},10,2);
\r
94 my $sec=substr($payments[$i]{'timestamp'},12,2);
\r
95 my $time="$hour:$min:$sec";
\r
96 my $time2="$payments[$i]{'date'}";
\r
97 my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
\r
99 # lets build up a row
\r
100 my %rows1 = (branch => $branch,
\r
101 datetime => $payments[$i]->{'datetime'},
\r
102 surname => $payments[$i]->{'surname'},
\r
103 firstname => $payments[$i]->{'firstname'},
\r
104 description => $charges[$i2]->{'description'},
\r
105 accounttype => $charges[$i2]->{'accounttype'},
\r
106 amount => sprintf("%.2f", $charges[$i2]->{'amount'}), # rounding amounts to 2dp
\r
107 type => $payments[$i]->{'type'},
\r
108 value => sprintf("%.2f", $charges[$i2]->{'type'})); # rounding amounts to 2dp
\r
110 push (@loop1, \%rows1);
\r
115 $i++; #increment the while loop
\r
116 $totalpaid = $totalpaid + $payments[$i]->{'value'};
\r
119 #get credits and append to the bottom of payments
\r
120 my @credits=getcredits($date,$date2);
\r
122 my $count=@credits;
\r
125 while ($i<$count ){
\r
127 my %rows2 = (creditbranch => $credits[$i]->{'branchcode'},
\r
128 creditdate => $credits[$i]->{'date'},
\r
129 creditsurname => $credits[$i]->{'surname'},
\r
130 creditfirstname => $credits[$i]->{'firstname'},
\r
131 creditdescription => $credits[$i]->{'description'},
\r
132 creditaccounttype => $credits[$i]->{'accounttype'},
\r
133 creditamount => $credits[$i]->{'amount'});
\r
135 push (@loop2, \%rows2);
\r
136 $i++; #increment the while loop
\r
137 $totalcredits = $totalcredits + $credits[$i]->{'amount'};
\r
142 #takes off first char minus sign "-100.00"
\r
143 $totalcredits = substr($totalcredits, 1);
\r
145 $template->param( loop1 => \@loop1,
\r
147 totalpaid => $totalpaid,
\r
148 totalcredits => $totalcredits,
\r
149 totalwritten => $totalwritten );
\r
151 output_html_with_http_headers $input, $cookie, $template->output;
\r