Bug 15049: (Signed off) Hide currency but preserv alert
[koha.git] / circ / branchtransfers.pl
blob22c9a078f4776d8e5139fd34ae67b04c6f83770a
1 #!/usr/bin/perl
3 #script to execute branch transfers of books
5 # Copyright 2000-2002 Katipo Communications
6 # copyright 2010 BibLibre
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use strict;
24 use warnings;
25 use CGI qw ( -utf8 );
26 use C4::Circulation;
27 use C4::Output;
28 use C4::Reserves;
29 use C4::Biblio;
30 use C4::Items;
31 use C4::Auth qw/:DEFAULT get_session/;
32 use C4::Branch; # GetBranches
33 use C4::Koha;
34 use C4::Members;
36 ###############################################
37 # Getting state
39 my $query = new CGI;
41 if (!C4::Context->userenv){
42 my $sessionID = $query->cookie("CGISESSID");
43 my $session;
44 $session = get_session($sessionID) if $sessionID;
45 if (!$session or $session->param('branch') eq 'NO_LIBRARY_SET'){
46 # no branch set we can't transfer
47 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
48 exit;
52 #######################################################################################
53 # Make the page .....
54 my ($template, $user, $cookie) = get_template_and_user(
56 template_name => "circ/branchtransfers.tt",
57 query => $query,
58 type => "intranet",
59 authnotrequired => 0,
60 flagsrequired => { circulate => "circulate_remaining_permissions" },
64 my $branches = GetBranches;
66 my $messages;
67 my $found;
68 my $reserved;
69 my $waiting;
70 my $reqmessage;
71 my $cancelled;
72 my $setwaiting;
74 my $request = $query->param('request') || '';
75 my $borrowernumber = $query->param('borrowernumber') || 0;
76 my $tobranchcd = $query->param('tobranchcd') || '';
78 my $ignoreRs = 0;
79 ############
80 # Deal with the requests....
81 if ( $request eq "KillWaiting" ) {
82 my $item = $query->param('itemnumber');
83 CancelReserve({
84 itemnumber => $item,
85 borrowernumber => $borrowernumber
86 });
87 $cancelled = 1;
88 $reqmessage = 1;
90 elsif ( $request eq "SetWaiting" ) {
91 my $item = $query->param('itemnumber');
92 ModReserveAffect( $item, $borrowernumber );
93 $ignoreRs = 1;
94 $setwaiting = 1;
95 $reqmessage = 1;
97 elsif ( $request eq 'KillReserved' ) {
98 my $biblio = $query->param('biblionumber');
99 CancelReserve({
100 biblionumber => $biblio,
101 borrowernumber => $borrowernumber
103 $cancelled = 1;
104 $reqmessage = 1;
107 # collect the stack of books already transfered so they can printed...
108 my @trsfitemloop;
109 my %transfereditems;
110 my $transfered;
111 my $barcode = $query->param('barcode');
112 # strip whitespace
113 defined $barcode and $barcode =~ s/\s*//g; # FIXME: barcodeInputFilter
114 # warn "barcode : $barcode";
115 if ($barcode) {
117 my $iteminformation;
118 ( $transfered, $messages, $iteminformation ) =
119 transferbook( $tobranchcd, $barcode, $ignoreRs );
120 # use Data::Dumper;
121 # warn "Transfered : $transfered / ".Dumper($messages);
122 $found = $messages->{'ResFound'};
123 if ($transfered) {
124 my %item;
125 my $frbranchcd = C4::Context->userenv->{'branch'};
126 # if ( not($found) ) {
127 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
128 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
129 $item{'title'} = $iteminformation->{'title'};
130 $item{'author'} = $iteminformation->{'author'};
131 $item{'itemtype'} = $iteminformation->{'itemtype'};
132 $item{'ccode'} = $iteminformation->{'ccode'};
133 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
134 $item{'location'} = GetKohaAuthorisedValueLib("LOC",$iteminformation->{'location'});
135 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
136 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
138 $item{counter} = 0;
139 $item{barcode} = $barcode;
140 $item{frombrcd} = $frbranchcd;
141 $item{tobrcd} = $tobranchcd;
142 push( @trsfitemloop, \%item );
143 # warn Dumper(@trsfitemloop);
147 foreach ( $query->param ) {
148 (next) unless (/bc-(\d*)/);
149 my $counter = $1;
150 my %item;
151 my $bc = $query->param("bc-$counter");
152 my $frbcd = $query->param("fb-$counter");
153 my $tobcd = $query->param("tb-$counter");
154 $counter++;
155 $item{counter} = $counter;
156 $item{barcode} = $bc;
157 $item{frombrcd} = $frbcd;
158 $item{tobrcd} = $tobcd;
159 my ($iteminformation) = GetBiblioFromItemNumber( GetItemnumberFromBarcode($bc) );
160 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
161 $item{'itemnumber'} = $iteminformation->{'itemnumber'};
162 $item{'title'} = $iteminformation->{'title'};
163 $item{'author'} = $iteminformation->{'author'};
164 $item{'itemtype'} = $iteminformation->{'itemtype'};
165 $item{'ccode'} = $iteminformation->{'ccode'};
166 $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
167 $item{'location'} = GetKohaAuthorisedValueLib("LOC",$iteminformation->{'location'});
168 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
169 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
170 push( @trsfitemloop, \%item );
173 my $itemnumber;
174 my $biblionumber;
176 #####################
178 if ($found) {
179 my $res = $messages->{'ResFound'};
180 $itemnumber = $res->{'itemnumber'};
182 if ( $res->{'ResFound'} eq "Waiting" ) {
183 $waiting = 1;
185 elsif ( $res->{'ResFound'} eq "Reserved" ) {
186 $reserved = 1;
187 $biblionumber = $res->{'biblionumber'};
191 my @errmsgloop;
192 foreach my $code ( keys %$messages ) {
193 if ( $code ne 'WasTransfered' ) {
194 my %err;
195 if ( $code eq 'BadBarcode' ) {
196 $err{msg} = $messages->{'BadBarcode'};
197 $err{errbadcode} = 1;
199 elsif ( $code eq "NotAllowed" ) {
200 warn "NotAllowed: $messages->{'NotAllowed'} to " . $branches->{ $messages->{'NotAllowed'} }->{'branchname'};
201 # Do we really want a error log message here? --atz
202 $err{errnotallowed} = 1;
203 my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
204 $err{tbr} = $branches->{ $tbr }->{'branchname'};
205 $err{code} = $typecode;
207 elsif ( $code eq 'IsPermanent' ) {
208 $err{errispermanent} = 1;
209 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
211 elsif ( $code eq 'WasReturned' ) {
212 $err{errwasreturned} = 1;
213 $err{borrowernumber} = $messages->{'WasReturned'};
214 my $borrower = GetMember('borrowernumber'=>$messages->{'WasReturned'});
215 $err{title} = $borrower->{'title'};
216 $err{firstname} = $borrower->{'firstname'};
217 $err{surname} = $borrower->{'surname'};
218 $err{cardnumber} = $borrower->{'cardnumber'};
220 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
221 push( @errmsgloop, \%err );
225 # use Data::Dumper;
226 # warn "FINAL ============= ".Dumper(@trsfitemloop);
227 $template->param(
228 found => $found,
229 reserved => $reserved,
230 waiting => $waiting,
231 borrowernumber => $borrowernumber,
232 itemnumber => $itemnumber,
233 barcode => $barcode,
234 biblionumber => $biblionumber,
235 tobranchcd => $tobranchcd,
236 reqmessage => $reqmessage,
237 cancelled => $cancelled,
238 setwaiting => $setwaiting,
239 trsfitemloop => \@trsfitemloop,
240 branchoptionloop => GetBranchesLoop($tobranchcd),
241 errmsgloop => \@errmsgloop,
242 CircAutocompl => C4::Context->preference("CircAutocompl")
244 output_html_with_http_headers $query, $cookie, $template->output;