6 #script to display reports
9 # Copyright 2000-2002 Katipo Communications
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA 02111-1307 USA
26 use CGI qw/:standard/;
29 use C4::Circulation::Circ2;
34 my $configfile=configfile();
35 my $intranetdir=$configfile->{'intranetdir'};
39 my $time=$input->param('time');
40 #print $input->header;
43 my $branches=getbranches(\%env);
44 my $printers=getprinters(\%env);
45 my $branch=$input->param('branch');
46 my $printer=$input->param('printer');
47 ($branch) || ($branch=$input->cookie('branch'));
48 ($printer) || ($printer=$input->cookie('printer'));
49 my ($oldbranch, $oldprinter);
50 if ($input->param('selectnewbranchprinter')) {
56 $env{'branchcode'}=$branch;
57 $env{'printer'}=$printer;
58 #$env{'queue'}=$printer;
63 foreach (keys %$branches) {
68 ($selected='selected') if ($_ eq $oldbranch);
69 ($selected='selected') if ($_ eq $branch);
70 $branchoptions.="<option value=$_ $selected>$branches->{$_}->{'branchname'}\n";
72 foreach (keys %$printers) {
76 ($selected='selected') if ($_ eq $oldprinter || $_ eq $printer);
77 $printeroptions.="<option value=$_ $selected>$printers->{$_}->{'printername'}\n";
79 if ($printercount==1) {
80 ($printer)=keys %$printers;
82 if ($branchcount==1) {
83 ($branch)=keys %$branches;
89 if ($branch && $printer) {
90 $branchname=$branches->{$branch}->{'branchname'};
91 $printername=$printers->{$printer}->{'printername'};
95 my $branchcookie=$input->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y', -path=>'/cgi-bin/koha/');
96 my $printercookie=$input->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y', -path=>'/cgi-bin/koha/');
98 print $input->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie]);
100 unless ($input->param('printable')) {
101 print startmenu('report');
107 my $type=$input->param('type');
108 my $groups=getgroups();
109 if ($input->param('print')) {
110 if ($input->param('groupsselected')) {
111 foreach ($input->param()) {
114 printgroup($group,$input->param('type'));
118 print "<h2>Select the groups to print</h2>\n";
119 print "<form method=post>\n";
120 print "<input type=hidden name=print value=1>\n";
121 print "<input type=hidden name=groupsselected value=1>\n";
122 print "<table border=0><tr><td bgcolor=#dddddd>\n";
123 print "<table border=1 cellspacing=5 cellpadding=10><tr>\n";
125 foreach (sort {$groups->{$a} cmp $groups->{$b}} keys %$groups) {
126 (next) unless ($groups->{$_});
133 <td><input type=checkbox name=print_$_ value=0> $groups->{$_}
143 <select name=printer>
147 <input type=radio name=type value=issues> Issues <input type=radio name=type value=overdues checked> Overdues
149 <input type=submit value=Print>
155 if (my $group=$input->param('group')) {
156 print "<a href=groups.pl?type=$type>Back to group list</a><p>\n";
157 if ($input->param('printable')) {
158 print "<head><title>Overdue list for $groups->{$group}</title></head><body>\n";
160 my $members=groupmembers($env, $group);
161 print "<table border=0><tr><td bgcolor=#dddddd>\n";
162 print "<table border=1 cellspacing=5 cellpadding=10>\n";
164 ($type eq 'overdues') ? ($typetext="Overdues") : ($typetext="Issues");
165 print "<thead><tr><th>Card #</th><th>Name</th><th>IS/OD</th><th>$typetext</th></tr></thead>\n";
166 foreach (sort { $a->{'surname'}." ".$a->{'firstname'} cmp $b->{'surname'}." ".$b->{'firstname'} } @$members) {
167 my $fullname=$_->{'firstname'}." ".$_->{'surname'};
168 my $userid=$_->{'userid'};
169 my $cardnumber=$_->{'cardnumber'};
170 my $currentissues=$_->{'currentissues'};
172 my $overduecounter=0;
174 foreach (keys %$currentissues) {
176 if ($currentissues->{$_}->{'overdue'}) {
178 $title=$currentissues->{$_}->{'title'};
179 $author=$currentissues->{$_}->{'author'};
180 $date_due=$currentissues->{$_}->{'date_due'};
181 $overduelist.="<u>$title</u> by $author (<font color=red>$date_due</font>)<br>\n";
183 if ($type eq 'issues') {
184 $title=$currentissues->{$_}->{'title'};
185 $author=$currentissues->{$_}->{'author'};
186 $date_due=$currentissues->{$_}->{'date_due'};
187 $overduelist.="<u>$title</u> by $author due on $date_due<br>\n";
192 if ($overduecounter) {
193 $overduetext="<font color=red>$overduecounter</font>";
195 (next) unless ($overduecounter || $counter);
196 if ($overduecounter==0 && $type eq 'overdues') {
199 print "<tr><td align=center>$cardnumber</td><td>$fullname</td><td align=center>$counter/$overduetext</td><td>$overduelist</td></tr>\n";
202 print "</td></tr></table>\n";
204 print "<a href=groups.pl?print=1>Print Reports</a><p>\n";
205 print "<h2>Pick a group</h2>\n";
206 print "<table border=0><tr><td bgcolor=#dddddd>\n";
207 print "<table border=1 cellspacing=5 cellpadding=10><tr>\n";
209 foreach (sort {$groups->{$a} cmp $groups->{$b}} keys %$groups) {
210 (next) unless ($groups->{$_});
217 <td align=center>$groups->{$_}
219 <a href=groups.pl?type=issues&group=$_>Issues</a> | <a href=groups.pl?type=overdues&group=$_>Overdues</a>
224 print "</tr></table>\n";
225 print "</td></tr></table>\n";
229 unless ($input->param('printable')) {
230 print endmenu('report');
239 $output= "<head><title>Overdue list for $groups->{$group}</title></head><body><center>\n";
240 my $members=groupmembers($env, $group);
241 ($type eq 'overdues') && ($output.="<img src=/images/overdues.jpg><br>\n");
242 $output.= "<table border=1 cellspacing=5 cellpadding=10>\n";
244 ($type eq 'overdues') ? ($typetext="Overdues") : ($typetext="Issues");
245 $output.= "<thead><tr><th>Card #</th><th>Name</th><th>IS/OD</th><th>$typetext</th></tr></thead>\n";
246 foreach (sort { $a->{'surname'}." ".$a->{'firstname'} cmp $b->{'surname'}." ".$b->{'firstname'} } @$members) {
247 my $fullname=$_->{'firstname'}." ".$_->{'surname'};
248 my $userid=$_->{'userid'};
249 my $cardnumber=$_->{'cardnumber'};
250 my $currentissues=$_->{'currentissues'};
252 my $overduecounter=0;
254 foreach (keys %$currentissues) {
256 if ($currentissues->{$_}->{'overdue'}) {
258 $title=$currentissues->{$_}->{'title'};
259 $author=$currentissues->{$_}->{'author'};
260 $date_due=$currentissues->{$_}->{'date_due'};
261 $overduelist.="<u>$title</u> by $author (<font color=red>$date_due</font>)<br>\n";
263 if ($type eq 'issues') {
264 $title=$currentissues->{$_}->{'title'};
265 $author=$currentissues->{$_}->{'author'};
266 $date_due=$currentissues->{$_}->{'date_due'};
267 $overduelist.="<u>$title</u> by $author due on $date_due<br>\n";
272 if ($overduecounter) {
273 $overduetext="<font color=red>$overduecounter</font>";
275 (next) unless ($overduecounter || $counter);
276 if ($overduecounter==0 && $type eq 'overdues') {
279 $output.= "<tr><td align=center>$cardnumber</td><td>$fullname</td><td align=center>$counter/$overduetext</td><td>$overduelist</td></tr>\n";
281 $output.= "</table>\n";
282 $output.= "</td></tr></table>\n";
283 open (P, "|html2ps | lpr -P$printer");