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