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