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');
//-------------------------------------------------------------------------------------
{
$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
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();
+}
. " " . ($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 "<td>$label</td>\n";
echo "<td>";
- echo fiscalyears_list($name, $selected_id);
+ echo fiscalyears_list($name, $selected_id, $submit_on_change);
echo "</td>\n";
}
-function fiscalyears_list_row($label, $name, $selected_id=null)
+function fiscalyears_list_row($label, $name, $selected_id=null, $submit_on_change=false)
{
echo "<tr><td class='label'>$label</td>";
- fiscalyears_list_cells(null, $name, $selected_id);
+ fiscalyears_list_cells(null, $name, $selected_id, $submit_on_change);
echo "</tr>\n";
}
//------------------------------------------------------------------------------------
}
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 "<tr><td class='label'>$label</td>";
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 "</tr>\n";
}