From 32f3a2aff642e39f4334b097ddc73271d79ca211 Mon Sep 17 00:00:00 2001 From: kamel Date: Fri, 13 May 2022 10:45:18 +0200 Subject: [PATCH 1/3] NEW - Add all id prof checker on thirdparty for code compta customer and supplier --- htdocs/comm/card.php | 1 + htdocs/fourn/card.php | 1 + .../fourn/class/fournisseur.facture.class.php | 50 ++++++++++++++++++- htdocs/langs/en_US/errors.lang | 1 + htdocs/societe/admin/societe.php | 21 ++------ htdocs/societe/class/societe.class.php | 44 ++++++++++++++-- 6 files changed, 96 insertions(+), 22 deletions(-) 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 ''; - print ''.$langs->trans('CustomerAccountancyCodeShort')."\n"; - print ''; - - if (!empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_INVOICE_MANDATORY)) { - print ''; - print img_picto($langs->trans("Activated"), 'switch_on'); - print ''; - } else { - print ''; - print img_picto($langs->trans("Disabled"), 'switch_off'); - print ''; - } - print "\n"; -} - print "\n"; print ''; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 1d32063c27b..7c35e84a3e2 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1152,9 +1152,11 @@ class Societe extends CommonObject } // Check for duplicate or mandatory fields defined into setup - $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL'); + $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL', 'ACCOUNTANCY_CODE_CUSTOMER', 'ACCOUNTANCY_CODE_SUPPLIER'); foreach ($array_to_check as $key) { $keymin = strtolower($key); + if ($key == 'ACCOUNTANCY_CODE_CUSTOMER') $keymin = 'code_compta'; + elseif ($key == 'ACCOUNTANCY_CODE_SUPPLIER') $keymin = 'code_compta_fournisseur'; $i = (int) preg_replace('/[^0-9]/', '', $key); $vallabel = $this->$keymin; @@ -1198,6 +1200,40 @@ class Societe extends CommonObject } } } + elseif ($key == 'ACCOUNTANCY_CODE_CUSTOMER' && ! empty($this->client)) { + // Check for unicity + if ($vallabel && !empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_UNIQUE)) { + if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { + $langs->loadLangs(array("errors", 'compta')); + $error++; + $this->errors[] = $langs->trans('CustomerAccountancyCodeShort') . " " . $langs->trans("ErrorProdIdAlreadyExist", $vallabel) . ' (' . $langs->trans("ForbiddenBySetupRules") . ')'; + } + } + + // Check for mandatory + if (!empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_MANDATORY) && (!isset($vallabel) || trim($vallabel) === '')) { + $langs->loadLangs(array("errors", 'compta')); + $error++; + $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv('CustomerAccountancyCodeShort')) . ' (' . $langs->trans("ForbiddenBySetupRules") . ')'; + } + } + elseif ($key == 'ACCOUNTANCY_CODE_SUPPLIER' && ! empty($this->fournisseur)) { + // Check for unicity + if ($vallabel && !empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_UNIQUE)) { + if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { + $langs->loadLangs(array("errors", 'compta')); + $error++; + $this->errors[] = $langs->trans('SupplierAccountancyCodeShort') . " " . $langs->trans("ErrorProdIdAlreadyExist", $vallabel) . ' (' . $langs->trans("ForbiddenBySetupRules") . ')'; + } + } + + // Check for mandatory + if (!empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_MANDATORY) && (!isset($vallabel) || trim($vallabel) === '')) { + $langs->loadLangs(array("errors", 'compta')); + $error++; + $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv('SupplierAccountancyCodeShort')) . ' (' . $langs->trans("ForbiddenBySetupRules") . ')'; + } + } } } @@ -3359,18 +3395,18 @@ class Societe extends CommonObject global $conf; if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) { + $module=$conf->global->SOCIETE_CODECOMPTA_ADDON; $res = false; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); foreach ($dirsociete as $dirroot) { - $res = dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php'); + $res = dol_include_once($dirroot.$module.'.php'); if ($res) { break; } } if ($res) { - $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON; - $mod = new $classname; + $mod = new $module(); // Set code count in $mod->code $result = $mod->get_code($this->db, $this, $type); From 23fe8bef37ab7024611756607c526000ac83db97 Mon Sep 17 00:00:00 2001 From: kamel Date: Fri, 13 May 2022 10:53:00 +0200 Subject: [PATCH 2/3] Correction Stickler CI --- htdocs/fourn/class/fournisseur.facture.class.php | 3 +-- htdocs/societe/class/societe.class.php | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index e8e10008fae..5aea9b9e278 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1825,8 +1825,7 @@ class FactureFournisseur extends CommonInvoice dol_syslog(__METHOD__.' '.$this->error, LOG_ERR); return -1; } - } - elseif ($key == 'ACCOUNTANCY_CODE_SUPPLIER') { + } 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"); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 7c35e84a3e2..8ec94cd4471 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1199,8 +1199,7 @@ class Societe extends CommonObject $error++; $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')'; } } - } - elseif ($key == 'ACCOUNTANCY_CODE_CUSTOMER' && ! empty($this->client)) { + } elseif ($key == 'ACCOUNTANCY_CODE_CUSTOMER' && !empty($this->client)) { // Check for unicity if ($vallabel && !empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_UNIQUE)) { if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { @@ -1216,8 +1215,7 @@ class Societe extends CommonObject $error++; $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv('CustomerAccountancyCodeShort')) . ' (' . $langs->trans("ForbiddenBySetupRules") . ')'; } - } - elseif ($key == 'ACCOUNTANCY_CODE_SUPPLIER' && ! empty($this->fournisseur)) { + } elseif ($key == 'ACCOUNTANCY_CODE_SUPPLIER' && !empty($this->fournisseur)) { // Check for unicity if ($vallabel && !empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_SUPPLIER_UNIQUE)) { if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { From e1eb85ffb0829d4a3bb88e602320eb8c1f704e2d Mon Sep 17 00:00:00 2001 From: kamel Date: Fri, 13 May 2022 11:53:23 +0200 Subject: [PATCH 3/3] relaunch travis