X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=gl%2Fmanage%2Fbank_accounts.php;h=9dda5cd367a1c4e452cfc600226feebd9ff620f8;hb=4c09b19388f22b15edee7024a392055418275188;hp=97a5dbba252aad596f8e5a37efe76245860f0d9a;hpb=1aba32cffc99e8e44ff80534384a8253cc044000;p=fa-stable.git diff --git a/gl/manage/bank_accounts.php b/gl/manage/bank_accounts.php index 97a5dbba..9dda5cd3 100644 --- a/gl/manage/bank_accounts.php +++ b/gl/manage/bank_accounts.php @@ -25,28 +25,20 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') //initialise no input errors assumed initially before we test $input_error = 0; - $curr = get_company_currency(); - if ($curr != $_POST['BankAccountCurrency']) - { - $sql = "SELECT account_code FROM ".TB_PREF."bank_accounts - WHERE account_code = '".$_POST['account_code']."' - AND id <> $selected_id"; - $result = db_query($sql,"could not get bank accounts"); - if (db_num_rows($result) > 0) - { - $input_error = 1; - display_error(_("The GL account is already in use.")); - set_focus('account_code'); - } - } + //first off validate inputs sensible - if ($input_error == 0 && strlen($_POST['bank_account_name']) == 0) + if (strlen($_POST['bank_account_name']) == 0) { $input_error = 1; display_error(_("The bank account name cannot be empty.")); set_focus('bank_account_name'); } - + if ($Mode=='ADD_ITEM' && (gl_account_in_bank_accounts(get_post('account_code')) + || key_in_foreign_table(get_post('account_code'), 'gl_trans', 'account'))) { + $input_error = 1; + display_error(_("The GL account selected is already in use. Select another GL account.")); + set_focus('account_code'); + } if ($input_error != 1) { if ($selected_id != -1) @@ -76,21 +68,15 @@ elseif( $Mode == 'Delete') //the link to delete a selected record was clicked instead of the submit button $cancel_delete = 0; - $acc = db_escape($selected_id); // PREVENT DELETES IF DEPENDENT RECORDS IN 'bank_trans' - $sql= "SELECT COUNT(*) FROM ".TB_PREF."bank_trans WHERE bank_act=$acc"; - $result = db_query($sql,"check failed"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if (key_in_foreign_table($selected_id, 'bank_trans', 'bank_act') || key_in_foreign_table(get_post('account_code'), 'gl_trans', 'account')) { $cancel_delete = 1; display_error(_("Cannot delete this bank account because transactions have been created using this account.")); } - $sql= "SELECT COUNT(*) FROM ".TB_PREF."sales_pos WHERE pos_account=$acc"; - $result = db_query($sql,"check failed"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + + if (key_in_foreign_table($selected_id, 'sales_pos', 'pos_account')) { $cancel_delete = 1; display_error(_("Cannot delete this bank account because POS definitions have been created using this account.")); @@ -112,18 +98,10 @@ if ($Mode == 'RESET') /* Always show the list of accounts */ -$sql = "SELECT account.*, gl_account.account_name - FROM ".TB_PREF."bank_accounts account, ".TB_PREF."chart_master gl_account - WHERE account.account_code = gl_account.account_code"; -if (!check_value('show_inactive')) $sql .= " AND !account.inactive"; -$sql .= " ORDER BY account_code, bank_curr_code"; - -$result = db_query($sql,"could not get bank accounts"); - -check_db_error("The bank accounts set up could not be retreived", $sql); +$result = get_bank_accounts(check_value('show_inactive')); start_form(); -start_table("$table_style width='80%'"); +start_table(TABLESTYLE, "width='80%'"); $th = array(_("Account Name"), _("Type"), _("Currency"), _("GL Account"), _("Bank"), _("Number"), _("Bank Address"), _("Dflt"), '',''); @@ -157,11 +135,11 @@ while ($myrow = db_fetch($result)) inactive_control_row($th); end_table(1); -$is_editing = $selected_id != -1; +$is_used = $selected_id != -1 && key_in_foreign_table($selected_id, 'bank_trans', 'bank_act'); -start_table($table_style2); +start_table(TABLESTYLE2); -if ($is_editing) +if ($selected_id != -1) { if ($Mode == 'Edit') { $myrow = get_bank_account($selected_id); @@ -184,7 +162,7 @@ if ($is_editing) text_row(_("Bank Account Name:"), 'bank_account_name', null, 50, 100); -if ($is_editing) +if ($is_used) { label_row(_("Account Type:"), $bank_account_types[$_POST['account_type']]); } @@ -192,7 +170,7 @@ else { bank_account_types_list_row(_("Account Type:"), 'account_type', null); } -if ($is_editing) +if ($is_used) { label_row(_("Bank Account Currency:"), $_POST['BankAccountCurrency']); } @@ -203,10 +181,9 @@ else yesno_list_row(_("Default currency account:"), 'dflt_curr_act'); -$curr = get_company_currency(); -if ($is_editing && $curr == $_POST['BankAccountCurrency']) +if($is_used) label_row(_("Bank Account GL Code:"), $_POST['account_code']); -else +else gl_all_accounts_list_row(_("Bank Account GL Code:"), 'account_code', null); text_row(_("Bank Name:"), 'bank_name', null, 50, 60);