Direct posting to GL accountswith more than one related tax type forbidden.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 20 Jun 2009 12:14:59 +0000 (12:14 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 20 Jun 2009 12:14:59 +0000 (12:14 +0000)
gl/gl_journal.php
includes/ui/ui_view.inc
purchasing/supplier_credit.php
purchasing/supplier_invoice.php
taxes/db/tax_types_db.inc
taxes/tax_types.php

index 8d2853348a85e80cc339dbb635c7f78a77e15a83..77ba76b4ee1b4ba7761f90cf1264bf8772dd2fdf 100644 (file)
@@ -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'])) 
        {
index e978b36d9b9564a931ad25a1cb14989915d00977..df4a2bddbb98fe668cf63f1fe6fa19fc3995dbcf 100644 (file)
@@ -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'], 
index fc16875ce1b1214053447a7cdc30d8ad56c7ac94..bc60f4de4a92e4b089bace07d72bc3b61d52d478 100644 (file)
@@ -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,
index fa379e903e65365943143fde506e7c0b36c398c9..b1bd2ece237921d589dd3402bdb57646c2a927c8 100644 (file)
@@ -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,
index 97a623290a272e0360390e4fe4895c666c65e8eb..672a4e3613a53a327eeb32e4e64edc83fb7b74b7 100644 (file)
@@ -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
index c6860daa3b412dfd6fdbaace746fd7a34cb53f97..20369be770dfdd5bc06a8bae6d672822393a5c98 100644 (file)
@@ -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 (%)"),