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");
82 my $request = $query->param('request') || '';
83 my $borrowernumber = $query->param('borrowernumber') || 0;
84 my $tobranchcd = $query->param('tobranchcd') || '';
88 # Deal with the requests....
89 if ( $request eq "KillWaiting" ) {
90 my $item = $query->param('itemnumber');
91 my $holds = Koha::Holds->search({
93 borrowernumber => $borrowernumber
95 if ( $holds->count ) {
101 elsif ( $request eq "SetTransit" ) {
102 my $item = $query->param('itemnumber');
103 my $reserve_id = $query->param('reserve_id');
104 ModReserveAffect( $item, $borrowernumber, 1, $reserve_id );
109 elsif ( $request eq 'KillReserved' ) {
110 my $biblionumber = $query->param('biblionumber');
111 my $reserve_id = $query->param('reserve_id');
112 my $hold = Koha::Holds->find({ reserve_id => $reserve_id });
120 # collect the stack of books already transferred so they can printed...
123 my $barcode = $query->param('barcode');
124 # remove leading/trailing whitespace
125 defined $barcode and $barcode =~ s/^\s*|\s*$//g; # FIXME: barcodeInputFilter
126 # warn "barcode : $barcode";
129 ( $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'} unless $settransit;
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 #####################
173 $hold = Koha::Holds->find(
174 { reserve_id => $found->{reserve_id} },
175 { prefetch => ['item','patron'] }
177 $itemnumber = $found->{'itemnumber'};
178 $borrowernumber = $found->{'borrowernumber'};
180 if ( $found->{'ResFound'} eq "Waiting" ) {
182 } elsif ( $found->{'ResFound'} eq "Transferred" ) {
183 $hold_transferred = 1;
184 } elsif ( $found->{'ResFound'} eq "Processing" ) {
186 } elsif ( $found->{'ResFound'} eq "Reserved" ) {
188 $biblionumber = $found->{'biblionumber'};
193 foreach my $code ( keys %$messages ) {
194 if ( $code ne 'WasTransfered' ) {
196 if ( $code eq 'BadBarcode' ) {
197 $err{msg} = $messages->{'BadBarcode'};
198 $err{errbadcode} = 1;
200 elsif ( $code eq "NotAllowed" ) {
201 warn "NotAllowed: $messages->{'NotAllowed'} to branchcode " . $messages->{'NotAllowed'};
202 # Do we really want a error log message here? --atz
203 $err{errnotallowed} = 1;
204 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
206 $err{code} = $typecode;
208 elsif ( $code eq 'WasReturned' ) {
209 $err{errwasreturned} = 1;
210 $err{borrowernumber} = $messages->{'WasReturned'};
211 my $patron = Koha::Patrons->find( $messages->{'WasReturned'} );
212 if ( $patron ) { # Just in case...
213 $err{patron} = $patron;
216 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
217 push( @errmsgloop, \%err );
222 # warn "FINAL ============= ".Dumper(@trsfitemloop);
227 reserved => $reserved,
229 transferred => $hold_transferred,
230 processing => $hold_processed,
231 borrowernumber => $borrowernumber,
232 itemnumber => $itemnumber,
234 biblionumber => $biblionumber,
235 tobranchcd => $tobranchcd,
236 reqmessage => $reqmessage,
237 cancelled => $cancelled,
238 settransit => $settransit,
239 trsfitemloop => \@trsfitemloop,
240 errmsgloop => \@errmsgloop,
241 PatronAutoComplete => C4::Context->preference("PatronAutoComplete"),
244 # Checking if there is a Fast Cataloging Framework
245 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
247 output_html_with_http_headers $query, $cookie, $template->output;