cataloge subdir (and cataloguing) - Dates.pm integration and warnings fixes.
[koha.git] / circ / branchtransfers.pl
blob7d15cf76775dc2827883a75d9b6aa5f70cc253cf
1 #!/usr/bin/perl
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
14 # version.
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
24 use strict;
25 use CGI;
26 use C4::Circulation;
27 use C4::Output;
28 use C4::Reserves;
29 use C4::Biblio;
30 use C4::Auth;
31 use C4::Branch; # GetBranches
32 use C4::Koha;
34 ###############################################
35 # Getting state
37 my $query = new CGI;
39 #######################################################################################
40 # Make the page .....
41 my ( $template, $cookie );
42 my $user;
43 ( $template, $user, $cookie ) = get_template_and_user(
45 template_name => "circ/branchtransfers.tmpl",
46 query => $query,
47 type => "intranet",
48 authnotrequired => 0,
49 flagsrequired => { circulate => 1 },
53 my $branches = GetBranches;
54 my $branch = GetBranch( $query, $branches );
56 my $messages;
57 my $found;
58 my $reserved;
59 my $waiting;
60 my $reqmessage;
61 my $cancelled;
62 my $setwaiting;
64 my $request = $query->param('request');
65 my $borrowernumber = $query->param('borrowernumber');
66 my $tobranchcd = $query->param('tobranchcd');
68 ############
69 # Deal with the requests....
70 if ( $request eq "KillWaiting" ) {
71 my $item = $query->param('itemnumber');
73 CancelReserve( 0, $item, $borrowernumber );
74 $cancelled = 1;
75 $reqmessage = 1;
78 my $ignoreRs = 0;
79 if ( $request eq "SetWaiting" ) {
80 my $item = $query->param('itemnumber');
81 ModReserveAffect( $item, $borrowernumber );
82 $ignoreRs = 1;
83 $setwaiting = 1;
84 $reqmessage = 1;
86 if ( $request eq 'KillReserved' ) {
87 my $biblio = $query->param('biblionumber');
88 CancelReserve( $biblio, 0, $borrowernumber );
89 $cancelled = 1;
90 $reqmessage = 1;
93 # set up the branchselect options....
94 my @branchoptionloop;
95 foreach my $br ( keys %$branches ) {
96 my %branch;
97 $branch{selected} = ( $br eq $tobranchcd );
98 $branch{code} = $br;
99 $branch{name} = $branches->{$br}->{'branchname'};
100 push( @branchoptionloop, \%branch );
103 # collect the stack of books already transfered so they can printed...
104 my @trsfitemloop;
105 my %transfereditems;
106 my $transfered;
107 my $barcode = $query->param('barcode');
108 # warn "barcode : $barcode";
109 if ($barcode) {
111 my $iteminformation;
112 ( $transfered, $messages, $iteminformation ) =
113 transferbook( $tobranchcd, $barcode, $ignoreRs );
114 # use Data::Dumper;
115 # warn "Transfered : $transfered / ".Dumper($messages);
116 $found = $messages->{'ResFound'};
117 if ($transfered) {
118 my %item;
119 my $frbranchcd = C4::Context->userenv->{'branch'};
120 # if ( not($found) ) {
121 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
122 $item{'title'} = $iteminformation->{'title'};
123 $item{'author'} = $iteminformation->{'author'};
124 $item{'itemtype'} = $iteminformation->{'itemtype'};
125 $item{'ccode'} = $iteminformation->{'ccode'};
126 $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
127 $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
129 $item{counter} = 0;
130 $item{barcode} = $barcode;
131 $item{frombrcd} = $frbranchcd;
132 $item{tobrcd} = $tobranchcd;
133 push( @trsfitemloop, \%item );
134 # warn Dumper(@trsfitemloop);
138 foreach ( $query->param ) {
139 (next) unless (/bc-(\d*)/);
140 my $counter = $1;
141 my %item;
142 my $bc = $query->param("bc-$counter");
143 my $frbcd = $query->param("fb-$counter");
144 my $tobcd = $query->param("tb-$counter");
145 $counter++;
146 $item{counter} = $counter;
147 $item{barcode} = $bc;
148 $item{frombrcd} = $frbcd;
149 $item{tobrcd} = $tobcd;
150 my ($iteminformation) = GetBiblioFromItemNumber( GetItemnumberFromBarcode($bc) );
151 $item{'biblionumber'} = $iteminformation->{'biblionumber'};
152 $item{'title'} = $iteminformation->{'title'};
153 $item{'author'} = $iteminformation->{'author'};
154 $item{'itemtype'} = $iteminformation->{'itemtype'};
155 $item{'ccode'} = $iteminformation->{'ccode'};
156 $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
157 $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
158 push( @trsfitemloop, \%item );
161 my $itemnumber;
162 my $biblionumber;
164 #####################
166 if ($found) {
167 my $res = $messages->{'ResFound'};
168 $itemnumber = $res->{'itemnumber'};
170 if ( $res->{'ResFound'} eq "Waiting" ) {
171 $waiting = 1;
173 if ( $res->{'ResFound'} eq "Reserved" ) {
174 $reserved = 1;
175 $biblionumber = $res->{'biblionumber'};
179 #####################
181 my @errmsgloop;
182 foreach my $code ( keys %$messages ) {
183 my %err;
185 if ( $code eq 'BadBarcode' ) {
186 $err{msg} = $messages->{'BadBarcode'};
187 $err{errbadcode} = 1;
190 if ( $code eq 'IsPermanent' ) {
191 $err{errispermanent} = 1;
192 $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
194 $err{errdesteqholding} = ( $code eq 'DestinationEqualsHolding' );
196 if ( $code eq 'WasReturned' ) {
197 $err{errwasreturned} = 1;
199 push( @errmsgloop, \%err );
202 # use Data::Dumper;
203 # warn "FINAL ============= ".Dumper(@trsfitemloop);
204 $template->param(
205 found => $found,
206 reserved => $reserved,
207 waiting => $waiting,
208 borrowernumber => $borrowernumber,
209 itemnumber => $itemnumber,
210 barcode => $barcode,
211 biblionumber => $biblionumber,
212 tobranchcd => $tobranchcd,
213 reqmessage => $reqmessage,
214 cancelled => $cancelled,
215 setwaiting => $setwaiting,
216 trsfitemloop => \@trsfitemloop,
217 branchoptionloop => \@branchoptionloop,
218 errmsgloop => \@errmsgloop,
219 CircAutocompl => C4::Context->preference("CircAutocompl")
221 output_html_with_http_headers $query, $cookie, $template->output;
223 sub name {
224 my ($borinfo) = @_;
225 return $borinfo->{'surname'} . " "
226 . $borinfo->{'title'} . " "
227 . $borinfo->{'firstname'};
230 # Local Variables:
231 # tab-width: 4
232 # End: