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>.
30 use C4
::Auth qw
/:DEFAULT get_session/;
33 use Koha
::BiblioFrameworks
;
34 use Koha
::AuthorisedValues
;
39 ###############################################
44 if (!C4
::Context
->userenv){
45 my $sessionID = $query->cookie("CGISESSID");
47 $session = get_session
($sessionID) if $sessionID;
49 # no branch set we can't transfer
50 print $query->redirect("/cgi-bin/koha/circ/set-library.pl");
55 #######################################################################################
57 my ($template, $user, $cookie, $flags ) = get_template_and_user
(
59 template_name
=> "circ/branchtransfers.tt",
62 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
66 # Check transfers is allowed from system preference
67 if ( C4
::Context
->preference("IndependentBranchesTransfers") && !C4
::Context
->IsSuperLibrarian() ) {
68 print $query->redirect("/cgi-bin/koha/errors/403.pl");
80 my $request = $query->param('request') || '';
81 my $borrowernumber = $query->param('borrowernumber') || 0;
82 my $tobranchcd = $query->param('tobranchcd') || '';
86 # Deal with the requests....
87 if ( $request eq "KillWaiting" ) {
88 my $item = $query->param('itemnumber');
89 my $holds = Koha
::Holds
->search({
91 borrowernumber
=> $borrowernumber
93 if ( $holds->count ) {
99 elsif ( $request eq "SetWaiting" ) {
100 my $item = $query->param('itemnumber');
101 ModReserveAffect
( $item, $borrowernumber );
106 elsif ( $request eq 'KillReserved' ) {
107 my $biblionumber = $query->param('biblionumber');
108 my $holds = Koha
::Holds
->search({
109 biblionumber
=> $biblionumber,
110 borrowernumber
=> $borrowernumber
112 if ( $holds->count ) {
113 $holds->next->cancel;
119 # collect the stack of books already transferred so they can printed...
122 my $barcode = $query->param('barcode');
123 # remove leading/trailing whitespace
124 defined $barcode and $barcode =~ s/^\s*|\s*$//g; # FIXME: barcodeInputFilter
125 # warn "barcode : $barcode";
128 ( $transferred, $messages ) =
131 from_branch
=> C4
::Context
->userenv->{'branch'},
132 to_branch
=> $tobranchcd,
134 ignore_reserves
=> $ignoreRs,
137 my $item = Koha
::Items
->find({ barcode
=> $barcode });
138 $found = $messages->{'ResFound'};
141 my $frbranchcd = C4
::Context
->userenv->{'branch'};
142 $trsfitem{item
} = $item;
143 $trsfitem{counter
} = 0;
144 $trsfitem{frombrcd
} = $frbranchcd;
145 $trsfitem{tobrcd
} = $tobranchcd;
146 push( @trsfitemloop, \
%trsfitem );
150 foreach ( $query->param ) {
151 (next) unless (/bc-(\d*)/);
154 my $bc = $query->param("bc-$counter");
155 my $frbcd = $query->param("fb-$counter");
156 my $tobcd = $query->param("tb-$counter");
158 $trsfitem{counter
} = $counter;
159 $trsfitem{frombrcd
} = $frbcd;
160 $trsfitem{tobrcd
} = $tobcd;
161 my $item = Koha
::Items
->find({ barcode
=> $bc });
162 $trsfitem{item
} = $item;
163 push( @trsfitemloop, \
%trsfitem );
169 #####################
172 my $res = $messages->{'ResFound'};
173 $itemnumber = $res->{'itemnumber'};
174 $borrowernumber = $res->{'borrowernumber'};
176 if ( $res->{'ResFound'} eq "Waiting" ) {
179 elsif ( $res->{'ResFound'} eq "Reserved" ) {
181 $biblionumber = $res->{'biblionumber'};
186 foreach my $code ( keys %$messages ) {
187 if ( $code ne 'WasTransfered' ) {
189 if ( $code eq 'BadBarcode' ) {
190 $err{msg
} = $messages->{'BadBarcode'};
191 $err{errbadcode
} = 1;
193 elsif ( $code eq "NotAllowed" ) {
194 warn "NotAllowed: $messages->{'NotAllowed'} to branchcode " . $messages->{'NotAllowed'};
195 # Do we really want a error log message here? --atz
196 $err{errnotallowed
} = 1;
197 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
199 $err{code
} = $typecode;
201 elsif ( $code eq 'WasReturned' ) {
202 $err{errwasreturned
} = 1;
203 $err{borrowernumber
} = $messages->{'WasReturned'};
204 my $patron = Koha
::Patrons
->find( $messages->{'WasReturned'} );
205 if ( $patron ) { # Just in case...
206 $err{patron
} = $patron;
209 $err{errdesteqholding
} = ( $code eq 'DestinationEqualsHolding' );
210 push( @errmsgloop, \
%err );
215 # warn "FINAL ============= ".Dumper(@trsfitemloop);
219 reserved
=> $reserved,
221 borrowernumber
=> $borrowernumber,
222 itemnumber
=> $itemnumber,
224 biblionumber
=> $biblionumber,
225 tobranchcd
=> $tobranchcd,
226 reqmessage
=> $reqmessage,
227 cancelled
=> $cancelled,
228 setwaiting
=> $setwaiting,
229 trsfitemloop
=> \
@trsfitemloop,
230 errmsgloop
=> \
@errmsgloop,
231 PatronAutoComplete
=> C4
::Context
->preference("PatronAutoComplete"),
234 # Checking if there is a Fast Cataloging Framework
235 $template->param( fast_cataloging
=> 1 ) if Koha
::BiblioFrameworks
->find( 'FA' );
237 output_html_with_http_headers
$query, $cookie, $template->output;