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 # FIXME - Dunno what this line was supposed to do, but "CU" never
68 # appears anywhere else, so this was preventing this code from
69 # working, by creating an empty <select> block later on.
70 # (next) unless $branches->{$br}->{'CU'};
72 ($selected='selected') if ($br eq $tobranchcd);
73 $tobranchoptions.="<option value=$br $selected>$branches->{$br}->{'branchname'}\n";
76 # collect the stack of books already transfered so they can printed...
81 foreach ($query->param){
82 (next) unless (/bc-(\d*)/);
84 my $barcode=$query->param("bc-$counter");
85 my $frbcd=$query->param("fb-$counter");
86 my $tobcd=$query->param("tb-$counter");
88 $transfereditems{$counter}=$barcode;
89 $frbranchcds{$counter}=$frbcd;
90 $tobranchcds{$counter}=$tobcd;
91 $ritext.="<input type=hidden name=bc-$counter value=$barcode>\n";
92 $ritext.="<input type=hidden name=fb-$counter value=$frbcd>\n";
93 $ritext.="<input type=hidden name=tb-$counter value=$tobcd>\n";
97 # Collect a few messages here...
101 # Deal with the requests....
102 if ($request eq "KillWaiting") {
103 my $item = $query->param('itemnumber');
104 my $borrnum = $query->param('borrowernumber');
105 CancelReserve(0, $item, $borrnum);
106 $messagetext .= "Reserve Cancelled<br>";
109 if ($request eq "SetWaiting") {
110 my $item = $query->param('itemnumber');
111 my $borrnum = $query->param('borrowernumber');
112 $tobranchcd = ReserveWaiting($item, $borrnum);
114 $messagetext .= "Item should now be waiting at branch: $branches->{$tobranchcd}->{'branchname'}<br>";
116 if ($request eq 'KillReserved'){
117 my $biblio = $query->param('biblionumber');
118 my $borrnum = $query->param('borrowernumber');
119 CancelReserve($biblio, 0, $borrnum);
120 $messagetext .= "Reserve Cancelled<br>";
126 # Warnings etc that get displayed at top of next page....
128 # if the barcode has been entered action that and write a message
129 # and put onto the top of the stack...
131 my $barcode = $query->param('barcode');
135 ($transfered, $messages, $iteminformation)
136 = transferbook($tobranchcd, $barcode, $ignoreRs);
138 my $frbranchcd = $iteminformation->{'holdingbranch'};
139 $ritext.="<input type=hidden name=bc-0 value=$barcode>\n";
140 $ritext.="<input type=hidden name=fb-0 value=$frbranchcd>\n";
141 $ritext.="<input type=hidden name=tb-0 value=$tobranchcd>\n";
142 $transfereditems{0}=$barcode;
143 $frbranchcds{0}=$frbranchcd;
144 $tobranchcds{0}=$tobranchcd;
149 #################################################################################
151 # collect together the various elements...
153 my $entrytext= << "EOF";
154 <form method=post action=/cgi-bin/koha/circ/branchtransfers.pl>
155 <table border=1 cellpadding=5 cellspacing=0 align=left>
156 <tr><td colspan=2 align=center background=$backgroundimage>
157 <font color=black><b>Select Branch</b></font></td></tr>
158 <tr><td>Destination Branch:</td>
159 <td><select name=tobranchcd> $tobranchoptions </select></td></tr></table>
161 <img src="/images/holder.gif" width=24 height=50 align=left>
163 <table border=1 cellpadding=5 cellspacing=0 ><tr>
164 <td colspan=2 align=center background=$backgroundimage>
165 <font color=black><b>Enter Book Barcode</b></font></td></tr>
166 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
168 <input type=hidden name=tobranchcd value=$tobranchcd>
175 #####################
177 my $reservefoundtext;
178 if ($messages->{'ResFound'}) {
179 my $res = $messages->{'ResFound'};
181 my $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
182 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
183 my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
184 my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
185 if ($res->{'ResFound'} eq "Waiting") {
186 $reservetext = <<"EOF";
187 <font color='red' size='+2'>Item marked Waiting:</font><br>
188 Item is marked waiting at $branchname for $name ($number).<br>
189 <table border=1 cellpadding=5 cellspacing=0>
190 <tr><td>Cancel reservation and then attempt transfer: </td>
192 <form method=post action='branchtransfers.pl'>
194 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
195 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
196 <input type=hidden name=tobranchcd value=$tobranchcd>
197 <input type=hidden name=barcode value=$barcode>
198 <input type=hidden name=request value='KillWaiting'>
199 <input type=submit value="Cancel">
202 <tr><td>Ignore and return to transfers: </td>
204 <form method=post action='branchtransfers.pl'>
206 <input type=hidden name=tobranchcd value=$tobranchcd>
207 <input type=hidden name=barcode value=0>
208 <input type=submit value="Ignore">
213 if ($res->{'ResFound'} eq "Reserved") {
214 $reservetext = <<"EOF";
215 <font color='red' size='+2'>Reserved:</font> reserve found for $name ($number).
216 <table border=1 cellpadding=5 cellspacing=0>
217 <tr><td>Set reserve to waiting and transfer book to <b>$branchname </b>: </td>
219 <form method=post action='branchtransfers.pl'>
221 <input type=hidden name=itemnumber value=$res->{'itemnumber'}>
222 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
223 <input type=hidden name=barcode value=$barcode>
224 <input type=hidden name=request value='SetWaiting'>
225 <input type=submit value="Waiting">
228 <tr><td>Cancel reservation and then attempt transfer: </td>
230 <form method=post action='branchtransfers.pl'>
232 <input type=hidden name=biblionumber value=$res->{'biblionumber'}>
233 <input type=hidden name=borrowernumber value=$res->{'borrowernumber'}>
234 <input type=hidden name=tobranchcd value=$tobranchcd>
235 <input type=hidden name=barcode value=$barcode>
236 <input type=hidden name=request value='KillReserved'>
237 <input type=submit value="Cancel">
239 </td></tr><tr><td>Ignore and return to transfers: </td>
241 <form method=post action='branchtransfers.pl'>
242 <input type=hidden name=tobranchcd value=$tobranchcd>
243 <input type=hidden name=barcode value=0>
245 <input type=submit value="Ignore">
250 $reservefoundtext = <<"EOF";
251 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
252 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Reserve Found</font></th></tr>
253 <tr><td> $reservetext </td></tr></table>
257 #####################
259 foreach my $code (keys %$messages) {
260 if ($code eq 'BadBarcode'){
261 $messagetext .= "<font color='red' size='+2'> No Item with barcode: $messages->{'BadBarcode'} </font> <br>";
263 if ($code eq 'IsPermanent'){
264 my $braname = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
265 $messagetext .= "<font color='red' size='+2'> Please return item to home branch: $braname </font> <br>";
267 if ($code eq 'DestinationEqualsHolding'){
268 $messagetext .= "<font color='red' size='+2'> Item is already at destination branch. </font> <br>";
270 if ($code eq 'WasReturned') {
271 my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
274 <a href=/cgi-bin/koha/moremember.pl?bornum=$borrowerinfo->{'borrowernumber'}
275 onClick="openWindow(this,'Member', 480, 640)">$borrowerinfo->{'cardnumber'}</a>
276 $borrowerinfo->{'surname'}, $borrowerinfo->{'title'} $borrowerinfo->{'firstname'}
278 $messagetext .= "Item was on loan to $binfo and has been returned. <br>";
280 if ($code eq 'WasTransfered'){
281 # Put code here if you want to notify the user that item was transfered...
284 $messagetext = substr($messagetext, 0, -4);
288 $messagetable = << "EOF";
289 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
290 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
291 <tr><td> $messagetext </td></tr></table>
292 <img src="/images/holder.gif" width=24 height=24>
296 #######################################################################################
297 # Make the page .....
299 print $query->header;
301 #print startmenu('circulation');
302 my @inp=startmenu('circulation');
304 for (my $i=0;$i<$count;$i++){
305 $inp[$i]=~ s/document.forms\[0\].elements\[0\]/document\.forms\[0\]\.elements\[1\]/;
309 #foreach my $key (%$messages) {
310 # print $key." : ".$messages->{$key}."<br>";
314 <table align=right><tr><td>
315 <a href=circulation.pl>
316 <img src="/images/button-issues.gif" width="99" height="42" border="0" alt="Next Borrower"></a>  
318 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
321 <FONT SIZE=6><em>Circulation: Transfers</em></FONT><br>
322 <b>Branch:</b> $branches->{$branch}->{'branchname'}  
323 <b>Printer:</b> $printers->{$printer}->{'printername'}<br>
324 <a href=selectbranchprinter.pl>Change Settings</a>
325 <input type=hidden name=branch value=$branch>
326 <input type=hidden name=printer value=$printer>
330 if ($reservefoundtext) {
331 print $reservefoundtext;
336 if (%transfereditems) {
339 <table border=1 cellpadding=5 cellspacing=0 bgcolor=#dddddd>
340 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>Transfered Items</font></th></tr>
341 <tr><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>From</th><th>To</th></tr>
344 foreach (sort keys %transfereditems) {
345 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
346 my $barcode=$transfereditems{$_};
347 my $frbcd=$frbranchcds{$_};
348 my $tobcd=$tobranchcds{$_};
349 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);
351 <tr><td bgcolor=$color align=center>
352 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
353 &type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
354 <td bgcolor=$color>$iteminformation->{'title'}</td>
355 <td bgcolor=$color>$iteminformation->{'author'}</td>
356 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
357 <td bgcolor=$color align=center>$branches->{$frbcd}->{'branchname'}</td>
358 <td bgcolor=$color align=center>$branches->{$tobcd}->{'branchname'}</td>
366 print endmenu('circulation');