diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index ea7c3342663..c70c9fc1354 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -166,6 +166,7 @@ if (empty($reshook)) { $result = $object->update($object->id, $user, 1, 1, 0); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + $action = 'editcustomeraccountancycode'; } } diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index dfd7d20248e..a5185f50acc 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -108,6 +108,7 @@ if (empty($reshook)) { $result = $object->update($object->id, $user, 1, 0, 1); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + $action = 'editsupplieraccountancycode'; } } // Set vat number accounting account diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 8cc3497e41d..597e3d668e6 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1770,7 +1770,7 @@ class FactureFournisseur extends CommonInvoice */ public function validate($user, $force_number = '', $idwarehouse = 0, $notrigger = 0) { - global $conf, $langs; + global $mysoc, $conf, $langs; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -1799,6 +1799,53 @@ class FactureFournisseur extends CommonInvoice return -1; } + // Check for mandatory fields in thirdparty (defined into setup) + if (!empty($this->thirdparty) && is_object($this->thirdparty)) { + $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL', 'ACCOUNTANCY_CODE_SUPPLIER'); + foreach ($array_to_check as $key) { + $keymin = strtolower($key); + if ($keymin == 'accountancy_code_supplier') $keymin = 'code_compta_fournisseur'; + if (!property_exists($this->thirdparty, $keymin)) { + continue; + } + $vallabel = $this->thirdparty->$keymin; + + $i = (int) preg_replace('/[^0-9]/', '', $key); + 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; + } + } elseif ($key == 'ACCOUNTANCY_CODE_SUPPLIER') { + // Check for mandatory + if (!empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_INVOICE_MANDATORY) && empty($this->thirdparty->code_compta_fournisseur)) { + $langs->load("errors"); + $this->error = $langs->trans("ErrorAccountancyCodeSupplierIsMandatory", $this->thirdparty->name).' ('.$langs->trans("ForbiddenBySetupRules").')'; + dol_syslog(__METHOD__.' '.$this->error, LOG_ERR); + return -1; + } + } + } + } + } + $this->db->begin(); // Define new ref diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 10ed321688c..173e9bcff62 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -32,6 +32,7 @@ ErrorBadThirdPartyName=Bad value for third-party name ForbiddenBySetupRules=Forbidden by setup rules ErrorProdIdIsMandatory=The %s is mandatory ErrorAccountancyCodeCustomerIsMandatory=The accountancy code of customer %s is mandatory +ErrorAccountancyCodeSupplierIsMandatory=The accountancy code of supplier %s is mandatory ErrorBadCustomerCodeSyntax=Bad syntax for customer code ErrorBadBarCodeSyntax=Bad syntax for barcode. May be you set a bad barcode type or you defined a barcode mask for numbering that does not match value scanned. ErrorCustomerCodeRequired=Customer code required diff --git a/htdocs/societe/admin/societe.php b/htdocs/societe/admin/societe.php index 76cc8a60831..16102685e3e 100644 --- a/htdocs/societe/admin/societe.php +++ b/htdocs/societe/admin/societe.php @@ -676,6 +676,12 @@ $profid['IDPROF6'][0] = $langs->trans("ProfId6"); $profid['IDPROF6'][1] = $langs->transcountry('ProfId6', $mysoc->country_code); $profid['EMAIL'][0] = $langs->trans("EMail"); $profid['EMAIL'][1] = $langs->trans('Email'); +if (isModEnabled('accounting')) { + $profid['ACCOUNTANCY_CODE_CUSTOMER'][0] = $langs->trans("CustomerAccountancyCodeShort"); + $profid['ACCOUNTANCY_CODE_CUSTOMER'][1] = $langs->trans('CustomerAccountancyCodeShort'); + $profid['ACCOUNTANCY_CODE_SUPPLIER'][0] = $langs->trans("SupplierAccountancyCodeShort"); + $profid['ACCOUNTANCY_CODE_SUPPLIER'][1] = $langs->trans('SupplierAccountancyCodeShort'); +} $nbofloop = count($profid); foreach ($profid as $key => $val) { @@ -728,23 +734,6 @@ foreach ($profid as $key => $val) { $i++; } -if (isModEnabled('accounting')) { - print '