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/;
32 use C4
::Branch
; # GetBranches
36 ###############################################
41 if (!C4
::Context
->userenv){
42 my $sessionID = $query->cookie("CGISESSID");
44 $session = get_session
($sessionID) if $sessionID;
45 if (!$session or $session->param('branch') eq 'NO_LIBRARY_SET'){
46 # no branch set we can't transfer
47 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
52 #######################################################################################
54 my ($template, $user, $cookie) = get_template_and_user
(
56 template_name
=> "circ/branchtransfers.tt",
60 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
64 my $branches = GetBranches
;
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";
117 ( $transfered, $messages, $iteminformation ) =
118 transferbook
( $tobranchcd, $barcode, $ignoreRs );
120 # warn "Transfered : $transfered / ".Dumper($messages);
121 $found = $messages->{'ResFound'};
124 my $frbranchcd = C4
::Context
->userenv->{'branch'};
125 # if ( not($found) ) {
126 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
127 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
128 $item{'title'} = $iteminformation->{'title'};
129 $item{'author'} = $iteminformation->{'author'};
130 $item{'itemtype'} = $iteminformation->{'itemtype'};
131 $item{'ccode'} = $iteminformation->{'ccode'};
132 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
133 $item{'location'} = GetKohaAuthorisedValueLib
("LOC",$iteminformation->{'location'});
134 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
135 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
138 $item{barcode
} = $barcode;
139 $item{frombrcd
} = $frbranchcd;
140 $item{tobrcd
} = $tobranchcd;
141 push( @trsfitemloop, \
%item );
142 # warn Dumper(@trsfitemloop);
146 foreach ( $query->param ) {
147 (next) unless (/bc-(\d*)/);
150 my $bc = $query->param("bc-$counter");
151 my $frbcd = $query->param("fb-$counter");
152 my $tobcd = $query->param("tb-$counter");
154 $item{counter
} = $counter;
155 $item{barcode
} = $bc;
156 $item{frombrcd
} = $frbcd;
157 $item{tobrcd
} = $tobcd;
158 my ($iteminformation) = GetBiblioFromItemNumber
( GetItemnumberFromBarcode
($bc) );
159 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
160 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
161 $item{'title'} = $iteminformation->{'title'};
162 $item{'author'} = $iteminformation->{'author'};
163 $item{'itemtype'} = $iteminformation->{'itemtype'};
164 $item{'ccode'} = $iteminformation->{'ccode'};
165 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
166 $item{'location'} = GetKohaAuthorisedValueLib
("LOC",$iteminformation->{'location'});
167 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
168 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
169 push( @trsfitemloop, \
%item );
175 #####################
178 my $res = $messages->{'ResFound'};
179 $itemnumber = $res->{'itemnumber'};
181 if ( $res->{'ResFound'} eq "Waiting" ) {
184 elsif ( $res->{'ResFound'} eq "Reserved" ) {
186 $biblionumber = $res->{'biblionumber'};
190 #####################
192 # Used for branch transfer limits error messages.
193 my $codeTypeDescription = 'Collection Code';
194 my $codeType = C4
::Context
->preference("BranchTransferLimitsType");
195 if ( $codeType eq 'itemtype' ) {
196 $codeTypeDescription = 'Item Type';
200 foreach my $code ( keys %$messages ) {
201 if ( $code ne 'WasTransfered' ) {
203 if ( $code eq 'BadBarcode' ) {
204 $err{msg
} = $messages->{'BadBarcode'};
205 $err{errbadcode
} = 1;
207 elsif ( $code eq "NotAllowed" ) {
208 warn "NotAllowed: $messages->{'NotAllowed'} to " . $branches->{ $messages->{'NotAllowed'} }->{'branchname'};
209 # Do we really want a error log message here? --atz
210 $err{errnotallowed
} = 1;
211 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
212 $err{tbr
} = $branches->{ $tbr }->{'branchname'};
213 $err{code
} = $typecode;
214 $err{codeType
} = $codeTypeDescription;
216 elsif ( $code eq 'IsPermanent' ) {
217 $err{errispermanent
} = 1;
218 $err{msg
} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
220 elsif ( $code eq 'WasReturned' ) {
221 $err{errwasreturned
} = 1;
222 $err{borrowernumber
} = $messages->{'WasReturned'};
223 my $borrower = GetMember
('borrowernumber'=>$messages->{'WasReturned'});
224 $err{title
} = $borrower->{'title'};
225 $err{firstname
} = $borrower->{'firstname'};
226 $err{surname
} = $borrower->{'surname'};
227 $err{cardnumber
} = $borrower->{'cardnumber'};
229 $err{errdesteqholding
} = ( $code eq 'DestinationEqualsHolding' );
230 push( @errmsgloop, \
%err );
235 # warn "FINAL ============= ".Dumper(@trsfitemloop);
238 reserved
=> $reserved,
240 borrowernumber
=> $borrowernumber,
241 itemnumber
=> $itemnumber,
243 biblionumber
=> $biblionumber,
244 tobranchcd
=> $tobranchcd,
245 reqmessage
=> $reqmessage,
246 cancelled
=> $cancelled,
247 setwaiting
=> $setwaiting,
248 trsfitemloop
=> \
@trsfitemloop,
249 branchoptionloop
=> GetBranchesLoop
($tobranchcd),
250 errmsgloop
=> \
@errmsgloop,
251 CircAutocompl
=> C4
::Context
->preference("CircAutocompl")
253 output_html_with_http_headers
$query, $cookie, $template->output;