Hello and welcome,
Yes, there's an option to add that.
The recommended way to handle that is:
Step 1. Have a custom module that you use to modify epesi functionality (tutorial)
Step 2. In that module installation, set QFfield callback for Tax ID field:
Utils_RecordBrowserCommon::set_QFfield_callback('company', 'Tax ID', array('YourModuleCommon', 'tax_id_QFfield'));
Step 3. Example code for tax_id_QFfield:
public static function tax_id_QFfield(&$form, $field, $label, $mode, $default, $desc, $rb_obj = null) {
if ($mode=='add' || $mode=='edit') {
$form->addElement('text', $field, $label);
if ($mode=='edit') $form->setDefaults(array($field=>$default));
$form->addFormRule(array('YourModuleCommon', 'check_tax_id_unique'));
} else {
$form->addElement('static', $field, $label, $default);
}
}
Note that
$form->addFormRule(array('YourModuleCommon', 'check_tax_id_unique'));
call here. This is where you will check for Tax ID duplicates.
Step 4. Create check_tax_id_unique method and check for Tax ID duplicates there.
The method takes one argument containing QuickForm data and should return either true (if there are no errors to report) or an array where key is field name and value is error message to be displayed.
Simply get all the companies with given tax ID:
$recs = CRM_ContactsCommon::get_companies(array('tax_id'=>$data['tax_id']));
And if it's not empty, return QFerror:
if (!empty($recs)) return array('tax_id'=>Base_LangCommon::ts('YourModule','Duplicate Tax ID found!'));
With some tweaking you can also create a link to the record containing that Tax ID.
Some notes on this solution:
- If you want to add this feature quickly and you don't mind making changes after every epesi update, you can add Form Rule in any QFfield directly in ContactsCommon and add method checking for duplicates also there. That skips steps 1-3. It is not a recommended solution.
- This is not a check on DB transaction-level. With this solution there's a chance two companies will end up with the same Tax ID if they are being input at the exact same time. However, given the nature of the field this solution will suffice.
- In many cases, when comparing strings, you will want to use case-insensitive check. To do that, simply replace crits in point 4 with
array('~"tax_id'=>DB::Concat(DB::qstr('%'),DB::qstr($data['tax_id']),DB::qstr('%')))
Kind regards,
Arek