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 ) =
132 from_branch => C4::Context->userenv->{'branch'},
133 to_branch => $tobranchcd,
135 ignore_reserves => $ignoreRs,
138 my $item = Koha::Items->find({ barcode => $barcode });
139 $found = $messages->{'ResFound'};
142 my $frbranchcd = C4::Context->userenv->{'branch'};
143 $trsfitem{item} = $item;
144 $trsfitem{counter} = 0;
145 $trsfitem{frombrcd} = $frbranchcd;
146 $trsfitem{tobrcd} = $tobranchcd;
147 push( @trsfitemloop, \%trsfitem );
151 foreach ( $query->param ) {
152 (next) unless (/bc-(\d*)/);
155 my $bc = $query->param("bc-$counter");
156 my $frbcd = $query->param("fb-$counter");
157 my $tobcd = $query->param("tb-$counter");
159 $trsfitem{counter} = $counter;
160 $trsfitem{frombrcd} = $frbcd;
161 $trsfitem{tobrcd} = $tobcd;
162 my $item = Koha::Items->find({ barcode => $bc });
163 $trsfitem{item} = $item;
164 push( @trsfitemloop, \%trsfitem );
170 #####################
174 $hold = Koha::Holds->find(
175 { reserve_id => $found->{reserve_id} },
176 { prefetch => ['item','patron'] }
178 $itemnumber = $found->{'itemnumber'};
179 $borrowernumber = $found->{'borrowernumber'};
181 if ( $found->{'ResFound'} eq "Waiting" ) {
183 } elsif ( $found->{'ResFound'} eq "Transferred" ) {
184 $hold_transferred = 1;
185 } elsif ( $found->{'ResFound'} eq "Processing" ) {
187 } elsif ( $found->{'ResFound'} eq "Reserved" ) {
189 $biblionumber = $found->{'biblionumber'};
194 foreach my $code ( keys %$messages ) {
195 if ( $code ne 'WasTransfered' ) {
197 if ( $code eq 'BadBarcode' ) {
198 $err{msg} = $messages->{'BadBarcode'};
199 $err{errbadcode} = 1;
201 elsif ( $code eq "NotAllowed" ) {
202 warn "NotAllowed: $messages->{'NotAllowed'} to branchcode " . $messages->{'NotAllowed'};
203 # Do we really want a error log message here? --atz
204 $err{errnotallowed} = 1;
205 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
207 $err{code} = $typecode;
209 elsif ( $code eq 'WasReturned' ) {
210 $err{errwasreturned} = 1;
211 $err{borrowernumber} = $messages->{'WasReturned'};
212 my $patron = Koha::Patrons->find( $messages->{'WasReturned'} );
213 if ( $patron ) { # Just in case...
214 $err{patron} = $patron;
217 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
218 push( @errmsgloop, \%err );
223 # warn "FINAL ============= ".Dumper(@trsfitemloop);
228 reserved => $reserved,
230 transferred => $hold_transferred,
231 processing => $hold_processed,
232 borrowernumber => $borrowernumber,
233 itemnumber => $itemnumber,
235 biblionumber => $biblionumber,
236 tobranchcd => $tobranchcd,
237 reqmessage => $reqmessage,
238 cancelled => $cancelled,
239 settransit => $settransit,
240 trsfitemloop => \@trsfitemloop,
241 errmsgloop => \@errmsgloop,
242 PatronAutoComplete => C4::Context->preference("PatronAutoComplete"),
245 # Checking if there is a Fast Cataloging Framework
246 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
248 output_html_with_http_headers $query, $cookie, $template->output;