Several fixes to allow for creation of valid Code 128 barcodes.
[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 use Data::Dumper;\r
13 \r
14 &Date_Init("DateFormat=non-US"); # set non-USA date, eg:19/08/2005\r
15 \r
16 my $input=new CGI;\r
17 my $time=$input->param('time');\r
18 my $time2=$input->param('time2');\r
19 \r
20 \r
21 my ($template, $loggedinuser, $cookie)\r
22     = get_template_and_user({template_name => "stats_screen.tmpl",\r
23                              query => $input,\r
24                              type => "intranet",\r
25                              authnotrequired => 1,\r
26                              flagsrequired => {borrowers => 1},\r
27                              debug => 1,\r
28                              });\r
29 \r
30 my $date;\r
31 my $date2;\r
32 if ($time eq 'yesterday'){\r
33         $date=ParseDate('yesterday');\r
34         $date2=ParseDate('today');\r
35 }\r
36 if ($time eq 'today'){\r
37         $date=ParseDate('today');\r
38         $date2=ParseDate('tomorrow');\r
39 }\r
40 if ($time eq 'daybefore'){\r
41         $date=ParseDate('2 days ago');\r
42         $date2=ParseDate('yesterday');\r
43 }\r
44 if ($time eq 'month') {\r
45         $date = ParseDate('1 month ago');\r
46         $date2 = ParseDate('today');\r
47 \r
48 }\r
49 if ($time=~ /\//){\r
50         $date=ParseDate($time);\r
51         $date2=ParseDateDelta('+ 1 day');\r
52         $date2=DateCalc($date,$date2);\r
53 }\r
54 # if time is blank\r
55 if ($time eq ''){\r
56         $date=ParseDate('today');\r
57         $date2=ParseDate('tomorrow');\r
58 }\r
59 \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
64 }\r
65 \r
66 \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
71 \r
72 #get a list of every payment\r
73 my @payments=TotalPaid($date,$date2);\r
74 \r
75 \r
76 my $count=@payments;\r
77 # print "MASON: number of payments=$count\n";\r
78 \r
79 my $i=0;\r
80 my $totalcharges=0;\r
81 my $totalcredits=0;\r
82 my $totalpaid=0;\r
83 my $totalwritten=0;\r
84 my @loop1;\r
85 my @loop2;\r
86 \r
87 \r
88 # lets get a a list of all individual item charges paid for by that payment\r
89 while ($i<$count ){\r
90 \r
91        my $count;\r
92        my @charges;\r
93 \r
94 \r
95        if ($payments[$i]{'type'} ne 'writeoff'){\r
96 \r
97 #       warn Dumper $payments[$i];\r
98 \r
99            @charges=getcharges($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'});\r
100            $totalcharges++;\r
101            $count=@charges;\r
102 \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
112 \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
123 \r
124                push (@loop1, \%rows1);\r
125            }\r
126        } else {\r
127          ++$totalwritten;\r
128        }\r
129        $i++; #increment the while loop\r
130        $totalpaid = $totalpaid + $payments[$i]->{'value'};\r
131 }\r
132 \r
133 #get credits and append to the bottom of payments\r
134 my @credits=getcredits($date,$date2);\r
135 \r
136 my $count=@credits;\r
137 my $i=0;\r
138 \r
139 while ($i<$count ){\r
140 \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
148                     );\r
149 \r
150        push (@loop2, \%rows2);\r
151        $i++; #increment the while loop\r
152        $totalcredits = $totalcredits + $credits[$i]->{'amount'};\r
153        ;\r
154 \r
155 }\r
156 \r
157 #takes off first char minus sign "-100.00"\r
158 $totalcredits = substr($totalcredits, 1);\r
159 \r
160 $template->param( loop1               => \@loop1,\r
161                   loop2               => \@loop2,\r
162                   totalpaid           => $totalpaid,\r
163                   totalcredits        => $totalcredits,\r
164                   totalwritten        => $totalwritten );\r
165 \r
166 output_html_with_http_headers $input, $cookie, $template->output;\r
167 \r