Use C4::Context->preference, rather than getting all system
[koha.git] / acqui / newbiblio.pl
1 #!/usr/bin/perl
2
3 #script to show display basket of 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 my $title=$input->param('title');
36 my $author=$input->param('author');
37 my $copyright=$input->param('copyright');
38 my ($count,@booksellers)=bookseller($id);
39 my $ordnum=$input->param('ordnum');
40 my $biblio=$input->param('biblio');
41 my $data;
42 my $new;
43 if ($ordnum eq ''){
44   $new='yes';
45   $ordnum=newordernum;
46   if ($biblio) {
47                 $data=bibdata($biblio);
48         }
49   if ($data->{'title'} eq ''){
50     $data->{'title'}=$title;
51     $data->{'author'}=$author;
52     $data->{'copyrightdate'}=$copyright;
53   }
54 }else {
55   $data=getsingleorder($ordnum);
56   $biblio=$data->{'biblionumber'};
57 }
58
59 print startpage;
60
61 print startmenu('acquisitions');
62
63
64 my $basket=$input->param('basket');
65 print <<printend
66
67
68 <script language="javascript" type="text/javascript">
69
70 <!--
71
72 function update(f){
73   //collect values
74   quantity=f.quantity.value
75   discount=f.discount.value
76   listinc=parseInt(f.listinc.value)
77   currency=f.currency.value
78   applygst=parseInt(f.applygst.value)
79   listprice=f.list_price.value
80   //  rrp=f.rrp.value
81   //  ecost=f.ecost.value  //budgetted cost
82   //  GST=f.GST.value
83   //  total=f.total.value
84   //make useful constants out of the above
85   exchangerate=f.elements[currency].value      //get exchange rate
86   gst_on=(!listinc && applygst);
87   //do real stuff
88   rrp=listprice*exchangerate;
89   ecost=rrp*(100-discount)/100
90   GST=0;
91   if (gst_on){
92     rrp=rrp*1.125;
93     GST=ecost*0.125
94   }
95
96   total=(ecost+GST)*quantity
97
98
99   f.rrp.value=display(rrp)
100   f.ecost.value=display(ecost)
101   f.GST.value=display(GST)
102   f.total.value=display(total)
103
104 }
105
106
107
108 function messenger(X,Y,etc){
109 win=window.open("","mess","height="+X+",width="+Y+",screenX=150,screenY=0");
110 win.focus();
111 win.document.close();
112 win.document.write("<body link='#333333' bgcolor='#ffffff' text='#000000'><font size=2><p><br>");
113 win.document.write(etc);
114 win.document.write("<center><form><input type=button onclick='self.close()' value=Close></form></center>");
115 win.document.write("</font></body></html>");
116 }
117 //-->
118
119 </script>
120 <form action=/cgi-bin/koha/acqui/addorder.pl method=post name=frusin>
121 printend
122 ;
123
124 if ($biblio eq ''){
125   print "<input type=hidden name=existing value=no>";
126 }
127
128 print <<printend
129 <!--$title-->
130 <input type=hidden name=ordnum value=$ordnum>
131 <input type=hidden name=basket value=$basket>
132 <input type=hidden name=supplier value=$id>
133 <input type=hidden name=biblio value=$biblio>
134 <input type=hidden name=bibitemnum value=$data->{'biblioitemnumber'}>
135 <input type=hidden name=oldtype value=$data->{'itemtype'}>
136 <input type=hidden name=discount value=$booksellers[0]->{'discount'}>
137 <input type=hidden name=listinc value=$booksellers[0]->{'listincgst'}>
138 <input type=hidden name=currency value=$booksellers[0]->{'listprice'}>
139 <input type=hidden name=applygst value=$booksellers[0]->{'gstreg'}>
140 printend
141 ;
142 my ($count2,$currencies)=getcurrencies;
143 for (my $i=0;$i<$count2;$i++){
144   print "<input type=hidden name=\"$currencies->[$i]->{'currency'}\" value=$currencies->[0]->{'rate'}>\n";
145 }
146 if ($new ne 'yes'){
147   print "<input type=hidden name=orderexists value=yes>\n";
148 }
149 print <<printend
150 <a href=basket.pl?basket=$basket><img src=/images/view-basket.gif width=187 heigth=42 border=0 align=right alt="View Basket"></a>
151 <FONT SIZE=6><em>$ordnum - Order Details </em></FONT><br>
152 Shopping Basket For: $booksellers[0]->{'name'}
153 <P>
154 <CENTER>
155 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 align=left width="40%">
156 <tr valign=top bgcolor=#99cc33><td background="/images/background-mem.gif" colspan=2><B>CATALOGUE DETAILS</B></td></tr>
157 <TR VALIGN=TOP>
158 <TD><b>Title *</b></td>
159 <td><input type=text size=20 name=title value="$data->{'title'}">
160 </td>
161 </tr>
162 <TR VALIGN=TOP>
163 <TD>Author</td>
164 <td><input type=text size=20 name=author value="$data->{'author'}" >
165 </td>
166 </tr>
167 <TR VALIGN=TOP>
168 <TD>Copyright Date</td>
169 <td><input type=text size=20 name=copyright value="$data->{'copyrightdate'}">
170 </td>
171 </tr>
172 <TR VALIGN=TOP>
173 <TD>Format</td>
174 <td>
175 <select name=format size=1>
176 printend
177 ;
178
179 my $dbh = C4::Context->dbh;
180 my $query="Select itemtype,description from itemtypes order by description";
181 my $sth=$dbh->prepare($query);
182 $sth->execute;
183 print "<option value=\"\">Please choose:\n";
184 while (my $data2=$sth->fetchrow_hashref){
185         if ($data2->{'itemtype'} eq $data->{'itemtype'}) {
186                 print "<option value=\"" . $data2->{'itemtype'} . "\" SELECTED>" . $data2->{'description'} . "\n";
187         } else {
188                 print "<option value=\"" . $data2->{'itemtype'} . "\">" . $data2->{'description'} . "\n";
189         }
190 }
191 $sth->finish;
192
193 print <<printend
194 </select>
195
196
197 </td>
198 </tr>
199 <TR VALIGN=TOP>
200 <TD>ISBN</td>
201 <td><input type=text size=20 name=ISBN value=$data->{'isbn'}>
202 </td>
203 </tr>
204 <TR VALIGN=TOP>
205 <TD>Series</td>
206 <td><input type=text size=20 name=Series value="$data->{'seriestitle'}">
207 </td>
208 </tr>
209 <TR VALIGN=TOP>
210 <TD>Branch</td>
211 <td><select name=branch size=1>
212 printend
213 ;
214 my @branches;
215 ($count2,@branches)=branches();
216 for (my $i=0;$i<$count2;$i++){
217   print "<option value=$branches[$i]->{'branchcode'}";
218   if ($data->{'branchcode'} == $branches[$i]->{'branchcode'}){
219     print " Selected";
220   }
221   print ">$branches[$i]->{'branchname'}";
222 }
223
224 print <<printend
225 </select>
226 </td>
227 </tr>
228 <TR VALIGN=TOP  bgcolor=#ffffcc>
229 <TD >Item Barcode</td>
230 <td><input type=text size=20 name=barcode value=
231 printend
232 ;
233
234 my $auto_barcode = C4::Context->preference("autoBarcode") || 0;
235         # See whether barcodes should be automatically allocated.
236         # Defaults to 0, meaning "no".
237 if ($auto_barcode eq '1') {
238   my $dbh = C4::Context->dbh;
239   my $query="Select barcode from items order by barcode desc";
240   my $sth=$dbh->prepare($query);
241   $sth->execute;
242   my $data=$sth->fetchrow_hashref;
243   print $data->{'barcode'}+1;
244   $sth->finish;
245 }
246
247 print <<printend
248 >
249 </td>
250 </tr>
251 </table>
252 <img src="/images/holder.gif" width=32 height=250 align=left>
253 <table border=1 cellspacing=0 cellpadding=5 width="40%">
254 <tr valign=top bgcolor=#99cc33><td background="/images/background-mem.gif" colspan=2><B>ACCOUNTING DETAILS</B></td></tr>
255 <TR VALIGN=TOP>
256 <TD>Quantity</td>
257 <td><input type=text size=20 name=quantity value="$data->{'quantity'}" onchange='update(this.form)' >
258 </td>
259 </tr>
260 <TR VALIGN=TOP>
261 <TD>Bookfund</td>
262 <td><select name=bookfund size=1>
263 printend
264 ;
265
266 my @bookfund;
267 ($count2,@bookfund)=bookfunds();
268 for (my $i=0;$i<$count2;$i++){
269   print "<option value=$bookfund[$i]->{'bookfundid'}";
270   if ($data->{'bookfundid'} == $bookfund[$i]->{'bookfundid'}){
271     print " Selected";
272   }
273   print ">$bookfund[$i]->{'bookfundname'}";
274 }
275
276 print <<printend
277 </select>
278 </td>
279 </tr>
280 <TR VALIGN=TOP>
281 <TD>Suppliers List Price</td>
282 <td><input type=text size=20 name=list_price value="$data->{'listprice'}" onchange='update(this.form)'>
283 </tr>
284 <TR VALIGN=TOP>
285 <TD>Replacement Cost <br>
286 <FONT SIZE=2>(NZ\$ inc GST)</td>
287 <td><input type=text size=20 name=rrp value="$data->{'rrp'}" onchange='update(this.form)'>
288 </tr>
289 <TR VALIGN=TOP>
290 <TD>
291 Budgeted Cost<BR>
292 <FONT SIZE=2>(NZ\$ ex GST, inc discount)</FONT> </td>
293 <td><input type=text size=20 name=ecost value="$data->{'ecost'}" onchange='update(this.form)'>
294 </td>
295 </tr>
296 <TR VALIGN=TOP>
297 <TD>
298 Budgeted GST</td>
299 <td><input type=text size=20 name=GST value="" onchange='update(this.form)'>
300 </td>
301 </tr>
302 <TR VALIGN=TOP>
303 <TD><B>
304 BUDGETED TOTAL</B></td>
305 <td><input type=text size=20 name=total value="" onchange='update(this.form)'>
306 </td>
307 </tr>
308 <TR VALIGN=TOP  bgcolor=#ffffcc>
309 <TD>Actual Cost</td>
310 <td><input type=text size=20 name=cost>
311 </td>
312 </tr>
313 <TR VALIGN=TOP  bgcolor=#ffffcc>
314 <TD>Invoice Number *</td>
315 <td><input type=text size=20 name=invoice >
316 <TR VALIGN=TOP>
317 <TD>Notes</td>
318 <td><input type=text size=20 name=notes value="$data->{'notes'}">
319 </td>
320 </tr>
321 <TR VALIGN=TOP>
322 <TD colspan=2>
323 <input type=image  name=submit src=/images/add-order.gif border=0 width=187 height=42 align=right>
324 </td>
325 </tr>
326 </table>
327 </form>
328 </center>
329 <table>
330 <tr><td bgcolor=#cccc99  background="/images/background-mem.gif"><B>HELP</B><br>
331 <UL>
332 <LI>If ordering more than one copy of an item you will be prompted to  choose additional bookfunds, and put in additional barcodes at the next screen<P>
333 <LI><B>Bold</B> fields must be filled in to create a new bibilo and item.<p>
334 <LI>Shaded fields can be used to do a "quick" receive, when items have been purchased locally or gifted. In this case the quantity "ordered" will also  be entered into the database as the quantity received.
335 </UL>
336 </td></tr></table>
337 <p> &nbsp; </p>
338 printend
339 ;
340
341 print endmenu('acquisitions');
342
343 print endpage;