e430b45508f2b3ac1c9728875d6b76e1bd84cc43
[fa-stable.git] / sales / view / view_invoice.php
1 <?php
2
3 $page_security = 1;
4 $path_to_root="../..";
5 include_once($path_to_root . "/includes/session.inc");
6
7 include_once($path_to_root . "/sales/includes/sales_ui.inc");
8
9 include_once($path_to_root . "/sales/includes/sales_db.inc");
10
11 $js = "";
12 if ($use_popup_windows)
13         $js .= get_js_open_window(900, 600);
14 page(_("View Sales Invoice"), true, false, "", $js);
15
16
17 if (isset($_GET["trans_no"]))
18 {
19         $trans_id = $_GET["trans_no"];
20 }
21 elseif (isset($_POST["trans_no"]))
22 {
23         $trans_id = $_POST["trans_no"];
24 }
25
26 // 3 different queries to get the information - what a JOKE !!!!
27
28 $myrow = get_customer_trans($trans_id, 10);
29
30 $branch = get_branch($myrow["branch_code"]);
31
32 $sales_order = get_sales_order_header($myrow["order_"]);
33
34 display_heading(sprintf(_("SALES INVOICE #%d"),$trans_id));
35
36 echo "<br>";
37 start_table("$table_style2 width=95%");
38 echo "<tr valign=top><td>"; // outer table
39
40 /*Now the customer charged to details in a sub table*/
41 start_table("$table_style width=100%");
42 $th = array(_("Charge To"));
43 table_header($th);
44
45 label_row(null, $myrow["DebtorName"] . "<br>" . nl2br($myrow["address"]), "nowrap");
46
47 end_table();
48
49 /*end of the small table showing charge to account details */
50
51 echo "</td><td>"; // outer table
52
53 /*end of the main table showing the company name and charge to details */
54
55 start_table("$table_style width=100%");
56 $th = array(_("Charge Branch"));
57 table_header($th);
58
59 label_row(null, $branch["br_name"] . "<br>" . nl2br($branch["br_address"]), "nowrap");
60 end_table();
61
62 echo "</td><td>"; // outer table
63
64 start_table("$table_style width=100%");
65 $th = array(_("Delivered To"));
66 table_header($th);
67
68 label_row(null, $sales_order["deliver_to"] . "<br>" . nl2br($sales_order["delivery_address"]),
69         "nowrap");
70 end_table();
71
72 echo "</td><td>"; // outer table
73
74 start_table("$table_style width=100%");
75 start_row();
76 label_cells(_("Reference"), $myrow["reference"], "class='tableheader2'");
77 label_cells(_("Currency"), $sales_order["curr_code"], "class='tableheader2'");
78 label_cells(_("Our Order No"),
79         get_customer_trans_view_str(systypes::sales_order(),$sales_order["order_no"]), "class='tableheader2'");
80 end_row();
81 start_row();
82 label_cells(_("Customer Order Ref."), $sales_order["customer_ref"], "class='tableheader2'");
83 label_cells(_("Shipping Company"), $myrow["shipper_name"], "class='tableheader2'");
84 label_cells(_("Sales Type"), $myrow["sales_type"], "class='tableheader2'");
85 end_row();
86 start_row();
87 label_cells(_("Invoice Date"), sql2date($myrow["tran_date"]), "class='tableheader2'", "nowrap");
88 label_cells(_("Due Date"), sql2date($myrow["due_date"]), "class='tableheader2'", "nowrap");
89 label_cells(_("Deliveries"), get_customer_trans_view_str(systypes::cust_dispatch(), 
90         get_parent_trans(10,$trans_id)), "class='tableheader2'");
91 end_row();
92 comments_display_row(10, $trans_id);
93 end_table();
94
95 echo "</td></tr>";
96 end_table(1); // outer table
97
98
99 $result = get_customer_trans_details(10, $trans_id);
100
101 start_table("$table_style width=95%");
102
103 if (db_num_rows($result) > 0)
104 {
105         $th = array(_("Item Code"), _("Item Description"), _("Quantity"),
106                 _("Unit"), _("Price"), _("Discount %"), _("Total"));
107         table_header($th);
108
109         $k = 0; //row colour counter
110         $sub_total = 0;
111         while ($myrow2 = db_fetch($result))
112         {
113             if($myrow2["quantity"]==0) continue;
114                 alt_table_row_color($k);
115
116                 $value = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
117                    user_price_dec());
118                 $sub_total += $value;
119
120             if ($myrow2["discount_percent"] == 0)
121             {
122                         $display_discount = "";
123             }
124             else
125             {
126                         $display_discount = percent_format($myrow2["discount_percent"]*100) . "%";
127             }
128
129             label_cell($myrow2["stock_id"]);
130                 label_cell($myrow2["StockDescription"]);
131         qty_cell($myrow2["quantity"], false, get_qty_dec($myrow2["stock_id"]));
132         label_cell($myrow2["units"], "align=right");
133         amount_cell($myrow2["unit_price"]);
134         label_cell($display_discount, "nowrap align=right");
135         amount_cell($value);
136                 end_row();
137         } //end while there are line items to print out
138
139 }
140 else
141         display_note(_("There are no line items on this invoice."), 1, 2);
142
143 $display_sub_tot = price_format($sub_total);
144 $display_freight = price_format($myrow["ov_freight"]);
145
146 /*Print out the invoice text entered */
147 label_row(_("Sub-total"), $display_sub_tot, "colspan=6 align=right",
148         "nowrap align=right width=15%");
149 label_row(_("Shipping"), $display_freight, "colspan=6 align=right", "nowrap align=right");
150
151 $tax_items = get_customer_trans_tax_details(10, $trans_id);
152 display_customer_trans_tax_details($tax_items, 6);
153
154 $display_total = price_format($myrow["ov_freight"]+$myrow["ov_gst"]+$myrow["ov_amount"]+$myrow["ov_freight_tax"]);
155
156 label_row(_("TOTAL INVOICE"), $display_total, "colspan=6 align=right",
157         "nowrap align=right");
158 end_table(1);
159
160 is_voided_display(10, $trans_id, _("This invoice has been voided."));
161
162 end_page(true);
163
164 ?>