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/;
35 ###############################################
40 if (!C4::Context->userenv){
41 my $sessionID = $query->cookie("CGISESSID");
43 $session = get_session($sessionID) if $sessionID;
44 if (!$session or $session->param('branch') eq 'NO_LIBRARY_SET'){
45 # no branch set we can't transfer
46 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
51 #######################################################################################
53 my ($template, $user, $cookie) = get_template_and_user(
55 template_name => "circ/branchtransfers.tt",
59 flagsrequired => { circulate => "circulate_remaining_permissions" },
71 my $request = $query->param('request') || '';
72 my $borrowernumber = $query->param('borrowernumber') || 0;
73 my $tobranchcd = $query->param('tobranchcd') || '';
77 # Deal with the requests....
78 if ( $request eq "KillWaiting" ) {
79 my $item = $query->param('itemnumber');
82 borrowernumber => $borrowernumber
87 elsif ( $request eq "SetWaiting" ) {
88 my $item = $query->param('itemnumber');
89 ModReserveAffect( $item, $borrowernumber );
94 elsif ( $request eq 'KillReserved' ) {
95 my $biblio = $query->param('biblionumber');
97 biblionumber => $biblio,
98 borrowernumber => $borrowernumber
104 # collect the stack of books already transfered so they can printed...
107 my $barcode = $query->param('barcode');
108 # remove leading/trailing whitespace
109 defined $barcode and $barcode =~ s/^\s*|\s*$//g; # FIXME: barcodeInputFilter
110 # warn "barcode : $barcode";
114 ( $transfered, $messages, $iteminformation ) =
115 transferbook( $tobranchcd, $barcode, $ignoreRs );
117 # warn "Transfered : $transfered / ".Dumper($messages);
118 $found = $messages->{'ResFound'};
121 my $frbranchcd = C4::Context->userenv->{'branch'};
122 # if ( not($found) ) {
123 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
124 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
125 $item{'title'} = $iteminformation->{'title'};
126 $item{'author'} = $iteminformation->{'author'};
127 $item{'itemtype'} = $iteminformation->{'itemtype'};
128 $item{'ccode'} = $iteminformation->{'ccode'};
129 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
130 $item{'location'} = GetKohaAuthorisedValueLib("LOC",$iteminformation->{'location'});
133 $item{barcode} = $barcode;
134 $item{frombrcd} = $frbranchcd;
135 $item{tobrcd} = $tobranchcd;
136 push( @trsfitemloop, \%item );
137 # warn Dumper(@trsfitemloop);
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 ($iteminformation) = GetBiblioFromItemNumber( GetItemnumberFromBarcode($bc) );
154 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
155 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
156 $item{'title'} = $iteminformation->{'title'};
157 $item{'author'} = $iteminformation->{'author'};
158 $item{'itemtype'} = $iteminformation->{'itemtype'};
159 $item{'ccode'} = $iteminformation->{'ccode'};
160 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
161 $item{'location'} = GetKohaAuthorisedValueLib("LOC",$iteminformation->{'location'});
162 push( @trsfitemloop, \%item );
168 #####################
171 my $res = $messages->{'ResFound'};
172 $itemnumber = $res->{'itemnumber'};
174 if ( $res->{'ResFound'} eq "Waiting" ) {
177 elsif ( $res->{'ResFound'} eq "Reserved" ) {
179 $biblionumber = $res->{'biblionumber'};
184 foreach my $code ( keys %$messages ) {
185 if ( $code ne 'WasTransfered' ) {
187 if ( $code eq 'BadBarcode' ) {
188 $err{msg} = $messages->{'BadBarcode'};
189 $err{errbadcode} = 1;
191 elsif ( $code eq "NotAllowed" ) {
192 warn "NotAllowed: $messages->{'NotAllowed'} to branchcode " . $messages->{'NotAllowed'};
193 # Do we really want a error log message here? --atz
194 $err{errnotallowed} = 1;
195 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
197 $err{code} = $typecode;
199 elsif ( $code eq 'IsPermanent' ) {
200 $err{errispermanent} = 1;
201 $err{msg} = $messages->{'IsPermanent'};
203 elsif ( $code eq 'WasReturned' ) {
204 $err{errwasreturned} = 1;
205 $err{borrowernumber} = $messages->{'WasReturned'};
206 my $borrower = GetMember('borrowernumber'=>$messages->{'WasReturned'});
207 $err{title} = $borrower->{'title'};
208 $err{firstname} = $borrower->{'firstname'};
209 $err{surname} = $borrower->{'surname'};
210 $err{cardnumber} = $borrower->{'cardnumber'};
212 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
213 push( @errmsgloop, \%err );
218 # warn "FINAL ============= ".Dumper(@trsfitemloop);
221 reserved => $reserved,
223 borrowernumber => $borrowernumber,
224 itemnumber => $itemnumber,
226 biblionumber => $biblionumber,
227 tobranchcd => $tobranchcd,
228 reqmessage => $reqmessage,
229 cancelled => $cancelled,
230 setwaiting => $setwaiting,
231 trsfitemloop => \@trsfitemloop,
232 errmsgloop => \@errmsgloop,
233 CircAutocompl => C4::Context->preference("CircAutocompl")
235 output_html_with_http_headers $query, $cookie, $template->output;