From: Janusz Dobrowolski Date: Fri, 26 Jul 2019 13:29:43 +0000 (+0200) Subject: Budget Entry: ajax page reload on params change, added atomic functions for budget... X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=5a7ef37131354aabdcf04c639a903e5876b743e4;p=fa-stable.git Budget Entry: ajax page reload on params change, added atomic functions for budget update/delete. --- diff --git a/gl/gl_budget.php b/gl/gl_budget.php index 6c2ad64b..949d7fd5 100644 --- a/gl/gl_budget.php +++ b/gl/gl_budget.php @@ -29,26 +29,27 @@ check_db_has_gl_account_groups(_("There are no account groups defined. Please de if (isset($_POST['add']) || isset($_POST['delete'])) { - begin_transaction(); - for ($i = 0, $da = $_POST['begin']; date1_greater_date2($_POST['end'], $da); $i++) - { - if (isset($_POST['add'])) - add_update_gl_budget_trans($da, $_POST['account'], $_POST['dim1'], $_POST['dim2'], input_num('amount'.$i)); - else - delete_gl_budget_trans($da, $_POST['account'], $_POST['dim1'], $_POST['dim2']); + $amounts = array(); + for ($i = 0, $da = $_POST['begin']; date1_greater_date2($_POST['end'], $da); $i++) { + $amounts[$da] = input_num('amount'.$i); $da = add_months($da, 1); } - commit_transaction(); + if (isset($_POST['add'])) { - if (isset($_POST['add'])) + add_budget($_POST['account'], $_POST['dim1'], $_POST['dim2'], $amounts); display_notification_centered(_("The Budget has been saved.")); - else + + } else { + + delete_budget($_POST['account'], $_POST['dim1'], $_POST['dim2'], array_keys($amounts)); display_notification_centered(_("The Budget has been deleted.")); + } + $Ajax->activate('budget_tbl'); } -if (isset($_POST['submit']) || isset($_POST['update'])) +if (isset($_POST['submit']) || isset($_POST['update']) || list_updated('fyear') || list_updated('account')) $Ajax->activate('budget_tbl'); //------------------------------------------------------------------------------------- @@ -59,20 +60,20 @@ if (db_has_gl_accounts()) { $dim = get_company_pref('use_dimension'); start_table(TABLESTYLE2); - fiscalyears_list_row(_("Fiscal Year:"), 'fyear', null); - gl_all_accounts_list_row(_("Account Code:"), 'account', null); + fiscalyears_list_row(_("Fiscal Year:"), 'fyear', null, true); + gl_all_accounts_list_row(_("Account Code:"), 'account', null, true, false, false, true); if (!isset($_POST['dim1'])) $_POST['dim1'] = 0; if (!isset($_POST['dim2'])) $_POST['dim2'] = 0; if ($dim == 2) { - dimensions_list_row(_("Dimension")." 1", 'dim1', $_POST['dim1'], true, null, false, 1); - dimensions_list_row(_("Dimension")." 2", 'dim2', $_POST['dim2'], true, null, false, 2); + dimensions_list_row(_("Dimension")." 1", 'dim1', $_POST['dim1'], true, null, false, 1, true); + dimensions_list_row(_("Dimension")." 2", 'dim2', $_POST['dim2'], true, null, false, 2, true); } elseif ($dim == 1) { - dimensions_list_row(_("Dimension"), 'dim1', $_POST['dim1'], true, null, false, 1); + dimensions_list_row(_("Dimension"), 'dim1', $_POST['dim1'], true, null, false, 1, true); hidden('dim2', 0); } else diff --git a/gl/includes/gl_db.inc b/gl/includes/gl_db.inc index 2577ecc3..951af9ee 100644 --- a/gl/includes/gl_db.inc +++ b/gl/includes/gl_db.inc @@ -21,3 +21,23 @@ include_once($path_to_root . "/gl/includes/db/gl_db_rates.inc"); include_once($path_to_root . "/gl/includes/db/gl_db_accounts.inc"); include_once($path_to_root . "/gl/includes/db/gl_db_account_types.inc"); //-------------------------------------------------------------------------------- + +function add_budget($account, $dim1, $dim2, $amounts) +{ + begin_transaction(); + + foreach($amounts as $date => $amount) { + add_update_gl_budget_trans($date, $account, $dim1, $dim2, $amount); + } + commit_transaction(); +} + +function delete_budget($account, $dim1, $dim2, $dates) +{ + begin_transaction(); + + foreach($amounts as $date) { + delete_gl_budget_trans($date, $account, $dim1, $dim2); + } + commit_transaction(); +} diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 58a2bae2..b803ac32 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -761,19 +761,19 @@ function _format_fiscalyears($row) . "  " . ($row[3] ? _('Closed') : _('Active')); } -function fiscalyears_list_cells($label, $name, $selected_id=null) +function fiscalyears_list_cells($label, $name, $selected_id=null, $submit_on_change=false) { if ($label != null) echo "$label\n"; echo ""; - echo fiscalyears_list($name, $selected_id); + echo fiscalyears_list($name, $selected_id, $submit_on_change); echo "\n"; } -function fiscalyears_list_row($label, $name, $selected_id=null) +function fiscalyears_list_row($label, $name, $selected_id=null, $submit_on_change=false) { echo "$label"; - fiscalyears_list_cells(null, $name, $selected_id); + fiscalyears_list_cells(null, $name, $selected_id, $submit_on_change); echo "\n"; } //------------------------------------------------------------------------------------ @@ -1907,11 +1907,11 @@ function gl_all_accounts_list_cells($label, $name, $selected_id=null, } function gl_all_accounts_list_row($label, $name, $selected_id=null, - $skip_bank_accounts=false, $cells=false, $all_option=false, $type_id=false) + $skip_bank_accounts=false, $cells=false, $all_option=false, $submit_on_change=false, $all=false, $type_id=false) { echo "$label"; gl_all_accounts_list_cells(null, $name, $selected_id, - $skip_bank_accounts, $cells, $all_option, $type_id); + $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all, $type_id); echo "\n"; }