3 #written 11/3/2002 by Finlay
4 #script to execute branch transfers of books
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
26 use C4::Circulation::Circ2;
30 ###############################################
34 my $headerbackgroundcolor='#99cc33';
35 my $circbackgroundcolor='#ffffcc';
36 my $circbackgroundcolor='white';
37 my $linecolor1='#ffffcc';
38 my $linecolor2='white';
39 my $backgroundimage="/images/background-mem.gif";
41 my $branches = getbranches();
42 my $printers = getprinters(\%env);
45 ###############################################
51 my $branch = $query->param("branch");
52 my $printer = $query->param("printer");
55 ($branch) || ($branch=$query->cookie('branch')) ;
56 ($printer) || ($printer=$query->cookie('printer')) ;
58 my $request=$query->param('request');
61 my $tobranchcd=$query->param('tobranchcd');
64 # set up the branchselect options....
66 foreach my $br (keys %$branches) {
67 (next) unless $branches->{$br}->{'CU'};
69 ($selected='selected') if ($br eq $tobranchcd);
70 $tobranchoptions.="<option value=$br $selected>$branches->{$br}->{'branchname'}\n";
73 # collect the stack of books already transfered so they can printed...
78 foreach ($query->param){
79 (next) unless (/bc-(\d*)/);
81 my $barcode=$query->param("bc-$counter");
82 my $frbcd=$query->param("fb-$counter");
83 my $tobcd=$query->param("tb-$counter");
85 $transfereditems{$counter}=$barcode;
86 $frbranchcds{$counter}=$frbcd;
87 $tobranchcds{$counter}=$tobcd;
88 $ritext.="<input type=hidden name=bc-$counter value=$barcode>\n";
89 $ritext.="<input type=hidden name=fb-$counter value=$frbcd>\n";
90 $ritext.="<input type=hidden name=tb-$counter value=$tobcd>\n";
94 # Collect a few messages here...
98 # Deal with the requests....
99 if ($request eq "KillWaiting") {
100 my $item = $query->param('itemnumber');
101 my $borrnum = $query->param('borrowernumber');
102 CancelReserve(0, $item, $borrnum);
103 $messagetext .= "Reserve Cancelled<br>";
106 if ($request eq "SetWaiting") {
107 my $item = $query->param('itemnumber');
108 my $borrnum = $query->param('borrowernumber');
109 $tobranchcd = ReserveWaiting($item, $borrnum);
111 $messagetext .= "Item should now be waiting at branch: $branches->{$tobranchcd}->{'branchname'}<br>";
113 if ($request eq 'KillReserved'){
114 my $biblio = $query->param('biblionumber');
115 my $borrnum = $query->param('borrowernumber');
116 CancelReserve($biblio, 0, $borrnum);
117 $messagetext .= "Reserve Cancelled<br>";
123 # Warnings etc that get displayed at top of next page....
125 # if the barcode has been entered action that and write a message
126 # and put onto the top of the stack...
128 my $barcode = $query->param('barcode');
132 ($transfered, $messages, $iteminformation)
133 = transferbook($tobranchcd, $barcode, $ignoreRs);
135 my $frbranchcd = $iteminformation->{'holdingbranch'};
136 $ritext.="<input type=hidden name=bc-0 value=$barcode>\n";
137 $ritext.="<input type=hidden name=fb-0 value=$frbranchcd>\n";
138 $ritext.="<input type=hidden name=tb-0 value=$tobranchcd>\n";
139 $transfereditems{0}=$barcode;
140 $frbranchcds{0}=$frbranchcd;
141 $tobranchcds{0}=$tobranchcd;
146 #################################################################################
148 # collect together the various elements...
150 my $entrytext= << "EOF";
151 <form method=post action=/cgi-bin/koha/circ/branchtransfers.pl>
152 <table border=1 cellpadding=5 cellspacing=0 align=left>
153 <tr><td colspan=2 align=center background=$backgroundimage>
154 <font color=black><b>Select Branch</b></font></td></tr>
155 <tr><td>Destination Branch:</td>
156 <td><select name=tobranchcd> $tobranchoptions </select></td></tr></table>
158 <img src="/images/holder.gif" width=24 height=50 align=left>
160 <table border=1 cellpadding=5 cellspacing=0 ><tr>
161 <td colspan=2 align=center background=$backgroundimage>
162 <font color=black><b>Enter Book Barcode</b></font></td></tr>
163 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
165 <input type=hidden name=tobranchcd value=$tobranchcd>
172 #####################
174 my $reservefoundtext;
175 if ($messages->{'ResFound'}) {
176 my $res = $messages->{'ResFound'};
178 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
179 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
180 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
181 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
182 if ($res->{'ResFound'} eq "Waiting") {
183 $reservetext = <<"EOF";
184 <font color='red' size='+2'>Item marked Waiting:</font><br>
185 Item is marked waiting at $branchname for $name ($number).<br>
186 <table border=1 cellpadding=5 cellspacing=0>
187 <tr><td>Cancel reservation and then attempt transfer: </td>
189 <form method=post action='branchtransfers.pl'>
191 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
192 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
193 <input type=hidden name=tobranchcd value=$tobranchcd>
194 <input type=hidden name=barcode value=$barcode>
195 <input type=hidden name=request value='KillWaiting'>
196 <input type=submit value="Cancel">
199 <tr><td>Ignore and return to transfers: </td>
201 <form method=post action='branchtransfers.pl'>
203 <input type=hidden name=tobranchcd value=$tobranchcd>
204 <input type=hidden name=barcode value=0>
205 <input type=submit value="Ignore">
210 if ($res->{'ResFound'} eq "Reserved") {
211 $reservetext = <<"EOF";
212 <font color='red' size='+2'>Reserved:</font> reserve found for $name ($number).
213 <table border=1 cellpadding=5 cellspacing=0>
214 <tr><td>Set reserve to waiting and transfer book to <b>$branchname </b>: </td>
216 <form method=post action='branchtransfers.pl'>
218 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
219 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
220 <input type=hidden name=barcode value=$barcode>
221 <input type=hidden name=request value='SetWaiting'>
222 <input type=submit value="Waiting">
225 <tr><td>Cancel reservation and then attempt transfer: </td>
227 <form method=post action='branchtransfers.pl'>
229 <input type=hidden name=biblionumber value=$res->{'biblionumber'}>
230 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
231 <input type=hidden name=tobranchcd value=$tobranchcd>
232 <input type=hidden name=barcode value=$barcode>
233 <input type=hidden name=request value='KillReserved'>
234 <input type=submit value="Cancel">
236 </td></tr><tr><td>Ignore and return to transfers: </td>
238 <form method=post action='branchtransfers.pl'>
239 <input type=hidden name=tobranchcd value=$tobranchcd>
240 <input type=hidden name=barcode value=0>
242 <input type=submit value="Ignore">
247 $reservefoundtext = <<"EOF";
248 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
249 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Reserve Found</font></th></tr>
250 <tr><td> $reservetext </td></tr></table>
254 #####################
256 foreach my $code (keys %$messages) {
257 if ($code eq 'BadBarcode'){
258 $messagetext .= "<font color='red' size='+2'> No Item with barcode: $messages->{'BadBarcode'} </font> <br>";
260 if ($code eq 'IsPermanent'){
261 my $braname = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
262 $messagetext .= "<font color='red' size='+2'> Please return item to home branch: $braname </font> <br>";
264 if ($code eq 'DestinationEqualsHolding'){
265 $messagetext .= "<font color='red' size='+2'> Item is already at destination branch. </font> <br>";
267 if ($code eq 'WasReturned') {
268 my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
271 <a href=/cgi-bin/koha/moremember.pl?bornum=$borrowerinfo->{'borrowernumber'}
272 onClick="openWindow(this,'Member', 480, 640)">$borrowerinfo->{'cardnumber'}</a>
273 $borrowerinfo->{'surname'}, $borrowerinfo->{'title'} $borrowerinfo->{'firstname'}
275 $messagetext .= "Item was on loan to $binfo and has been returned. <br>";
277 if ($code eq 'WasTransfered'){
278 # Put code here if you want to notify the user that item was transfered...
281 $messagetext = substr($messagetext, 0, -4);
285 $messagetable = << "EOF";
286 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
287 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
288 <tr><td> $messagetext </td></tr></table>
289 <img src="/images/holder.gif" width=24 height=24>
293 #######################################################################################
294 # Make the page .....
296 print $query->header;
298 #print startmenu('circulation');
299 my @inp=startmenu('circulation');
301 for (my $i=0;$i<$count;$i++){
302 $inp[$i]=~ s/document.forms\[0\].elements\[0\]/document\.forms\[0\]\.elements\[1\]/;
306 #foreach my $key (%$messages) {
307 # print $key." : ".$messages->{$key}."<br>";
311 <table align=right><tr><td>
312 <a href=circulation.pl>
313 <img src="/images/button-issues.gif" width="99" height="42" border="0" alt="Next Borrower"></a>  
315 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
318 <FONT SIZE=6><em>Circulation: Transfers</em></FONT><br>
319 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
320 <b>Printer:</b> $printers->{$printer}->{'printername'}<br>
321 <a href=selectbranchprinter.pl>Change Settings</a>
322 <input type=hidden name=branch value=$branch>
323 <input type=hidden name=printer value=$printer>
327 if ($reservefoundtext) {
328 print $reservefoundtext;
333 if (%transfereditems) {
336 <table border=1 cellpadding=5 cellspacing=0 bgcolor=#dddddd>
337 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>Transfered Items</font></th></tr>
338 <tr><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>From</th><th>To</th></tr>
341 foreach (sort keys %transfereditems) {
342 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
343 my $barcode=$transfereditems{$_};
344 my $frbcd=$frbranchcds{$_};
345 my $tobcd=$tobranchcds{$_};
346 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);
348 <tr><td bgcolor=$color align=center>
349 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
350 &type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
351 <td bgcolor=$color>$iteminformation->{'title'}</td>
352 <td bgcolor=$color>$iteminformation->{'author'}</td>
353 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
354 <td bgcolor=$color align=center>$branches->{$frbcd}->{'branchname'}</td>
355 <td bgcolor=$color align=center>$branches->{$tobcd}->{'branchname'}</td>
363 print endmenu('circulation');