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