No display of shipping if there are no shipping costs on sales documents or views.
[fa-stable.git] / sales / view / view_credit.php
1 <?php
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");
15
16 include_once($path_to_root . "/includes/date_functions.inc");
17 include_once($path_to_root . "/includes/ui.inc");
18
19 include_once($path_to_root . "/sales/includes/sales_db.inc");
20
21 $js = "";
22 if ($use_popup_windows)
23         $js .= get_js_open_window(900, 500);
24 page(_($help_context = "View Credit Note"), true, false, "", $js);
25
26 if (isset($_GET["trans_no"]))
27 {
28         $trans_id = $_GET["trans_no"];
29 }
30 elseif (isset($_POST["trans_no"]))
31 {
32         $trans_id = $_POST["trans_no"];
33 }
34
35 $myrow = get_customer_trans($trans_id, ST_CUSTCREDIT);
36
37 $branch = get_branch($myrow["branch_code"]);
38
39 display_heading("<font color=red>" . sprintf(_("CREDIT NOTE #%d"), $trans_id). "</font>");
40 echo "<br>";
41
42 start_table(TABLESTYLE2, "width='95%'");
43 echo "<tr valign=top><td>"; // outer table
44
45 /*Now the customer charged to details in a sub table*/
46 start_table(TABLESTYLE, "width='100%'");
47 $th = array(_("Customer"));
48 table_header($th);
49
50 label_row(null, $myrow["DebtorName"] . "<br>" . nl2br($myrow["address"]), "nowrap");
51
52 end_table();
53 /*end of the small table showing charge to account details */
54
55 echo "</td><td>"; // outer table
56
57 start_table(TABLESTYLE, "width='100%'");
58 $th = array(_("Branch"));
59 table_header($th);
60
61 label_row(null, $branch["br_name"] . "<br>" . nl2br($branch["br_address"]), "nowrap");
62 end_table();
63
64 echo "</td><td>"; // outer table
65
66 start_table(TABLESTYLE, "width='100%'");
67 start_row();
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'");
71 end_row();
72 start_row();
73 label_cells(_("Sales Type"), $myrow["sales_type"], "class='tableheader2'");
74 label_cells(_("Shipping Company"), $myrow["shipper_name"], "class='tableheader2'");
75 end_row();
76 comments_display_row(ST_CUSTCREDIT, $trans_id);
77 end_table();
78
79 echo "</td></tr>";
80 end_table(1); // outer table
81
82 $sub_total = 0;
83
84 $result = get_customer_trans_details(ST_CUSTCREDIT, $trans_id);
85
86 start_table(TABLESTYLE, "width='95%'");
87
88 if (db_num_rows($result) > 0)
89 {
90         $th = array(_("Item Code"), _("Item Description"), _("Quantity"),
91                 _("Unit"), _("Price"), _("Discount %"), _("Total"));
92         table_header($th);
93
94         $k = 0; //row colour counter
95         $sub_total = 0;
96
97         while ($myrow2 = db_fetch($result))
98         {
99                 if ($myrow2["quantity"] == 0) continue;
100                 alt_table_row_color($k);
101
102                 $value = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
103                    user_price_dec());
104                 $sub_total += $value;
105
106                 if ($myrow2["discount_percent"] == 0)
107                 {
108                         $display_discount = "";
109                 }
110                 else
111                 {
112                    $display_discount = percent_format($myrow2["discount_percent"]*100) . "%";
113                 }
114
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");
121                 amount_cell($value);
122                 end_row();
123         } //end while there are line items to print out
124 }
125 else
126         display_note(_("There are no line items on this credit note."), 1, 2);
127
128 $display_sub_tot = price_format($sub_total);
129
130 $credit_total = $myrow["ov_freight"]+$myrow["ov_gst"]+$myrow["ov_amount"]+$myrow["ov_freight_tax"];
131 $display_total = price_format($credit_total);
132
133 /*Print out the invoice text entered */
134 if ($sub_total != 0)
135         label_row(_("Sub Total"), $display_sub_tot, "colspan=6 align=right",
136                 "nowrap align=right width='15%'");
137
138 if ($myrow["ov_freight"] != 0.0)
139 {
140         $display_freight = price_format($myrow["ov_freight"]);
141         label_row(_("Shipping"), $display_freight, "colspan=6 align=right", "nowrap align=right");
142 }
143 $tax_items = get_trans_tax_details(ST_CUSTCREDIT, $trans_id);
144 display_customer_trans_tax_details($tax_items, 6);
145
146 label_row("<font color=red>" . _("TOTAL CREDIT") . "</font",
147         "<font color=red>$display_total</font>", "colspan=6 align=right", "nowrap align=right");
148 end_table(1);
149
150 $voided = is_voided_display(ST_CUSTCREDIT, $trans_id, _("This credit note has been voided."));
151
152 if (!$voided)
153         display_allocations_from(PT_CUSTOMER,
154                 $myrow['debtor_no'], ST_CUSTCREDIT, $trans_id, $credit_total);
155
156 /* end of check to see that there was an invoice record to print */
157
158 end_page(true, false, false, ST_CUSTCREDIT, $trans_id);
159
160 ?>