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;
39 ###############################################
44 if (!C4::Context->userenv){
45 my $sessionID = $query->cookie("CGISESSID");
47 $session = get_session($sessionID) if $sessionID;
48 if (!$session or $session->param('branch') eq 'NO_LIBRARY_SET'){
49 # no branch set we can't transfer
50 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
55 #######################################################################################
57 my ($template, $user, $cookie, $flags ) = get_template_and_user(
59 template_name => "circ/branchtransfers.tt",
63 flagsrequired => { circulate => "circulate_remaining_permissions" },
75 my $request = $query->param('request') || '';
76 my $borrowernumber = $query->param('borrowernumber') || 0;
77 my $tobranchcd = $query->param('tobranchcd') || '';
81 # Deal with the requests....
82 if ( $request eq "KillWaiting" ) {
83 my $item = $query->param('itemnumber');
86 borrowernumber => $borrowernumber
91 elsif ( $request eq "SetWaiting" ) {
92 my $item = $query->param('itemnumber');
93 ModReserveAffect( $item, $borrowernumber );
98 elsif ( $request eq 'KillReserved' ) {
99 my $biblio = $query->param('biblionumber');
101 biblionumber => $biblio,
102 borrowernumber => $borrowernumber
108 # collect the stack of books already transfered so they can printed...
111 my $barcode = $query->param('barcode');
112 # remove leading/trailing whitespace
113 defined $barcode and $barcode =~ s/^\s*|\s*$//g; # FIXME: barcodeInputFilter
114 # warn "barcode : $barcode";
117 ( $transfered, $messages ) =
118 transferbook( $tobranchcd, $barcode, $ignoreRs );
119 my $item = Koha::Items->find({ barcode => $barcode });
120 $found = $messages->{'ResFound'};
123 my $biblio = $item->biblio;
124 my $frbranchcd = C4::Context->userenv->{'branch'};
125 $item{'biblionumber'} = $item->biblionumber;
126 $item{'itemnumber'} = $item->itemnumber;
127 $item{'title'} = $biblio->title;
128 $item{'author'} = $biblio->author;
129 $item{'itemtype'} = $biblio->biblioitem->itemtype;
130 $item{'ccode'} = $item->ccode;
131 $item{'itemcallnumber'} = $item->itemcallnumber;
132 my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $item->location });
133 $item{'location'} = $av->count ? $av->next->lib : '';
135 $item{barcode} = $barcode;
136 $item{frombrcd} = $frbranchcd;
137 $item{tobrcd} = $tobranchcd;
138 push( @trsfitemloop, \%item );
142 foreach ( $query->param ) {
143 (next) unless (/bc-(\d*)/);
146 my $bc = $query->param("bc-$counter");
147 my $frbcd = $query->param("fb-$counter");
148 my $tobcd = $query->param("tb-$counter");
150 $item{counter} = $counter;
151 $item{barcode} = $bc;
152 $item{frombrcd} = $frbcd;
153 $item{tobrcd} = $tobcd;
154 my $item = Koha::Items->find({ barcode => $bc });
155 my $biblio = $item->biblio;
156 $item{'biblionumber'} = $item->biblionumber;
157 $item{'itemnumber'} = $item->itemnumber;
158 $item{'title'} = $biblio->title;
159 $item{'author'} = $biblio->author;
160 $item{'itemtype'} = $biblio->biblioitem->itemtype;
161 $item{'ccode'} = $item->ccode;
162 $item{'itemcallnumber'} = $item->itemcallnumber;
163 my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $item->location });
164 $item{'location'} = $av->count ? $av->next->lib : '';
165 push( @trsfitemloop, \%item );
171 #####################
174 my $res = $messages->{'ResFound'};
175 $itemnumber = $res->{'itemnumber'};
177 if ( $res->{'ResFound'} eq "Waiting" ) {
180 elsif ( $res->{'ResFound'} eq "Reserved" ) {
182 $biblionumber = $res->{'biblionumber'};
187 foreach my $code ( keys %$messages ) {
188 if ( $code ne 'WasTransfered' ) {
190 if ( $code eq 'BadBarcode' ) {
191 $err{msg} = $messages->{'BadBarcode'};
192 $err{errbadcode} = 1;
194 elsif ( $code eq "NotAllowed" ) {
195 warn "NotAllowed: $messages->{'NotAllowed'} to branchcode " . $messages->{'NotAllowed'};
196 # Do we really want a error log message here? --atz
197 $err{errnotallowed} = 1;
198 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
200 $err{code} = $typecode;
202 elsif ( $code eq 'IsPermanent' ) {
203 $err{errispermanent} = 1;
204 $err{msg} = $messages->{'IsPermanent'};
206 elsif ( $code eq 'WasReturned' ) {
207 $err{errwasreturned} = 1;
208 $err{borrowernumber} = $messages->{'WasReturned'};
209 my $patron = Koha::Patrons->find( $messages->{'WasReturned'} );
210 if ( $patron ) { # Just in case...
211 $err{title} = $patron->title;
212 $err{firstname} = $patron->firstname;
213 $err{surname} = $patron->surname;
214 $err{cardnumber} = $patron->cardnumber;
217 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
218 push( @errmsgloop, \%err );
223 # warn "FINAL ============= ".Dumper(@trsfitemloop);
226 reserved => $reserved,
228 borrowernumber => $borrowernumber,
229 itemnumber => $itemnumber,
231 biblionumber => $biblionumber,
232 tobranchcd => $tobranchcd,
233 reqmessage => $reqmessage,
234 cancelled => $cancelled,
235 setwaiting => $setwaiting,
236 trsfitemloop => \@trsfitemloop,
237 errmsgloop => \@errmsgloop,
238 CircAutocompl => C4::Context->preference("CircAutocompl")
241 # Checking if there is a Fast Cataloging Framework
242 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
244 output_html_with_http_headers $query, $cookie, $template->output;