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 under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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.tmpl",
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');
83 CancelReserve
( 0, $item, $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');
96 CancelReserve
( $biblio, 0, $borrowernumber );
101 # collect the stack of books already transfered so they can printed...
105 my $barcode = $query->param('barcode');
107 defined $barcode and $barcode =~ s/\s*//g; # FIXME: barcodeInputFilter
108 # warn "barcode : $barcode";
112 ( $transfered, $messages, $iteminformation ) =
113 transferbook
( $tobranchcd, $barcode, $ignoreRs );
115 # warn "Transfered : $transfered / ".Dumper($messages);
116 $found = $messages->{'ResFound'};
119 my $frbranchcd = C4
::Context
->userenv->{'branch'};
120 # if ( not($found) ) {
121 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
122 $item{'title'} = $iteminformation->{'title'};
123 $item{'author'} = $iteminformation->{'author'};
124 $item{'itemtype'} = $iteminformation->{'itemtype'};
125 $item{'ccode'} = $iteminformation->{'ccode'};
126 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
127 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
130 $item{barcode
} = $barcode;
131 $item{frombrcd
} = $frbranchcd;
132 $item{tobrcd
} = $tobranchcd;
133 push( @trsfitemloop, \
%item );
134 # warn Dumper(@trsfitemloop);
138 foreach ( $query->param ) {
139 (next) unless (/bc-(\d*)/);
142 my $bc = $query->param("bc-$counter");
143 my $frbcd = $query->param("fb-$counter");
144 my $tobcd = $query->param("tb-$counter");
146 $item{counter
} = $counter;
147 $item{barcode
} = $bc;
148 $item{frombrcd
} = $frbcd;
149 $item{tobrcd
} = $tobcd;
150 my ($iteminformation) = GetBiblioFromItemNumber
( GetItemnumberFromBarcode
($bc) );
151 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
152 $item{'title'} = $iteminformation->{'title'};
153 $item{'author'} = $iteminformation->{'author'};
154 $item{'itemtype'} = $iteminformation->{'itemtype'};
155 $item{'ccode'} = $iteminformation->{'ccode'};
156 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
157 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
158 push( @trsfitemloop, \
%item );
164 #####################
167 my $res = $messages->{'ResFound'};
168 $itemnumber = $res->{'itemnumber'};
170 if ( $res->{'ResFound'} eq "Waiting" ) {
173 elsif ( $res->{'ResFound'} eq "Reserved" ) {
175 $biblionumber = $res->{'biblionumber'};
179 #####################
181 # Used for branch transfer limits error messages.
182 my $codeTypeDescription = 'Collection Code';
183 my $codeType = C4
::Context
->preference("BranchTransferLimitsType");
184 if ( $codeType eq 'itemtype' ) {
185 $codeTypeDescription = 'Item Type';
189 foreach my $code ( keys %$messages ) {
191 if ( $code eq 'BadBarcode' ) {
192 $err{msg
} = $messages->{'BadBarcode'};
193 $err{errbadcode
} = 1;
195 elsif ( $code eq "NotAllowed" ) {
196 warn "NotAllowed: $messages->{'NotAllowed'} to " . $branches->{ $messages->{'NotAllowed'} }->{'branchname'};
197 # Do we really want a error log message here? --atz
198 $err{errnotallowed
} = 1;
199 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
200 $err{tbr
} = $branches->{ $tbr }->{'branchname'};
201 $err{code
} = $typecode;
202 $err{codeType
} = $codeTypeDescription;
204 elsif ( $code eq 'IsPermanent' ) {
205 $err{errispermanent
} = 1;
206 $err{msg
} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
208 elsif ( $code eq 'WasReturned' ) {
209 $err{errwasreturned
} = 1;
210 $err{borrowernumber
} = $messages->{'WasReturned'};
211 my $borrower = GetMember
('borrowernumber'=>$messages->{'WasReturned'});
212 $err{title
} = $borrower->{'title'};
213 $err{firstname
} = $borrower->{'firstname'};
214 $err{surname
} = $borrower->{'surname'};
215 $err{cardnumber
} = $borrower->{'cardnumber'};
217 $err{errdesteqholding
} = ( $code eq 'DestinationEqualsHolding' );
218 push( @errmsgloop, \
%err );
222 # warn "FINAL ============= ".Dumper(@trsfitemloop);
225 reserved
=> $reserved,
227 borrowernumber
=> $borrowernumber,
228 itemnumber
=> $itemnumber,
230 biblionumber
=> $biblionumber,
231 tobranchcd
=> $tobranchcd,
232 reqmessage
=> $reqmessage,
233 cancelled
=> $cancelled,
234 setwaiting
=> $setwaiting,
235 trsfitemloop
=> \
@trsfitemloop,
236 branchoptionloop
=> GetBranchesLoop
($tobranchcd),
237 errmsgloop
=> \
@errmsgloop,
238 CircAutocompl
=> C4
::Context
->preference("CircAutocompl")
240 output_html_with_http_headers
$query, $cookie, $template->output;