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/;
34 use Koha
::BiblioFrameworks
;
35 use Koha
::AuthorisedValues
;
37 ###############################################
42 if (!C4
::Context
->userenv){
43 my $sessionID = $query->cookie("CGISESSID");
45 $session = get_session
($sessionID) if $sessionID;
46 if (!$session or $session->param('branch') eq 'NO_LIBRARY_SET'){
47 # no branch set we can't transfer
48 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
53 #######################################################################################
55 my ($template, $user, $cookie, $flags ) = get_template_and_user
(
57 template_name
=> "circ/branchtransfers.tt",
61 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
73 my $request = $query->param('request') || '';
74 my $borrowernumber = $query->param('borrowernumber') || 0;
75 my $tobranchcd = $query->param('tobranchcd') || '';
79 # Deal with the requests....
80 if ( $request eq "KillWaiting" ) {
81 my $item = $query->param('itemnumber');
84 borrowernumber
=> $borrowernumber
89 elsif ( $request eq "SetWaiting" ) {
90 my $item = $query->param('itemnumber');
91 ModReserveAffect
( $item, $borrowernumber );
96 elsif ( $request eq 'KillReserved' ) {
97 my $biblio = $query->param('biblionumber');
99 biblionumber
=> $biblio,
100 borrowernumber
=> $borrowernumber
106 # collect the stack of books already transfered so they can printed...
109 my $barcode = $query->param('barcode');
110 # remove leading/trailing whitespace
111 defined $barcode and $barcode =~ s/^\s*|\s*$//g; # FIXME: barcodeInputFilter
112 # warn "barcode : $barcode";
116 ( $transfered, $messages, $iteminformation ) =
117 transferbook
( $tobranchcd, $barcode, $ignoreRs );
119 # warn "Transfered : $transfered / ".Dumper($messages);
120 $found = $messages->{'ResFound'};
123 my $frbranchcd = C4
::Context
->userenv->{'branch'};
124 # if ( not($found) ) {
125 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
126 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
127 $item{'title'} = $iteminformation->{'title'};
128 $item{'author'} = $iteminformation->{'author'};
129 $item{'itemtype'} = $iteminformation->{'itemtype'};
130 $item{'ccode'} = $iteminformation->{'ccode'};
131 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
132 my $av = Koha
::AuthorisedValues
->search({ category
=> 'LOC', authorised_value
=> $iteminformation->{location
} });
133 $item{'location'} = $av->count ?
$av->next->lib : '';
136 $item{barcode
} = $barcode;
137 $item{frombrcd
} = $frbranchcd;
138 $item{tobrcd
} = $tobranchcd;
139 push( @trsfitemloop, \
%item );
140 # warn Dumper(@trsfitemloop);
144 foreach ( $query->param ) {
145 (next) unless (/bc-(\d*)/);
148 my $bc = $query->param("bc-$counter");
149 my $frbcd = $query->param("fb-$counter");
150 my $tobcd = $query->param("tb-$counter");
152 $item{counter
} = $counter;
153 $item{barcode
} = $bc;
154 $item{frombrcd
} = $frbcd;
155 $item{tobrcd
} = $tobcd;
156 my ($iteminformation) = GetBiblioFromItemNumber
( GetItemnumberFromBarcode
($bc) );
157 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
158 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
159 $item{'title'} = $iteminformation->{'title'};
160 $item{'author'} = $iteminformation->{'author'};
161 $item{'itemtype'} = $iteminformation->{'itemtype'};
162 $item{'ccode'} = $iteminformation->{'ccode'};
163 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
164 my $av = Koha
::AuthorisedValues
->search({ category
=> 'LOC', authorised_value
=> $iteminformation->{location
} });
165 $item{'location'} = $av->count ?
$av->next->lib : '';
166 push( @trsfitemloop, \
%item );
172 #####################
175 my $res = $messages->{'ResFound'};
176 $itemnumber = $res->{'itemnumber'};
178 if ( $res->{'ResFound'} eq "Waiting" ) {
181 elsif ( $res->{'ResFound'} eq "Reserved" ) {
183 $biblionumber = $res->{'biblionumber'};
188 foreach my $code ( keys %$messages ) {
189 if ( $code ne 'WasTransfered' ) {
191 if ( $code eq 'BadBarcode' ) {
192 $err{msg
} = $messages->{'BadBarcode'};
193 $err{errbadcode
} = 1;
195 elsif ( $code eq "NotAllowed" ) {
196 warn "NotAllowed: $messages->{'NotAllowed'} to branchcode " . $messages->{'NotAllowed'};
197 # Do we really want a error log message here? --atz
198 $err{errnotallowed
} = 1;
199 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
201 $err{code
} = $typecode;
203 elsif ( $code eq 'IsPermanent' ) {
204 $err{errispermanent
} = 1;
205 $err{msg
} = $messages->{'IsPermanent'};
207 elsif ( $code eq 'WasReturned' ) {
208 $err{errwasreturned
} = 1;
209 $err{borrowernumber
} = $messages->{'WasReturned'};
210 my $borrower = GetMember
('borrowernumber'=>$messages->{'WasReturned'});
211 $err{title
} = $borrower->{'title'};
212 $err{firstname
} = $borrower->{'firstname'};
213 $err{surname
} = $borrower->{'surname'};
214 $err{cardnumber
} = $borrower->{'cardnumber'};
216 $err{errdesteqholding
} = ( $code eq 'DestinationEqualsHolding' );
217 push( @errmsgloop, \
%err );
222 # warn "FINAL ============= ".Dumper(@trsfitemloop);
225 reserved
=> $reserved,
227 borrowernumber
=> $borrowernumber,
228 itemnumber
=> $itemnumber,
230 biblionumber
=> $biblionumber,
231 tobranchcd
=> $tobranchcd,
232 reqmessage
=> $reqmessage,
233 cancelled
=> $cancelled,
234 setwaiting
=> $setwaiting,
235 trsfitemloop
=> \
@trsfitemloop,
236 errmsgloop
=> \
@errmsgloop,
237 CircAutocompl
=> C4
::Context
->preference("CircAutocompl")
240 # Checking if there is a Fast Cataloging Framework
241 $template->param( fast_cataloging
=> 1 ) if Koha
::BiblioFrameworks
->find( 'FA' );
243 output_html_with_http_headers
$query, $cookie, $template->output;