3 include_once($path_to_root . "/includes/ui.inc");
5 // ------------------------------------------------------------------------------
7 function display_credit_header(&$order)
9 global $table_style, $Ajax;
10 start_table("width=80% $table_style");
11 echo "<tr><td valign=top>"; // outer table
17 if (!isset($_POST['customer_id']) && (get_global_customer() != reserved_words::get_all()))
18 $_POST['customer_id'] = get_global_customer();
20 customer_list_row(_("Customer:"), 'customer_id', null, false, true);
22 if ($order->customer_id != $_POST['customer_id'] /*|| $order->sales_type != $_POST['sales_type_id']*/)
24 // customer has changed
25 $Ajax->activate('branch_id');
28 customer_branches_list_row(_("Branch:"), $_POST['customer_id'],
29 'branch_id', null, false, true, true);
31 //if (($_SESSION['credit_items']->order_no == 0) ||
32 // ($order->customer_id != $_POST['customer_id']) ||
33 // ($order->Branch != $_POST['branch_id']))
34 // $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']);
35 if (($order->customer_id != $_POST['customer_id']) ||
36 ($order->Branch != $_POST['branch_id']))
39 $old_order = (PHP_VERSION<5) ? $order : clone( $order );
40 $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']);
42 $_POST['Location'] = $order->Location;
43 $_POST['deliver_to'] = $order->deliver_to;
44 $_POST['delivery_address'] = $order->delivery_address;
45 $_POST['phone'] = $order->phone;
46 $Ajax->activate('Location');
47 $Ajax->activate('deliver_to');
48 $Ajax->activate('phone');
49 $Ajax->activate('delivery_address');
50 // change prices if necessary
51 // what about discount in template case?
52 if ($old_order->customer_currency != $order->customer_currency) {
55 if ($old_order->sales_type != $order->sales_type) {
56 // || $old_order->default_discount!=$order->default_discount
57 $_POST['sales_type_id'] = $order->sales_type;
58 $Ajax->activate('sales_type_id');
63 set_global_customer($_POST['customer_id']);
65 if (!isset($_POST['ref']))
66 $_POST['ref'] = references::get_next(11);
67 if ($_SESSION['Items']->trans_no==0)
68 ref_row(_("Reference").':', 'ref');
70 label_row(_("Reference").':', $_POST['ref'] );
76 echo "</td><td>"; // outer table
78 if (!is_company_currency($order->customer_currency))
80 div_start('currency');
81 echo "<table height='5'>";
82 label_row(_("Customer Currency:"), $order->customer_currency);
83 exchange_rate_display($order->customer_currency, get_company_currency(),
86 echo "</td><td>"; // outer table
90 echo "<table height='5'>";
92 if (!isset($_POST['sales_type_id']))
93 $_POST['sales_type_id'] = $order->sales_type;
94 sales_types_list_row(_("Sales Type"), 'sales_type_id', $_POST['sales_type_id'], true);
96 if ($order->sales_type != $_POST['sales_type_id']) {
97 $myrow = get_sales_type($_POST['sales_type_id']);
98 $order->set_sales_type($myrow['id'], $myrow['sales_type'],
99 $myrow['tax_included'], $myrow['factor']);
100 $Ajax->activate('sales_type_id');
104 label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%");
107 echo "</td><td>"; // outer table
109 echo "<table height='5'>";
111 if (!isset($_POST['OrderDate']) || $_POST['OrderDate'] == "")
112 $_POST['OrderDate'] = $order->document_date;
114 date_row(_("Date:"), 'OrderDate', '', null, 0, 0, 0, null, true);
115 if (isset($_POST['_OrderDate_changed'])) {
116 if (!is_company_currency($order->customer_currency)
117 && (get_base_sales_type()>0)) {
120 $Ajax->activate('currency');
122 shippers_list_row(_("Shipping Company:"), 'ShipperID', $order->ship_via);
128 end_table(1); // outer table
130 if ($change_prices != 0) {
131 foreach ($order->line_items as $line_no=>$item) {
132 $line = &$order->line_items[$line_no];
133 $line->price = get_price($line->stock_id, $order->customer_currency,
134 $order->sales_type, $order->price_factor, get_post('OrderDate'));
135 // $line->discount_percent = $order->default_discount;
137 $Ajax->activate('items_table');
141 return $customer_error;
144 //---------------------------------------------------------------------------------
146 function display_credit_items($title, &$order)
148 global $table_style, $path_to_root;
150 display_heading($title);
151 div_start('items_table');
152 start_table("$table_style width=90%");
153 $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"),
154 _("Price"), _("Discount %"), _("Total"),'');
156 if (count($order->line_items)) $th[]= '';
161 $k = 0; //row colour counter
163 $id = find_submit('Edit');
165 foreach ($order->line_items as $line_no=>$line)
167 $line_total = round($line->qty_dispatched * $line->price * (1 - $line->discount_percent),
170 if ( $id != $line_no)
172 alt_table_row_color($k);
174 label_cell("<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?" . SID . "stock_id=" . $line->stock_id . "'>$line->stock_id</a>");
175 label_cell($line->item_description, "nowrap");
176 qty_cell($line->qty_dispatched, false, get_qty_dec($line->stock_id));
177 label_cell($line->units);
178 amount_cell($line->price);
180 amount_cell($line->discount_percent * 100);
181 amount_cell($line_total);
183 edit_button_cell("Edit$line_no", _('Edit'),
184 _('Edit document line'));
185 edit_button_cell("Delete$line_no", _('Delete'),
186 _('Remove line from document'));
192 credit_edit_item_controls($order, $k, $line_no);
195 $subtotal += $line_total;
199 credit_edit_item_controls($order, $k);
201 $display_sub_total = price_format($subtotal);
202 label_row(_("Sub-total"), $display_sub_total, "colspan=6 align=right", "align=right", 2);
204 if (!isset($_POST['ChargeFreightCost']) OR ($_POST['ChargeFreightCost'] == ""))
205 $_POST['ChargeFreightCost'] = price_format(0);
207 amount_cells_ex(_("Shipping"), 'ChargeFreightCost', 8, 8, $_POST['ChargeFreightCost'], "colspan=6 align=right");
208 label_cell('', 'colspan=2');
210 $taxes = $order->get_taxes($_POST['ChargeFreightCost']);
212 $tax_total = display_edit_tax_items($taxes, 6, $_SESSION['Items']->tax_included);
214 $display_total = price_format(($subtotal + $_POST['ChargeFreightCost'] + $tax_total));
216 label_row(_("Credit Note Total"), $display_total, "colspan=6 align=right","class='amount'", 2);
222 //---------------------------------------------------------------------------------
224 function credit_edit_item_controls(&$order, $rowcounter, $line_no=-1)
227 alt_table_row_color($rowcounter);
228 $id = find_submit('Edit');
230 if ($line_no!=-1 && $line_no == $id)
232 $_POST['stock_id'] = $order->line_items[$id]->stock_id;
233 $_POST['qty'] = qty_format($order->line_items[$id]->qty_dispatched, $_POST['stock_id'], $dec);
234 $_POST['price'] = price_format($order->line_items[$id]->price);
235 $_POST['Disc'] = percent_format(($order->line_items[$id]->discount_percent)*100);
236 $_POST['units'] = $order->line_items[$id]->units;
237 hidden('stock_id', $_POST['stock_id']);
238 label_cell($_POST['stock_id']);
239 label_cell($order->line_items[$id]->item_description, "nowrap");
240 $Ajax->activate('items_table');
244 stock_items_list_cells(null,'stock_id', null, false, true);
245 if (list_updated('stock_id')) {
246 $Ajax->activate('price');
247 $Ajax->activate('qty');
248 $Ajax->activate('units');
249 $Ajax->activate('line_total');
251 $item_info = get_item_edit_info($_POST['stock_id']);
253 $_POST['units'] = $item_info["units"];
254 $_POST['qty'] = qty_format(0, $_POST['stock_id'], $dec);
255 $_POST['price'] = price_format(get_price($_POST['stock_id'], $order->customer_currency,
256 $order->sales_type, $order->price_factor, $order->document_date));
258 // default to the customer's discount %
259 $_POST['Disc'] = percent_format($order->default_discount * 100);
262 qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
264 label_cell($_POST['units']);
265 amount_cells(null, 'price', null);
266 small_amount_cells(null, 'Disc', percent_format(0), null, null, user_percent_dec());
268 amount_cell(input_num('qty') * input_num('price') * (1 - input_num('Disc')/100));
272 edit_button_cell('UpdateItem', _("Update"),
273 _('Confirm changes'));
274 edit_button_cell('CancelItemChanges', _("Cancel"),
275 _('Cancel changes'));
276 hidden('line_no', $line_no);
281 submit_cells('AddItem', _("Add Item"), "colspan=2",
282 _('Add new item to document'), true);
289 //---------------------------------------------------------------------------------
291 function credit_options_controls()
293 global $table_style2, $Ajax;
296 if (isset($_POST['_CreditType_update']))
297 $Ajax->activate('options');
299 div_start('options');
300 start_table("$table_style2");
302 credit_type_list_row(_("Credit Note Type"), 'CreditType', null, true);
304 if ($_POST['CreditType'] == "Return")
307 /*if the credit note is a return of goods then need to know which location to receive them into */
308 if (!isset($_POST['Location']))
309 $_POST['Location'] = $_SESSION['Items']->Location;
310 locations_list_row(_("Items Returned to Location"), 'Location', $_POST['Location']);
314 /* the goods are to be written off to somewhere */
315 gl_all_accounts_list_row(_("Write off the cost of the items to"), 'WriteOffGLCode', null);
318 textarea_row(_("Memo"), "CreditText", null, 51, 3);
324 //---------------------------------------------------------------------------------