$input_error = 1;
}
-
if (!is_date($_POST['date_']))
{
display_error(_("The entered date is invalid."));
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']))
{
$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'],
}
}
+ 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,
}
}
+ 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,
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);
}
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
function can_process()
{
+ global $selected_id;
+
if (strlen($_POST['name']) == 0)
{
display_error(_("The tax type name cannot be empty."));
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;
}
$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 (%)"),