From: Janusz Dobrowolski Date: Sat, 20 Jun 2009 12:14:59 +0000 (+0000) Subject: Direct posting to GL accountswith more than one related tax type forbidden. X-Git-Tag: 2.3-final~1198 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=93a920d7c98e55be77d2ea84e6c457f681b7a4e4;hp=47e386676320471986d462929c707552f0ab7362;p=fa-stable.git Direct posting to GL accountswith more than one related tax type forbidden. --- diff --git a/gl/gl_journal.php b/gl/gl_journal.php index 8d285334..77ba76b4 100644 --- a/gl/gl_journal.php +++ b/gl/gl_journal.php @@ -91,7 +91,6 @@ if (isset($_POST['Process'])) $input_error = 1; } - if (!is_date($_POST['date_'])) { display_error(_("The entered date is invalid.")); @@ -169,7 +168,12 @@ function check_item_data() set_focus('AmountCredit'); return false; } - + + if (!is_tax_gl_unique(get_post('code_id'))) { + display_error(_("Cannot post to GL account used by more than one tax type.")); + set_focus('code_id'); + return false; + } if ($_SESSION["wa_current_user"]->access != 2 && is_bank_account($_POST['code_id'])) { diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index e978b36d..df4a2bdd 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -608,6 +608,11 @@ function display_quick_entries(&$cart, $id, $base, $type, $descr='') $gl_code = ($type == QE_DEPOSIT || ($type == QE_JOURNAL && $base < 0)) ? $item_tax['sales_gl_code'] : $item_tax['purchasing_gl_code']; $tax_total += $tax; + if ($tax==0) continue; + if (!is_tax_gl_unique($gl_code)) { + display_error(_("Cannot post to GL account used by more than one tax type.")); + break 3; + } if ($type != QE_SUPPINV) $cart->add_gl_item($gl_code, $qe_line['dimension_id'], $qe_line['dimension2_id'], diff --git a/purchasing/supplier_credit.php b/purchasing/supplier_credit.php index fc16875c..bc60f4de 100644 --- a/purchasing/supplier_credit.php +++ b/purchasing/supplier_credit.php @@ -130,6 +130,12 @@ if (isset($_POST['AddGLCodeToTrans'])){ } } + if (!is_tax_gl_unique(get_post('gl_code'))) { + display_error(_("Cannot post to GL account used by more than one tax type.")); + set_focus('gl_code'); + $input_error = true; + } + if ($input_error == false) { $_SESSION['supp_trans']->add_gl_codes_to_trans($_POST['gl_code'], $gl_act_name, diff --git a/purchasing/supplier_invoice.php b/purchasing/supplier_invoice.php index fa379e90..b1bd2ece 100644 --- a/purchasing/supplier_invoice.php +++ b/purchasing/supplier_invoice.php @@ -130,6 +130,12 @@ if (isset($_POST['AddGLCodeToTrans'])){ } } + if (!is_tax_gl_unique(get_post('gl_code'))) { + display_error(_("Cannot post to GL account used by more than one tax type.")); + set_focus('gl_code'); + $input_error = true; + } + if ($input_error == false) { $_SESSION['supp_trans']->add_gl_codes_to_trans($_POST['gl_code'], $gl_act_name, diff --git a/taxes/db/tax_types_db.inc b/taxes/db/tax_types_db.inc index 97a62329..672a4e36 100644 --- a/taxes/db/tax_types_db.inc +++ b/taxes/db/tax_types_db.inc @@ -60,7 +60,6 @@ function get_tax_type($type_id) AND ".TB_PREF."tax_types.purchasing_gl_code = Chart2.account_code AND id=$type_id"; $result = db_query($sql, "could not get tax type"); - return db_fetch($result); } @@ -90,4 +89,27 @@ function delete_tax_type($type_id) commit_transaction(); } +/* + Check if gl_code is used by more than 2 tax types, + or check if the two gl codes are not used by any other + than selected tax type. + Necessary for pre-2.2 installations. +*/ +function is_tax_gl_unique($gl_code, $gl_code2=-1, $selected_id=-1) { + + $purch_code = $gl_code2== -1 ? $gl_code : $gl_code2; + + $sql = "SELECT count(*) FROM " + .TB_PREF."tax_types + WHERE (sales_gl_code=" .db_escape($gl_code) + ." OR purchasing_gl_code=" .db_escape($purch_code). ")"; + + if ($selected_id != -1) + $sql .= " AND id!=".db_escape($selected_id); + + $res = db_query($sql, "could not query gl account uniqueness"); + $row = db_fetch($res); + + return $gl_code2 == -1 ? ($row[0] <= 1) : ($row[0] == 0); +} ?> \ No newline at end of file diff --git a/taxes/tax_types.php b/taxes/tax_types.php index c6860daa..20369be7 100644 --- a/taxes/tax_types.php +++ b/taxes/tax_types.php @@ -23,6 +23,8 @@ simple_page_mode(true); function can_process() { + global $selected_id; + if (strlen($_POST['name']) == 0) { display_error(_("The tax type name cannot be empty.")); @@ -36,6 +38,11 @@ function can_process() return false; } + if (!is_tax_gl_unique(get_post('sales_gl_code', 'purchasing_gl_code', $selected_id))) { + display_error( _("Selected GL Accounts cannot be used by another tax type.")); + set_focus('sales_gl_code'); + return false; + } return true; } @@ -102,6 +109,8 @@ if ($Mode == 'RESET') $result = get_all_tax_types(); start_form(); + +display_note(_("To avoid problems with manual journal entry all tax types should have unique Sales/Purchasing GL accounts.")); start_table($table_style); $th = array(_("Description"), _("Default Rate (%)"),