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