Fixed numeric fields to accept user native number format.
[fa-stable.git] / sales / view / view_credit.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 . "/includes/date_functions.inc");
8 include_once($path_to_root . "/includes/ui.inc");
9
10 include_once($path_to_root . "/sales/includes/sales_db.inc");
11
12 $js = "";
13 if ($use_popup_windows)
14         $js .= get_js_open_window(900, 500);
15 page(_("View Credit Note"), true, false, "", $js);
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 $myrow = get_customer_trans($trans_id, 11);
27
28 $branch = get_branch($myrow["branch_code"]);
29
30 display_heading("<font color=red>" . sprintf(_("CREDIT NOTE #%d"), $trans_id). "</font>");
31 echo "<br>";
32
33 start_table("$table_style2 width=95%");
34 echo "<tr valign=top><td>"; // outer table
35
36 /*Now the customer charged to details in a sub table*/
37 start_table("$table_style width=100%");
38 $th = array(_("Customer"));
39 table_header($th);
40
41 label_row(null, $myrow["DebtorName"] . "<br>" . nl2br($myrow["address"]), "nowrap");
42
43 end_table();
44 /*end of the small table showing charge to account details */
45
46 echo "</td><td>"; // outer table
47
48 start_table("$table_style width=100%");
49 $th = array(_("Branch"));
50 table_header($th);
51
52 label_row(null, $branch["br_name"] . "<br>" . nl2br($branch["br_address"]), "nowrap");
53 end_table();
54
55 echo "</td><td>"; // outer table
56
57 start_table("$table_style width=100%");
58 start_row();
59 label_cells(_("Ref"), $myrow["reference"], "class='tableheader2'");
60 label_cells(_("Date"), sql2date($myrow["tran_date"]), "class='tableheader2'");
61 label_cells(_("Currency"), $myrow["curr_code"], "class='tableheader2'");
62 end_row();
63 start_row();
64 label_cells(_("Sales Type"), $myrow["sales_type"], "class='tableheader2'");
65 label_cells(_("Shipping Company"), $myrow["shipper_name"], "class='tableheader2'");
66 end_row();
67 comments_display_row(11, $trans_id);
68 end_table();
69
70 echo "</td></tr>";
71 end_table(1); // outer table
72
73 $sub_total = 0;
74
75 $result = get_customer_trans_details(11, $trans_id);
76
77 start_table("$table_style width=95%");
78
79 if (db_num_rows($result) > 0)
80 {
81         $th = array(_("Item Code"), _("Item Description"), _("Quantity"),
82                 _("Unit"), _("Price"), _("Discount %"), _("Total"));
83         table_header($th);      
84
85         $k = 0; //row colour counter
86         $sub_total = 0;
87
88         while ($myrow2 = db_fetch($result))
89         {
90
91                 alt_table_row_color($k);
92
93                 $value = ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]);
94                 $sub_total += $value;
95
96                 if ($myrow2["discount_percent"] == 0)
97                 {
98                         $display_discount = "";
99                 } 
100                 else 
101                 {
102                    $display_discount = percent_format($myrow2["discount_percent"]*100) . "%";
103                 }
104
105                 label_cell($myrow2["stock_id"]);
106                 label_cell($myrow2["StockDescription"]);
107                 qty_cell($myrow2["quantity"]);
108                 label_cell($myrow2["units"], "align=right");
109                 amount_cell($myrow2["unit_price"]);
110                 label_cell($display_discount, "align=right");
111                 amount_cell($value);
112                 end_row();
113         } //end while there are line items to print out
114
115 else
116         display_note(_("There are no line items on this credit note."), 1, 2);
117
118 $display_sub_tot = price_format($sub_total);
119 $display_freight = price_format($myrow["ov_freight"]);
120
121 $credit_total = $myrow["ov_freight"]+$myrow["ov_gst"]+$myrow["ov_amount"]+$myrow["ov_freight_tax"];
122 $display_total = price_format($credit_total);
123
124 /*Print out the invoice text entered */
125 if ($sub_total != 0)
126         label_row(_("Sub Total"), $display_sub_tot, "colspan=6 align=right",
127                 "nowrap align=right width=15%");
128 label_row(_("Shipping"), $display_freight, "colspan=6 align=right", "nowrap align=right");
129
130 $tax_items = get_customer_trans_tax_details(11, $trans_id);
131 display_customer_trans_tax_details($tax_items, 6);
132
133 label_row("<font color=red>" . _("TOTAL CREDIT") . "</font",
134         "<font color=red>$display_total</font>", "colspan=6 align=right", "nowrap align=right");
135 end_table(1);
136
137 $voided = is_voided_display(11, $trans_id, _("This credit note has been voided."));
138
139 if (!$voided)
140         display_allocations_from(payment_person_types::customer(), 
141                 $myrow['debtor_no'], 11, $trans_id, $credit_total);
142
143 /* end of check to see that there was an invoice record to print */
144
145 end_page(true);
146
147 ?>