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;
30 use C4::Interface::CGI::Output;
33 ###############################################
37 my $linecolor1='#ffffcc';
38 my $linecolor2='white';
40 my $branches = GetBranches();
41 my $printers = getprinters(\%env);
44 ###############################################
50 my $branch = getbranch($query, $branches);
51 my $printer = getprinter($query, $printers);
53 my $genbrname = $branches->{$branch}->{'branchname'} ;
54 my $genprname = $printers->{$printer}->{'printername'};
64 my $user=$query->param('loggedinuser');
65 my $request=$query->param('request');
66 my $borrnum = $query->param('borrowernumber');
68 my $tobranchcd=$query->param('tobranchcd');
70 my $dbh=C4::Context->dbh;
72 # Deal with the requests....
73 if ($request eq "KillWaiting") {
74 my $item = $query->param('itemnumber');
75 CancelReserve(0, $item, $borrnum);
81 if ($request eq "SetWaiting") {
82 my $item = $query->param('itemnumber');
83 $tobranchcd = ReserveWaiting($item, $borrnum);
84 $reqbrchname = $branches->{$tobranchcd}->{'branchname'};
89 if ($request eq 'KillReserved'){
90 my $biblio = $query->param('biblionumber');
91 CancelReserve($biblio, 0, $borrnum);
98 # set up the branchselect options....
100 foreach my $br (keys %$branches) {
101 #(next) unless $branches->{$br}->{'CU'}; #FIXME disabled to fix bug 202
103 $branch{selected}=($br eq $tobranchcd);
105 $branch{name}=$branches->{$br}->{'branchname'};
106 push (@branchoptionloop, \%branch);
110 # collect the stack of books already transfered so they can printed...
115 my $color=$linecolor2;
117 my $barcode = $query->param('barcode');
121 ($transfered, $messages, $iteminformation)
122 = transferbook($tobranchcd, $barcode, $ignoreRs,$user);
123 $found = $messages->{'ResFound'};
126 my $frbranchcd = $iteminformation->{'holdingbranch'};
128 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
129 $item{'color'}=$color;
130 $item{'biblionumber'}=$iteminformation->{'biblionumber'};
131 $item{'title'}=$iteminformation->{'title'};
132 $item{'author'}=$iteminformation->{'author'};
133 $item{'itemtype'}=$iteminformation->{'itemtype'};
134 $item{'frbrname'}=$branches->{$frbranchcd}->{'branchname'};
135 $item{'tobrname'}=$branches->{$tobranchcd}->{'branchname'};
138 $item{barcode}=$barcode;
139 $item{frombrcd}=$frbranchcd;
140 $item{tobrcd}=$tobranchcd;
142 #Are these lines still useful ???
143 $transfereditems{0}=$barcode;
144 $frbranchcds{0}=$frbranchcd;
145 $tobranchcds{0}=$tobranchcd;
147 push (@trsfitemloop, \%item);
151 foreach ($query->param){
152 (next) unless (/bc-(\d*)/);
155 my $bc=$query->param("bc-$counter");
156 my $frbcd=$query->param("fb-$counter");
157 my $tobcd=$query->param("tb-$counter");
159 $item{counter}=$counter;
161 $item{frombrcd}=$frbcd;
162 $item{tobrcd}=$tobcd;
163 my ($iteminformation) = getiteminformation(\%env, 0, $bc);
164 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
165 $item{'color'}=$color;
166 $item{'biblionumber'}=$iteminformation->{'biblionumber'};
167 $item{'title'}=$iteminformation->{'title'};
168 $item{'author'}=$iteminformation->{'author'};
169 $item{'itemtype'}=$iteminformation->{'itemtype'};
170 $item{'frbrname'}=$branches->{$frbcd}->{'branchname'};
171 $item{'tobrname'}=$branches->{$tobcd}->{'branchname'};
173 #Are these lines still useful ???
174 $transfereditems{$counter}=$bc;
175 $frbranchcds{$counter}=$frbcd;
176 $tobranchcds{$counter}=$tobcd;
178 push (@trsfitemloop, \%item);
190 #####################
193 my $res = $messages->{'ResFound'};
194 $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
195 my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
197 $bornum = $borr->{'borrowernumber'}; #Hopefully, borr->{borrowernumber}=res->{borrowernumber}
198 $borcnum = $borr->{'cardnumber'};
199 $itemnumber = $res->{'itemnumber'};
201 if ($res->{'ResFound'} eq "Waiting") {
204 if ($res->{'ResFound'} eq "Reserved") {
206 $biblionum = $res->{'biblionumber'};
210 #####################
213 foreach my $code (keys %$messages) {
215 $err{errbadcode} = ($code eq 'BadBarcode');
216 if ($code eq 'BadBarcode') {
217 $err{msg}=$messages->{'BadBarcode'};
220 $err{errispermanent} = ($code eq 'IsPermanent');
221 if ($code eq 'IsPermanent'){
222 $err{msg} = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
223 # Here, msg contains the branchname
224 # Not so satisfied with this... But should work
226 $err{errdesteqholding} = ($code eq 'DestinationEqualsHolding');
228 $err{errwasreturned} = ($code eq 'WasReturned');
229 if ($code eq 'WasReturned') {
230 my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
231 $name =name($borrowerinfo);
232 $bornum =$borrowerinfo->{'borrowernumber'};
233 $borcnum =$borrowerinfo->{'cardnumber'};
235 if ($code eq 'WasTransfered'){
236 # Put code here if you want to notify the user that item was transfered...
238 push (@errmsgloop, \%err);
242 #######################################################################################
243 # Make the page .....
244 my ($template, $borrowernumber, $cookie)
245 = get_template_and_user({template_name => "circ/branchtransfers.tmpl",
248 authnotrequired => 0,
249 flagsrequired => {editcatalogue => 1},
251 $template->param( genbrname => $genbrname,
252 genprname => $genprname,
256 reserved => $reserved,
261 branchname => $branchname,
262 itemnumber => $itemnumber,
264 biblionumber => $biblionum,
265 tobranchcd => $tobranchcd,
266 reqmessage => $reqmessage,
267 cancelled => $cancelled,
268 setwaiting => $setwaiting,
269 trsfitemloop => \@trsfitemloop,
270 branchoptionloop => \@branchoptionloop,
271 errmsgloop => \@errmsgloop
273 output_html_with_http_headers $query, $cookie, $template->output;
278 return $borinfo->{'surname'}." ".$borinfo->{'title'}." ".$borinfo->{'firstname'};