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::Interface::CGI::Output;
32 use C4::Branch; # GetBranches
35 ###############################################
40 #######################################################################################
42 my ( $template, $cookie );
44 ( $template, $user, $cookie ) = get_template_and_user(
46 template_name => "circ/branchtransfers.tmpl",
50 flagsrequired => { circulate => 1 },
54 my $branches = GetBranches;
55 my $branch = GetBranch( $query, $branches );
65 my $request = $query->param('request');
66 my $borrowernumber = $query->param('borrowernumber');
67 my $tobranchcd = $query->param('tobranchcd');
70 # Deal with the requests....
71 if ( $request eq "KillWaiting" ) {
72 my $item = $query->param('itemnumber');
74 CancelReserve( 0, $item, $borrowernumber );
80 if ( $request eq "SetWaiting" ) {
81 my $item = $query->param('itemnumber');
82 $tobranchcd = ReserveWaiting( $item, $borrowernumber );
87 if ( $request eq 'KillReserved' ) {
88 my $biblio = $query->param('biblionumber');
89 CancelReserve( $biblio, 0, $borrowernumber );
94 # set up the branchselect options....
96 foreach my $br ( keys %$branches ) {
98 $branch{selected} = ( $br eq $tobranchcd );
100 $branch{name} = $branches->{$br}->{'branchname'};
101 push( @branchoptionloop, \%branch );
104 # collect the stack of books already transfered so they can printed...
108 my $barcode = $query->param('barcode');
109 # warn "barcode : $barcode";
113 ( $transfered, $messages, $iteminformation ) =
114 transferbook( $tobranchcd, $barcode, $ignoreRs );
116 # warn "Transfered : $transfered / ".Dumper($messages);
117 $found = $messages->{'ResFound'};
120 my $frbranchcd = C4::Context->userenv->{'branch'};
121 # if ( not($found) ) {
122 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
123 $item{'title'} = $iteminformation->{'title'};
124 $item{'author'} = $iteminformation->{'author'};
125 $item{'itemtype'} = $iteminformation->{'itemtype'};
126 $item{'ccode'} = $iteminformation->{'ccode'};
127 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
128 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
131 $item{barcode} = $barcode;
132 $item{frombrcd} = $frbranchcd;
133 $item{tobrcd} = $tobranchcd;
134 push( @trsfitemloop, \%item );
135 # warn Dumper(@trsfitemloop);
139 foreach ( $query->param ) {
140 (next) unless (/bc-(\d*)/);
143 my $bc = $query->param("bc-$counter");
144 my $frbcd = $query->param("fb-$counter");
145 my $tobcd = $query->param("tb-$counter");
147 $item{counter} = $counter;
148 $item{barcode} = $bc;
149 $item{frombrcd} = $frbcd;
150 $item{tobrcd} = $tobcd;
151 my ($iteminformation) = GetBiblioFromItemNumber( GetItemnumberFromBarcode($bc) );
152 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
153 $item{'title'} = $iteminformation->{'title'};
154 $item{'author'} = $iteminformation->{'author'};
155 $item{'itemtype'} = $iteminformation->{'itemtype'};
156 $item{'ccode'} = $iteminformation->{'ccode'};
157 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
158 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
159 push( @trsfitemloop, \%item );
165 #####################
168 my $res = $messages->{'ResFound'};
169 $itemnumber = $res->{'itemnumber'};
171 if ( $res->{'ResFound'} eq "Waiting" ) {
174 if ( $res->{'ResFound'} eq "Reserved" ) {
176 $biblionumber = $res->{'biblionumber'};
180 #####################
183 foreach my $code ( keys %$messages ) {
186 if ( $code eq 'BadBarcode' ) {
187 $err{msg} = $messages->{'BadBarcode'};
188 $err{errbadcode} = 1;
191 if ( $code eq 'IsPermanent' ) {
192 $err{errispermanent} = 1;
193 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
195 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
197 if ( $code eq 'WasReturned' ) {
198 $err{errwasreturned} = 1;
200 push( @errmsgloop, \%err );
204 # warn "FINAL ============= ".Dumper(@trsfitemloop);
207 reserved => $reserved,
209 borrowernumber => $borrowernumber,
210 itemnumber => $itemnumber,
212 biblionumber => $biblionumber,
213 tobranchcd => $tobranchcd,
214 reqmessage => $reqmessage,
215 cancelled => $cancelled,
216 setwaiting => $setwaiting,
217 trsfitemloop => \@trsfitemloop,
218 branchoptionloop => \@branchoptionloop,
219 errmsgloop => \@errmsgloop,
221 output_html_with_http_headers $query, $cookie, $template->output;
225 return $borinfo->{'surname'} . " "
226 . $borinfo->{'title'} . " "
227 . $borinfo->{'firstname'};