--- /dev/null
+#!/usr/bin/perl\r
+\r
+#things to do\r
+\r
+# First sort by branch\r
+#Then sort by surname\r
+\r
+#_Branch_: Could we have Levin displaying as L, please, not C__\r
+\r
+#_Totals_ :\r
+#*Total Paid *\r
+#*Total written off*\r
+#*Total credits (which will include manual credits and credits for lost books returned*\r
+\r
+#use strict;\r
+use CGI;\r
+use C4::Output;\r
+use HTML::Template;\r
+use C4::Auth;\r
+use C4::Interface::CGI::Output;\r
+use C4::Context;\r
+use Date::Manip;\r
+use C4::Stats;\r
+use Data::Dumper;\r
+\r
+use Text::CSV_XS;\r
+\r
+my $csv = Text::CSV_XS->new(\r
+ {\r
+ 'quote_char' => '"',\r
+ 'escape_char' => '"',\r
+ 'sep_char' => ',',\r
+ 'binary' => 1,\r
+ 'always_quote' => 1,\r
+ }\r
+);\r
+\r
+my $input=new CGI;\r
+\r
+\r
+my $input=new CGI;\r
+my $time=$input->param('time');\r
+\r
+my ($template, $loggedinuser, $cookie)\r
+ = get_template_and_user({template_name => "stats.screen.tmpl",\r
+ query => $input,\r
+ type => "intranet",\r
+ authnotrequired => 1,\r
+ flagsrequired => {borrowers => 1},\r
+ debug => 1,\r
+ });\r
+\r
+\r
+\r
+#my $time=$input->param('time');\r
+#my $time="month";\r
+#my $time="today";\r
+\r
+my $date;\r
+my $date2;\r
+if ($time eq 'yesterday'){\r
+ $date=ParseDate('yesterday');\r
+ $date2=ParseDate('today');\r
+}\r
+if ($time eq 'today'){\r
+ $date=ParseDate('today');\r
+ $date2=ParseDate('tomorrow');\r
+}\r
+if ($time eq 'daybefore'){\r
+ $date=ParseDate('2 days ago');\r
+ $date2=ParseDate('yesterday');\r
+}\r
+if ($time eq 'month') {\r
+ $date = ParseDate('1 month ago');\r
+ $date2 = ParseDate('today');\r
+\r
+}\r
+if ($time=~ /\//){\r
+ $date=ParseDate($time);\r
+ $date2=ParseDateDelta('+ 1 day');\r
+ $date2=DateCalc($date,$date2);\r
+}\r
+\r
+#my $date=UnixDate($date,'%Y-%m-%d');\r
+#my $date2=UnixDate($date2,'%Y-%m-%d');\r
+\r
+my $date="2005-08-19";\r
+my $date2="2005-08-20";\r
+\r
+#my $date="2005-01-05";\r
+#my $date2="2005-01-06";\r
+\r
+#get a list of every payment\r
+my @payments=TotalPaid($date,$date2);\r
+\r
+my $count=@payments;\r
+# print "MASON: number of payments=$count\n";\r
+\r
+my $i=0;\r
+my $totalcharges=0;\r
+my $totalcredits=0;\r
+my $totalpaid=0;\r
+my $totalwritten=0;\r
+\r
+# lets get a a list of all individual item charges paid for by that payment\r
+while ($i<$count ){\r
+\r
+ my $count;\r
+ my @charges;\r
+\r
+ if ($payments[$i]{'type'} ne 'writeoff'){ # lets ignore writeoff payments!.\r
+ @charges=getcharges($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'});\r
+ $totalcharges++;\r
+ $count=@charges;\r
+ # getting each of the charges and putting them into a array to be printed out\r
+ #this loops per charge per person\r
+ for (my $i2=0;$i2<$count;$i2++){\r
+ my $hour=substr($payments[$i]{'timestamp'},8,2);\r
+ my $min=substr($payments[$i]{'timestamp'},10,2);\r
+ my $sec=substr($payments[$i]{'timestamp'},12,2);\r
+ my $time="$hour:$min:$sec";\r
+ my $time2="$payments[$i]{'date'}";\r
+ my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});\r
+\r
+\r
+ my $fullname = join ' ', $payments[$i]->{'firstname'}, $payments[$i]->{'surname'};\r
+\r
+ # lets build up a row\r
+ my %rows1 = (branch => $branch,\r
+ datetime => $payments[$i]->{'datetime'},\r
+ surname => $payments[$i]->{'surname'},\r
+ firstname => $payments[$i]->{'firstname'},\r
+ description => $charges[$i2]->{'description'},\r
+ accounttype => $charges[$i2]->{'accounttype'},\r
+ amount => sprintf("%.2f", $charges[$i2]->{'amount'}), # rounding amounts to 2dp\r
+ type => $payments[$i]->{'type'},\r
+ value => sprintf("%.2f", $charges[$i2]->{'type'})); # rounding amounts to 2dp\r
+\r
+ push (@loop1, \%rows1);\r
+ }\r
+ } else {\r
+ ++$totalwritten;\r
+ }\r
+ $i++; #increment the while loop\r
+ $totalpaid = $totalpaid + $payments[$i]->{'value'};\r
+}\r
+\r
+\r
+\r
+#get credits and append to the bottom of payments\r
+my @credits=getcredits($date,$date2);\r
+\r
+#print Dumper(@credits);\r
+\r
+my $count=@credits;\r
+my $i=0;\r
+\r
+while ($i<$count ){\r
+\r
+ my %rows2 = (creditbranch => $credits[$i]->{'branchcode'},\r
+ creditdate => $credits[$i]->{'date'},\r
+ creditsurname => $credits[$i]->{'surname'},\r
+ creditfirstname => $credits[$i]->{'firstname'},\r
+ creditdescription => $credits[$i]->{'description'},\r
+ creditaccounttype => $credits[$i]->{'accounttype'},\r
+ creditamount => $credits[$i]->{'amount'});\r
+\r
+ push (@loop2, \%rows2);\r
+ $i++; #increment the while loop\r
+ $totalcredits = $totalcredits + $credits[$i]->{'amount'};\r
+ ;\r
+\r
+}\r
+#takes off first char minus sign "-100.00"\r
+\r
+\r
+$totalcredits = substr($totalcredits, 1);\r
+\r
+$template->param( loop1 => \@loop1,\r
+ loop2 => \@loop2,\r
+ totalpaid => $totalpaid,\r
+ totalcredits => $totalcredits,\r
+ totalwritten => $totalwritten );\r
+\r
+output_html_with_http_headers $input, $cookie, $template->output;\r
+\r
+\r