FIX check mandatory thirdparty fields for mass action

This commit is contained in:
lvessiller 2022-03-08 11:29:01 +01:00
parent d13ae9f721
commit 397776d4a4
2 changed files with 41 additions and 40 deletions

View File

@ -566,45 +566,6 @@ if (empty($reshook))
// Check parameters
// Check for mandatory fields in thirdparty (defined into setup)
$array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL');
foreach ($array_to_check as $key)
{
$keymin = strtolower($key);
$i = (int) preg_replace('/[^0-9]/', '', $key);
$vallabel = $object->thirdparty->$keymin;
if ($i > 0)
{
if ($object->thirdparty->isACompany())
{
// Check for mandatory prof id (but only if country is other than ours)
if ($mysoc->country_id > 0 && $object->thirdparty->country_id == $mysoc->country_id)
{
$idprof_mandatory = 'SOCIETE_'.$key.'_INVOICE_MANDATORY';
if (!$vallabel && !empty($conf->global->$idprof_mandatory))
{
$langs->load("errors");
$error++;
setEventMessages($langs->trans('ErrorProdIdIsMandatory', $langs->transcountry('ProfId'.$i, $object->thirdparty->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')', null, 'errors');
}
}
}
} else {
//var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
if ($key == 'EMAIL')
{
// Check for mandatory
if (!empty($conf->global->SOCIETE_EMAIL_INVOICE_MANDATORY) && !isValidEMail($object->thirdparty->email))
{
$langs->load("errors");
$error++;
setEventMessages($langs->trans("ErrorBadEMail", $object->thirdparty->email).' ('.$langs->trans("ForbiddenBySetupRules").')', null, 'errors');
}
}
}
}
// Check for mandatory fields in invoice
$array_to_check = array('REF_CUSTOMER'=>'RefCustomer');
foreach ($array_to_check as $key => $val)

View File

@ -2470,7 +2470,7 @@ class Facture extends CommonInvoice
*/
public function validate($user, $force_number = '', $idwarehouse = 0, $notrigger = 0, $batch_rule = 0)
{
global $conf, $langs;
global $conf, $langs, $mysoc;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$productStatic = null;
@ -2512,6 +2512,46 @@ class Facture extends CommonInvoice
return -1;
}
// Check for mandatory fields in thirdparty (defined into setup)
$array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL');
foreach ($array_to_check as $key)
{
$keymin = strtolower($key);
$i = (int) preg_replace('/[^0-9]/', '', $key);
$vallabel = $this->thirdparty->$keymin;
if ($i > 0)
{
if ($this->thirdparty->isACompany())
{
// Check for mandatory prof id (but only if country is other than ours)
if ($mysoc->country_id > 0 && $this->thirdparty->country_id == $mysoc->country_id)
{
$idprof_mandatory = 'SOCIETE_'.$key.'_INVOICE_MANDATORY';
if (!$vallabel && !empty($conf->global->$idprof_mandatory))
{
$langs->load("errors");
$this->error = $langs->trans('ErrorProdIdIsMandatory', $langs->transcountry('ProfId'.$i, $this->thirdparty->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')'.' ['.$langs->trans('Company').' : '.$this->thirdparty->name.']';
dol_syslog(__METHOD__.' '.$this->error, LOG_ERR);
return -1;
}
}
}
} else {
if ($key == 'EMAIL')
{
// Check for mandatory
if (!empty($conf->global->SOCIETE_EMAIL_INVOICE_MANDATORY) && !isValidEMail($this->thirdparty->email))
{
$langs->load("errors");
$this->error = $langs->trans("ErrorBadEMail", $this->thirdparty->email).' ('.$langs->trans("ForbiddenBySetupRules").')'.' ['.$langs->trans('Company').' : '.$this->thirdparty->name.']';
dol_syslog(__METHOD__.' '.$this->error, LOG_ERR);
return -1;
}
}
}
}
$this->db->begin();
// Check parameters