NEW - Add all id prof checker on thirdparty for code compta customer and supplier

This commit is contained in:
kamel 2022-05-13 10:45:18 +02:00
parent 775a8c5334
commit 32f3a2aff6
6 changed files with 96 additions and 22 deletions

View file

@ -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';
}
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 '<tr class="oddeven">';
print '<td colspan="2">'.$langs->trans('CustomerAccountancyCodeShort')."</td>\n";
print '<td colspan="2"></td>';
if (!empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_INVOICE_MANDATORY)) {
print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setaccountancycodecustomerinvoicemandatory&token='.newToken().'&value=0">';
print img_picto($langs->trans("Activated"), 'switch_on');
print '</a></td>';
} else {
print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setaccountancycodecustomerinvoicemandatory&token='.newToken().'&value=1">';
print img_picto($langs->trans("Disabled"), 'switch_off');
print '</a></td>';
}
print "</tr>\n";
}
print "</table>\n";
print '</div>';

View file

@ -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);