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['credit_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);
47 if ($_SESSION['Items']->trans_no==0)
48 ref_row(_("Reference:"), 'ref');
50 label_row(_("Reference"), $_POST['ref'], "class='tableheader2'");
56 echo "</td><td>"; // outer table
58 if (!is_company_currency($order->customer_currency))
60 echo "<table height='5'>";
61 label_row(_("Customer Currency:"), $order->customer_currency);
62 exchange_rate_display($order->customer_currency, get_company_currency(),
63 $_POST['OrderDate'], true);
65 echo "</td><td>"; // outer table
68 echo "<table height='5'>";
70 if (!isset($_POST['sales_type_id']))
71 $_POST['sales_type_id'] = $order->default_sales_type;
72 sales_types_list_row(_("Sales Type"), 'sales_type_id', $_POST['sales_type_id']);
74 label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%");
77 echo "</td><td>"; // outer table
79 echo "<table height='5'>";
81 if (!isset($_POST['OrderDate']) || $_POST['OrderDate'] == "")
82 $_POST['OrderDate'] = $order->document_date;
84 date_row(_("Date:"), 'OrderDate');
86 // if (!isset($_POST['tax_group_id']) || $_POST['tax_group_id'] == "")
87 // $_POST['tax_group_id'] = $order->tax_group_id;
88 // tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null, true);
89 shippers_list_row(_("Shipping Company:"), 'ShipperID', $order->ship_via);
95 end_table(1); // outer table
97 return $customer_error;
100 //---------------------------------------------------------------------------------
102 function display_credit_items($title, &$order)
104 global $table_style, $path_to_root;
106 display_heading($title);
107 start_table("$table_style width=90%");
108 $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"),
109 _("Price"), _("Discount %"), _("Total"),'');
111 if (count($order->line_items)) $th[]= '';
116 $k = 0; //row colour counter
118 foreach ($order->line_items as $line_no=>$line)
120 $line_total = $line->qty_dispatched * $line->price * (1 - $line->discount_percent);
121 if (!isset($_GET['Edit']))
126 if ( $id != $line_no)
129 alt_table_row_color($k);
131 label_cell("<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?" . SID . "stock_id=" . $line->stock_id . "'>$line->stock_id</a>");
132 label_cell($line->item_description);
133 qty_cell($line->qty_dispatched);
134 label_cell($line->units);
135 amount_cell($line->price);
137 amount_cell($line->discount_percent * 100);
138 amount_cell($line_total);
140 edit_link_cell(SID . "Edit=$line_no");
141 delete_link_cell(SID . "Delete=$line_no");
143 //labelt_cell(get_tax_free_price_for_item($line->stock_id, $line_total, $_POST['tax_group_id']));
149 credit_edit_item_controls($order, $line_no);
152 $subtotal += $line_total;
155 if (!isset($_GET['Edit']))
156 credit_edit_item_controls($order);
158 $display_sub_total = number_format2($subtotal,user_price_dec());
159 label_row(_("Sub-total"), $display_sub_total, "colspan=6 align=right", "align=right");
161 if (!isset($_POST['ChargeFreightCost']) OR ($_POST['ChargeFreightCost'] == ""))
162 $_POST['ChargeFreightCost'] = 0;
164 text_row(_("Shipping"), 'ChargeFreightCost', $_POST['ChargeFreightCost'], 8, 8, "colspan=6 align=right");
166 $taxes = $order->get_taxes($_POST['ChargeFreightCost']);
168 $tax_total = display_edit_tax_items($taxes, 6, $_SESSION['Items']->tax_included);
170 $display_total = number_format2(($subtotal + $_POST['ChargeFreightCost'] + $tax_total), user_price_dec());
171 label_row(_("Credit Note Total"), $display_total, "colspan=6 align=right","align=right");
176 //---------------------------------------------------------------------------------
178 function credit_edit_item_controls(&$order, $line_no=-1)
181 if (isset($_GET['Edit']) && $line_no != -1)
184 if (!isset($_POST['stock_id']))
185 $_POST['stock_id'] = $order->line_items[$_GET['Edit']]->stock_id;
186 if (!isset($_POST['qty']) || ($_POST['qty']==""))
187 $_POST['qty'] = $order->line_items[$_GET['Edit']]->qty_dispatched;
188 if (!isset($_POST['price']) || ($_POST['price']==""))
189 $_POST['price'] = $order->line_items[$_GET['Edit']]->price;
190 if (!isset($_POST['Disc']) || ($_POST['Disc']==""))
191 $_POST['Disc'] = ($order->line_items[$_GET['Edit']]->discount_percent)*100;
193 $_POST['units'] = $order->line_items[$_GET['Edit']]->units;
195 hidden('stock_id', $_POST['stock_id']);
196 label_cell($_POST['stock_id']);
197 label_cell($order->line_items[$_GET['Edit']]->item_description);
201 global $no_item_list;
204 echo "<td colspan=2>\n";
205 stock_items_list('stock_id', null, false, true);
210 text_cells(null, "StockID2", "", 12, 10, "", "", "onkeyup='recalcAccounts();' onKeyDown='if (event.keyCode==13) event.keyCode=9;' onblur='return setAccount(0, true);'");
211 stock_items_list_cells(null, 'stock_id', null, false, false, "onchange='return setAccount(1, true)'");
213 $item_info = get_item_edit_info($_POST['stock_id']);
215 $_POST['units'] = $item_info["units"];
218 $_POST['price'] = get_price($_POST['stock_id'], $order->customer_id);
219 // default to the customer's discount %
220 $_POST['Disc'] = $order->default_discount * 100;
224 text_cells(null, 'qty', $_POST['qty'], 13, 15);
225 // if ($order->trans_no!=0) {
226 // amount_cell($line_no==-1 ? 0 :$order->line_items[$line_no]->qty_done);
228 label_cell($_POST['units']);
229 text_cells(null, 'price', null, 13, 15);
230 text_cells(null, 'Disc', $_POST['Disc'], 7, 5);
232 amount_cell($_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc']/100));
234 if (isset($_GET['Edit']))
236 submit_cells('UpdateItem', _("Update"));
237 submit_cells('CancelItemChanges', _("Cancel"));
238 hidden('LineNo', $line_no);
242 submit_cells('AddItem', _("Add Item"), "colspan=2");
249 //---------------------------------------------------------------------------------
251 function credit_options_controls()
253 global $table_style2;
255 start_table("$table_style2");
257 credit_type_list_row(_("Credit Note Type"), 'CreditType', null, true);
259 if ($_POST['CreditType'] == "Return")
262 /*if the credit note is a return of goods then need to know which location to receive them into */
263 if (!isset($_POST['Location']))
264 $_POST['Location'] = $_SESSION['Items']->Location;
265 locations_list_row(_("Items Returned to Location"), 'Location', $_POST['Location']);
270 /* the goods are to be written off to somewhere */
271 gl_all_accounts_list_row(_("Write off the cost of the items to"), 'WriteOffGLCode', null);
274 textarea_row(_("Memo"), "CreditText", null, 51, 3);
279 //---------------------------------------------------------------------------------