DB query optimisation
[wip/koha-chris_n.git] / acqui / receive.pl
1 #!/usr/bin/perl
2
3 #script to recieve orders
4 #written by chris@katipo.co.nz 24/2/2000
5
6 use C4::Acquisitions;
7 use C4::Output;
8 use CGI;
9 use strict;
10
11 my $input=new CGI;
12 print $input->header();
13 my $id=$input->param('id');
14 my ($count,@booksellers)=bookseller($id);
15 my $invoice=$input->param('invoice');
16 my $freight=$input->param('freight');
17 my $gst=$input->param('gst');
18 my $user=$input->remote_user;
19 my $date=localtime(time);
20 print startpage;
21
22 print startmenu('acquisitions');
23
24 print <<EOP
25
26 <div align=right>
27 Invoice: $invoice<br>
28 Received By: $user<br>
29 $date
30 </div>
31 <FONT SIZE=6><em>Receipt Summary For : <a href=whitcoulls.html>$booksellers[0]->{'name'}</a> </em></FONT>
32 <CENTER>
33
34 <FORM ACTION="/cgi-bin/koha/acqui/acquire.pl">
35 <input type=hidden name=gst value=$gst>
36 <input type=hidden name=freight value=$freight>
37 <input type=hidden name=invoice value=$invoice>
38
39 <b>Search ISBN or Title:</b> <INPUT TYPE="text"  SIZE="25"   NAME="recieve">
40 </form>
41 <p>
42 <FORM ACTION="" method=post name=orderform>
43
44 <table border=0 cellspacing=0 cellpadding=5>
45 <tr valign=top bgcolor=#99cc33>
46 <td background="/images/background-mem.gif"><b>BASKET</b></td>
47 <td background="/images/background-mem.gif"><b>ISBN</b></td>
48 <td background="/images/background-mem.gif"><b>TITLE</b></td>
49 <td background="/images/background-mem.gif"><b>AUTHOR</b></td>
50 <td background="/images/background-mem.gif"><b>ACTUAL</b></td>
51 <td background="/images/background-mem.gif"><b>P&P</b></td>
52 <td background="/images/background-mem.gif"><b>QTY</b></td>
53 <td background="/images/background-mem.gif"><b>TOTAL</b></td></tr>
54
55 EOP
56 ;
57 my ($count,@results);
58 if ($invoice eq ''){
59         ($count,@results)=getallorders($id);
60 } else {
61         ($count,@results)=invoice($invoice);
62 }
63 print $count;
64 my $totalprice=0;
65 my $totalfreight=0;
66 my $totalquantity=0;
67 my $total;
68 my $tototal;
69 for (my$i=0;$i<$count;$i++){
70  $total=($results[$i]->{'unitprice'} + $results[$i]->{'freight'}) * $results[$i]->{'quantityreceived'};
71 $results[$i]->{'unitprice'}+=0;
72 print <<EOP
73 <tr valign=top bgcolor=#ffffcc>
74 <td>$results[$i]->{'basketno'}</td>
75 <td>$results[$i]->{'isbn'}</td>
76 <td><a href="acquire.pl?recieve=$results[$i]->{'ordernumber'}&biblio=$results[$i]->{'biblionumber'}&invoice=$invoice&gst=$gst&freight=$freight">$results[$i]->{'title'}</a></td>
77 <td>$results[$i]->{'author'}</td>
78 <td>\$$results[$i]->{'unitprice'}</td>
79 <td></td>
80 <td>$results[$i]->{'quantityreceived'}</td>
81 <td>\$ $total</td>
82 </tr>
83 EOP
84 ;
85 $totalprice+=$results[$i]->{'unitprice'};
86 $totalfreight+=$results[$i]->{'freight'};
87 $totalquantity+=$results[$i]->{'quantityreceived'};
88 $tototal+=$total;
89 }
90 $totalfreight=$freight;
91 $tototal=$tototal+$freight;
92
93 my $grandtot=$tototal+$gst;
94 print <<EOP
95 <tr valign=top bgcolor=white>
96 <td colspan=8><hr>
97 </td></tr>
98
99
100
101 <tr valign=top bgcolor=white>
102 <td></td>
103 <td></td>
104 <td></td>
105 <td><b>SUBTOTALS</b></td>
106 <td>\$$totalprice</td>
107 <td>$totalfreight</td>
108 <td>$totalquantity</td>
109 <td>\$$tototal</td>
110 </tr>
111 <tr valign=top bgcolor=white>
112 <td colspan=5 rowspan=2  bgcolor=#99cc33 background="/images/background-mem.gif">
113 <b>HELP</b>
114 <br>
115 The total at the bottom of the page should be within a few cents of the total for the invoice.<p>
116 When you have finished this invoice save the changes.
117 </td>                                                                                                                                                                                                                                           
118 <td colspan=2 align=right><b>GST</b></td>
119 <td>\$$gst</td>
120 </tr>
121 <tr valign=top bgcolor=white>
122 <td colspan=2 align=right ><b>TOTAL</b></td>
123 <td>\$$grandtot</td>
124 </tr>
125 <tr valign=top bgcolor=white>
126 <td></td>
127 <td></td>
128 <td></td>
129 <td></td>
130 <td></td>
131 <td></td>
132 <td colspan=3><input type=image  name=submit src=/images/save-changes.gif border=0 width=187 height=42 align=right></td>
133 </tr>
134 </table>
135 </CENTER>
136 EOP
137 ;
138
139
140 print endmenu('acquisitions');
141
142 print endpage;