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'};
191 foreach my $code ( keys %$messages ) {
192 if ( $code ne 'WasTransfered' ) {
194 if ( $code eq 'BadBarcode' ) {
195 $err{msg
} = $messages->{'BadBarcode'};
196 $err{errbadcode
} = 1;
198 elsif ( $code eq "NotAllowed" ) {
199 warn "NotAllowed: $messages->{'NotAllowed'} to " . $branches->{ $messages->{'NotAllowed'} }->{'branchname'};
200 # Do we really want a error log message here? --atz
201 $err{errnotallowed
} = 1;
202 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
203 $err{tbr
} = $branches->{ $tbr }->{'branchname'};
204 $err{code
} = $typecode;
206 elsif ( $code eq 'IsPermanent' ) {
207 $err{errispermanent
} = 1;
208 $err{msg
} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
210 elsif ( $code eq 'WasReturned' ) {
211 $err{errwasreturned
} = 1;
212 $err{borrowernumber
} = $messages->{'WasReturned'};
213 my $borrower = GetMember
('borrowernumber'=>$messages->{'WasReturned'});
214 $err{title
} = $borrower->{'title'};
215 $err{firstname
} = $borrower->{'firstname'};
216 $err{surname
} = $borrower->{'surname'};
217 $err{cardnumber
} = $borrower->{'cardnumber'};
219 $err{errdesteqholding
} = ( $code eq 'DestinationEqualsHolding' );
220 push( @errmsgloop, \
%err );
225 # warn "FINAL ============= ".Dumper(@trsfitemloop);
228 reserved
=> $reserved,
230 borrowernumber
=> $borrowernumber,
231 itemnumber
=> $itemnumber,
233 biblionumber
=> $biblionumber,
234 tobranchcd
=> $tobranchcd,
235 reqmessage
=> $reqmessage,
236 cancelled
=> $cancelled,
237 setwaiting
=> $setwaiting,
238 trsfitemloop
=> \
@trsfitemloop,
239 branchoptionloop
=> GetBranchesLoop
($tobranchcd),
240 errmsgloop
=> \
@errmsgloop,
241 CircAutocompl
=> C4
::Context
->preference("CircAutocompl")
243 output_html_with_http_headers
$query, $cookie, $template->output;