8 use C4::Interface::CGI::Output;
\r
14 &Date_Init("DateFormat=non-US"); # set non-USA date, eg:19/08/2005
\r
17 my $time=$input->param('time');
\r
18 my $time2=$input->param('time2');
\r
21 my ($template, $loggedinuser, $cookie)
\r
22 = get_template_and_user({template_name => "stats_screen.tmpl",
\r
25 authnotrequired => 1,
\r
26 flagsrequired => {borrowers => 1},
\r
32 if ($time eq 'yesterday'){
\r
33 $date=ParseDate('yesterday');
\r
34 $date2=ParseDate('today');
\r
36 if ($time eq 'today'){
\r
37 $date=ParseDate('today');
\r
38 $date2=ParseDate('tomorrow');
\r
40 if ($time eq 'daybefore'){
\r
41 $date=ParseDate('2 days ago');
\r
42 $date2=ParseDate('yesterday');
\r
44 if ($time eq 'month') {
\r
45 $date = ParseDate('1 month ago');
\r
46 $date2 = ParseDate('today');
\r
50 $date=ParseDate($time);
\r
51 $date2=ParseDateDelta('+ 1 day');
\r
52 $date2=DateCalc($date,$date2);
\r
56 $date=ParseDate('today');
\r
57 $date2=ParseDate('tomorrow');
\r
60 # if script is called with a start and finsh date range...
\r
61 if ($time ne '' && $time2 ne ''){
\r
62 $date=ParseDate($time);
\r
63 $date2=ParseDate($time2);
\r
67 my $date=UnixDate($date,'%Y-%m-%d');
\r
68 my $date2=UnixDate($date2,'%Y-%m-%d');
\r
69 warn "MASON: TIME: $time, $time2";
\r
70 warn "MASON: DATE: $date, $date2";
\r
72 #get a list of every payment
\r
73 my @payments=TotalPaid($date,$date2);
\r
76 my $count=@payments;
\r
77 # print "MASON: number of payments=$count\n";
\r
88 # lets get a a list of all individual item charges paid for by that payment
\r
95 if ($payments[$i]{'type'} ne 'writeoff'){
\r
97 # warn Dumper $payments[$i];
\r
99 @charges=getcharges($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'});
\r
103 # getting each of the charges and putting them into a array to be printed out
\r
104 #this loops per charge per person
\r
105 for (my $i2=0;$i2<$count;$i2++){
\r
106 my $hour=substr($payments[$i]{'timestamp'},8,2);
\r
107 my $min=substr($payments[$i]{'timestamp'},10,2);
\r
108 my $sec=substr($payments[$i]{'timestamp'},12,2);
\r
109 my $time="$hour:$min:$sec";
\r
110 my $time2="$payments[$i]{'date'}";
\r
111 my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
\r
113 # lets build up a row
\r
114 my %rows1 = (branch => $branch,
\r
115 datetime => $payments[$i]->{'datetime'},
\r
116 surname => $payments[$i]->{'surname'},
\r
117 firstname => $payments[$i]->{'firstname'},
\r
118 description => $charges[$i2]->{'description'},
\r
119 accounttype => $charges[$i2]->{'accounttype'},
\r
120 amount => sprintf("%.2f", $charges[$i2]->{'amount'}), # rounding amounts to 2dp
\r
121 type => $payments[$i]->{'type'},
\r
122 value => sprintf("%.2f", $charges[$i2]->{'type'})); # rounding amounts to 2dp
\r
124 push (@loop1, \%rows1);
\r
129 $i++; #increment the while loop
\r
130 $totalpaid = $totalpaid + $payments[$i]->{'value'};
\r
133 #get credits and append to the bottom of payments
\r
134 my @credits=getcredits($date,$date2);
\r
136 my $count=@credits;
\r
139 while ($i<$count ){
\r
141 my %rows2 = (creditbranch => $credits[$i]->{'branchcode'},
\r
142 creditdate => $credits[$i]->{'date'},
\r
143 creditsurname => $credits[$i]->{'surname'},
\r
144 creditfirstname => $credits[$i]->{'firstname'},
\r
145 creditdescription => $credits[$i]->{'description'},
\r
146 creditaccounttype => $credits[$i]->{'accounttype'},
\r
147 creditamount => sprintf("%.2f", $credits[$i]->{'amount'})
\r
150 push (@loop2, \%rows2);
\r
151 $i++; #increment the while loop
\r
152 $totalcredits = $totalcredits + $credits[$i]->{'amount'};
\r
157 #takes off first char minus sign "-100.00"
\r
158 $totalcredits = substr($totalcredits, 1);
\r
160 $template->param( loop1 => \@loop1,
\r
162 totalpaid => $totalpaid,
\r
163 totalcredits => $totalcredits,
\r
164 totalwritten => $totalwritten );
\r
166 output_html_with_http_headers $input, $cookie, $template->output;
\r