*** empty log message ***
[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(_("Sales Invoices"));
36 echo "</td><td>";
37 display_heading2(_("Credit Notes"));
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
70 $th = array(_("#"), _("Ref"), _("Date"), _("Total"));
71 table_header($th);
72
73 $sql = "SELECT * FROM ".TB_PREF."debtor_trans WHERE type=10 AND order_=" . $_GET['trans_no'];
74 $result = db_query($sql,"The related invoices could not be retreived");
75
76 $invoices_total = 0;
77 $k = 0;
78
79 while ($inv_row = db_fetch($result)) 
80 {
81
82         alt_table_row_color($k);
83
84         $this_total = $inv_row["ov_freight"] + $inv_row["ov_gst"] + $inv_row["ov_amount"];
85         $invoices_total += $this_total;
86
87         label_cell(get_customer_trans_view_str($inv_row["type"], $inv_row["trans_no"]));
88         label_cell($inv_row["reference"]);
89         label_cell(sql2date($inv_row["tran_date"]));
90         amount_cell($this_total);
91         end_row();
92
93 }
94
95 label_row(null, number_format2($invoices_total,user_price_dec()), "", "colspan=4 align=right");
96
97 end_table();
98
99 echo "</td><td valign='top'>";
100 start_table($table_style);
101 $th = array(_("#"), _("Ref"), _("Date"), _("Total"));
102 table_header($th);
103
104 $sql = "SELECT * FROM ".TB_PREF."debtor_trans WHERE type=11 AND order_=" . $_GET['trans_no'];
105 $result = db_query($sql,"The related credit notes could not be retreived");
106
107 $credits_total = 0;
108 $k = 0;
109
110 while ($credits_row = db_fetch($result)) 
111 {
112
113         alt_table_row_color($k);
114
115         $this_total = $credits_row["ov_freight"] + $credits_row["ov_gst"] + $credits_row["ov_amount"];
116         $credits_total += $this_total;
117
118         label_cell(get_customer_trans_view_str($credits_row["type"], $credits_row["trans_no"]));
119         label_cell($credits_row["reference"]);
120         label_cell(sql2date($credits_row["tran_date"]));
121         amount_cell(-$this_total);
122         end_row();
123
124 }
125
126 label_row(null, "<font color=red>" . number_format2(-$credits_total,user_price_dec()) . "</font>",
127         "", "colspan=4 align=right");
128
129
130 end_table();
131
132 echo "</td></tr>";
133
134 end_table();
135
136 echo "<center>";
137 display_heading2(_("Line Details"));
138
139 start_table("colspan=9 width=95% $table_style");
140 $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"),
141         _("Price"), _("Discount"), _("Total"), _("Quantity Delivered"));
142 table_header($th);
143
144 $k = 0;  //row colour counter
145
146 foreach ($_SESSION['Items']->line_items as $stock_item) {
147
148         $line_total =   $stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent);
149
150         alt_table_row_color($k);
151
152         label_cell($stock_item->stock_id);
153         label_cell($stock_item->item_description);
154         qty_cell($stock_item->quantity);
155         label_cell($stock_item->units);
156         amount_cell($stock_item->price);
157         amount_cell($stock_item->discount_percent * 100);
158         amount_cell($line_total);
159         
160         qty_cell($stock_item->qty_inv);
161         end_row();
162 }
163
164 $items_total = $_SESSION['Items']->get_items_total();
165
166 $display_total = number_format2($items_total + $_SESSION['Items']->freight_cost,user_price_dec());
167
168 label_row(_("Shipping"), number_format2($_SESSION['Items']->freight_cost,user_price_dec()),
169         "align=right colspan=6", "nowrap align=right");
170 label_row(_("Total Excluding Tax"), $display_total, "align=right colspan=6",
171         "nowrap align=right");
172
173 end_table(2);
174
175 end_page(true);
176
177 ?>