Merge pull request #22599 from fboitel/NEW#22594-unique-vat-id

NEW #22594: can chose if VAT ID is unique or not for third parties
This commit is contained in:
Laurent Destailleur 2022-11-02 17:08:37 +01:00 committed by GitHub
commit 3543a56231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -181,6 +181,20 @@ if ($action == "setaccountancycodecustomerinvoicemandatory") {
}
}
//Activate Set vat id unique
if ($action == "setvatintraunique") {
$setvatintraunique = GETPOST('value', 'int');
$res = dolibarr_set_const($db, "SOCIETE_VAT_INTRA_UNIQUE", $setvatintraunique, 'yesno', 0, '', $conf->entity);
if (!($res > 0)) {
$error++;
}
if (!$error) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
setEventMessages($langs->trans("Error"), null, 'errors');
}
}
//Activate Set ref in list
if ($action == "setaddrefinlist") {
$setaddrefinlist = GETPOST('value', 'int');
@ -731,6 +745,22 @@ if (isModEnabled('accounting')) {
print "</tr>\n";
}
// VAT ID
print '<tr class="oddeven">';
print '<td colspan="2">'.$langs->trans('VATIntra')."</td>\n";
if (!empty($conf->global->SOCIETE_VAT_INTRA_UNIQUE)) {
print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setvatintraunique&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=setvatintraunique&token='.newToken().'&value=1">';
print img_picto($langs->trans("Disabled"), 'switch_off');
print '</a></td>';
}
print '<td colspan="2"></td>';
print "</tr>\n";
print "</table>\n";
print '</div>';

View File

@ -1171,7 +1171,7 @@ 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', 'TVA_INTRA');
foreach ($array_to_check as $key) {
$keymin = strtolower($key);
$i = (int) preg_replace('/[^0-9]/', '', $key);
@ -1216,6 +1216,14 @@ class Societe extends CommonObject
$error++; $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
}
}
} elseif ($key == 'TVA_INTRA') {
// Check for unicity
if ($vallabel && !empty($conf->global->SOCIETE_VAT_INTRA_UNIQUE)) {
if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) {
$langs->load("errors");
$error++; $this->errors[] = $langs->trans('VATIntra')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
}
}
}
}
}