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
26 // delete all the order items - drastic but necessary because of
27 // change of currency, sales type, etc
28 // $order->clear_items();
30 // clear the branch selection
31 // unset($_POST['branch_id']);
32 $_POST['branch_id'] = '';
33 $Ajax->activate('branch_id');
36 customer_branches_list_row(_("Branch:"), $_POST['customer_id'],
37 'branch_id', null, false, true, true);
39 //if (($_SESSION['credit_items']->order_no == 0) ||
40 // ($order->customer_id != $_POST['customer_id']) ||
41 // ($order->Branch != $_POST['branch_id']))
42 // $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']);
43 if (($order->customer_id != $_POST['customer_id']) ||
44 ($order->Branch != $_POST['branch_id']))
47 $old_order = (PHP_VERSION<5) ? $order : clone( $order );
48 $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']);
50 $_POST['Location'] = $order->Location;
51 $_POST['deliver_to'] = $order->deliver_to;
52 $_POST['delivery_address'] = $order->delivery_address;
53 $_POST['phone'] = $order->phone;
54 $Ajax->activate('Location');
55 $Ajax->activate('deliver_to');
56 $Ajax->activate('phone');
57 $Ajax->activate('delivery_address');
58 // change prices if necessary
59 // what about discount in template case?
60 if ($old_order->customer_currency != $order->customer_currency) {
63 if ($old_order->sales_type != $order->sales_type) {
64 // || $old_order->default_discount!=$order->default_discount
65 $_POST['sales_type'] = $order->sales_type;
66 $Ajax->activate('sales_type_id');
71 set_global_customer($_POST['customer_id']);
73 if (!isset($_POST['ref']))
74 $_POST['ref'] = references::get_next(11);
75 if ($_SESSION['Items']->trans_no==0)
76 ref_row(_("Reference").':', 'ref');
78 label_row(_("Reference").':', $_POST['ref'] );
84 echo "</td><td>"; // outer table
86 if (!is_company_currency($order->customer_currency))
88 echo "<table height='5'>";
89 label_row(_("Customer Currency:"), $order->customer_currency);
90 exchange_rate_display($order->customer_currency, get_company_currency(),
91 $_POST['OrderDate'], true);
93 echo "</td><td>"; // outer table
96 echo "<table height='5'>";
98 if (!isset($_POST['sales_type_id']))
99 $_POST['sales_type_id'] = $order->sales_type;
100 sales_types_list_row(_("Sales Type"), 'sales_type_id', $_POST['sales_type_id'], true);
102 if ($order->sales_type != $_POST['sales_type_id']) {
103 $myrow = get_sales_type($_POST['sales_type_id']);
104 $order->set_sales_type($myrow['id'], $myrow['sales_type'],
105 $myrow['tax_included'], $myrow['factor']);
106 $Ajax->activate('sales_type_id');
110 if ($change_prices != 0) {
111 foreach ($order->line_items as $line_no=>$item) {
112 $line = &$order->line_items[$line_no];
113 $line->price = get_price($line->stock_id, $order->customer_currency,
114 $order->sales_type, $order->price_factor, $order->document_date);
115 // $line->discount_percent = $order->default_discount;
117 $Ajax->activate('items_table');
120 label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%");
123 echo "</td><td>"; // outer table
125 echo "<table height='5'>";
127 if (!isset($_POST['OrderDate']) || $_POST['OrderDate'] == "")
128 $_POST['OrderDate'] = $order->document_date;
130 date_row(_("Date:"), 'OrderDate');
132 shippers_list_row(_("Shipping Company:"), 'ShipperID', $order->ship_via);
138 end_table(1); // outer table
140 return $customer_error;
143 //---------------------------------------------------------------------------------
145 function display_credit_items($title, &$order)
147 global $table_style, $path_to_root;
149 display_heading($title);
150 div_start('items_table');
151 start_table("$table_style width=90%");
152 $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"),
153 _("Price"), _("Discount %"), _("Total"),'');
155 if (count($order->line_items)) $th[]= '';
160 $k = 0; //row colour counter
162 $id = find_submit('Edit');
164 foreach ($order->line_items as $line_no=>$line)
166 $line_total = round($line->qty_dispatched * $line->price * (1 - $line->discount_percent),
169 if ( $id != $line_no)
171 alt_table_row_color($k);
173 label_cell("<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?" . SID . "stock_id=" . $line->stock_id . "'>$line->stock_id</a>");
174 label_cell($line->item_description, "nowrap");
175 qty_cell($line->qty_dispatched, false, get_qty_dec($line->stock_id));
176 label_cell($line->units);
177 amount_cell($line->price);
179 amount_cell($line->discount_percent * 100);
180 amount_cell($line_total);
182 edit_button_cell("Edit$line_no", _('Edit'),
183 _('Edit document line'));
184 edit_button_cell("Delete$line_no", _('Delete'),
185 _('Remove line from document'));
191 credit_edit_item_controls($order, $k, $line_no);
194 $subtotal += $line_total;
198 credit_edit_item_controls($order, $k);
200 $display_sub_total = price_format($subtotal);
201 label_row(_("Sub-total"), $display_sub_total, "colspan=6 align=right", "align=right", 2);
203 if (!isset($_POST['ChargeFreightCost']) OR ($_POST['ChargeFreightCost'] == ""))
204 $_POST['ChargeFreightCost'] = price_format(0);
206 amount_cells_ex(_("Shipping"), 'ChargeFreightCost', 8, 8, $_POST['ChargeFreightCost'], "colspan=6 align=right");
207 label_cell('', 'colspan=2');
209 $taxes = $order->get_taxes($_POST['ChargeFreightCost']);
211 $tax_total = display_edit_tax_items($taxes, 6, $_SESSION['Items']->tax_included);
213 $display_total = price_format(($subtotal + $_POST['ChargeFreightCost'] + $tax_total));
215 label_row(_("Credit Note Total"), $display_total, "colspan=6 align=right","class='amount'", 2);
221 //---------------------------------------------------------------------------------
223 function credit_edit_item_controls(&$order, $rowcounter, $line_no=-1)
226 alt_table_row_color($rowcounter);
227 $id = find_submit('Edit');
229 if ($line_no!=-1 && $line_no == $id)
231 $_POST['stock_id'] = $order->line_items[$id]->stock_id;
232 $_POST['qty'] = qty_format($order->line_items[$id]->qty_dispatched, $_POST['stock_id'], $dec);
233 $_POST['price'] = price_format($order->line_items[$id]->price);
234 $_POST['Disc'] = percent_format(($order->line_items[$id]->discount_percent)*100);
235 $_POST['units'] = $order->line_items[$id]->units;
236 hidden('stock_id', $_POST['stock_id']);
237 label_cell($_POST['stock_id']);
238 label_cell($order->line_items[$id]->item_description, "nowrap");
239 $Ajax->activate('items_table');
243 stock_items_list_cells(null,'stock_id', null, false, true);
244 if(isset($_POST['_stock_id_update'])) {
245 $Ajax->activate('price');
246 $Ajax->activate('qty');
247 $Ajax->activate('units');
248 $Ajax->activate('line_total');
250 $item_info = get_item_edit_info($_POST['stock_id']);
252 $_POST['units'] = $item_info["units"];
253 $_POST['qty'] = qty_format(0, $_POST['stock_id'], $dec);
254 $_POST['price'] = price_format(get_price($_POST['stock_id'], $order->customer_currency,
255 $order->sales_type, $order->price_factor, $order->document_date));
257 // default to the customer's discount %
258 $_POST['Disc'] = percent_format($order->default_discount * 100);
261 qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
263 label_cell($_POST['units']);
264 amount_cells(null, 'price', null);
265 small_amount_cells(null, 'Disc', percent_format(0), null, null, user_percent_dec());
267 amount_cell($_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc']/100));
271 edit_button_cell('UpdateItem', _("Update"),
272 _('Confirm changes'));
273 edit_button_cell('CancelItemChanges', _("Cancel"),
274 _('Cancel changes'));
275 hidden('line_no', $line_no);
280 submit_cells('AddItem', _("Add Item"), "colspan=2",
281 _('Add new item to document'), true);
288 //---------------------------------------------------------------------------------
290 function credit_options_controls()
292 global $table_style2, $Ajax;
295 if (isset($_POST['_CreditType_update']))
296 $Ajax->activate('options');
298 div_start('options');
299 start_table("$table_style2");
301 credit_type_list_row(_("Credit Note Type"), 'CreditType', null, true);
303 if ($_POST['CreditType'] == "Return")
306 /*if the credit note is a return of goods then need to know which location to receive them into */
307 if (!isset($_POST['Location']))
308 $_POST['Location'] = $_SESSION['Items']->Location;
309 locations_list_row(_("Items Returned to Location"), 'Location', $_POST['Location']);
313 /* the goods are to be written off to somewhere */
314 gl_all_accounts_list_row(_("Write off the cost of the items to"), 'WriteOffGLCode', null);
317 textarea_row(_("Memo"), "CreditText", null, 51, 3);
323 //---------------------------------------------------------------------------------