3 include_once($path_to_root . "/includes/ui.inc");
5 // ------------------------------------------------------------------------------
7 function display_credit_header(&$order)
10 start_table("width=80% $table_style");
11 echo "<tr><td valign=top>"; // outer table
16 if (!isset($_POST['customer_id']) && (get_global_customer() != reserved_words::get_all()))
17 $_POST['customer_id'] = get_global_customer();
19 customer_list_row(_("Customer:"), 'customer_id', null, false, true);
21 if ($order->customer_id != $_POST['customer_id'])
23 // customer has changed
25 // delete all the order items - drastic but necessary because of
26 // change of currency, sales type, etc
27 $order->clear_items();
29 // clear the branch selection
30 unset($_POST['branch_id']);
33 customer_branches_list_row(_("Branch:"), $_POST['customer_id'], 'branch_id', null, false, true, true);
35 //if (($_SESSION['Items']->order_no == 0) ||
36 // ($order->customer_id != $_POST['customer_id']) ||
37 // ($order->Branch != $_POST['branch_id']))
38 // $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']);
39 if (($order->customer_id != $_POST['customer_id']) ||
40 ($order->Branch != $_POST['branch_id']))
41 $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']);
43 set_global_customer($_POST['customer_id']);
45 if (!isset($_POST['ref']))
46 $_POST['ref'] = references::get_next(11);
48 ref_row(_("Reference:"), 'ref');
52 echo "</td><td>"; // outer table
54 if (!is_company_currency($order->customer_currency))
56 echo "<table height='5'>";
57 label_row(_("Customer Currency:"), $order->customer_currency);
58 exchange_rate_display($order->customer_currency, get_company_currency(),
59 $_POST['OrderDate'], true);
61 echo "</td><td>"; // outer table
64 echo "<table height='5'>";
66 if (!isset($_POST['sales_type_id']))
67 $_POST['sales_type_id'] = $order->default_sales_type;
68 sales_types_list_row(_("Sales Type"), 'sales_type_id', $_POST['sales_type_id']);
70 label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%");
73 echo "</td><td>"; // outer table
75 echo "<table height='5'>";
77 if (!isset($_POST['OrderDate']) || $_POST['OrderDate'] == "")
78 $_POST['OrderDate'] = $order->orig_order_date;
80 date_row(_("Date:"), 'OrderDate');
82 if (!isset($_POST['tax_group_id']) || $_POST['tax_group_id'] == "")
83 $_POST['tax_group_id'] = $order->tax_group_id;
84 tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null, true);
90 end_table(1); // outer table
92 return $customer_error;
95 //---------------------------------------------------------------------------------
97 function display_credit_items($title, &$order)
99 global $table_style, $path_to_root;
101 display_heading($title);
102 start_table("$table_style width=90%");
103 $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"),
104 _("Price"), _("Discount %"), _("Total"));
108 $k = 0; //row colour counter
110 foreach ($order->line_items as $stock_item)
113 $line_total = $stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent);
115 if (!isset($_GET['Edit']) || $_GET['Edit'] != $stock_item->stock_id)
117 alt_table_row_color($k);
119 label_cell("<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?" . SID . "stock_id=" . $stock_item->stock_id . "'>$stock_item->stock_id</a>");
120 label_cell($stock_item->item_description);
121 qty_cell($stock_item->quantity);
122 label_cell($stock_item->units);
123 amount_cell($stock_item->price);
125 amount_cell($stock_item->discount_percent * 100);
126 amount_cell($line_total);
128 edit_link_cell(SID . "Edit=$stock_item->stock_id");
129 delete_link_cell(SID . "Delete=$stock_item->stock_id");
131 //labelt_cell(get_tax_free_price_for_item($stock_item->stock_id, $line_total, $_POST['tax_group_id']));
137 credit_edit_item_controls($order, $stock_item->stock_id);
140 $subtotal += $line_total;
143 if (!isset($_GET['Edit']))
144 credit_edit_item_controls($order);
146 $display_sub_total = number_format2($subtotal,user_price_dec());
147 label_row(_("Sub-total"), $display_sub_total, "colspan=6 align=right", "align=right");
149 if (!isset($_POST['ChargeFreightCost']) OR ($_POST['ChargeFreightCost'] == ""))
150 $_POST['ChargeFreightCost'] = 0;
152 text_row(_("Shipping"), 'ChargeFreightCost', $_POST['ChargeFreightCost'], 8, 8, "colspan=6 align=right");
154 $taxes = $order->get_taxes($_POST['tax_group_id'], $_POST['ChargeFreightCost']);
156 $tax_total = display_edit_tax_items($taxes, 6);
158 $display_total = number_format2(($subtotal + $_POST['ChargeFreightCost'] + $tax_total), user_price_dec());
159 label_row(_("Credit Note Total"), $display_total, "colspan=6 align=right","align=right");
164 //---------------------------------------------------------------------------------
166 function credit_edit_item_controls(&$order, $stock_id=null)
170 if (isset($_GET['Edit']) and $stock_id!=null)
172 if (!isset($_POST['stock_id']))
173 $_POST['stock_id'] = $order->line_items[$stock_id]->stock_id;
174 if (!isset($_POST['qty']) OR ($_POST['qty']==""))
175 $_POST['qty'] = $order->line_items[$stock_id]->quantity;
176 if (!isset($_POST['price']) OR ($_POST['price']==""))
177 $_POST['price'] = $order->line_items[$stock_id]->price;
178 if (!isset($_POST['Disc']) OR ($_POST['Disc']==""))
179 $_POST['Disc'] = ($order->line_items[$stock_id]->discount_percent)*100;
181 $_POST['units'] = $order->line_items[$stock_id]->units;
183 hidden('stock_id', $_POST['stock_id']);
184 label_cell($_POST['stock_id']);
185 label_cell($order->line_items[$stock_id]->item_description);
189 echo "<td colspan=2>";
190 stock_items_list('stock_id', null, false, true);
193 $item_info = get_item_edit_info($_POST['stock_id']);
195 $_POST['units'] = $item_info["units"];
198 $_POST['price'] = get_price($_POST['stock_id'], $order->customer_id);
199 // default to the customer's discount %
200 $_POST['Disc'] = $order->default_discount * 100;
204 text_cells(null, 'qty', $_POST['qty'], 13, 15);
205 label_cell($_POST['units']);
206 text_cells(null, 'price', null, 13, 15);
207 text_cells(null, 'Disc', $_POST['Disc'], 7, 5);
208 amount_cell($_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc']/100));
210 if (isset($_GET['Edit']))
212 submit_cells('UpdateItem', _("Update"));
213 submit_cells('CancelItemChanges', _("Cancel"));
217 submit_cells('AddItem', _("Add Item"), "colspan=2");
224 //---------------------------------------------------------------------------------
226 function credit_options_controls()
228 global $table_style2;
230 start_table("$table_style2");
232 credit_type_list_row(_("Credit Note Type"), 'CreditType', null, true);
234 if ($_POST['CreditType'] == "Return")
237 /*if the credit note is a return of goods then need to know which location to receive them into */
238 if (!isset($_POST['Location']))
239 $_POST['Location'] = $_SESSION['credit_items']->Location;
240 locations_list_row(_("Items Returned to Location"), 'Location', $_POST['Location']);
245 /* the goods are to be written off to somewhere */
246 gl_all_accounts_list_row(_("Write off the cost of the items to"), 'WriteOffGLCode', null);
249 textarea_row(_("Memo"), "CreditText", null, 51, 3);
254 //---------------------------------------------------------------------------------