From: Janusz Dobrowolski Date: Wed, 18 Jun 2008 15:09:55 +0000 (+0000) Subject: Added ajax and some smaller fixes in sales module files X-Git-Tag: v2.4.2~19^2~2008 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=fed6bc04a7b050a0b69136a332e92ee651812487;p=fa-stable.git Added ajax and some smaller fixes in sales module files --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ea6154de..0e88b440 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,26 @@ Legend: ! -> Note $ -> Affected files +18-Jun-2008 Janusz Dobrowolski ++ Added ajax improvements +$ /sales/credit_note_entry.php + /sales/customer_payments.php + /sales/sales_order_entry.php + /sales/includes/ui/sales_credit_ui.inc + /sales/includes/ui/sales_order_ui.inc + /sales/inquiry/customer_allocation_inquiry.php + /sales/inquiry/customer_inquiry.php ++ Added optional trigger parameter to div_start() +$ /includes/ui/ui_controls.inc ++ Added dec attribute ajax update for amount fields +$ /includes/ui/ui_input.inc ++ Ajaxified stock item types and credit types lists +$ /includes/ui/ui_lists.inc +# Fixed onblur for amount fields, extended onchange event handling for selects +$ /js/inserts.js +# Fixed addAssign() js handler for nonstandard attributes +$ /js/utils.js + 17-Jun-2008 Joe Hunt ! More files with Quantity routines needed fix due to php4 related issue. $ /includes/current_user.inc @@ -95,7 +115,7 @@ $ /sales/inquiry/sales_deliveries_view.php ! Added text selection after focus. $ /js/inserts.js /js/utils.js -+ Added submit_on_change option to ref input functions ++ Added submit_on_change option to ref input functions, fixed data picker $ /includes/ui/ui_input.inc # Fixed bug in non-js mode for combos type 0 (stock_items_lists). $ /includes/ui/ui_lists.inc diff --git a/includes/ajax.inc b/includes/ajax.inc index 3ad2966e..c07bea68 100644 --- a/includes/ajax.inc +++ b/includes/ajax.inc @@ -118,7 +118,8 @@ class Ajax extends JsHttpRequest { break; } } -// display_error(htmlentities(print_r($this->aCommands, true))); +// display_error('Activate:'.htmlentities(print_r($this->triggers, true))); +// display_error('Commands :'.htmlentities(print_r($this->aCommands, true))); $GLOBALS['_RESULT'] = $this->aCommands; // exit(); } diff --git a/includes/ui/ui_controls.inc b/includes/ui/ui_controls.inc index d9d1f057..3452b0bd 100644 --- a/includes/ui/ui_controls.inc +++ b/includes/ui/ui_controls.inc @@ -192,11 +192,11 @@ function br($num=1) $ajax_divs = array(); -function div_start($id='') +function div_start($id='', $trigger=null) { global $ajax_divs; - array_push($ajax_divs, $id); + array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger)); echo "
"; ob_start(); } @@ -207,8 +207,8 @@ function div_end() if (count($ajax_divs)) { - $id = array_pop($ajax_divs); - $Ajax->addUpdate($id, $id, ob_get_flush()); + $div = array_pop($ajax_divs); + $Ajax->addUpdate($div[1], $div[0], ob_get_flush()); echo "
"; } } diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index 753fc3d9..613f53b3 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -440,6 +440,7 @@ function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=nu echo "\n"; $Ajax->addUpdate($name, $name, $_POST[$name]); + $Ajax->addAssign($name, $name, 'dec', $dec); } diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index e46fe645..375498d0 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -94,9 +94,11 @@ $opts = array( // default options $rel = "rel='$search_box'"; // set relation to list if ($opts['search_submit']) { - if (isset($_POST[$search_submit])) { - $Ajax->activate($name); + if (!$opts['async']) + $Ajax->activate('_page_body'); + else + $Ajax->activate($name); } if ($txt == '') { if ($spec_option === false) @@ -699,7 +701,8 @@ function stock_item_types_list_row($label, $name, $selected_id, $enabled=true) echo "$label\n"; echo ""; if ($enabled) - $sel = "\n"; + else $sel = ""; // FIX ajax + echo " onchange='JsHttpRequest.request(\"_{$name}_update\", this.form);'>"; else echo ">"; echo "\n"; diff --git a/js/inserts.js b/js/inserts.js index b535cd03..33bff885 100644 --- a/js/inserts.js +++ b/js/inserts.js @@ -74,15 +74,15 @@ function _set_combo_input(e) { } } } - }; - e.onkeydown = function(ev) { + }; + e.onkeydown = function(ev) { ev = ev||window.event; key = ev.keyCode||ev.which; if(key == 13) { this.blur(); return false; } - } + } } function _update_box(s) { @@ -99,9 +99,15 @@ function _update_box(s) { } function _set_combo_select(e) { + // When combo position is changed via js (eg from searchbox) + // no onchange event is generated. To ensure proper change + // signaling we must track selectedIndex in onblur handler. + e.setAttribute('_last', e.selectedIndex); e.onblur = function() { if(this.className=='combo') _update_box(this); + if (this.selectedIndex != this.getAttribute('_last')) + this.onchange(); } e.onchange = function() { var s = this; @@ -155,14 +161,14 @@ var inserts = { 'input.ajaxsubmit,input.editbutton,input.navibutton': function(e) { e.onclick = function() { - JsHttpRequest.request(this); - return false; + JsHttpRequest.request(this); + return false; } }, '.amount': function(e) { if(e.onblur==undefined) { - var dec = e.getAttribute("dec"); e.onblur = function() { + var dec = this.getAttribute("dec"); price_format(this.name, get_amount(this.name), dec); }; } diff --git a/js/utils.js b/js/utils.js index a2dc4ba1..5dbbcbf9 100644 --- a/js/utils.js +++ b/js/utils.js @@ -26,7 +26,6 @@ values[trigger] = 1; // this is to avoid caching problems values['_random'] = Math.random()*1234567; - JsHttpRequest.query( 'POST '+url, // backend values, @@ -45,7 +44,7 @@ // seek element by id if there is no elemnt with given name objElement = document.getElementsByName(id)[0] || document.getElementById(id); if(cmd=='as') { - eval("objElement."+property+"=data;"); + eval("objElement.setAttribute('"+property+"',"+data+");"); } else if(cmd=='up') { // if(!objElement) debug('No element "'+id+'"'); if (objElement.tagName == 'INPUT' || objElement.tagName == 'TEXTAREA') diff --git a/sales/credit_note_entry.php b/sales/credit_note_entry.php index 1946aca1..2b7ded83 100644 --- a/sales/credit_note_entry.php +++ b/sales/credit_note_entry.php @@ -57,7 +57,9 @@ if (isset($_GET['AddedID'])) { //-------------------------------------------------------------------------------- function line_start_focus() { - set_focus(get_company_pref('no_supplier_list') ? 'stock_id_edit' : 'StockID2'); + global $Ajax; + $Ajax->activate('items_table'); + set_focus('_stock_id_edit'); } //----------------------------------------------------------------------------- @@ -93,6 +95,7 @@ function handle_new_credit($trans_no) processing_start(); $_SESSION['Items'] = new Cart(11,$trans_no); copy_from_cn(); + line_start_focus(); } //----------------------------------------------------------------------------- @@ -135,6 +138,7 @@ if (isset($_POST['ProcessCredit']) && can_process()) { display_note(_("For credit notes created to write off the stock, a general ledger account is required to be selected."), 1, 0); display_note(_("Please select an account to write the cost of the stock off to, then click on Process again."), 1, 0); exit; + } if (!isset($_POST['WriteOffGLCode'])) { $_POST['WriteOffGLCode'] = 0; diff --git a/sales/customer_payments.php b/sales/customer_payments.php index de86600d..c93db3a1 100644 --- a/sales/customer_payments.php +++ b/sales/customer_payments.php @@ -99,7 +99,10 @@ if (isset($_POST['AddPaymentItem'])) { unset($_POST['AddPaymentItem']); } } - +if (isset($_POST['_customer_id_button'])) { +// unset($_POST['branch_id']); + $Ajax->activate('branch_id'); +} //---------------------------------------------------------------------------------------------- if (isset($_POST['AddPaymentItem'])) { @@ -148,7 +151,6 @@ function display_item_form() } } customer_list_row(_("From Customer:"), 'customer_id', null, false, true); - if (db_customer_has_branches($_POST['customer_id'])) { customer_branches_list_row(_("Branch:"), $_POST['customer_id'], 'BranchID', null, false, true, true); } else { @@ -202,7 +204,7 @@ function display_item_form() echo"
"; - submit_center('AddPaymentItem', _("Add Payment")); + submit_center('AddPaymentItem', _("Add Payment"), true, '', true); } echo "
"; diff --git a/sales/includes/ui/sales_credit_ui.inc b/sales/includes/ui/sales_credit_ui.inc index 3267bb43..fe1e1dbe 100644 --- a/sales/includes/ui/sales_credit_ui.inc +++ b/sales/includes/ui/sales_credit_ui.inc @@ -6,31 +6,35 @@ include_once($path_to_root . "/includes/ui.inc"); function display_credit_header(&$order) { - global $table_style; + global $table_style, $Ajax; start_table("width=80% $table_style"); echo ""; // outer table echo ""; $customer_error = ""; + $change_prices = 0; if (!isset($_POST['customer_id']) && (get_global_customer() != reserved_words::get_all())) $_POST['customer_id'] = get_global_customer(); customer_list_row(_("Customer:"), 'customer_id', null, false, true); - if ($order->customer_id != $_POST['customer_id'] || $order->sales_type != $_POST['sales_type_id']) + if ($order->customer_id != $_POST['customer_id'] /*|| $order->sales_type != $_POST['sales_type_id']*/) { // customer has changed // delete all the order items - drastic but necessary because of // change of currency, sales type, etc - $order->clear_items(); +// $order->clear_items(); // clear the branch selection - unset($_POST['branch_id']); +// unset($_POST['branch_id']); + $_POST['branch_id'] = ''; + $Ajax->activate('branch_id'); } - customer_branches_list_row(_("Branch:"), $_POST['customer_id'], 'branch_id', null, false, true, true); + customer_branches_list_row(_("Branch:"), $_POST['customer_id'], + 'branch_id', null, false, true, true); //if (($_SESSION['credit_items']->order_no == 0) || // ($order->customer_id != $_POST['customer_id']) || @@ -38,8 +42,32 @@ function display_credit_header(&$order) // $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']); if (($order->customer_id != $_POST['customer_id']) || ($order->Branch != $_POST['branch_id'])) - $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']); - + { + + $old_order = (PHP_VERSION<5) ? $order : clone( $order ); + $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']); + + $_POST['Location'] = $order->Location; + $_POST['deliver_to'] = $order->deliver_to; + $_POST['delivery_address'] = $order->delivery_address; + $_POST['phone'] = $order->phone; + $Ajax->activate('Location'); + $Ajax->activate('deliver_to'); + $Ajax->activate('phone'); + $Ajax->activate('delivery_address'); + // change prices if necessary + // what about discount in template case? + if ($old_order->customer_currency != $order->customer_currency) { + $change_prices = 1; + } + if ($old_order->sales_type != $order->sales_type) { + // || $old_order->default_discount!=$order->default_discount + $_POST['sales_type'] = $order->sales_type; + $Ajax->activate('sales_type_id'); + $change_prices = 1; + } + unset($old_order); + } set_global_customer($_POST['customer_id']); if (!isset($_POST['ref'])) @@ -70,6 +98,24 @@ function display_credit_header(&$order) if (!isset($_POST['sales_type_id'])) $_POST['sales_type_id'] = $order->sales_type; sales_types_list_row(_("Sales Type"), 'sales_type_id', $_POST['sales_type_id'], true); + + if ($order->sales_type != $_POST['sales_type_id']) { + $myrow = get_sales_type($_POST['sales_type_id']); + $order->set_sales_type($myrow['id'], $myrow['sales_type'], + $myrow['tax_included'], $myrow['factor']); + $Ajax->activate('sales_type_id'); + $change_prices = 1; + } + + if ($change_prices != 0) { + foreach ($order->line_items as $line_no=>$item) { + $line = &$order->line_items[$line_no]; + $line->price = get_price($line->stock_id, $order->customer_currency, + $order->sales_type, $order->price_factor, $order->document_date); + // $line->discount_percent = $order->default_discount; + } + $Ajax->activate('items_table'); + } label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%"); echo "
"; @@ -83,9 +129,6 @@ function display_credit_header(&$order) date_row(_("Date:"), 'OrderDate'); -// if (!isset($_POST['tax_group_id']) || $_POST['tax_group_id'] == "") -// $_POST['tax_group_id'] = $order->tax_group_id; -// tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null, true); shippers_list_row(_("Shipping Company:"), 'ShipperID', $order->ship_via); echo ""; @@ -104,6 +147,7 @@ function display_credit_items($title, &$order) global $table_style, $path_to_root; display_heading($title); + div_start('items_table'); start_table("$table_style width=90%"); $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"), _("Price"), _("Discount %"), _("Total"),''); @@ -135,8 +179,10 @@ function display_credit_items($title, &$order) amount_cell($line->discount_percent * 100); amount_cell($line_total); - edit_button_cell("Edit$line_no", _('Edit')); - edit_button_cell("Delete$line_no", _('Delete')); + edit_button_cell("Edit$line_no", _('Edit'), + _('Edit document line')); + edit_button_cell("Delete$line_no", _('Delete'), + _('Remove line from document')); end_row(); } @@ -169,18 +215,19 @@ function display_credit_items($title, &$order) label_row(_("Credit Note Total"), $display_total, "colspan=6 align=right","class='amount'", 2); end_table(); + div_end(); } //--------------------------------------------------------------------------------- function credit_edit_item_controls(&$order, $rowcounter, $line_no=-1) { + global $Ajax; alt_table_row_color($rowcounter); $id = find_submit('Edit'); if ($line_no!=-1 && $line_no == $id) { - $_POST['stock_id'] = $order->line_items[$id]->stock_id; $_POST['qty'] = qty_format($order->line_items[$id]->qty_dispatched, $_POST['stock_id'], $dec); $_POST['price'] = price_format($order->line_items[$id]->price); @@ -189,14 +236,20 @@ function credit_edit_item_controls(&$order, $rowcounter, $line_no=-1) hidden('stock_id', $_POST['stock_id']); label_cell($_POST['stock_id']); label_cell($order->line_items[$id]->item_description, "nowrap"); + $Ajax->activate('items_table'); } else { stock_items_list_cells(null,'stock_id', null, false, true); + if(isset($_POST['_stock_id_update'])) { + $Ajax->activate('price'); + $Ajax->activate('qty'); + $Ajax->activate('units'); + $Ajax->activate('line_total'); + } $item_info = get_item_edit_info($_POST['stock_id']); $_POST['units'] = $item_info["units"]; - $_POST['qty'] = qty_format(0, $_POST['stock_id'], $dec); $_POST['price'] = price_format(get_price($_POST['stock_id'], $order->customer_currency, $order->sales_type, $order->price_factor, $order->document_date)); @@ -205,11 +258,8 @@ function credit_edit_item_controls(&$order, $rowcounter, $line_no=-1) $_POST['Disc'] = percent_format($order->default_discount * 100); } - qty_cells(null, 'qty', $_POST['qty'], null, null, $dec); -// if ($order->trans_no!=0) { -// amount_cell($line_no==-1 ? 0 :$order->line_items[$line_no]->qty_done); -// } + label_cell($_POST['units']); amount_cells(null, 'price', null); small_amount_cells(null, 'Disc', percent_format(0), null, null, user_percent_dec()); @@ -218,14 +268,17 @@ function credit_edit_item_controls(&$order, $rowcounter, $line_no=-1) if ($id!=-1) { - edit_button_cell('UpdateItem', _("Update")); - edit_button_cell('CancelItemChanges', _("Cancel")); + edit_button_cell('UpdateItem', _("Update"), + _('Confirm changes')); + edit_button_cell('CancelItemChanges', _("Cancel"), + _('Cancel changes')); hidden('line_no', $line_no); set_focus('qty'); } else { - submit_cells('AddItem', _("Add Item"), "colspan=2"); + submit_cells('AddItem', _("Add Item"), "colspan=2", + _('Add new item to document'), true); } end_row(); @@ -236,8 +289,13 @@ function credit_edit_item_controls(&$order, $rowcounter, $line_no=-1) function credit_options_controls() { - global $table_style2; + global $table_style2, $Ajax; echo "
"; + +if (isset($_POST['_CreditType_update'])) + $Ajax->activate('options'); + + div_start('options'); start_table("$table_style2"); credit_type_list_row(_("Credit Note Type"), 'CreditType', null, true); @@ -249,7 +307,6 @@ function credit_options_controls() if (!isset($_POST['Location'])) $_POST['Location'] = $_SESSION['Items']->Location; locations_list_row(_("Items Returned to Location"), 'Location', $_POST['Location']); - } else { @@ -259,6 +316,7 @@ function credit_options_controls() textarea_row(_("Memo"), "CreditText", null, 51, 3); echo ""; + div_end(); } diff --git a/sales/includes/ui/sales_order_ui.inc b/sales/includes/ui/sales_order_ui.inc index fa628d91..f836a020 100644 --- a/sales/includes/ui/sales_order_ui.inc +++ b/sales/includes/ui/sales_order_ui.inc @@ -331,6 +331,7 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1) if(isset($_POST['_stock_id_update'])) { $Ajax->activate('price'); $Ajax->activate('units'); + $Ajax->activate('qty'); $Ajax->activate('line_total'); } @@ -371,7 +372,6 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1) _('Cancel changes')); hidden('LineNo', $line_no); set_focus('qty'); - $Ajax->addFocus(true, 'qty'); } else { diff --git a/sales/inquiry/customer_allocation_inquiry.php b/sales/inquiry/customer_allocation_inquiry.php index 700bb185..2770fb22 100644 --- a/sales/inquiry/customer_allocation_inquiry.php +++ b/sales/inquiry/customer_allocation_inquiry.php @@ -38,7 +38,7 @@ cust_allocations_list_cells(_("Type:"), 'filterType', null); check_cells(" " . _("show settled:"), 'showSettled', null); -submit_cells('Refresh Inquiry', _("Search")); +submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), true); set_global_customer($_POST['customer_id']); @@ -116,16 +116,19 @@ function get_transactions() $result = get_transactions(); -if (db_num_rows($result) == 0) +//------------------------------------------------------------------------------------------------ +if(get_post('RefreshInquiry')) { - display_note(_("The selected customer has no transactions for the given dates."), 1, 1); - end_page(); - exit; + $Ajax->activate('doc_tbl'); } - //------------------------------------------------------------------------------------------------ +div_start('doc_tbl'); +if (db_num_rows($result) == 0) +{ + display_note(_("The selected customer has no transactions for the given dates."), 1, 1); +} else { -start_table("$table_style width='80%'"); + start_table("$table_style width='80%'"); if ($_POST['customer_id'] == reserved_words::get_all()) $th = array(_("Type"), _("Number"), _("Reference"), _("Order"), _("Date"), _("Due Date"), @@ -214,11 +217,11 @@ while ($myrow = db_fetch($result)) //end of page full new headings if } //end of while loop - end_table(1); if ($over_due) display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'"); - +} +div_end(); end_page(); ?> diff --git a/sales/inquiry/customer_inquiry.php b/sales/inquiry/customer_inquiry.php index 1bffa40b..0524673d 100644 --- a/sales/inquiry/customer_inquiry.php +++ b/sales/inquiry/customer_inquiry.php @@ -41,7 +41,7 @@ if (!isset($_POST['filterType'])) cust_allocations_list_cells(null, 'filterType', $_POST['filterType'], true); -submit_cells('Refresh Inquiry', _("Search")); +submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), true); end_row(); end_table(); @@ -146,44 +146,51 @@ function get_transactions() } //------------------------------------------------------------------------------------------------ + +div_start('totals_tbl'); if ($_POST['customer_id'] != "" && $_POST['customer_id'] != reserved_words::get_all()) { $customer_record = get_customer_details($_POST['customer_id']); display_customer_summary($customer_record); echo "
"; } - +div_end(); //------------------------------------------------------------------------------------------------ $result = get_transactions(); -if (db_num_rows($result) == 0) +//------------------------------------------------------------------------------------------------ +if(get_post('RefreshInquiry')) { - display_note(_("The selected customer has no transactions for the given dates."), 0, 2); - end_page(); - exit; + $Ajax->activate('trans_tbl'); + $Ajax->activate('totals_tbl'); } - //------------------------------------------------------------------------------------------------ - print_hidden_script(10); -start_table("$table_style width='80%'"); + +div_start('trans_tbl'); +if (db_num_rows($result) == 0) +{ + display_note(_("The selected customer has no transactions for the given dates."), 0, 2); +} else { + + start_table("$table_style width='80%'"); $th = array(_("Type"), _("#"), _("Order"), _("Reference"), _("Date"), _("Due Date"), _("Customer"), _("Branch"), _("Currency"), _("Debit"), _("Credit"), "", "","",""); -if ($_POST['customer_id'] != reserved_words::get_all()) { - unset($th[6], $th[8]); -} + if ($_POST['customer_id'] != reserved_words::get_all()) { + unset($th[6], $th[8]); + } -table_header($th); + table_header($th); -$j = 1; -$k = 0; //row colour counter -$over_due = false; -while ($myrow = db_fetch($result)) -{ + $j = 1; + $k = 0; //row colour counter + $over_due = false; + while ($myrow = db_fetch($result)) + { if ($myrow['OverDue'] == 1) { @@ -269,19 +276,20 @@ while ($myrow = db_fetch($result)) label_cell(''); end_row(); - $j++; - if ($j == 12) - { - $j = 1; - table_header($th); - } //end of page full new headings if -} //end of transaction while loop - -end_table(1); + $j++; + if ($j == 12) + { + $j = 1; + table_header($th); + } //end of page full new headings if + } //end of transaction while loop -if ($over_due) - display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'"); + end_table(1); + if ($over_due) + display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'"); +} +div_end(); end_page(); ?> diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index 9aa99e20..4d850359 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -16,7 +16,6 @@ include_once($path_to_root . "/sales/includes/ui/sales_order_ui.inc"); include_once($path_to_root . "/sales/includes/sales_db.inc"); include_once($path_to_root . "/sales/includes/db/sales_types_db.inc"); include_once($path_to_root . "/reporting/includes/reporting.inc"); - $js = ''; if ($use_popup_windows) { @@ -189,7 +188,6 @@ function line_start_focus() { global $Ajax; $Ajax->activate('items_table'); - $Ajax->addFocus(true, '_stock_id_edit'); set_focus('_stock_id_edit'); } //-------------------------------------------------------------------------------- @@ -417,8 +415,6 @@ if (isset($_POST['CancelItemChanges']) || isset($_POST['UpdateItem'])) { line_start_focus(); } -if (isset($_POST['_customer_id_update'])) - set_focus('branch_id'); //-------------------------------------------------------------------------------- check_db_has_stock_items(_("There are no inventory items defined in the system."));