Added some FIXME comments.
[koha.git] / acqui / acquire.pl
1 #!/usr/bin/perl
2
3 #script to recieve orders
4 #written by chris@katipo.co.nz 24/2/2000
5
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
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.
15 #
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.
19 #
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
23
24 use strict;
25 use CGI;
26 use C4::Context;
27 use C4::Catalogue;
28 use C4::Biblio;
29 use C4::Output;
30 use C4::Search;
31
32 my $input=new CGI;
33 print $input->header();
34 my $id=$input->param('id');
35
36 print startpage;
37
38 print startmenu('acquisitions');
39
40 my $search=$input->param('recieve');
41 my $invoice=$input->param('invoice');
42 my $freight=$input->param('freight');
43 my $biblio=$input->param('biblio');
44 my $catview=$input->param('catview');
45 my $gst=$input->param('gst');
46 my ($count,@results)=ordersearch($search,$biblio,$catview);
47 my ($count2,@booksellers)=bookseller($results[0]->{'booksellerid'}); 
48 #print $count;
49 my @date=split('-',$results[0]->{'entrydate'});
50 my $date="$date[2]/$date[1]/$date[0]";
51
52 if ($count == 1){
53
54
55 print <<EOP
56
57 <script language="javascript" type="text/javascript">
58 <!--
59 function messenger(X,Y,etc){
60 win=window.open("","mess","height="+X+",width="+Y+",screenX=150,screenY=0");
61 win.focus();
62 win.document.close();
63 win.document.write("<body link='#333333' bgcolor='#ffffff' text='#000000'><font size=2><p><br>");
64 win.document.write(etc);
65 win.document.write("<center><form><input type=button onclick='self.close()' value=Close></form></center>");
66 win.document.write("</font></body></html>");
67 }
68 //-->
69 </script>
70 <form action="/cgi-bin/koha/acqui/finishreceive.pl" method=post>
71 <input type=hidden name=biblio value=$results[0]->{'biblionumber'}>
72 <input type=hidden name=ordnum value=$results[0]->{'ordernumber'}>
73 <input type=hidden name=biblioitemnum value=$results[0]->{'biblioitemnumber'}>
74 <input type=hidden name=bookseller value=$results[0]->{'booksellerid'}>
75 <input type=hidden name=freight value=$freight>
76 <input type=hidden name=gst value=$gst>
77 EOP
78 ;
79 if ($catview ne 'yes'){
80   print "<input type=image  name=submit src=/images/save-changes.gif border=0 width=187 height=42 align=right>";
81 } else {
82   print "<a href=/cgi-bin/koha/acqui/newbiblio.pl?ordnum=$results[0]->{'ordernumber'}&id=$results[0]->{'booksellerid'}><img src=/images/modify-mem.gif align=right border=0></a>";
83 }
84 print <<EOP
85 <FONT SIZE=6><em>$results[0]->{'ordernumber'} - Receive Order</em></FONT><br>
86 Shopping Basket For: $booksellers[0]->{'name'}
87 <br> Order placed: $date
88 <P>
89 <CENTER>
90 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 align=left width="40%">
91 <tr valign=top bgcolor=#99cc33><td background="/images/background-mem.gif" colspan=2><B>CATALOGUE DETAILS</B></td></tr>
92
93 <TR VALIGN=TOP>
94 <TD><b>Title *</b></td>
95 <td><input type=text size=20 name=title value="$results[0]->{'title'}" >
96 </td>
97 </tr>
98 <TR VALIGN=TOP>
99 <TD>Author</td>
100 <td><input type=text size=20 name=author value="$results[0]->{'author'}" >
101 </td>
102 </tr>
103 <TR VALIGN=TOP>
104 <TD>Copyright Date</td>
105 <td><input type=text size=20 name=copyright value="$results[0]->{'copyrightdate'}" >
106 </td>
107 </tr>
108 <TR VALIGN=TOP>
109
110 <TD>Format</td>
111 <td>
112 <select name=format size=1>
113 EOP
114 ;
115
116 my $dbh = C4::Context->dbh;
117 my $query="Select itemtype,description from itemtypes order by description";
118 my $sth=$dbh->prepare($query);
119 $sth->execute;
120 while (my $data=$sth->fetchrow_hashref){
121   if ($data->{'itemtype'} eq $results[0]->{'itemtype'}) {
122     print "<option SELECTED value=\"" . $data->{'itemtype'} . "\">" . $data->{'description'} . "\n";
123   } else {
124     print "<option value=\"" . $data->{'itemtype'} . "\">" . $data->{'description'} . "\n";
125   }
126 }
127 $sth->finish;
128
129 print <<EOP
130 </select>
131
132 </td>
133 </tr>
134
135 <TR VALIGN=TOP>
136
137 <TD>ISBN</td>
138 <td><input type=text size=20 name=ISBN value="$results[0]->{'isbn'}">
139 </td>
140 </tr>
141
142 <TR VALIGN=TOP>
143
144 <TD>Series</td>
145 <td><input type=text size=20 name=Series value="$results[0]->{'seriestitle'}">
146 </td>
147 </tr>
148
149 <TR VALIGN=TOP>
150 <TD>Branch</td>
151 <td><select name=branch size=1>
152 EOP
153 ;
154 my ($count2,@branches)=branches();                                                                         
155 for (my $i=0;$i<$count2;$i++){                                                                           
156   print "<option value=$branches[$i]->{'branchcode'}";                                                   
157   if ($results[0]->{'branchcode'} == $branches[$i]->{'branchcode'}){                                           
158   print " Selected";                                                                                   
159   }                                                                                                      
160   print ">$branches[$i]->{'branchname'}";                                                                
161 }   
162 print <<EOP
163 </select>
164 </td>
165 </tr>
166
167 <TR VALIGN=TOP bgcolor=#ffffcc >
168 <TD><B>Item Barcode *</B></td>
169
170 <td><input type=text size=20 name=barcode value=
171 EOP
172 ;
173
174 my $auto_barcode = C4::Context->preference("autoBarcode") || 0;
175         # See whether barcodes should be automatically allocated.
176         # Defaults to 0, meaning "no".
177 if ($auto_barcode eq '1') {
178   my $dbh = C4::Context->dbh;
179   my $query="Select barcode from items order by barcode desc";
180   my $sth=$dbh->prepare($query);
181   $sth->execute;
182   my $data=$sth->fetchrow_hashref;
183   print $data->{'barcode'}+1;
184   $sth->finish;
185 }
186
187 print <<EOP
188 >
189 </td>
190 </tr>
191
192 <TR VALIGN=TOP bgcolor=#ffffcc >
193 <TD><B>Volume Info (for serials) *</B></td>
194
195 <td><input type=text size=20 name=volinf>
196 </td>
197 </tr>
198 </table>
199
200
201
202 <img src="/images/holder.gif" width=32 height=250 align=left>
203
204 <table border=1 cellspacing=0 cellpadding=5 width="40%">
205
206 <tr valign=top bgcolor=#99cc33><td background="/images/background-mem.gif" colspan=2><B>ACCOUNTING DETAILS</B></td></tr>
207 <TR VALIGN=TOP>
208 <TD><B>Bookfund *</B></td>
209 <td><select name=bookfund size=1>
210 EOP
211 ;
212 my @bookfund;
213 ($count2,@bookfund)=bookfunds();                                                    
214 for (my $i=0;$i<$count2;$i++){                                                       
215   print "<option value=$bookfund[$i]->{'bookfundid'}";
216   if ($bookfund[$i]->{'bookfundid'}==$results[0]->{'bookfundid'}){
217     print " Selected";
218   }
219   print ">$bookfund[$i]->{'bookfundname'}";
220 }      
221
222 my $rrp=$results[0]->{'rrp'};
223 if ($results[0]->{'quantityreceived'} == 0){
224   $results[0]->{'quantityreceived'}='';
225 }
226 if ($results[0]->{'unitprice'} == 0){
227   $results[0]->{'unitprice'}='';
228 }
229 print <<EOP
230 </select>
231 </td>
232 </tr>
233 <TR VALIGN=TOP>
234 <TD>Quantity Ordered</td>
235 <td><input type=text size=20 name=quantity value=$results[0]->{'quantity'}>
236 </td>
237 </tr>
238 <TR VALIGN=TOP bgcolor=#ffffcc>
239 <TD><B>Quantity Received *</B></td>
240 <td><input type=text size=20 name=quantityrec value=$results[0]->{'quantityreceived'}>
241 </td>
242 </tr>
243 <TR VALIGN=TOP>
244 <TD>Replacement Cost</td>
245 <td><input type=text size=20 name=rrp value=$rrp>
246 </tr>
247 <TR VALIGN=TOP>
248 <TD>
249 Budgeted Cost </td>
250 <td><input type=text size=20 name=ecost value="$results[0]->{'ecost'}">
251 </td>
252 </tr>
253 <TR VALIGN=TOP bgcolor=#ffffcc>
254 <TD><B>Actual Cost *</B></td>
255 <td><input type=text size=20 name=cost value="$results[0]->{'unitprice'}">
256 </td>
257 </tr>
258 <TR VALIGN=TOP bgcolor=#ffffcc>
259 <TD>Invoice Number</td>
260 <td>$invoice
261 <input type=hidden name=invoice value="$invoice">
262 </td>
263 </tr>
264 <TR VALIGN=TOP>
265 <TD>Notes</td>
266 <td><input type=text size=20 name=notes value="$results[0]->{'notes'}">
267 </td>
268 </tr>
269 </table>
270 </form>
271 </center>
272 <br clear=all>          
273 <p> &nbsp; </p>
274
275 EOP
276 ;
277 } else {
278 print "<center><table>";
279 print <<EOP
280 <tr valign=top bgcolor=#99cc33>                                                                
281
282 <td background="/images/background-mem.gif"><b>ISBN</b></td>                                   
283 <td background="/images/background-mem.gif"><b>TITLE</b></td>                                  
284 <td background="/images/background-mem.gif"><b>AUTHOR</b></td>                                 
285 </tr>
286 EOP
287 ;
288 for (my $i=0;$i<$count;$i++){
289   print "<tr><td>$results[$i]->{'isbn'}</td>
290   <td><a href=acquire.pl?recieve=$results[$i]->{'ordernumber'}&biblio=$results[$i]->{'biblionumber'}&invoice=$invoice&freight=$freight&gst=$gst>$results[$i]->{'title'}</a></td>
291   <td>$results[$i]->{'author'}</td></tr>";
292 }
293 print "</table></center>";
294 }
295
296
297
298 print endmenu('acquisitions');
299
300 print endpage;