diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 411efc5ae93..055432dc76c 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -167,6 +167,7 @@ if (empty($reshook)) { $result = $object->update($object->id, $user, 1, 1, 0); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + $_GET['action'] = 'editcustomeraccountancycode'; } } diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index 8ad44d198a8..27493417312 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -103,6 +103,7 @@ if (empty($reshook)) { $result = $object->update($object->id, $user, 1, 0, 1); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + $_GET['action'] = 'editsupplieraccountancycode'; } } // terms of the settlement diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 52d9b19bfaf..e8e10008fae 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1762,7 +1762,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'; @@ -1791,6 +1791,54 @@ 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 60b2b424aaa..e12751834eb 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -31,6 +31,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 2fb9285379f..870c8dd96b1 100644 --- a/htdocs/societe/admin/societe.php +++ b/htdocs/societe/admin/societe.php @@ -672,6 +672,10 @@ $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'); +$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) { @@ -724,23 +728,6 @@ foreach ($profid as $key => $val) { $i++; } -if ($conf->accounting->enabled) { - print '