modified script to enable circulation system to show picture of borrower for verifica...
[koha.git] / stats.screen.pl
1 #!/usr/bin/perl\r
2 \r
3 use strict;\r
4 use CGI;\r
5 use C4::Output;\r
6 use HTML::Template;\r
7 use C4::Auth;\r
8 use C4::Interface::CGI::Output;\r
9 use C4::Context;\r
10 use Date::Manip;\r
11 use C4::Stats;\r
12 \r
13 \r
14 my $input=new CGI;\r
15 my $time=$input->param('time');\r
16 \r
17 my ($template, $loggedinuser, $cookie)\r
18     = get_template_and_user({template_name => "stats.screen.tmpl",\r
19                              query => $input,\r
20                              type => "intranet",\r
21                              authnotrequired => ,\r
22                              flagsrequired => {borrowers => 1},\r
23                              debug => 1,\r
24                              });\r
25 \r
26 my $date;\r
27 my $date2;\r
28 if ($time eq 'yesterday'){\r
29         $date=ParseDate('yesterday');\r
30         $date2=ParseDate('today');\r
31 }\r
32 if ($time eq 'today'){\r
33         $date=ParseDate('today');\r
34         $date2=ParseDate('tomorrow');\r
35 }\r
36 if ($time eq 'daybefore'){\r
37         $date=ParseDate('2 days ago');\r
38         $date2=ParseDate('yesterday');\r
39 }\r
40 if ($time eq 'month') {\r
41         $date = ParseDate('1 month ago');\r
42         $date2 = ParseDate('today');\r
43 \r
44 }\r
45 if ($time=~ /\//){\r
46         $date=ParseDate($time);\r
47         $date2=ParseDateDelta('+ 1 day');\r
48         $date2=DateCalc($date,$date2);\r
49 }\r
50 \r
51 my $date=UnixDate($date,'%Y-%m-%d');\r
52 my $date2=UnixDate($date2,'%Y-%m-%d');\r
53 \r
54 #get a list of every payment\r
55 my @payments=TotalPaid($date,$date2);\r
56 \r
57 my $count=@payments;\r
58 # print "MASON: number of payments=$count\n";\r
59 \r
60 my $i=0;\r
61 my $totalcharges=0;\r
62 my $totalcredits=0;\r
63 my $totalpaid=0;\r
64 my $totalwritten=0;\r
65 \r
66 # lets get a a list of all individual item charges paid for by that payment\r
67 while ($i<$count ){\r
68 \r
69        my $count;\r
70        my @charges;\r
71 \r
72        if ($payments[$i]{'type'} ne 'writeoff'){         # lets ignore writeoff payments!.\r
73            @charges=getcharges($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'});\r
74            $totalcharges++;\r
75            $count=@charges;\r
76 \r
77            # getting each of the charges and putting them into a array to be printed out\r
78            #this loops per charge per person\r
79            for (my $i2=0;$i2<$count;$i2++){\r
80                my $hour=substr($payments[$i]{'timestamp'},8,2);\r
81                my $min=substr($payments[$i]{'timestamp'},10,2);\r
82                my $sec=substr($payments[$i]{'timestamp'},12,2);\r
83                my $time="$hour:$min:$sec";\r
84                my $time2="$payments[$i]{'date'}";\r
85                my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});\r
86 \r
87                # lets build up a row\r
88                my %rows1 = (branch => $branch,\r
89                             datetime => $payments[$i]->{'datetime'},\r
90                             surname => $payments[$i]->{'surname'},\r
91                             firstname => $payments[$i]->{'firstname'},\r
92                             description => $charges[$i2]->{'description'},\r
93                             accounttype => $charges[$i2]->{'accounttype'},\r
94                             amount => sprintf("%.2f", $charges[$i2]->{'amount'}), # rounding amounts to 2dp\r
95                             type => $payments[$i]->{'type'},\r
96                             value => sprintf("%.2f", $charges[$i2]->{'type'})); # rounding amounts to 2dp\r
97 \r
98                push (@loop1, \%rows1);\r
99            }\r
100        } else {\r
101          ++$totalwritten;\r
102        }\r
103        $i++; #increment the while loop\r
104        $totalpaid = $totalpaid + $payments[$i]->{'value'};\r
105 }\r
106 \r
107 #get credits and append to the bottom of payments\r
108 my @credits=getcredits($date,$date2);\r
109 \r
110 my $count=@credits;\r
111 my $i=0;\r
112 \r
113 while ($i<$count ){\r
114 \r
115        my %rows2 = (creditbranch        => $credits[$i]->{'branchcode'},\r
116                     creditdate          => $credits[$i]->{'date'},\r
117                     creditsurname       => $credits[$i]->{'surname'},\r
118                     creditfirstname     => $credits[$i]->{'firstname'},\r
119                     creditdescription   => $credits[$i]->{'description'},\r
120                     creditaccounttype   => $credits[$i]->{'accounttype'},\r
121                     creditamount        => $credits[$i]->{'amount'});\r
122 \r
123        push (@loop2, \%rows2);\r
124        $i++; #increment the while loop\r
125        $totalcredits = $totalcredits + $credits[$i]->{'amount'};\r
126        ;\r
127 \r
128 }\r
129 \r
130 #takes off first char minus sign "-100.00"\r
131 $totalcredits = substr($totalcredits, 1);\r
132 \r
133 $template->param( loop1               => \@loop1,\r
134                   loop2               => \@loop2,\r
135                   totalpaid           => $totalpaid,\r
136                   totalcredits        => $totalcredits,\r
137                   totalwritten        => $totalwritten );\r
138 \r
139 output_html_with_http_headers $input, $cookie, $template->output;\r