Changed the Quantity routines to use the Item Units decimals if any. A lot of files.
[fa-stable.git] / sales / view / view_sales_order.php
1 <?php
2
3 $page_security = 2;
4 $path_to_root="../..";
5 include_once($path_to_root . "/sales/includes/cart_class.inc");
6
7 include_once($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/includes/date_functions.inc");
9
10 include_once($path_to_root . "/sales/includes/sales_ui.inc");
11 include_once($path_to_root . "/sales/includes/sales_db.inc");
12
13 $js = "";
14 if ($use_popup_windows)
15         $js .= get_js_open_window(900, 600);
16
17 page(_("View Sales Order"), true, false, "", $js);
18
19 display_heading(sprintf(_("Sales Order #%d"),$_GET['trans_no']));
20
21 if (isset($_SESSION['Items']))
22 {
23         unset ($_SESSION['Items']);
24 }
25
26 $_SESSION['Items'] = new Cart(30, $_GET['trans_no'], true);
27
28 start_table("$table_style2 width=95%", 5);
29 echo "<tr valign=top><td>";
30 display_heading2(_("Order Information"));
31 echo "</td><td>";
32 display_heading2(_("Deliveries"));
33 echo "</td><td>";
34 display_heading2(_("Invoices/Credits"));
35 echo "</td></tr>";
36
37 echo "<tr valign=top><td>";
38
39 start_table("$table_style width=95%");
40 label_row(_("Customer Name"), $_SESSION['Items']->customer_name, "class='tableheader2'",
41         "colspan=3");
42 start_row();
43 label_cells(_("Customer Order Ref."), $_SESSION['Items']->cust_ref, "class='tableheader2'");
44 label_cells(_("Deliver To Branch"), $_SESSION['Items']->deliver_to, "class='tableheader2'");
45 end_row();
46 start_row();
47 label_cells(_("Ordered On"), $_SESSION['Items']->document_date, "class='tableheader2'");
48 label_cells(_("Requested Delivery"), $_SESSION['Items']->due_date, "class='tableheader2'");
49 end_row();
50 start_row();
51 label_cells(_("Order Currency"), $_SESSION['Items']->customer_currency, "class='tableheader2'");
52 label_cells(_("Deliver From Location"), $_SESSION['Items']->location_name, "class='tableheader2'");
53 end_row();
54
55 label_row(_("Delivery Address"), nl2br($_SESSION['Items']->delivery_address),
56         "class='tableheader2'", "colspan=3");
57 label_row(_("Telephone"), $_SESSION['Items']->phone, "class='tableheader2'", "colspan=3");
58 label_row(_("E-mail"), "<a href='mailto:" . $_SESSION['Items']->email . "'>" . $_SESSION['Items']->email . "</a>",
59         "class='tableheader2'", "colspan=3");
60 label_row(_("Comments"), $_SESSION['Items']->Comments, "class='tableheader2'", "colspan=3");
61 end_table();
62
63 echo "</td><td valign='top'>";
64
65 start_table($table_style);
66 display_heading2(_("Delivery Notes"));
67
68 $th = array(_("#"), _("Ref"), _("Date"), _("Total"));
69 table_header($th);
70
71 $sql = "SELECT * FROM ".TB_PREF."debtor_trans WHERE type=13 AND order_=" . $_GET['trans_no'];
72 $result = db_query($sql,"The related delivery notes could not be retreived");
73
74 $delivery_total = 0;
75 $k = 0;
76
77 while ($del_row = db_fetch($result))
78 {
79
80         alt_table_row_color($k);
81
82         $this_total = $del_row["ov_freight"]+ $del_row["ov_amount"] + $del_row["ov_freight_tax"]  + $del_row["ov_gst"] ;
83         $delivery_total += $this_total;
84
85         label_cell(get_customer_trans_view_str($del_row["type"], $del_row["trans_no"]));
86         label_cell($del_row["reference"]);
87         label_cell(sql2date($del_row["tran_date"]));
88         amount_cell($this_total);
89         end_row();
90
91 }
92
93 label_row(null, price_format($delivery_total), "", "colspan=4 align=right");
94
95 end_table();
96 echo "</td><td valign='top'>";
97
98 start_table($table_style);
99 display_heading2(_("Sales Invoices"));
100
101 $th = array(_("#"), _("Ref"), _("Date"), _("Total"));
102 table_header($th);
103
104 $sql = "SELECT * FROM ".TB_PREF."debtor_trans WHERE type=10 AND order_=" . $_GET['trans_no'];
105 $result = db_query($sql,"The related invoices could not be retreived");
106
107 $invoices_total = 0;
108 $k = 0;
109
110 while ($inv_row = db_fetch($result))
111 {
112
113         alt_table_row_color($k);
114
115         $this_total = $inv_row["ov_freight"] + $inv_row["ov_freight_tax"]  + $inv_row["ov_gst"] + $inv_row["ov_amount"];
116         $invoices_total += $this_total;
117
118         label_cell(get_customer_trans_view_str($inv_row["type"], $inv_row["trans_no"]));
119         label_cell($inv_row["reference"]);
120         label_cell(sql2date($inv_row["tran_date"]));
121         amount_cell($this_total);
122         end_row();
123
124 }
125
126 label_row(null, price_format($invoices_total), "", "colspan=4 align=right");
127
128 end_table();
129
130 display_heading2(_("Credit Notes"));
131
132 start_table($table_style);
133 $th = array(_("#"), _("Ref"), _("Date"), _("Total"));
134 table_header($th);
135
136 $sql = "SELECT * FROM ".TB_PREF."debtor_trans WHERE type=11 AND order_=" . $_GET['trans_no'];
137 $result = db_query($sql,"The related credit notes could not be retreived");
138
139 $credits_total = 0;
140 $k = 0;
141
142 while ($credits_row = db_fetch($result))
143 {
144
145         alt_table_row_color($k);
146
147         $this_total = $credits_row["ov_freight"] + $credits_row["ov_freight_tax"]  + $credits_row["ov_gst"] + $credits_row["ov_amount"];
148         $credits_total += $this_total;
149
150         label_cell(get_customer_trans_view_str($credits_row["type"], $credits_row["trans_no"]));
151         label_cell($credits_row["reference"]);
152         label_cell(sql2date($credits_row["tran_date"]));
153         amount_cell(-$this_total);
154         end_row();
155
156 }
157
158 label_row(null, "<font color=red>" . price_format(-$credits_total) . "</font>",
159         "", "colspan=4 align=right");
160
161
162 end_table();
163
164 echo "</td></tr>";
165
166 end_table();
167
168 echo "<center>";
169 display_heading2(_("Line Details"));
170
171 start_table("colspan=9 width=95% $table_style");
172 $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"),
173         _("Price"), _("Discount"), _("Total"), _("Quantity Delivered"));
174 table_header($th);
175
176 $k = 0;  //row colour counter
177
178 foreach ($_SESSION['Items']->line_items as $stock_item) {
179
180         $line_total = round($stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent),
181            user_price_dec());
182
183         alt_table_row_color($k);
184
185         label_cell($stock_item->stock_id);
186         label_cell($stock_item->item_description);
187         $dec = get_qty_dec($stock_item->stock_id);
188         qty_cell($stock_item->quantity, false, $dec);
189         label_cell($stock_item->units);
190         amount_cell($stock_item->price);
191         amount_cell($stock_item->discount_percent * 100);
192         amount_cell($line_total);
193
194         qty_cell($stock_item->qty_done, false, $dec);
195         end_row();
196 }
197
198 $items_total = $_SESSION['Items']->get_items_total();
199
200 $display_total = price_format($items_total + $_SESSION['Items']->freight_cost);
201
202 label_row(_("Shipping"), price_format($_SESSION['Items']->freight_cost),
203         "align=right colspan=6", "nowrap align=right");
204 label_row(_("Total Order Value"), $display_total, "align=right colspan=6",
205         "nowrap align=right");
206
207 end_table(2);
208
209 end_page(true);
210
211 ?>