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');
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 if ( $res->{'ResFound'} eq "Reserved" ) {
175 $biblionumber = $res->{'biblionumber'};
179 #####################
182 foreach my $code ( keys %$messages ) {
185 if ( $code eq 'BadBarcode' ) {
186 $err{msg} = $messages->{'BadBarcode'};
187 $err{errbadcode} = 1;
190 if ( $code eq 'IsPermanent' ) {
191 $err{errispermanent} = 1;
192 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
194 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
196 if ( $code eq 'WasReturned' ) {
197 $err{errwasreturned} = 1;
199 push( @errmsgloop, \%err );
203 # warn "FINAL ============= ".Dumper(@trsfitemloop);
206 reserved => $reserved,
208 borrowernumber => $borrowernumber,
209 itemnumber => $itemnumber,
211 biblionumber => $biblionumber,
212 tobranchcd => $tobranchcd,
213 reqmessage => $reqmessage,
214 cancelled => $cancelled,
215 setwaiting => $setwaiting,
216 trsfitemloop => \@trsfitemloop,
217 branchoptionloop => \@branchoptionloop,
218 errmsgloop => \@errmsgloop,
220 output_html_with_http_headers $query, $cookie, $template->output;
224 return $borinfo->{'surname'} . " "
225 . $borinfo->{'title'} . " "
226 . $borinfo->{'firstname'};