2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_SALESTRANSVIEW';
13 $path_to_root = "../..";
14 include_once($path_to_root . "/includes/session.inc");
16 include_once($path_to_root . "/includes/date_functions.inc");
17 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/sales/includes/sales_db.inc");
22 if ($use_popup_windows)
23 $js .= get_js_open_window(900, 500);
24 page(_($help_context = "View Credit Note"), true, false, "", $js);
26 if (isset($_GET["trans_no"]))
28 $trans_id = $_GET["trans_no"];
30 elseif (isset($_POST["trans_no"]))
32 $trans_id = $_POST["trans_no"];
35 $myrow = get_customer_trans($trans_id, ST_CUSTCREDIT);
37 $branch = get_branch($myrow["branch_code"]);
39 display_heading("<font color=red>" . sprintf(_("CREDIT NOTE #%d"), $trans_id). "</font>");
42 start_table("$table_style2 width=95%");
43 echo "<tr valign=top><td>"; // outer table
45 /*Now the customer charged to details in a sub table*/
46 start_table("$table_style width=100%");
47 $th = array(_("Customer"));
50 label_row(null, $myrow["DebtorName"] . "<br>" . nl2br($myrow["address"]), "nowrap");
53 /*end of the small table showing charge to account details */
55 echo "</td><td>"; // outer table
57 start_table("$table_style width=100%");
58 $th = array(_("Branch"));
61 label_row(null, $branch["br_name"] . "<br>" . nl2br($branch["br_address"]), "nowrap");
64 echo "</td><td>"; // outer table
66 start_table("$table_style width=100%");
68 label_cells(_("Ref"), $myrow["reference"], "class='tableheader2'");
69 label_cells(_("Date"), sql2date($myrow["tran_date"]), "class='tableheader2'");
70 label_cells(_("Currency"), $myrow["curr_code"], "class='tableheader2'");
73 label_cells(_("Sales Type"), $myrow["sales_type"], "class='tableheader2'");
74 label_cells(_("Shipping Company"), $myrow["shipper_name"], "class='tableheader2'");
76 comments_display_row(ST_CUSTCREDIT, $trans_id);
80 end_table(1); // outer table
84 $result = get_customer_trans_details(ST_CUSTCREDIT, $trans_id);
86 start_table("$table_style width=95%");
88 if (db_num_rows($result) > 0)
90 $th = array(_("Item Code"), _("Item Description"), _("Quantity"),
91 _("Unit"), _("Price"), _("Discount %"), _("Total"));
94 $k = 0; //row colour counter
97 while ($myrow2 = db_fetch($result))
99 if ($myrow2["quantity"] == 0) continue;
100 alt_table_row_color($k);
102 $value = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
104 $sub_total += $value;
106 if ($myrow2["discount_percent"] == 0)
108 $display_discount = "";
112 $display_discount = percent_format($myrow2["discount_percent"]*100) . "%";
115 label_cell($myrow2["stock_id"]);
116 label_cell($myrow2["StockDescription"]);
117 qty_cell($myrow2["quantity"], false, get_qty_dec($myrow2["stock_id"]));
118 label_cell($myrow2["units"], "align=right");
119 amount_cell($myrow2["unit_price"]);
120 label_cell($display_discount, "align=right");
123 } //end while there are line items to print out
126 display_note(_("There are no line items on this credit note."), 1, 2);
128 $display_sub_tot = price_format($sub_total);
129 $display_freight = price_format($myrow["ov_freight"]);
131 $credit_total = $myrow["ov_freight"]+$myrow["ov_gst"]+$myrow["ov_amount"]+$myrow["ov_freight_tax"];
132 $display_total = price_format($credit_total);
134 /*Print out the invoice text entered */
136 label_row(_("Sub Total"), $display_sub_tot, "colspan=6 align=right",
137 "nowrap align=right width=15%");
138 label_row(_("Shipping"), $display_freight, "colspan=6 align=right", "nowrap align=right");
140 $tax_items = get_trans_tax_details(ST_CUSTCREDIT, $trans_id);
141 display_customer_trans_tax_details($tax_items, 6);
143 label_row("<font color=red>" . _("TOTAL CREDIT") . "</font",
144 "<font color=red>$display_total</font>", "colspan=6 align=right", "nowrap align=right");
147 $voided = is_voided_display(ST_CUSTCREDIT, $trans_id, _("This credit note has been voided."));
150 display_allocations_from(PT_CUSTOMER,
151 $myrow['debtor_no'], ST_CUSTCREDIT, $trans_id, $credit_total);
153 /* end of check to see that there was an invoice record to print */