2 # WARNING: This file uses 4-character tabs!
4 #written 11/3/2002 by Finlay
5 #script to execute branch transfers of books
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
31 use C4::Branch; # GetBranches
34 ###############################################
39 #######################################################################################
41 my ( $template, $cookie );
43 ( $template, $user, $cookie ) = get_template_and_user(
45 template_name => "circ/branchtransfers.tmpl",
49 flagsrequired => { circulate => 1 },
53 my $branches = GetBranches;
54 my $branch = GetBranch( $query, $branches );
64 my $request = $query->param('request');
65 my $borrowernumber = $query->param('borrowernumber');
66 my $tobranchcd = $query->param('tobranchcd');
69 # Deal with the requests....
70 if ( $request eq "KillWaiting" ) {
71 my $item = $query->param('itemnumber');
73 CancelReserve( 0, $item, $borrowernumber );
79 if ( $request eq "SetWaiting" ) {
80 my $item = $query->param('itemnumber');
81 ModReserveAffect( $item, $borrowernumber );
86 if ( $request eq 'KillReserved' ) {
87 my $biblio = $query->param('biblionumber');
88 CancelReserve( $biblio, 0, $borrowernumber );
93 # set up the branchselect options....
95 foreach my $br ( keys %$branches ) {
97 $branch{selected} = ( $br eq $tobranchcd );
99 $branch{name} = $branches->{$br}->{'branchname'};
100 push( @branchoptionloop, \%branch );
103 # collect the stack of books already transfered so they can printed...
107 my $barcode = $query->param('barcode');
109 $barcode =~ s/\s*//g;
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{'title'} = $iteminformation->{'title'};
125 $item{'author'} = $iteminformation->{'author'};
126 $item{'itemtype'} = $iteminformation->{'itemtype'};
127 $item{'ccode'} = $iteminformation->{'ccode'};
128 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
129 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
132 $item{barcode} = $barcode;
133 $item{frombrcd} = $frbranchcd;
134 $item{tobrcd} = $tobranchcd;
135 push( @trsfitemloop, \%item );
136 # warn Dumper(@trsfitemloop);
140 foreach ( $query->param ) {
141 (next) unless (/bc-(\d*)/);
144 my $bc = $query->param("bc-$counter");
145 my $frbcd = $query->param("fb-$counter");
146 my $tobcd = $query->param("tb-$counter");
148 $item{counter} = $counter;
149 $item{barcode} = $bc;
150 $item{frombrcd} = $frbcd;
151 $item{tobrcd} = $tobcd;
152 my ($iteminformation) = GetBiblioFromItemNumber( GetItemnumberFromBarcode($bc) );
153 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
154 $item{'title'} = $iteminformation->{'title'};
155 $item{'author'} = $iteminformation->{'author'};
156 $item{'itemtype'} = $iteminformation->{'itemtype'};
157 $item{'ccode'} = $iteminformation->{'ccode'};
158 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
159 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
160 push( @trsfitemloop, \%item );
166 #####################
169 my $res = $messages->{'ResFound'};
170 $itemnumber = $res->{'itemnumber'};
172 if ( $res->{'ResFound'} eq "Waiting" ) {
175 if ( $res->{'ResFound'} eq "Reserved" ) {
177 $biblionumber = $res->{'biblionumber'};
181 #####################
184 foreach my $code ( keys %$messages ) {
187 if ( $code eq 'BadBarcode' ) {
188 $err{msg} = $messages->{'BadBarcode'};
189 $err{errbadcode} = 1;
192 if ( $code eq 'IsPermanent' ) {
193 $err{errispermanent} = 1;
194 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
196 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
198 if ( $code eq 'WasReturned' ) {
199 $err{errwasreturned} = 1;
201 push( @errmsgloop, \%err );
205 # warn "FINAL ============= ".Dumper(@trsfitemloop);
208 reserved => $reserved,
210 borrowernumber => $borrowernumber,
211 itemnumber => $itemnumber,
213 biblionumber => $biblionumber,
214 tobranchcd => $tobranchcd,
215 reqmessage => $reqmessage,
216 cancelled => $cancelled,
217 setwaiting => $setwaiting,
218 trsfitemloop => \@trsfitemloop,
219 branchoptionloop => \@branchoptionloop,
220 errmsgloop => \@errmsgloop,
221 CircAutocompl => C4::Context->preference("CircAutocompl")
223 output_html_with_http_headers $query, $cookie, $template->output;
227 return $borinfo->{'surname'} . " "
228 . $borinfo->{'title'} . " "
229 . $borinfo->{'firstname'};