New system preference for setting date format when entering patron birth dates.
[koha.git] / stats.pl
blobc24cfcfe944f91e72fd3a5d54f06db80002fa1bf
1 #!/usr/bin/perl
3 #written 14/1/2000
4 #script to display reports
6 use C4::Stats;
7 use strict;
8 use Date::Manip;
9 use CGI;
10 use C4::Output;
12 my $input=new CGI;
13 my $time=$input->param('time');
14 print $input->header;
16 print startpage;
17 print startmenu('report');
18 print center;
20 my $date;
21 my $date2;
22 if ($time eq 'yesterday'){
23 $date=ParseDate('yesterday');
24 $date2=ParseDate('today');
26 if ($time eq 'today'){
27 $date=ParseDate('today');
28 $date2=ParseDate('tomorrow');
30 if ($time eq 'daybefore'){
31 $date=ParseDate('2 days ago');
32 $date2=ParseDate('yesterday');
34 if ($time=~ /\//){
35 $date=ParseDate($time);
36 $date2=ParseDateDelta('+ 1 day');
37 $date2=DateCalc($date,$date2);
39 $date=UnixDate($date,'%Y-%m-%d');
40 $date2=UnixDate($date2,'%Y-%m-%d');
41 my @payments=TotalPaid($date);
42 my $count=@payments;
43 my $total=0;
44 my %levin;
45 my %foxton;
46 my %shannon;
47 my $oldtime;
48 my $totalw=0;
49 #my $totalcf=0;
50 print mktablehdr;
51 print mktablerow(5,'#99cc33',bold('Name'),bold('Type'),bold('Date/time'),bold('Amount'), bold('Branch'),'/images/background-mem.gif');
52 my $i=0;
53 while ($i<$count){
54 my $time=$payments[$i]{'datetime'};
55 my $payments=$payments[$i]{'value'};
56 my $charge=0;
57 my @temp=split(/ /,$payments[$i]{'datetime'});
58 my $date=$temp[0];
59 my @charges=getcharges($payments[$i]{'borrowernumber'},$payments[$i]{'timestamp'});
60 my $count=@charges;
61 my $temptotalf=0;
62 my $temptotalr=0;
63 my $temptotalres=0;
64 my $temptotalren=0;
65 my $temptotalw=0;
66 for (my $i2=0;$i2<$count;$i2++){
67 $charge+=$charges[$i2]->{'amount'};
68 print mktablerow(6,'red',$charges[$i2]->{'description'},$charges[$i2]->{'accounttype'},$charges[$i2]->{'timestamp'},
69 $charges[$i2]->{'amount'},$charges[$i2]->{'amountoutstanding'});
70 if ($payments[$i]{'accountytpe'} ne 'W'){
71 if ($charges[$i2]->{'accounttype'} eq 'Rent'){
72 $temptotalr+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
74 if ($charges[$i2]->{'accounttype'} eq 'F' || $charges[$i2]->{'accounttype'} eq 'FU' || $charges[$i2]->{'accounttype'} eq 'FN' ){
75 $temptotalf+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
77 if ($charges[$i2]->{'accounttype'} eq 'Res'){
78 $temptotalres+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
80 if ($charges[$i2]->{'accounttype'} eq 'R'){
81 $temptotalren+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
86 # my $branch=
87 my $hour=substr($payments[$i]{'timestamp'},8,2);
88 my $min=substr($payments[$i]{'timestamp'},10,2);
89 my $sec=substr($payments[$i]{'timestamp'},12,2);
90 my $time="$hour:$min:$sec";
91 my $time2="$payments[$i]{'date'}";
92 my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
93 if ($branch eq 'C'){
94 $levin{'totalf'}+=$temptotalf;
95 $levin{'totalres'}+=$temptotalres;
96 $levin{'totalren'}+=$temptotalren;
97 $levin{'totalr'}+=$temptotalr;
98 } elsif ($branch eq 'F'){
99 $foxton{'totalf'}+=$temptotalf;
100 $foxton{'totalres'}+=$temptotalres;
101 $foxton{'totalren'}+=$temptotalren;
102 $foxton{'totalr'}+=$temptotalr;
103 } elsif ($branch eq 'S'){
104 $shannon{'totalf'}+=$temptotalf;
105 $shannon{'totalres'}+=$temptotalres;
106 $shannon{'totalren'}+=$temptotalren;
107 $shannon{'totalr'}+=$temptotalr;
109 my $bornum=$payments[$i]{'borrowernumber'};
110 my $oldtime=$payments[$i]{'timestamp'};
111 my $oldtype=$payments[$i]{'accounttype'};
112 while ($bornum eq $payments[$i]{'borrowernumber'} && $oldtype == $payments[$i]{'accounttype'} && $oldtime eq $payments[$i]{'timestamp'}){
113 my $hour=substr($payments[$i]{'timestamp'},8,2);
114 my $min=substr($payments[$i]{'timestamp'},10,2);
115 my $sec=substr($payments[$i]{'timestamp'},12,2);
116 my $time="$hour:$min:$sec";
117 my $time2="$payments[$i]{'date'}";
118 my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
120 if ($payments[$i]{'accounttype'} eq 'W'){
121 $totalw+=$payments[$i]{'amount'};
122 } else {
123 $payments[$i]{'amount'}=$payments[$i]{'amount'}*-1;
124 $total+=$payments[$i]{'amount'};
125 if ($branch eq 'C'){
126 $levin{'total'}+=$payments[$i]{'amount'};
128 if ($branch eq 'F'){
129 $foxton{'total'}+=$payments[$i]{'amount'};
131 if ($branch eq 'S'){
132 $shannon{'total'}+=$payments[$i]{'amount'};
136 # my $time2="$payments[$i]{'date'} $time";
139 print mktablerow(6,'white',"$payments[$i]{'firstname'} <b>$payments[$i]{'surname'}</b>",
140 ,$payments[$i]{'accounttype'},"$payments[$i]{'date'} $time",$payments[$i]{'amount'}
141 ,$branch);
142 $oldtype=$payments[$i]{'accounttype'};
143 $oldtime=$payments[$i]{'timestamp'};
144 $bornum=$payments[$i]{'borrowernumber'};
145 $i++;
148 print mktablerow('6','white','','','','','','');
150 print mktableft;
151 print endcenter;
152 #$totalw=$totalw * -1;
153 print "<p><b>Total Paid $total</b>";
154 print "<br><b>total written off $totalw</b>";
155 print mktablehdr;
156 $levin{'issues'}=Count('issue','C',$date,$date2);
157 $foxton{'issues'}=Count('issue','F',$date,$date2);
158 $shannon{'issues'}=Count('issue','S',$date,$date2);
159 $levin{'returns'}=Count('return','C',$date,$date2);
160 $foxton{'returns'}=Count('return','F',$date,$date2);
161 $shannon{'returns'}=Count('return','S',$date,$date2);
162 $levin{'renewals'}=Count('renew','C',$date,$date2);
163 $foxton{'renewals'}=Count('renew','F',$date,$date2);
164 $shannon{'renewals'}=Count('renew','S',$date,$date2);
165 $levin{'unknown'}=$levin{'total'}-($levin{'totalf'}+$levin{'totalr'}+$levin{'totalres'}+$levin{'totalren'});
166 $foxton{'unknown'}=$foxton{'total'}-($foxton{'totalf'}+$foxton{'totalr'}+$foxton{'totalres'}+$foxton{'totalren'});
167 $foxton{'unknown'}=$foxton{'total'}-($foxton{'totalf'}+$foxton{'totalr'}+$foxton{'totalres'}+$foxton{'totalren'});
168 print mktablerow(10,'white',"<b>Levin</b>","Fines $levin{'totalf'}","Rental Charges $levin{'totalr'}",
169 "Reserve Charges $levin{'totalres'}","Renewal Charges $levin{'totalren'}","Unknown $levin{'unknown'}","<b>Total $levin{'total'}</b>",
170 "Issues $levin{'issues'}","Renewals $levin{'renewals'}","Returns $levin{'returns'}");
171 print mktablerow(10,'white',"<b>foxton</b>","Fines $foxton{'totalf'}","Rental Charges $foxton{'totalr'}","Reserve Charges $foxton{'totalres'}","Renewal Charges $foxton{'totalren'}","Unknown $foxton{'unknown'}","<b>Total $foxton{'total'}</b>",
172 "Issues $foxton{'issues'}","Renewals $foxton{'renewals'}","Returns $foxton{'returns'}");
173 print mktablerow(10,'white',"<b>shannon</b>","Fines $shannon{'totalf'}","Rental Charges $shannon{'totalr'}","Reserve Charges $shannon{'totalres'}","Renewal Charges $shannon{'totalren'}","Unknown $shannon{'unknown'}","<b>Total $shannon{'total'}</b>",
174 "Issues $shannon{'issues'}","Renewals $shannon{'renewals'}","Returns $shannon{'returns'}");
175 print mktableft;
178 print endmenu('report');
179 print endpage;