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;
38 ###############################################
43 if (!C4::Context->userenv){
44 my $sessionID = $query->cookie("CGISESSID");
46 $session = get_session($sessionID) if $sessionID;
47 if (!$session or $session->param('branch') eq 'NO_LIBRARY_SET'){
48 # no branch set we can't transfer
49 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
54 #######################################################################################
56 my ($template, $user, $cookie, $flags ) = get_template_and_user(
58 template_name => "circ/branchtransfers.tt",
62 flagsrequired => { circulate => "circulate_remaining_permissions" },
74 my $request = $query->param('request') || '';
75 my $borrowernumber = $query->param('borrowernumber') || 0;
76 my $tobranchcd = $query->param('tobranchcd') || '';
80 # Deal with the requests....
81 if ( $request eq "KillWaiting" ) {
82 my $item = $query->param('itemnumber');
85 borrowernumber => $borrowernumber
90 elsif ( $request eq "SetWaiting" ) {
91 my $item = $query->param('itemnumber');
92 ModReserveAffect( $item, $borrowernumber );
97 elsif ( $request eq 'KillReserved' ) {
98 my $biblio = $query->param('biblionumber');
100 biblionumber => $biblio,
101 borrowernumber => $borrowernumber
107 # collect the stack of books already transfered so they can printed...
110 my $barcode = $query->param('barcode');
111 # remove leading/trailing whitespace
112 defined $barcode and $barcode =~ s/^\s*|\s*$//g; # FIXME: barcodeInputFilter
113 # warn "barcode : $barcode";
116 ( $transfered, $messages ) =
117 transferbook( $tobranchcd, $barcode, $ignoreRs );
118 my $item = Koha::Items->find({ barcode => $barcode });
119 $found = $messages->{'ResFound'};
122 my $biblio = $item->biblio;
123 my $frbranchcd = C4::Context->userenv->{'branch'};
124 $item{'biblionumber'} = $item->biblionumber;
125 $item{'itemnumber'} = $item->itemnumber;
126 $item{'title'} = $biblio->title;
127 $item{'author'} = $biblio->author;
128 $item{'itemtype'} = $biblio->biblioitem->itemtype;
129 $item{'ccode'} = $item->ccode;
130 $item{'itemcallnumber'} = $item->itemcallnumber;
131 my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $item->location });
132 $item{'location'} = $av->count ? $av->next->lib : '';
134 $item{barcode} = $barcode;
135 $item{frombrcd} = $frbranchcd;
136 $item{tobrcd} = $tobranchcd;
137 push( @trsfitemloop, \%item );
141 foreach ( $query->param ) {
142 (next) unless (/bc-(\d*)/);
145 my $bc = $query->param("bc-$counter");
146 my $frbcd = $query->param("fb-$counter");
147 my $tobcd = $query->param("tb-$counter");
149 $item{counter} = $counter;
150 $item{barcode} = $bc;
151 $item{frombrcd} = $frbcd;
152 $item{tobrcd} = $tobcd;
153 my $item = Koha::Items->find({ barcode => $bc });
154 my $biblio = $item->biblio;
155 $item{'biblionumber'} = $item->biblionumber;
156 $item{'itemnumber'} = $item->itemnumber;
157 $item{'title'} = $biblio->title;
158 $item{'author'} = $biblio->author;
159 $item{'itemtype'} = $biblio->biblioitem->itemtype;
160 $item{'ccode'} = $item->ccode;
161 $item{'itemcallnumber'} = $item->itemcallnumber;
162 my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $item->location });
163 $item{'location'} = $av->count ? $av->next->lib : '';
164 push( @trsfitemloop, \%item );
170 #####################
173 my $res = $messages->{'ResFound'};
174 $itemnumber = $res->{'itemnumber'};
176 if ( $res->{'ResFound'} eq "Waiting" ) {
179 elsif ( $res->{'ResFound'} eq "Reserved" ) {
181 $biblionumber = $res->{'biblionumber'};
186 foreach my $code ( keys %$messages ) {
187 if ( $code ne 'WasTransfered' ) {
189 if ( $code eq 'BadBarcode' ) {
190 $err{msg} = $messages->{'BadBarcode'};
191 $err{errbadcode} = 1;
193 elsif ( $code eq "NotAllowed" ) {
194 warn "NotAllowed: $messages->{'NotAllowed'} to branchcode " . $messages->{'NotAllowed'};
195 # Do we really want a error log message here? --atz
196 $err{errnotallowed} = 1;
197 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
199 $err{code} = $typecode;
201 elsif ( $code eq 'IsPermanent' ) {
202 $err{errispermanent} = 1;
203 $err{msg} = $messages->{'IsPermanent'};
205 elsif ( $code eq 'WasReturned' ) {
206 $err{errwasreturned} = 1;
207 $err{borrowernumber} = $messages->{'WasReturned'};
208 my $borrower = GetMember('borrowernumber'=>$messages->{'WasReturned'});
209 $err{title} = $borrower->{'title'};
210 $err{firstname} = $borrower->{'firstname'};
211 $err{surname} = $borrower->{'surname'};
212 $err{cardnumber} = $borrower->{'cardnumber'};
214 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
215 push( @errmsgloop, \%err );
220 # warn "FINAL ============= ".Dumper(@trsfitemloop);
223 reserved => $reserved,
225 borrowernumber => $borrowernumber,
226 itemnumber => $itemnumber,
228 biblionumber => $biblionumber,
229 tobranchcd => $tobranchcd,
230 reqmessage => $reqmessage,
231 cancelled => $cancelled,
232 setwaiting => $setwaiting,
233 trsfitemloop => \@trsfitemloop,
234 errmsgloop => \@errmsgloop,
235 CircAutocompl => C4::Context->preference("CircAutocompl")
238 # Checking if there is a Fast Cataloging Framework
239 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
241 output_html_with_http_headers $query, $cookie, $template->output;