2 # WARNING: This file uses 4-character tabs!
4 #written 11/3/2002 by Finlay
5 #script to execute branch transfers of books
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
27 use C4::Circulation::Circ2;
31 use C4::Interface::CGI::Output;
34 ###############################################
38 my $headerbackgroundcolor='#99cc33';
39 my $circbackgroundcolor='#ffffcc';
40 my $circbackgroundcolor='white';
41 my $linecolor1='#ffffcc';
42 my $linecolor2='white';
43 my $backgroundimage="/images/background-mem.gif";
45 my $branches = getbranches();
46 my $printers = getprinters(\%env);
49 ###############################################
55 my $branch = getbranch($query, $branches);
56 my $printer = getprinter($query, $printers);
58 my $genbrname = $branches->{$branch}->{'branchname'} ;
59 my $genprname = $printers->{$printer}->{'printername'};
70 my $request=$query->param('request');
71 my $borrnum = $query->param('borrowernumber');
73 my $tobranchcd=$query->param('tobranchcd');
77 # Deal with the requests....
78 if ($request eq "KillWaiting") {
79 my $item = $query->param('itemnumber');
80 CancelReserve(0, $item, $borrnum);
86 if ($request eq "SetWaiting") {
87 my $item = $query->param('itemnumber');
88 $tobranchcd = ReserveWaiting($item, $borrnum);
89 $reqbrchname = $branches->{$tobranchcd}->{'branchname'};
94 if ($request eq 'KillReserved'){
95 my $biblio = $query->param('biblionumber');
96 CancelReserve($biblio, 0, $borrnum);
103 # set up the branchselect options....
104 my @branchoptionloop;
105 foreach my $br (keys %$branches) {
106 #(next) unless $branches->{$br}->{'CU'}; #FIXME disabled to fix bug 202
108 $branch{selected}=($br eq $tobranchcd);
110 $branch{name}=$branches->{$br}->{'branchname'};
111 push (@branchoptionloop, \%branch);
115 # collect the stack of books already transfered so they can printed...
120 my $color=$linecolor2;
122 my $barcode = $query->param('barcode');
126 ($transfered, $messages, $iteminformation)
127 = transferbook($tobranchcd, $barcode, $ignoreRs);
128 $found = $messages->{'ResFound'};
131 my $frbranchcd = $iteminformation->{'holdingbranch'};
133 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
134 $item{'color'}=$color;
135 $item{'biblionumber'}=$iteminformation->{'biblionumber'};
136 $item{'title'}=$iteminformation->{'title'};
137 $item{'author'}=$iteminformation->{'author'};
138 $item{'itemtype'}=$iteminformation->{'itemtype'};
139 $item{'frbrname'}=$branches->{$frbranchcd}->{'branchname'};
140 $item{'tobrname'}=$branches->{$tobranchcd}->{'branchname'};
143 $item{barcode}=$barcode;
144 $item{frombrcd}=$frbranchcd;
145 $item{tobrcd}=$tobranchcd;
147 #Are these lines still useful ???
148 $transfereditems{0}=$barcode;
149 $frbranchcds{0}=$frbranchcd;
150 $tobranchcds{0}=$tobranchcd;
152 push (@trsfitemloop, \%item);
156 foreach ($query->param){
157 (next) unless (/bc-(\d*)/);
160 my $bc=$query->param("bc-$counter");
161 my $frbcd=$query->param("fb-$counter");
162 my $tobcd=$query->param("tb-$counter");
164 $item{counter}=$counter;
166 $item{frombrcd}=$frbcd;
167 $item{tobrcd}=$tobcd;
168 my ($iteminformation) = getiteminformation(\%env, 0, $bc);
169 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
170 $item{'color'}=$color;
171 $item{'biblionumber'}=$iteminformation->{'biblionumber'};
172 $item{'title'}=$iteminformation->{'title'};
173 $item{'author'}=$iteminformation->{'author'};
174 $item{'itemtype'}=$iteminformation->{'itemtype'};
175 $item{'frbrname'}=$branches->{$frbcd}->{'branchname'};
176 $item{'tobrname'}=$branches->{$tobcd}->{'branchname'};
178 #Are these lines still useful ???
179 $transfereditems{$counter}=$bc;
180 $frbranchcds{$counter}=$frbcd;
181 $tobranchcds{$counter}=$tobcd;
183 push (@trsfitemloop, \%item);
195 #####################
198 my $res = $messages->{'ResFound'};
199 $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
200 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
202 $bornum = $borr->{'borrowernumber'}; #Hopefully, borr->{borrowernumber}=res->{borrowernumber}
203 $borcnum = $borr->{'cardnumber'};
204 $itemnumber = $res->{'itemnumber'};
206 if ($res->{'ResFound'} eq "Waiting") {
209 if ($res->{'ResFound'} eq "Reserved") {
211 $biblionum = $res->{'biblionumber'};
215 #####################
218 foreach my $code (keys %$messages) {
220 $err{errbadcode} = ($code eq 'BadBarcode');
221 if ($code eq 'BadBarcode') {
222 $err{msg}=$messages->{'BadBarcode'};
225 $err{errispermanent} = ($code eq 'IsPermanent');
226 if ($code eq 'IsPermanent'){
227 $err{msg} = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
228 # Here, msg contains the branchname
229 # Not so satisfied with this... But should work
231 $err{errdesteqholding} = ($code eq 'DestinationEqualsHolding');
233 $err{errwasreturned} = ($code eq 'WasReturned');
234 if ($code eq 'WasReturned') {
235 my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
236 $name =name($borrowerinfo);
237 $bornum =$borrowerinfo->{'borrowernumber'};
238 $borcnum =$borrowerinfo->{'cardnumber'};
240 if ($code eq 'WasTransfered'){
241 # Put code here if you want to notify the user that item was transfered...
243 push (@errmsgloop, \%err);
247 #######################################################################################
248 # Make the page .....
249 my ($template, $borrowernumber, $cookie)
250 = get_template_and_user({template_name => "circ/branchtransfers.tmpl",
253 authnotrequired => 0,
254 flagsrequired => {circulate => 1},
256 $template->param( genbrname => $genbrname,
257 genprname => $genprname,
261 hdrbckgdcolor => $headerbackgroundcolor,
262 bckgdimg => $backgroundimage,
263 reserved => $reserved,
268 branchname => $branchname,
269 itemnumber => $itemnumber,
271 biblionumber => $biblionum,
272 tobranchcd => $tobranchcd,
273 reqmessage => $reqmessage,
274 cancelled => $cancelled,
275 setwaiting => $setwaiting,
276 trsfitemloop => \@trsfitemloop,
277 branchoptionloop => \@branchoptionloop,
278 errmsgloop => \@errmsgloop
280 output_html_with_http_headers $query, $cookie, $template->output;
285 return $borinfo->{'surname'}." ".$borinfo->{'title'}." ".$borinfo->{'firstname'};