2 # WARNING: This file uses 4-character tabs!
4 #written 11/3/2002 by Finlay
5 #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
31 use C4
::Auth qw
/:DEFAULT get_session/;
32 use C4
::Branch
; # GetBranches
36 ###############################################
41 if (!C4
::Context
->userenv){
42 my $sessionID = $query->cookie("CGISESSID");
43 my $session = get_session
($sessionID);
44 if ($session->param('branch') eq 'NO_LIBRARY_SET'){
45 # no branch set we can't transfer
46 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
52 #######################################################################################
54 my ( $template, $cookie );
56 ( $template, $user, $cookie ) = get_template_and_user
(
58 template_name
=> "circ/branchtransfers.tmpl",
62 flagsrequired
=> { circulate
=> 1 },
66 my $branches = GetBranches
;
67 my $branch = GetBranch
( $query, $branches );
77 my $request = $query->param('request');
78 my $borrowernumber = $query->param('borrowernumber');
79 my $tobranchcd = $query->param('tobranchcd');
82 # Deal with the requests....
83 if ( $request eq "KillWaiting" ) {
84 my $item = $query->param('itemnumber');
86 CancelReserve
( 0, $item, $borrowernumber );
92 if ( $request eq "SetWaiting" ) {
93 my $item = $query->param('itemnumber');
94 ModReserveAffect
( $item, $borrowernumber );
99 if ( $request eq 'KillReserved' ) {
100 my $biblio = $query->param('biblionumber');
101 CancelReserve
( $biblio, 0, $borrowernumber );
106 # set up the branchselect options....
107 my @branchoptionloop;
108 foreach my $br ( keys %$branches ) {
110 $branch{selected
} = ( $br eq $tobranchcd );
112 $branch{name
} = $branches->{$br}->{'branchname'};
113 push( @branchoptionloop, \
%branch );
116 # collect the stack of books already transfered so they can printed...
120 my $barcode = $query->param('barcode');
122 $barcode =~ s/\s*//g;
123 # warn "barcode : $barcode";
127 ( $transfered, $messages, $iteminformation ) =
128 transferbook
( $tobranchcd, $barcode, $ignoreRs );
130 # warn "Transfered : $transfered / ".Dumper($messages);
131 $found = $messages->{'ResFound'};
134 my $frbranchcd = C4
::Context
->userenv->{'branch'};
135 # if ( not($found) ) {
136 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
137 $item{'title'} = $iteminformation->{'title'};
138 $item{'author'} = $iteminformation->{'author'};
139 $item{'itemtype'} = $iteminformation->{'itemtype'};
140 $item{'ccode'} = $iteminformation->{'ccode'};
141 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
142 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
145 $item{barcode
} = $barcode;
146 $item{frombrcd
} = $frbranchcd;
147 $item{tobrcd
} = $tobranchcd;
148 push( @trsfitemloop, \
%item );
149 # warn Dumper(@trsfitemloop);
153 foreach ( $query->param ) {
154 (next) unless (/bc-(\d*)/);
157 my $bc = $query->param("bc-$counter");
158 my $frbcd = $query->param("fb-$counter");
159 my $tobcd = $query->param("tb-$counter");
161 $item{counter
} = $counter;
162 $item{barcode
} = $bc;
163 $item{frombrcd
} = $frbcd;
164 $item{tobrcd
} = $tobcd;
165 my ($iteminformation) = GetBiblioFromItemNumber
( GetItemnumberFromBarcode
($bc) );
166 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
167 $item{'title'} = $iteminformation->{'title'};
168 $item{'author'} = $iteminformation->{'author'};
169 $item{'itemtype'} = $iteminformation->{'itemtype'};
170 $item{'ccode'} = $iteminformation->{'ccode'};
171 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
172 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
173 push( @trsfitemloop, \
%item );
179 #####################
182 my $res = $messages->{'ResFound'};
183 $itemnumber = $res->{'itemnumber'};
185 if ( $res->{'ResFound'} eq "Waiting" ) {
188 if ( $res->{'ResFound'} eq "Reserved" ) {
190 $biblionumber = $res->{'biblionumber'};
194 #####################
197 foreach my $code ( keys %$messages ) {
200 if ( $code eq 'BadBarcode' ) {
201 $err{msg
} = $messages->{'BadBarcode'};
202 $err{errbadcode
} = 1;
205 if ( $code eq 'IsPermanent' ) {
206 $err{errispermanent
} = 1;
207 $err{msg
} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
209 $err{errdesteqholding
} = ( $code eq 'DestinationEqualsHolding' );
211 if ( $code eq 'WasReturned' ) {
212 $err{errwasreturned
} = 1;
213 $err{borrowernumber
}=$messages->{'WasReturned'};
214 my $borrower = GetMember
($messages->{'WasReturned'},'borrowernumber');
215 $err{title
}=$borrower->{'title'};
216 $err{firstname
}=$borrower->{'firstname'};
217 $err{surname
}=$borrower->{'surname'};
218 $err{cardnumber
} =$borrower->{'cardnumber'};
220 push( @errmsgloop, \
%err );
224 # warn "FINAL ============= ".Dumper(@trsfitemloop);
227 reserved
=> $reserved,
229 borrowernumber
=> $borrowernumber,
230 itemnumber
=> $itemnumber,
232 biblionumber
=> $biblionumber,
233 tobranchcd
=> $tobranchcd,
234 reqmessage
=> $reqmessage,
235 cancelled
=> $cancelled,
236 setwaiting
=> $setwaiting,
237 trsfitemloop
=> \
@trsfitemloop,
238 branchoptionloop
=> \
@branchoptionloop,
239 errmsgloop
=> \
@errmsgloop,
240 CircAutocompl
=> C4
::Context
->preference("CircAutocompl")
242 output_html_with_http_headers
$query, $cookie, $template->output;
246 return $borinfo->{'surname'} . " "
247 . $borinfo->{'title'} . " "
248 . $borinfo->{'firstname'};