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;
35 ###############################################
39 my $linecolor1='#ffffcc';
40 my $linecolor2='white';
42 my $branches = getbranches();
43 my $printers = getprinters(\%env);
46 ###############################################
52 my $branch = getbranch($query, $branches);
53 my $printer = getprinter($query, $printers);
55 my $genbrname = $branches->{$branch}->{'branchname'} ;
56 my $genprname = $printers->{$printer}->{'printername'};
67 my $request=$query->param('request');
68 my $borrnum = $query->param('borrowernumber');
70 my $tobranchcd=$query->param('tobranchcd');
74 # Deal with the requests....
75 if ($request eq "KillWaiting") {
76 my $item = $query->param('itemnumber');
77 CancelReserve(0, $item, $borrnum);
83 if ($request eq "SetWaiting") {
84 my $item = $query->param('itemnumber');
85 $tobranchcd = ReserveWaiting($item, $borrnum);
86 $reqbrchname = $branches->{$tobranchcd}->{'branchname'};
91 if ($request eq 'KillReserved'){
92 my $biblio = $query->param('biblionumber');
93 CancelReserve($biblio, 0, $borrnum);
100 # set up the branchselect options....
101 my @branchoptionloop;
102 foreach my $br (keys %$branches) {
103 #(next) unless $branches->{$br}->{'CU'}; #FIXME disabled to fix bug 202
105 $branch{selected}=($br eq $tobranchcd);
107 $branch{name}=$branches->{$br}->{'branchname'};
108 push (@branchoptionloop, \%branch);
112 # collect the stack of books already transfered so they can printed...
117 my $color=$linecolor2;
119 my $barcode = $query->param('barcode');
123 ($transfered, $messages, $iteminformation)
124 = transferbook($tobranchcd, $barcode, $ignoreRs);
125 $found = $messages->{'ResFound'};
128 my $frbranchcd = $iteminformation->{'holdingbranch'};
130 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
131 $item{'color'}=$color;
132 $item{'biblionumber'}=$iteminformation->{'biblionumber'};
133 $item{'title'}=$iteminformation->{'title'};
134 $item{'author'}=$iteminformation->{'author'};
135 $item{'itemtype'}=$iteminformation->{'itemtype'};
136 $item{'frbrname'}=$branches->{$frbranchcd}->{'branchname'};
137 $item{'tobrname'}=$branches->{$tobranchcd}->{'branchname'};
140 $item{barcode}=$barcode;
141 $item{frombrcd}=$frbranchcd;
142 $item{tobrcd}=$tobranchcd;
144 #Are these lines still useful ???
145 $transfereditems{0}=$barcode;
146 $frbranchcds{0}=$frbranchcd;
147 $tobranchcds{0}=$tobranchcd;
149 push (@trsfitemloop, \%item);
153 foreach ($query->param){
154 (next) unless (/bc-(\d*)/);
157 my $bc=$query->param("bc-$counter");
158 my $frbcd=$query->param("fb-$counter");
159 my $tobcd=$query->param("tb-$counter");
161 $item{counter}=$counter;
163 $item{frombrcd}=$frbcd;
164 $item{tobrcd}=$tobcd;
165 my ($iteminformation) = getiteminformation(\%env, 0, $bc);
166 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
167 $item{'color'}=$color;
168 $item{'biblionumber'}=$iteminformation->{'biblionumber'};
169 $item{'title'}=$iteminformation->{'title'};
170 $item{'author'}=$iteminformation->{'author'};
171 $item{'itemtype'}=$iteminformation->{'itemtype'};
172 $item{'frbrname'}=$branches->{$frbcd}->{'branchname'};
173 $item{'tobrname'}=$branches->{$tobcd}->{'branchname'};
175 #Are these lines still useful ???
176 $transfereditems{$counter}=$bc;
177 $frbranchcds{$counter}=$frbcd;
178 $tobranchcds{$counter}=$tobcd;
180 push (@trsfitemloop, \%item);
192 #####################
195 my $res = $messages->{'ResFound'};
196 $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
197 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
199 $bornum = $borr->{'borrowernumber'}; #Hopefully, borr->{borrowernumber}=res->{borrowernumber}
200 $borcnum = $borr->{'cardnumber'};
201 $itemnumber = $res->{'itemnumber'};
203 if ($res->{'ResFound'} eq "Waiting") {
206 if ($res->{'ResFound'} eq "Reserved") {
208 $biblionum = $res->{'biblionumber'};
212 #####################
215 foreach my $code (keys %$messages) {
217 $err{errbadcode} = ($code eq 'BadBarcode');
218 if ($code eq 'BadBarcode') {
219 $err{msg}=$messages->{'BadBarcode'};
222 $err{errispermanent} = ($code eq 'IsPermanent');
223 if ($code eq 'IsPermanent'){
224 $err{msg} = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
225 # Here, msg contains the branchname
226 # Not so satisfied with this... But should work
228 $err{errdesteqholding} = ($code eq 'DestinationEqualsHolding');
230 $err{errwasreturned} = ($code eq 'WasReturned');
231 if ($code eq 'WasReturned') {
232 my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
233 $name =name($borrowerinfo);
234 $bornum =$borrowerinfo->{'borrowernumber'};
235 $borcnum =$borrowerinfo->{'cardnumber'};
237 if ($code eq 'WasTransfered'){
238 # Put code here if you want to notify the user that item was transfered...
240 push (@errmsgloop, \%err);
244 #######################################################################################
245 # Make the page .....
246 my ($template, $borrowernumber, $cookie)
247 = get_template_and_user({template_name => "circ/branchtransfers.tmpl",
250 authnotrequired => 0,
251 flagsrequired => {circulate => 1},
253 $template->param( genbrname => $genbrname,
254 genprname => $genprname,
258 reserved => $reserved,
263 branchname => $branchname,
264 itemnumber => $itemnumber,
266 biblionumber => $biblionum,
267 tobranchcd => $tobranchcd,
268 reqmessage => $reqmessage,
269 cancelled => $cancelled,
270 setwaiting => $setwaiting,
271 trsfitemloop => \@trsfitemloop,
272 branchoptionloop => \@branchoptionloop,
273 errmsgloop => \@errmsgloop
275 output_html_with_http_headers $query, $cookie, $template->output;
280 return $borinfo->{'surname'}." ".$borinfo->{'title'}." ".$borinfo->{'firstname'};