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
;
40 ###############################################
45 if (!C4
::Context
->userenv){
46 my $sessionID = $query->cookie("CGISESSID");
48 $session = get_session
($sessionID) if $sessionID;
49 if (!$session or $session->param('branch') eq 'NO_LIBRARY_SET'){
50 # no branch set we can't transfer
51 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
56 #######################################################################################
58 my ($template, $user, $cookie, $flags ) = get_template_and_user
(
60 template_name
=> "circ/branchtransfers.tt",
64 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
76 my $request = $query->param('request') || '';
77 my $borrowernumber = $query->param('borrowernumber') || 0;
78 my $tobranchcd = $query->param('tobranchcd') || '';
82 # Deal with the requests....
83 if ( $request eq "KillWaiting" ) {
84 my $item = $query->param('itemnumber');
85 my $holds = Koha
::Holds
->search({
87 borrowernumber
=> $borrowernumber
89 if ( $holds->count ) {
95 elsif ( $request eq "SetWaiting" ) {
96 my $item = $query->param('itemnumber');
97 ModReserveAffect
( $item, $borrowernumber );
102 elsif ( $request eq 'KillReserved' ) {
103 my $biblionumber = $query->param('biblionumber');
104 my $holds = Koha
::Holds
->search({
105 biblionumber
=> $biblionumber,
106 borrowernumber
=> $borrowernumber
108 if ( $holds->count ) {
109 $holds->next->cancel;
115 # collect the stack of books already transfered so they can printed...
118 my $barcode = $query->param('barcode');
119 # remove leading/trailing whitespace
120 defined $barcode and $barcode =~ s/^\s*|\s*$//g; # FIXME: barcodeInputFilter
121 # warn "barcode : $barcode";
124 ( $transfered, $messages ) =
125 transferbook
( $tobranchcd, $barcode, $ignoreRs );
126 my $item = Koha
::Items
->find({ barcode
=> $barcode });
127 $found = $messages->{'ResFound'};
130 my $biblio = $item->biblio;
131 my $frbranchcd = C4
::Context
->userenv->{'branch'};
132 $item{'biblionumber'} = $item->biblionumber;
133 $item{'itemnumber'} = $item->itemnumber;
134 $item{'title'} = $biblio->title;
135 $item{'author'} = $biblio->author;
136 $item{'itemtype'} = $biblio->biblioitem->itemtype;
137 $item{'ccode'} = $item->ccode;
138 $item{'itemcallnumber'} = $item->itemcallnumber;
139 my $av = Koha
::AuthorisedValues
->search({ category
=> 'LOC', authorised_value
=> $item->location });
140 $item{'location'} = $av->count ?
$av->next->lib : '';
142 $item{barcode
} = $barcode;
143 $item{frombrcd
} = $frbranchcd;
144 $item{tobrcd
} = $tobranchcd;
145 push( @trsfitemloop, \
%item );
149 foreach ( $query->param ) {
150 (next) unless (/bc-(\d*)/);
153 my $bc = $query->param("bc-$counter");
154 my $frbcd = $query->param("fb-$counter");
155 my $tobcd = $query->param("tb-$counter");
157 $item{counter
} = $counter;
158 $item{barcode
} = $bc;
159 $item{frombrcd
} = $frbcd;
160 $item{tobrcd
} = $tobcd;
161 my $item = Koha
::Items
->find({ barcode
=> $bc });
162 my $biblio = $item->biblio;
163 $item{'biblionumber'} = $item->biblionumber;
164 $item{'itemnumber'} = $item->itemnumber;
165 $item{'title'} = $biblio->title;
166 $item{'author'} = $biblio->author;
167 $item{'itemtype'} = $biblio->biblioitem->itemtype;
168 $item{'ccode'} = $item->ccode;
169 $item{'itemcallnumber'} = $item->itemcallnumber;
170 my $av = Koha
::AuthorisedValues
->search({ category
=> 'LOC', authorised_value
=> $item->location });
171 $item{'location'} = $av->count ?
$av->next->lib : '';
172 push( @trsfitemloop, \
%item );
178 #####################
181 my $res = $messages->{'ResFound'};
182 $itemnumber = $res->{'itemnumber'};
184 if ( $res->{'ResFound'} eq "Waiting" ) {
187 elsif ( $res->{'ResFound'} eq "Reserved" ) {
189 $biblionumber = $res->{'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 'IsPermanent' ) {
210 $err{errispermanent
} = 1;
211 $err{msg
} = $messages->{'IsPermanent'};
213 elsif ( $code eq 'WasReturned' ) {
214 $err{errwasreturned
} = 1;
215 $err{borrowernumber
} = $messages->{'WasReturned'};
216 my $patron = Koha
::Patrons
->find( $messages->{'WasReturned'} );
217 if ( $patron ) { # Just in case...
218 $err{title
} = $patron->title;
219 $err{firstname
} = $patron->firstname;
220 $err{surname
} = $patron->surname;
221 $err{cardnumber
} = $patron->cardnumber;
224 $err{errdesteqholding
} = ( $code eq 'DestinationEqualsHolding' );
225 push( @errmsgloop, \
%err );
230 # warn "FINAL ============= ".Dumper(@trsfitemloop);
233 reserved
=> $reserved,
235 borrowernumber
=> $borrowernumber,
236 itemnumber
=> $itemnumber,
238 biblionumber
=> $biblionumber,
239 tobranchcd
=> $tobranchcd,
240 reqmessage
=> $reqmessage,
241 cancelled
=> $cancelled,
242 setwaiting
=> $setwaiting,
243 trsfitemloop
=> \
@trsfitemloop,
244 errmsgloop
=> \
@errmsgloop,
245 CircAutocompl
=> C4
::Context
->preference("CircAutocompl")
248 # Checking if there is a Fast Cataloging Framework
249 $template->param( fast_cataloging
=> 1 ) if Koha
::BiblioFrameworks
->find( 'FA' );
251 output_html_with_http_headers
$query, $cookie, $template->output;