- if ($selected_account)
- update_gl_account($_POST['account_code'], $_POST['account_name'], $_POST['account_type'], $_POST['account_code2'], $_POST['tax_code']);
- else
- add_gl_account($_POST['account_code'], $_POST['account_name'], $_POST['account_type'], $_POST['account_code2'], $_POST['tax_code']);
- meta_forward($_SERVER['PHP_SELF']);
+
+ if (!isset($_POST['account_tags']))
+ $_POST['account_tags'] = array();
+
+ if ($selected_account)
+ {
+ if (get_post('inactive') == 1 && is_bank_account($_POST['account_code']))
+ {
+ display_error(_("The account belongs to a bank account and cannot be inactivated."));
+ }
+ elseif (update_gl_account($_POST['account_code'], $_POST['account_name'],
+ $_POST['account_type'], $_POST['account_code2'])) {
+ update_record_status($_POST['account_code'], $_POST['inactive'],
+ 'chart_master', 'account_code');
+ update_tag_associations(TAG_ACCOUNT, $_POST['account_code'],
+ $_POST['account_tags']);
+ $Ajax->activate('account_code'); // in case of status change
+ display_notification(_("Account data has been updated."));
+ }
+ }
+ else
+ {
+ if (add_gl_account($_POST['account_code'], $_POST['account_name'],
+ $_POST['account_type'], $_POST['account_code2']))
+ {
+ add_tag_associations($_POST['account_code'], $_POST['account_tags']);
+ display_notification(_("New account has been added."));
+ $selected_account = $_POST['AccountList'] = $_POST['account_code'];
+ }
+ else
+ display_error(_("Account not added, possible duplicate Account Code."));
+ }
+ $Ajax->activate('_page_body');