3 #written 11/3/2002 by Finlay
4 #script to execute branch transfers of books
8 use C4::Circulation::Circ2;
14 my $headerbackgroundcolor='#99cc33';
15 my $circbackgroundcolor='#ffffcc';
16 my $circbackgroundcolor='white';
17 my $linecolor1='#ffffcc';
18 my $linecolor2='white';
19 my $backgroundimage="/images/background-mem.gif";
22 my $branches=getbranches(\%env);
24 my $tobranchcd=$query->param('tobranchcd');
27 $env{'tobranchcd'}=$tobranchcd;
31 foreach (keys %$branches) {
35 ($selected='selected') if ($_ eq $tobranchcd);
36 $tobranchoptions.="<option value=$_ $selected>$branches->{$_}->{'branchname'}\n";
39 # collect the stack of books already transfered so they can printed...
44 foreach ($query->param){
45 (next) unless (/bc-(\d*)/);
47 (next) if ($counter>20);
48 my $barcode=$query->param("bc-$counter");
49 my $frbcd=$query->param("fb-$counter");
50 my $tobcd=$query->param("tb-$counter");
52 $transfereditems{$counter}=$barcode;
53 $frbranchcds{$counter}=$frbcd;
54 $tobranchcds{$counter}=$tobcd;
55 $ritext.="<input type=hidden name=bc-$counter value=$barcode>\n";
56 $ritext.="<input type=hidden name=fb-$counter value=$frbcd>\n";
57 $ritext.="<input type=hidden name=tb-$counter value=$tobcd>\n";
60 #if the barcode has been entered action that and write a message and onto the top of the stack...
64 if (my $barcode=$query->param('barcode')) {
65 my $iteminformation = getiteminformation(\%env,0, $barcode);
67 if (not $iteminformation) {
69 @messages = ("There is no book with barcode: $barcode ", @messages);
71 $frbranchcd = $iteminformation->{'holdingbranch'};
72 %env->{'frbranchcd'} = $frbranchcd;
73 if ($frbranchcd eq $tobranchcd) {
75 @messages = ("You can't transfer the book to the branch it is already at!", @messages);
77 # should add some more tests ... like is the book already out, maybe it cant be moved....
79 my ($transfered, $message) = transferbook(\%env, $iteminformation, $barcode);
80 if (not $transfered) {@messages = ($message, @messages);}
82 $ritext.="<input type=hidden name=bc-0 value=$barcode>\n";
83 $ritext.="<input type=hidden name=fb-0 value=$frbranchcd>\n";
84 $ritext.="<input type=hidden name=tb-0 value=$tobranchcd>\n";
85 $transfereditems{0}=$barcode;
86 $frbranchcds{0}=$frbranchcd;
87 $tobranchcds{0}=$tobranchcd;
88 @messages = ("Book: $barcode has been transfered", @messages);
93 my $entrytext= << "EOF";
94 <form method=post action=/cgi-bin/koha/circ/branchtransfers.pl>
95 <table border=0 cellpadding=5 cellspacing=0 bgcolor=#dddddd >
96 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
97 <font color=black><b>Select Branch</b></font></td></tr>
98 <tr><td>Destination Branch:</td><td>
99 <select name=tobranchcd> $tobranchoptions </select>
102 </table><table border=0 cellpadding=5 cellspacing=0 bgcolor=#dddddd >
103 <tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
104 <font color=black><b>Enter Book Barcode</b></font></td></tr>
105 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td></tr>
108 <input type=hidden name=tobranchcd value=$tobranchcd>
115 foreach (@messages) {
116 $messagetext.="$_<p>\n";
118 $messagetable = << "EOF";
119 <table border=0 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
120 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>Messages</font></th></tr>
121 <tr><td> $messagetext </td></tr></table>
127 print $query->header;
129 print startmenu('circulation');
130 print "<h3>Branch Transfers</h3>";
133 print $messagetable if (@messages);
138 if (%transfereditems) {
141 <table border=0 cellpadding=5 cellspacing=0 bgcolor=#dddddd>
142 <tr><th colspan=6 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>Transfered Items</font></th></tr>
143 <tr><th>Bar Code</th><th>Title</th><th>Author</th><th>Type</th><th>From</th><th>To</th></tr>
146 foreach (keys %transfereditems) {
147 ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
148 my $barcode=$transfereditems{$_};
149 my $frbcd=$frbranchcds{$_};
150 my $tobcd=$tobranchcds{$_};
151 my ($iteminformation) = getiteminformation(\%env, 0, $barcode);
153 <tr><td bgcolor=$color align=center>
154 <a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}
155 &type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$barcode</a></td>
156 <td bgcolor=$color>$iteminformation->{'title'}</td>
157 <td bgcolor=$color>$iteminformation->{'author'}</td>
158 <td bgcolor=$color align=center>$iteminformation->{'itemtype'}</td>
159 <td bgcolor=$color align=center>$branches->{$frbcd}->{'branchname'}</td>
160 <td bgcolor=$color align=center>$branches->{$tobcd}->{'branchname'}</td>
167 print endmenu('circulation');
171 ############################################################################
173 # this is the database query that will go into C4::Circuation::Circ2
180 my ($env, $iteminformation, $barcode) = @_;
183 #new entry in branchtransfers....
184 my $sth = $dbh->prepare("insert into branchtransfers (itemnumber, frombranch, datearrived, tobranch) values($iteminformation->{'itemnumber'}, '$env->{'frbranchcd'}', now(), '$env->{'tobranchcd'}')");
185 $sth->execute || return (0,"database error: $sth->errstr");
187 #update holdingbranch in items .....
188 $sth = $dbh->prepare("update items set holdingbranch='$env->{'tobranchcd'}' where items.itemnumber=$iteminformation->{'itemnumber'}");
189 $sth->execute || return (0,"database error: $sth->errstr");
193 return (1, $messages);