Completely new. This file handles the issues, and sets branch and printer
[koha.git] / circ / branchtransfers.pl
1 #!/usr/bin/perl
2
3 #written 11/3/2002 by Finlay
4 #script to execute branch transfers of books
5
6 use strict;
7 use CGI;
8 use C4::Circulation::Circ2;
9 use C4::Output;
10
11 ###############################################
12 # constants
13
14 my %env;
15 my $headerbackgroundcolor='#99cc33';
16 my $circbackgroundcolor='#ffffcc';
17 my $circbackgroundcolor='white';
18 my $linecolor1='#ffffcc';
19 my $linecolor2='white';
20 my $backgroundimage="/images/background-mem.gif";
21
22 my $branches = getbranches();
23 my $printers = getprinters(\%env);
24
25
26 ###############################################
27 #  Getting state
28
29 my $query=new CGI;
30
31
32 my $branch = $query->param("branch");
33 my $printer = $query->param("printer");
34
35
36 ($branch) || ($branch=$query->cookie('branch')) ;
37 ($printer) || ($printer=$query->cookie('printer')) ;
38
39
40 my $tobranchcd=$query->param('tobranchcd');
41 my $frbranchcd='';
42
43
44 # set up the branchselect options....
45 my $tobranchoptions;
46 foreach my $br (keys %$branches) {
47     (next) unless $branches->{$br}->{'CU'};
48     my $selected='';
49     ($selected='selected') if ($br eq $tobranchcd);
50     $tobranchoptions.="<option value=$br $selected>$branches->{$br}->{'branchname'}\n";
51 }
52
53 # collect the stack of books already transfered so they can printed...
54 my %transfereditems;
55 my $ritext = '';
56 my %frbranchcds;
57 my %tobranchcds;
58 foreach ($query->param){
59     (next) unless (/bc-(\d*)/);
60     my $counter=$1;
61     my $barcode=$query->param("bc-$counter");
62     my $frbcd=$query->param("fb-$counter");
63     my $tobcd=$query->param("tb-$counter");
64     $counter++;
65     $transfereditems{$counter}=$barcode;
66     $frbranchcds{$counter}=$frbcd;
67     $tobranchcds{$counter}=$tobcd;
68     $ritext.="<input type=hidden name=bc-$counter value=$barcode>\n";
69     $ritext.="<input type=hidden name=fb-$counter value=$frbcd>\n";
70     $ritext.="<input type=hidden name=tb-$counter value=$tobcd>\n";
71     }
72
73 # Warnings etc that get displayed at top of next page....
74 my $messages;
75 #if the barcode has been entered action that and write a message and onto the top of the stack...
76 my $iteminformation;
77 if (my $barcode=$query->param('barcode')) {
78     my $transfered;
79     my $iteminformation;
80     ($transfered, $messages, $iteminformation) = transferbook($tobranchcd, $barcode);
81     if ($transfered) {
82         my $frbranchcd = $iteminformation->{'holdingbranch'};
83         $ritext.="<input type=hidden name=bc-0 value=$barcode>\n";
84         $ritext.="<input type=hidden name=fb-0 value=$frbranchcd>\n";
85         $ritext.="<input type=hidden name=tb-0 value=$tobranchcd>\n";
86         $transfereditems{0}=$barcode;
87         $frbranchcds{0}=$frbranchcd;
88         $tobranchcds{0}=$tobranchcd;
89     }
90 }
91
92
93 #################################################################################
94 # Html code....
95
96 my $entrytext= << "EOF";
97 <form method=post action=/cgi-bin/koha/circ/branchtransfers.pl>
98 <table border=1 cellpadding=5 cellspacing=0 align=left>
99 <tr><td colspan=2 align=center background=$backgroundimage>
100 <font color=black><b>Select Branch</b></font></td></tr>
101 <tr><td>Destination Branch:</td>
102     <td><select name=tobranchcd> $tobranchoptions </select></td></tr></table>    
103
104 <img src="/images/holder.gif" width=24 height=50 align=left>
105
106 <table border=1 cellpadding=5 cellspacing=0 ><tr>
107 <td colspan=2 align=center background=$backgroundimage>
108 <font color=black><b>Enter Book Barcode</b></font></td></tr>
109 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
110 </table>
111 <input type=hidden name=tobranchcd value=$tobranchcd>
112 $ritext
113 </form>
114 EOF
115
116
117
118 #####################
119
120 my $reservefoundtext;
121 if ($messages->{'ResFound'}) {
122     my $resrec = $messages->{'ResFound'};
123     my ($borr) = getpatroninformation(\%env, $resrec->{'borrowernumber'}, 0);
124     my $name = $borr->{'surname'}." ".$borr->{'title'}." ".$borr->{'firstname'};
125     my $number = "<a href=/cgi-bin/koha/moremember.pl?bornum=$borr->{'borrowernumber'} onClick='openWindow(this,'Member', 480, 640)'>$borr->{'cardnumber'}</a>";
126     my $branch = $branches->{$resrec->{'branchcode'}}->{'branchname'};
127     my $reservetext = "<font size='+2' color='red'>RESERVED</font><font size='+2'> for collection by $name ($number) at $branch </font>";
128     $reservefoundtext = <<"EOF";
129 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
130 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Reserve Found</font></th></tr>
131 <tr><td> $reservetext </td></tr></table>
132 EOF
133 }
134
135 #####################
136
137 my $messagetext='';
138 foreach my $code (keys %$messages) {
139     if ($code eq 'BadBarcode'){
140         $messagetext .= "<font color='red' size='+2'> No Item with barcode: $messages->{'BadBarcode'} </font> <br>";
141     }
142     if ($code eq 'IsPermanent'){
143         my $braname = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
144         $messagetext .= "<font color='red' size='+2'> Please return item to home branch: $braname  </font> <br>";
145     }
146     if ($code eq 'DestinationEqualsHolding'){
147         $messagetext .= "<font color='red' size='+2'> Item cannot be transfered to branch it is already at. </font> <br>";
148     }
149     if ($code eq 'WasReturned') {
150         my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
151
152         my $binfo = <<"EOF";
153 <a href=/cgi-bin/koha/moremember.pl?bornum=$borrowerinfo->{'borrowernumber'} 
154 onClick="openWindow(this,'Member', 480, 640)">$borrowerinfo->{'cardnumber'}</a>
155 $borrowerinfo->{'surname'}, $borrowerinfo->{'title'} $borrowerinfo->{'firstname'}
156 EOF
157         $messagetext .= "Item was on loan to $binfo and has been returned. <br>";
158     }
159     if ($code eq 'WasTransfered'){
160     }
161 }
162 $messagetext = substr($messagetext, 0, -4);
163
164 my $messagetable;
165 if ($messagetext) {
166     $messagetable = << "EOF";
167 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
168 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
169 <tr><td> $messagetext </td></tr></table>
170 EOF
171 }
172
173 #######################################################################################
174 # Make the page .....
175
176 print $query->header;
177 print startpage;
178 print startmenu('circulation');
179 print <<"EOF";
180 <p>
181 <table border=0 cellpadding=5 width=90%><tr>
182 <td align="left"><FONT SIZE=6><em>Circulation: Transfers</em></FONT><br>
183 <b>Branch:</b> $branches->{$branch}->{'branchname'} &nbsp
184 <b>Printer:</b> $printers->{$printer}->{'printername'}<br>
185 <a href=selectbranchprinter.pl>Change Settings</a>
186 </td>
187 <td align="right">
188 <FONT SIZE=2  face="arial, helvetica">
189 <a href=circulation.pl>Next Borrower</a> || 
190 <a href=returns.pl>Returns</a> || 
191 <a href=branchtransfers.pl>Transfers</a></font><p>
192 </td></tr></table>
193 <input type=hidden name=branch value=$branch>
194 <input type=hidden name=printer value=$printer>
195 </p>
196 EOF
197
198 print $reservefoundtext;
199
200 print $messagetable;
201
202 print $entrytext;
203
204 if (%transfereditems) {
205     print << "EOF"; 
206 <p>
207 <table border=1 cellpadding=5 cellspacing=0 bgcolor=#dddddd>                                                                
208 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>Transfered Items</font></th></tr>
209 <tr><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>From</th><th>To</th></tr>
210 EOF
211     my $color='';
212     foreach (keys %transfereditems) {
213         ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
214         my $barcode=$transfereditems{$_};
215         my $frbcd=$frbranchcds{$_};
216         my $tobcd=$tobranchcds{$_};
217         my ($iteminformation) = getiteminformation(\%env, 0, $barcode);
218         print << "EOF";
219 <tr><td bgcolor=$color align=center>
220 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
221 &type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
222 <td bgcolor=$color>$iteminformation->{'title'}</td>
223 <td bgcolor=$color>$iteminformation->{'author'}</td>
224 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
225 <td bgcolor=$color align=center>$branches->{$frbcd}->{'branchname'}</td>
226 <td bgcolor=$color align=center>$branches->{$tobcd}->{'branchname'}</td>
227 </tr>\n
228 EOF
229 }
230     print "</table>\n";
231 }
232
233 print endmenu('circulation');
234 print endpage;
235
236