Merge branch 'OPEN-DSI-develop_add_all_id_prof_checker_for_code_compta_customer_and_supplier' into develop
This commit is contained in:
commit
47df801779
6 changed files with 95 additions and 22 deletions
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 '<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";
|
||||
}
|
||||
|
||||
// VAT ID
|
||||
print '<tr class="oddeven">';
|
||||
print '<td colspan="2">'.$langs->trans('VATIntra')."</td>\n";
|
||||
|
|
|
|||
|
|
@ -1193,9 +1193,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', 'TVA_INTRA');
|
||||
$array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL', 'TVA_INTRA', '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;
|
||||
|
||||
|
|
@ -1246,6 +1248,38 @@ class Societe extends CommonObject
|
|||
$error++; $this->errors[] = $langs->trans('VATIntra')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
|
||||
}
|
||||
}
|
||||
} 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") . ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3532,18 +3566,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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue