3 #script to execute branch transfers of books
5 # Copyright 2000-2002 Katipo Communications
6 # copyright 2010 BibLibre
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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");
44 $session = get_session
($sessionID) if $sessionID;
45 if (!$session or $session->param('branch') eq 'NO_LIBRARY_SET'){
46 # no branch set we can't transfer
47 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
52 #######################################################################################
54 my ($template, $user, $cookie) = get_template_and_user
(
56 template_name
=> "circ/branchtransfers.tt",
60 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
64 my $branches = GetBranches
;
74 my $request = $query->param('request') || '';
75 my $borrowernumber = $query->param('borrowernumber') || 0;
76 my $tobranchcd = $query->param('tobranchcd') || '';
80 # Deal with the requests....
81 if ( $request eq "KillWaiting" ) {
82 my $item = $query->param('itemnumber');
85 borrowernumber
=> $borrowernumber
90 elsif ( $request eq "SetWaiting" ) {
91 my $item = $query->param('itemnumber');
92 ModReserveAffect
( $item, $borrowernumber );
97 elsif ( $request eq 'KillReserved' ) {
98 my $biblio = $query->param('biblionumber');
100 biblionumber
=> $biblio,
101 borrowernumber
=> $borrowernumber
107 # collect the stack of books already transfered so they can printed...
111 my $barcode = $query->param('barcode');
113 defined $barcode and $barcode =~ s/\s*//g; # FIXME: barcodeInputFilter
114 # warn "barcode : $barcode";
118 ( $transfered, $messages, $iteminformation ) =
119 transferbook
( $tobranchcd, $barcode, $ignoreRs );
121 # warn "Transfered : $transfered / ".Dumper($messages);
122 $found = $messages->{'ResFound'};
125 my $frbranchcd = C4
::Context
->userenv->{'branch'};
126 # if ( not($found) ) {
127 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
128 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
129 $item{'title'} = $iteminformation->{'title'};
130 $item{'author'} = $iteminformation->{'author'};
131 $item{'itemtype'} = $iteminformation->{'itemtype'};
132 $item{'ccode'} = $iteminformation->{'ccode'};
133 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
134 $item{'location'} = GetKohaAuthorisedValueLib
("LOC",$iteminformation->{'location'});
135 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
136 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
139 $item{barcode
} = $barcode;
140 $item{frombrcd
} = $frbranchcd;
141 $item{tobrcd
} = $tobranchcd;
142 push( @trsfitemloop, \
%item );
143 # warn Dumper(@trsfitemloop);
147 foreach ( $query->param ) {
148 (next) unless (/bc-(\d*)/);
151 my $bc = $query->param("bc-$counter");
152 my $frbcd = $query->param("fb-$counter");
153 my $tobcd = $query->param("tb-$counter");
155 $item{counter
} = $counter;
156 $item{barcode
} = $bc;
157 $item{frombrcd
} = $frbcd;
158 $item{tobrcd
} = $tobcd;
159 my ($iteminformation) = GetBiblioFromItemNumber
( GetItemnumberFromBarcode
($bc) );
160 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
161 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
162 $item{'title'} = $iteminformation->{'title'};
163 $item{'author'} = $iteminformation->{'author'};
164 $item{'itemtype'} = $iteminformation->{'itemtype'};
165 $item{'ccode'} = $iteminformation->{'ccode'};
166 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
167 $item{'location'} = GetKohaAuthorisedValueLib
("LOC",$iteminformation->{'location'});
168 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
169 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
170 push( @trsfitemloop, \
%item );
176 #####################
179 my $res = $messages->{'ResFound'};
180 $itemnumber = $res->{'itemnumber'};
182 if ( $res->{'ResFound'} eq "Waiting" ) {
185 elsif ( $res->{'ResFound'} eq "Reserved" ) {
187 $biblionumber = $res->{'biblionumber'};
191 #####################
193 # Used for branch transfer limits error messages.
194 my $codeTypeDescription = 'Collection Code';
195 my $codeType = C4
::Context
->preference("BranchTransferLimitsType");
196 if ( $codeType eq 'itemtype' ) {
197 $codeTypeDescription = 'Item Type';
201 foreach my $code ( keys %$messages ) {
202 if ( $code ne 'WasTransfered' ) {
204 if ( $code eq 'BadBarcode' ) {
205 $err{msg
} = $messages->{'BadBarcode'};
206 $err{errbadcode
} = 1;
208 elsif ( $code eq "NotAllowed" ) {
209 warn "NotAllowed: $messages->{'NotAllowed'} to " . $branches->{ $messages->{'NotAllowed'} }->{'branchname'};
210 # Do we really want a error log message here? --atz
211 $err{errnotallowed
} = 1;
212 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
213 $err{tbr
} = $branches->{ $tbr }->{'branchname'};
214 $err{code
} = $typecode;
215 $err{codeType
} = $codeTypeDescription;
217 elsif ( $code eq 'IsPermanent' ) {
218 $err{errispermanent
} = 1;
219 $err{msg
} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
221 elsif ( $code eq 'WasReturned' ) {
222 $err{errwasreturned
} = 1;
223 $err{borrowernumber
} = $messages->{'WasReturned'};
224 my $borrower = GetMember
('borrowernumber'=>$messages->{'WasReturned'});
225 $err{title
} = $borrower->{'title'};
226 $err{firstname
} = $borrower->{'firstname'};
227 $err{surname
} = $borrower->{'surname'};
228 $err{cardnumber
} = $borrower->{'cardnumber'};
230 $err{errdesteqholding
} = ( $code eq 'DestinationEqualsHolding' );
231 push( @errmsgloop, \
%err );
236 # warn "FINAL ============= ".Dumper(@trsfitemloop);
239 reserved
=> $reserved,
241 borrowernumber
=> $borrowernumber,
242 itemnumber
=> $itemnumber,
244 biblionumber
=> $biblionumber,
245 tobranchcd
=> $tobranchcd,
246 reqmessage
=> $reqmessage,
247 cancelled
=> $cancelled,
248 setwaiting
=> $setwaiting,
249 trsfitemloop
=> \
@trsfitemloop,
250 branchoptionloop
=> GetBranchesLoop
($tobranchcd),
251 errmsgloop
=> \
@errmsgloop,
252 CircAutocompl
=> C4
::Context
->preference("CircAutocompl")
254 output_html_with_http_headers
$query, $cookie, $template->output;