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{'itemnumber'} = $iteminformation->{'itemnumber'};
123 $item{'title'} = $iteminformation->{'title'};
124 $item{'author'} = $iteminformation->{'author'};
125 $item{'itemtype'} = $iteminformation->{'itemtype'};
126 $item{'ccode'} = $iteminformation->{'ccode'};
127 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
128 $item{'location'} = GetKohaAuthorisedValueLib("LOC",$iteminformation->{'location'});
129 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
130 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
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 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
163 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
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'};
185 #####################
187 # Used for branch transfer limits error messages.
188 my $codeTypeDescription = 'Collection Code';
189 my $codeType = C4::Context->preference("BranchTransferLimitsType");
190 if ( $codeType eq 'itemtype' ) {
191 $codeTypeDescription = 'Item Type';
195 foreach my $code ( keys %$messages ) {
196 if ( $code ne 'WasTransfered' ) {
198 if ( $code eq 'BadBarcode' ) {
199 $err{msg} = $messages->{'BadBarcode'};
200 $err{errbadcode} = 1;
202 elsif ( $code eq "NotAllowed" ) {
203 warn "NotAllowed: $messages->{'NotAllowed'} to " . $branches->{ $messages->{'NotAllowed'} }->{'branchname'};
204 # Do we really want a error log message here? --atz
205 $err{errnotallowed} = 1;
206 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
207 $err{tbr} = $branches->{ $tbr }->{'branchname'};
208 $err{code} = $typecode;
209 $err{codeType} = $codeTypeDescription;
211 elsif ( $code eq 'IsPermanent' ) {
212 $err{errispermanent} = 1;
213 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
215 elsif ( $code eq 'WasReturned' ) {
216 $err{errwasreturned} = 1;
217 $err{borrowernumber} = $messages->{'WasReturned'};
218 my $borrower = GetMember('borrowernumber'=>$messages->{'WasReturned'});
219 $err{title} = $borrower->{'title'};
220 $err{firstname} = $borrower->{'firstname'};
221 $err{surname} = $borrower->{'surname'};
222 $err{cardnumber} = $borrower->{'cardnumber'};
224 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
225 push( @errmsgloop, \%err );
230 # warn "FINAL ============= ".Dumper(@trsfitemloop);
233 reserved => $reserved,
235 borrowernumber => $borrowernumber,
236 itemnumber => $itemnumber,
238 biblionumber => $biblionumber,
239 tobranchcd => $tobranchcd,
240 reqmessage => $reqmessage,
241 cancelled => $cancelled,
242 setwaiting => $setwaiting,
243 trsfitemloop => \@trsfitemloop,
244 branchoptionloop => GetBranchesLoop($tobranchcd),
245 errmsgloop => \@errmsgloop,
246 CircAutocompl => C4::Context->preference("CircAutocompl")
248 output_html_with_http_headers $query, $cookie, $template->output;