{
if ($selected_id == -1)
return false;
- $sql = "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE tax_group_id=".db_escape($selected_id);
- $result = db_query($sql, "could not query customers");
- $myrow = db_fetch_row($result);
- if ($myrow[0] > 0)
+ if (key_in_foreign_table($selected_id, 'cust_branch', 'tax_group_id'))
{
- display_note(_("Cannot delete this tax group because customer branches been created referring to it."));
+ display_error(_("Cannot delete this tax group because customer branches been created referring to it."));
return false;
}
- $sql = "SELECT COUNT(*) FROM ".TB_PREF."suppliers WHERE tax_group_id=".db_escape($selected_id);
- $result = db_query($sql, "could not query suppliers");
- $myrow = db_fetch_row($result);
- if ($myrow[0] > 0)
+ if (key_in_foreign_table($selected_id, 'suppliers', 'tax_group_id'))
{
- display_note(_("Cannot delete this tax group because suppliers been created referring to it."));
+ display_error(_("Cannot delete this tax group because suppliers been created referring to it."));
return false;
}