8 use C4::Interface::CGI::Output;
13 &Date_Init("DateFormat=non-US"); # set non-USA date, eg:19/08/2005
16 my $time=$input->param('time');
17 my $date=$input->param('from');
18 my $date2=$input->param('to');
19 my ($template, $loggedinuser, $cookie)
20 = get_template_and_user({template_name => "reports/stats.screen.tmpl",
24 flagsrequired => {borrowers => 1},
29 #get a list of every payment
30 my @payments=TotalPaid($date,$date2);
33 # warn "number of payments=$count\n";
40 my $totalwrittenamount=0;
41 my $totalinvoicesamount=0;
47 # lets get a a list of all individual item charges paid for by that payment
53 if ($payments[$i]->{'accounttype'} ne 'W'){ # lets ignore writeoff payments!.
54 @charges=getcharges($payments[$i]{'borrowernumber'}, $payments[$i]{'offset'}, $payments[$i]{'accountno'});
58 # getting each of the charges and putting them into a array to be printed out
59 #this loops per charge per person
60 for (my $i2=0;$i2<$count;$i2++){
62 my $time2="$payments[$i]{'date'}";
63 # my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
66 my %rows1 = ( datetime => $payments[$i]->{'timestamp'},
67 surname => $payments[$i]->{'surname'},
68 firstname => $payments[$i]->{'firstname'},
69 description => $payments[$i]->{'description'},
70 accounttype => $charges[$i2]->{'accounttype'},
71 amount => sprintf("%.2f", $charges[$i2]->{'amount'}), # rounding amounts to 2dp
72 type => $payments[$i]->{'accounttype'},
73 value => sprintf("%.2f", $payments[$i]->{'amount'}*(-1))); # rounding amounts to 2dp
75 push (@loop1, \%rows1);
76 $totalpaid = sprintf("%.2f",$totalpaid + $payments[$i]->{'amount'}*(-1));
79 $totalwrittenamount= sprintf("%.2f",$totalwrittenamount + $payments[$i]->{'amount'}*(-1));
84 $i++; #increment the while loop
87 #get credits and append to the bottom of payments
88 my @credits=getcredits($date,$date2);
95 my %rows2 = (creditdate => format_date($credits[$i]->{'date'}),
96 creditsurname => $credits[$i]->{'surname'},
97 creditfirstname => $credits[$i]->{'firstname'},
98 creditdescription => $credits[$i]->{'description'},
99 creditaccounttype => $credits[$i]->{'accounttype'},
100 creditamount => sprintf("%.2f",$credits[$i]->{'amount'}*(-1)));
102 push (@loop2, \%rows2);
104 $totalcredits =sprintf("%.2f", $totalcredits + $credits[$i]->{'amount'});
105 $i++; #increment the while loop
110 #takes off first char minus sign "-100.00"
111 $totalcredits = substr($totalcredits, 1);
113 my @invoices=getinvoices($date,$date2);
119 my %rows3 = (invoicesdate => format_date($invoices[$i]->{'date'}),
120 invoicessurname => $invoices[$i]->{'surname'},
121 invoicesfirstname => $invoices[$i]->{'firstname'},
122 invoicesdescription => $invoices[$i]->{'description'},
123 invoicesaccounttype => $invoices[$i]->{'accounttype'},
124 invoicesamount => sprintf("%.2f",$invoices[$i]->{'amount'}),
125 invoicesamountremaining=>sprintf("%.2f",$invoices[$i]->{'amountoutstanding'}));
126 push (@loop3, \%rows3);
127 $totalinvoicesamount =sprintf("%.2f", $totalinvoicesamount + $invoices[$i]->{'amountoutstanding'});
128 $totalinvoices =sprintf("%.2f", $totalinvoices + $invoices[$i]->{'amount'});
129 $i++; #increment the while loop
132 $template->param( loop1 => \@loop1,
135 totalpaid => $totalpaid,
136 totalcredits => $totalcredits,
137 totalcreditsamount => sprintf("%.2f",$totalcredits-$totalwrittenamount),
138 totalwrittenamount => $totalwrittenamount,
139 totalwritten => $totalwritten ,
140 totalinvoices=>$totalinvoices, totalinvoicesamount=>$totalinvoicesamount );
142 output_html_with_http_headers $input, $cookie, $template->output;