Merge pull request #15570 from frederic34/strike

simplify function
This commit is contained in:
Laurent Destailleur 2020-11-29 19:10:06 +01:00 committed by GitHub
commit 8eacbaaf5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 57 deletions

View File

@ -137,10 +137,18 @@ abstract class ModeleProductCode
global $langs;
$langs->load("admin");
if ($this->version == 'development') return $langs->trans("VersionDevelopment");
if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
if ($this->version == 'dolibarr') return DOL_VERSION;
if ($this->version) return $this->version;
if ($this->version == 'development') {
return $langs->trans("VersionDevelopment");
}
if ($this->version == 'experimental') {
return $langs->trans("VersionExperimental");
}
if ($this->version == 'dolibarr') {
return DOL_VERSION;
}
if ($this->version) {
return $this->version;
}
return $langs->trans("NotAvailable");
}
@ -159,12 +167,10 @@ abstract class ModeleProductCode
$sql = "";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
$liste[$row[0]] = $row[1];
$i++;
@ -188,37 +194,37 @@ abstract class ModeleProductCode
global $conf;
$langs->load("admin");
$strikestart = '';
$strikeend = '';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
$strikestart = '<strike>';
$strikeend = '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
}
$s = '';
if ($type == -1) {
$s .= $langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>';
$s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
} elseif ($type == 0) {
$s .= $langs->trans("ProductCodeDesc").'<br>';
} elseif ($type == 1) {
$s .= $langs->trans("ServiceCodeDesc").'<br>';
}
if ($type != -1) {
$s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
}
if ($type == 0) $s .= $langs->trans("ProductCodeDesc").'<br>';
if ($type == 1) $s .= $langs->trans("ServiceCodeDesc").'<br>';
if ($type != -1) $s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
$s .= '<br>';
$s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
if ($type == 0)
{
$s .= $langs->trans("RequiredIfProduct").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
$s .= yn(!$this->code_null, 1, 2);
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
if ($type == 0) {
$s .= $langs->trans("RequiredIfProduct").': '.$strikestart;
$s .= yn(!$this->code_null, 1, 2).$strikeend;
$s .= '<br>';
} elseif ($type == 1)
{
$s .= $langs->trans("RequiredIfService").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
$s .= yn(!$this->code_null, 1, 2);
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
} elseif ($type == 1) {
$s .= $langs->trans("RequiredIfService").': '.$strikestart;
$s .= yn(!$this->code_null, 1, 2).$strikeend;
$s .= '<br>';
} elseif ($type == -1)
{
$s .= $langs->trans("Required").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
$s .= yn(!$this->code_null, 1, 2);
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
} elseif ($type == -1) {
$s .= $langs->trans("Required").': '.$strikestart;
$s .= yn(!$this->code_null, 1, 2).$strikeend;
$s .= '<br>';
}
$s .= $langs->trans("CanBeModifiedIfOk").': ';
@ -227,16 +233,18 @@ abstract class ModeleProductCode
$s .= $langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide, 1, 2).'<br>';
$s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>';
$s .= '<br>';
if ($type == 0 || $type == -1)
{
if ($type == 0 || $type == -1) {
$nextval = $this->getNextValue($product, 0);
if (empty($nextval)) $nextval = $langs->trans("Undefined");
if (empty($nextval)) {
$nextval = $langs->trans("Undefined");
}
$s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Product").')' : '').': <b>'.$nextval.'</b><br>';
}
if ($type == 1 || $type == -1)
{
if ($type == 1 || $type == -1) {
$nextval = $this->getNextValue($product, 1);
if (empty($nextval)) $nextval = $langs->trans("Undefined");
if (empty($nextval)) {
$nextval = $langs->trans("Undefined");
}
$s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Service").')' : '').': <b>'.$nextval.'</b>';
}
return $s;

View File

@ -168,12 +168,10 @@ abstract class ModeleThirdPartyCode
$sql = "";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
$liste[$row[0]] = $row[1];
$i++;
@ -197,6 +195,12 @@ abstract class ModeleThirdPartyCode
global $conf;
$langs->load("admin");
$strikestart = '';
$strikeend = '';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
$strikestart = '<strike>';
$strikeend = '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
}
$s = '';
if ($type == -1) {
@ -207,28 +211,23 @@ abstract class ModeleThirdPartyCode
$s .= $langs->trans("CustomerCodeDesc").'<br>';
} elseif ($type == 1) {
$s .= $langs->trans("SupplierCodeDesc").'<br>';
} elseif ($type != -1) {
}
if ($type != -1) {
$s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
}
$s .= '<br>';
$s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
if ($type == 0) {
$s .= $langs->trans("RequiredIfCustomer").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
$s .= yn(!$this->code_null, 1, 2);
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
$s .= $langs->trans("RequiredIfCustomer").': '.$strikestart;
$s .= yn(!$this->code_null, 1, 2).$strikeend;
$s .= '<br>';
} elseif ($type == 1) {
$s .= $langs->trans("RequiredIfSupplier").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
$s .= yn(!$this->code_null, 1, 2);
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
$s .= $langs->trans("RequiredIfSupplier").': '.$strikestart;
$s .= yn(!$this->code_null, 1, 2).$strikeend;
$s .= '<br>';
} elseif ($type == -1) {
$s .= $langs->trans("Required").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
$s .= yn(!$this->code_null, 1, 2);
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
$s .= $langs->trans("Required").': '.$strikestart;
$s .= yn(!$this->code_null, 1, 2).$strikeend;
$s .= '<br>';
}
$s .= $langs->trans("CanBeModifiedIfOk").': ';
@ -239,12 +238,16 @@ abstract class ModeleThirdPartyCode
$s .= '<br>';
if ($type == 0 || $type == -1) {
$nextval = $this->getNextValue($soc, 0);
if (empty($nextval)) $nextval = $langs->trans("Undefined");
if (empty($nextval)) {
$nextval = $langs->trans("Undefined");
}
$s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Customer").')' : '').': <b>'.$nextval.'</b><br>';
}
if ($type == 1 || $type == -1) {
$nextval = $this->getNextValue($soc, 1);
if (empty($nextval)) $nextval = $langs->trans("Undefined");
if (empty($nextval)) {
$nextval = $langs->trans("Undefined");
}
$s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Supplier").')' : '').': <b>'.$nextval.'</b>';
}
return $s;
@ -360,13 +363,17 @@ abstract class ModeleAccountancyCode
if ($type == 0 || $type == -1) {
$result = $this->get_code($db, $soc, 'customer');
$nextval = $this->code;
if (empty($nextval)) $nextval = $langs->trans("Undefined");
if (empty($nextval)) {
$nextval = $langs->trans("Undefined");
}
$s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Customer").')' : '').': <b>'.$nextval.'</b><br>';
}
if ($type == 1 || $type == -1) {
$result = $this->get_code($db, $soc, 'supplier');
$nextval = $this->code;
if (empty($nextval)) $nextval = $langs->trans("Undefined");
if (empty($nextval)) {
$nextval = $langs->trans("Undefined");
}
$s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Supplier").')' : '').': <b>'.$nextval.'</b>';
}
return $s;