';
$label .= Form::showphoto('societe', $this, 0, 40, 0, '', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
$label .= '
';
$label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
$label.= '
';
- if ($option == 'customer' || $option == 'compta' || $option == 'category')
- {
+ if ($option == 'customer' || $option == 'compta' || $option == 'category') {
$label .= img_picto('', $this->picto).'
'.$langs->trans("Customer").'';
$linkstart = '
'.$langs->trans("Prospect").'';
$linkstart = ''.$langs->trans("Supplier").'';
$linkstart = ''.$langs->trans("ThirdParty").'';
$linkstart = ''.$langs->trans("ThirdParty").'';
$linkstart = ''.$langs->trans("ThirdParty").'';
$linkstart = ''.$langs->trans("ThirdParty").'';
$linkstart = ''.$langs->trans("ThirdParty").'';
$linkstart = ''.$langs->trans("ThirdParty").'';
$linkstart = 'global->MAIN_OPTIMIZEFORTEXTBROWSER))
- {
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowCompany");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip refurl"';
- /*
+ /*
$hookmanager->initHooks(array('thirdpartydao'));
$parameters=array('id'=>$this->id);
$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
@@ -2478,15 +2466,18 @@ class Societe extends CommonObject
$linkend = '';
global $user;
- if (!$user->rights->societe->client->voir && $user->socid > 0 && $this->id != $user->socid)
- {
+ if (!$user->rights->societe->client->voir && $user->socid > 0 && $this->id != $user->socid) {
$linkstart = '';
$linkend = '';
}
$result .= $linkstart;
- if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
- if ($withpicto != 2) $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name);
+ if ($withpicto) {
+ $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ if ($withpicto != 2) {
+ $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name);
+ }
$result .= $linkend;
global $action;
@@ -2501,8 +2492,11 @@ class Societe extends CommonObject
'save_lastsearch_value'=> $save_lastsearch_value
);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
- if ($reshook > 0) $result = $hookmanager->resPrint;
- else $result .= $hookmanager->resPrint;
+ if ($reshook > 0) {
+ $result = $hookmanager->resPrint;
+ } else {
+ $result .= $hookmanager->resPrint;
+ }
return $result;
}
@@ -2533,10 +2527,11 @@ class Societe extends CommonObject
$langs->load('companies');
$statusType = 'status4';
- if ($status == 0) $statusType = 'status6';
+ if ($status == 0) {
+ $statusType = 'status6';
+ }
- if (empty($this->labelStatus) || empty($this->labelStatusShort))
- {
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
$this->labelStatus[0] = $langs->trans("ActivityCeased");
$this->labelStatus[1] = $langs->trans("InActivity");
$this->labelStatusShort[0] = $langs->trans("ActivityCeased");
@@ -2559,9 +2554,10 @@ class Societe extends CommonObject
global $langs;
$contact_emails = $this->contact_property_array('email', 1);
- if ($this->email && $addthirdparty)
- {
- if (empty($this->name)) $this->name = $this->nom;
+ if ($this->email && $addthirdparty) {
+ if (empty($this->name)) {
+ $this->name = $this->nom;
+ }
$contact_emails['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->email.">";
}
//var_dump($contact_emails)
@@ -2581,9 +2577,10 @@ class Societe extends CommonObject
$contact_phone = $this->contact_property_array('mobile');
- if (!empty($this->phone)) // If a phone of thirdparty is defined, we add it ot mobile of contacts
- {
- if (empty($this->name)) $this->name = $this->nom;
+ if (!empty($this->phone)) { // If a phone of thirdparty is defined, we add it ot mobile of contacts
+ if (empty($this->name)) {
+ $this->name = $this->nom;
+ }
// TODO: Tester si tel non deja present dans tableau contact
$contact_phone['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->phone.">";
}
@@ -2612,36 +2609,36 @@ class Societe extends CommonObject
$sql .= " ORDER BY lastname, firstname";
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$nump = $this->db->num_rows($resql);
- if ($nump)
- {
+ if ($nump) {
$sepa = "("; $sepb = ")";
- if ($mode == 'email')
- {
+ if ($mode == 'email') {
//$sepa="<"; $sepb=">";
$sepa = "<"; $sepb = ">";
}
$i = 0;
- while ($i < $nump)
- {
+ while ($i < $nump) {
$obj = $this->db->fetch_object($resql);
- if ($mode == 'email') $property = $obj->email;
- elseif ($mode == 'mobile') $property = $obj->phone_mobile;
- else $property = $obj->$mode;
+ if ($mode == 'email') {
+ $property = $obj->email;
+ } elseif ($mode == 'mobile') {
+ $property = $obj->phone_mobile;
+ } else {
+ $property = $obj->$mode;
+ }
// Show all contact. If hidedisabled is 1, showonly contacts with status = 1
- if ($obj->status == 1 || empty($hidedisabled))
- {
- if (empty($property))
- {
- if ($mode == 'email') $property = $langs->transnoentitiesnoconv("NoEMail");
- elseif ($mode == 'mobile') $property = $langs->transnoentitiesnoconv("NoMobilePhone");
+ if ($obj->status == 1 || empty($hidedisabled)) {
+ if (empty($property)) {
+ if ($mode == 'email') {
+ $property = $langs->transnoentitiesnoconv("NoEMail");
+ } elseif ($mode == 'mobile') {
+ $property = $langs->transnoentitiesnoconv("NoMobilePhone");
+ }
}
- if (!empty($obj->poste))
- {
+ if (!empty($obj->poste)) {
$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ? " - ".$obj->poste : "").(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : '');
} else {
$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : '');
@@ -2670,14 +2667,11 @@ class Societe extends CommonObject
$sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$nump = $this->db->num_rows($resql);
- if ($nump)
- {
+ if ($nump) {
$i = 0;
- while ($i < $nump)
- {
+ while ($i < $nump) {
$obj = $this->db->fetch_object($resql);
$contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname, $obj->lastname);
$i++;
@@ -2703,14 +2697,11 @@ class Societe extends CommonObject
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$nump = $this->db->num_rows($resql);
- if ($nump)
- {
+ if ($nump) {
$i = 0;
- while ($i < $nump)
- {
+ while ($i < $nump) {
$obj = $this->db->fetch_object($resql);
$contact = new Contact($this->db);
$contact->fetch($obj->rowid);
@@ -2737,23 +2728,26 @@ class Societe extends CommonObject
// phpcs:enable
$contact_property = '';
- if (empty($rowid)) return '';
+ if (empty($rowid)) {
+ return '';
+ }
$sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople";
$sql .= " WHERE rowid = ".((int) $rowid);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$nump = $this->db->num_rows($resql);
- if ($nump)
- {
+ if ($nump) {
$obj = $this->db->fetch_object($resql);
- if ($mode == 'email') $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">";
- elseif ($mode == 'mobile') $contact_property = $obj->phone_mobile;
+ if ($mode == 'email') {
+ $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">";
+ } elseif ($mode == 'mobile') {
+ $contact_property = $obj->phone_mobile;
+ }
}
return $contact_property;
} else {
@@ -2841,15 +2835,15 @@ class Societe extends CommonObject
{
// phpcs:enable
global $conf;
- if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
- {
+ if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
- foreach ($dirsociete as $dirroot)
- {
+ foreach ($dirsociete as $dirroot) {
$res = dol_include_once($dirroot.$module.'.php');
- if ($res) break;
+ if ($res) {
+ break;
+ }
}
$mod = new $module();
@@ -2873,15 +2867,15 @@ class Societe extends CommonObject
{
// phpcs:enable
global $conf;
- if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
- {
+ if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
- foreach ($dirsociete as $dirroot)
- {
+ foreach ($dirsociete as $dirroot) {
$res = dol_include_once($dirroot.$module.'.php');
- if ($res) break;
+ if ($res) {
+ break;
+ }
}
$mod = new $module();
@@ -2902,23 +2896,29 @@ class Societe extends CommonObject
{
// phpcs:enable
global $conf;
- if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
- {
+ if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
- foreach ($dirsociete as $dirroot)
- {
+ foreach ($dirsociete as $dirroot) {
$res = dol_include_once($dirroot.$module.'.php');
- if ($res) break;
+ if ($res) {
+ break;
+ }
}
$mod = new $module();
dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
- if ($mod->code_modifiable_null && !$this->code_client) return 1;
- if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
- if ($mod->code_modifiable) return 1; // A mettre en dernier
+ if ($mod->code_modifiable_null && !$this->code_client) {
+ return 1;
+ }
+ if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
+ return 1;
+ }
+ if ($mod->code_modifiable) {
+ return 1; // A mettre en dernier
+ }
return 0;
} else {
return 0;
@@ -2936,23 +2936,29 @@ class Societe extends CommonObject
{
// phpcs:enable
global $conf;
- if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
- {
+ if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
- foreach ($dirsociete as $dirroot)
- {
+ foreach ($dirsociete as $dirroot) {
$res = dol_include_once($dirroot.$module.'.php');
- if ($res) break;
+ if ($res) {
+ break;
+ }
}
$mod = new $module();
dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
- if ($mod->code_modifiable_null && !$this->code_fournisseur) return 1;
- if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
- if ($mod->code_modifiable) return 1; // A mettre en dernier
+ if ($mod->code_modifiable_null && !$this->code_fournisseur) {
+ return 1;
+ }
+ if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
+ return 1;
+ }
+ if ($mod->code_modifiable) {
+ return 1; // A mettre en dernier
+ }
return 0;
} else {
return 0;
@@ -2976,25 +2982,25 @@ class Societe extends CommonObject
{
// phpcs:enable
global $conf;
- if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
- {
+ if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
- foreach ($dirsociete as $dirroot)
- {
+ foreach ($dirsociete as $dirroot) {
$res = dol_include_once($dirroot.$module.'.php');
- if ($res) break;
+ if ($res) {
+ break;
+ }
}
$mod = new $module();
- dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module);
- $result = $mod->verif($this->db, $this->code_client, $this, 0);
- if ($result) { // If error
- $this->error = $mod->error;
- $this->errors = $mod->errors;
- }
+ dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module);
+ $result = $mod->verif($this->db, $this->code_client, $this, 0);
+ if ($result) { // If error
+ $this->error = $mod->error;
+ $this->errors = $mod->errors;
+ }
return $result;
} else {
return 0;
@@ -3010,20 +3016,22 @@ class Societe extends CommonObject
* -2 ErrorCustomerCodeRequired
* -3 ErrorCustomerCodeAlreadyUsed
* -4 ErrorPrefixRequired
+ * -5 NotConfigured - Setup empty so any value may be ok or not
+ * -6 Other (see this->error)
*/
public function check_codefournisseur()
{
// phpcs:enable
global $conf;
- if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
- {
+ if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) {
$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
- foreach ($dirsociete as $dirroot)
- {
+ foreach ($dirsociete as $dirroot) {
$res = dol_include_once($dirroot.$module.'.php');
- if ($res) break;
+ if ($res) {
+ break;
+ }
}
$mod = new $module();
@@ -3054,26 +3062,28 @@ class Societe extends CommonObject
// phpcs:enable
global $conf;
- if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
- {
+ if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) {
$res = false;
$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
- foreach ($dirsociete as $dirroot)
- {
+ foreach ($dirsociete as $dirroot) {
$res = dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
- if ($res) break;
+ if ($res) {
+ break;
+ }
}
- if ($res)
- {
+ if ($res) {
$classname = $conf->global->SOCIETE_CODECOMPTA_ADDON;
$mod = new $classname;
// Set code count in $mod->code
$result = $mod->get_code($this->db, $this, $type);
- if ($type == 'customer') $this->code_compta = $mod->code;
- elseif ($type == 'supplier') $this->code_compta_fournisseur = $mod->code;
+ if ($type == 'customer') {
+ $this->code_compta = $mod->code;
+ } elseif ($type == 'supplier') {
+ $this->code_compta_fournisseur = $mod->code;
+ }
return $result;
} else {
@@ -3081,8 +3091,11 @@ class Societe extends CommonObject
return -1;
}
} else {
- if ($type == 'customer') $this->code_compta = '';
- elseif ($type == 'supplier') $this->code_compta_fournisseur = '';
+ if ($type == 'customer') {
+ $this->code_compta = '';
+ } elseif ($type == 'supplier') {
+ $this->code_compta_fournisseur = '';
+ }
return 0;
}
@@ -3098,21 +3111,21 @@ class Societe extends CommonObject
public function set_parent($id)
{
// phpcs:enable
- if ($this->id)
- {
+ if ($this->id) {
$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
$sql .= " SET parent = ".($id > 0 ? $id : "null");
$sql .= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->parent = $id;
return 1;
} else {
return -1;
}
- } else return -1;
+ } else {
+ return -1;
+ }
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -3127,8 +3140,7 @@ class Societe extends CommonObject
// phpcs:enable
global $conf;
- switch ($idprof)
- {
+ switch ($idprof) {
case 1:
$ret = (empty($conf->global->SOCIETE_IDPROF1_UNIQUE) ? false : true);
break;
@@ -3168,8 +3180,7 @@ class Societe extends CommonObject
// phpcs:enable
$field = $idprof;
- switch ($idprof) // For backward compatibility
- {
+ switch ($idprof) { // For backward compatibility
case '1':
case 'idprof1':
$field = "siren";
@@ -3192,14 +3203,15 @@ class Societe extends CommonObject
case '6':
$field = "idprof6";
break;
- }
+ }
//Verify duplicate entries
$sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$this->db->escape($value)."' AND entity IN (".getEntity('societe').")";
- if ($socid) $sql .= " AND rowid <> ".$socid;
+ if ($socid) {
+ $sql .= " AND rowid <> ".$socid;
+ }
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$obj = $this->db->fetch_object($resql);
$count = $obj->idprof;
} else {
@@ -3208,8 +3220,11 @@ class Societe extends CommonObject
}
$this->db->free($resql);
- if ($count > 0) return true;
- else return false;
+ if ($count > 0) {
+ return true;
+ } else {
+ return false;
+ }
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -3228,111 +3243,144 @@ class Societe extends CommonObject
$ok = 1;
- if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
+ if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
+ return 1;
+ }
// Check SIREN if country FR
- if ($idprof == 1 && $soc->country_code == 'FR')
- {
+ if ($idprof == 1 && $soc->country_code == 'FR') {
$chaine = trim($this->idprof1);
$chaine = preg_replace('/(\s)/', '', $chaine);
- if (!is_numeric($chaine)) return -1;
- if (dol_strlen($chaine) != 9) return -1;
+ if (!is_numeric($chaine)) {
+ return -1;
+ }
+ if (dol_strlen($chaine) != 9) {
+ return -1;
+ }
// on prend chaque chiffre un par un
// si son index (position dans la chaîne en commence à 0 au premier caractère) est impair
// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
// on ajoute cette valeur à la somme totale
$sum = 0;
- for ($index = 0; $index < 9; $index++)
- {
+ for ($index = 0; $index < 9; $index++) {
$number = (int) $chaine[$index];
- if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; }
+ if (($index % 2) != 0) {
+ if (($number *= 2) > 9) {
+ $number -= 9;
+ }
+ }
$sum += $number;
}
// le numéro est valide si la somme des chiffres est multiple de 10
- if (($sum % 10) != 0) return -1;
+ if (($sum % 10) != 0) {
+ return -1;
+ }
}
// Verifie SIRET si pays FR
- if ($idprof == 2 && $soc->country_code == 'FR')
- {
+ if ($idprof == 2 && $soc->country_code == 'FR') {
$chaine = trim($this->idprof2);
$chaine = preg_replace('/(\s)/', '', $chaine);
- if (!is_numeric($chaine)) return -1;
- if (dol_strlen($chaine) != 14) return -1;
+ if (!is_numeric($chaine)) {
+ return -1;
+ }
+ if (dol_strlen($chaine) != 14) {
+ return -1;
+ }
// on prend chaque chiffre un par un
// si son index (position dans la chaîne en commence à 0 au premier caractère) est pair
// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
// on ajoute cette valeur à la somme totale
$sum = 0;
- for ($index = 0; $index < 14; $index++)
- {
+ for ($index = 0; $index < 14; $index++) {
$number = (int) $chaine[$index];
- if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; }
+ if (($index % 2) == 0) {
+ if (($number *= 2) > 9) {
+ $number -= 9;
+ }
+ }
$sum += $number;
}
// le numéro est valide si la somme des chiffres est multiple de 10
- if (($sum % 10) != 0) return -1;
+ if (($sum % 10) != 0) {
+ return -1;
+ }
}
//Verify CIF/NIF/NIE if pays ES
//Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad
- if ($idprof == 1 && $soc->country_code == 'ES')
- {
+ if ($idprof == 1 && $soc->country_code == 'ES') {
$string = trim($this->idprof1);
$string = preg_replace('/(\s)/', '', $string);
$string = strtoupper($string);
//Check format
- if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string))
- return 0;
+ if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) {
+ return 0;
+ }
$num = array();
- for ($i = 0; $i < 9; $i++)
- {
+ for ($i = 0; $i < 9; $i++) {
$num[$i] = substr($string, $i, 1);
}
//Check NIF
- if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string))
- if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
+ if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) {
+ if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) {
return 1;
- else return -1;
+ } else {
+ return -1;
+ }
+ }
//algorithm checking type code CIF
$sum = $num[2] + $num[4] + $num[6];
- for ($i = 1; $i < 8; $i += 2)
- $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
+ for ($i = 1; $i < 8; $i += 2) {
+ $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
+ }
$n = 10 - substr($sum, strlen($sum) - 1, 1);
//Chek special NIF
- if (preg_match('/^[KLM]{1}/', $string))
- if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
+ if (preg_match('/^[KLM]{1}/', $string)) {
+ if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) {
return 1;
- else return -1;
+ } else {
+ return -1;
+ }
+ }
//Check CIF
- if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string))
- if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
+ if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) {
+ if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) {
return 2;
- else return -2;
+ } else {
+ return -2;
+ }
+ }
//Check NIE T
- if (preg_match('/^[T]{1}/', $string))
- if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
+ if (preg_match('/^[T]{1}/', $string)) {
+ if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string)) {
return 3;
- else return -3;
+ } else {
+ return -3;
+ }
+ }
//Check NIE XYZ
- if (preg_match('/^[XYZ]{1}/', $string))
- if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1))
+ if (preg_match('/^[XYZ]{1}/', $string)) {
+ if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1)) {
return 3;
- else return -3;
+ } else {
+ return -3;
+ }
+ }
//Can not be verified
return -4;
@@ -3340,8 +3388,7 @@ class Societe extends CommonObject
//Verify NIF if country is PT
//Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad
- if ($idprof == 1 && $soc->country_code == 'PT')
- {
+ if ($idprof == 1 && $soc->country_code == 'PT') {
$string = trim($this->idprof1);
$string = preg_replace('/(\s)/', '', $string);
@@ -3420,8 +3467,7 @@ class Societe extends CommonObject
// phpcs:enable
$sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = '.$this->id;
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$obj = $this->db->fetch_object($resql);
$count = $obj->numproj;
} else {
@@ -3447,10 +3493,8 @@ class Societe extends CommonObject
$sql .= " WHERE s.rowid = ".$id;
$result = $this->db->query($sql);
- if ($result)
- {
- if ($this->db->num_rows($result))
- {
+ if ($result) {
+ if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
@@ -3493,11 +3537,13 @@ class Societe extends CommonObject
$isacompany = 1;
} elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) {
$isacompany = 1;
- } elseif (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
- {
+ } elseif (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN') {
// TODO Add a field is_a_company into dictionary
- if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany = 0;
- else $isacompany = 1;
+ if (preg_match('/^TE_PRIVATE/', $this->typent_code)) {
+ $isacompany = 0;
+ } else {
+ $isacompany = 1;
+ }
}
return $isacompany;
@@ -3529,10 +3575,8 @@ class Societe extends CommonObject
$sql .= " WHERE type = ".Categorie::TYPE_SUPPLIER;
$resql = $this->db->query($sql);
- if ($resql)
- {
- while ($obj = $this->db->fetch_object($resql))
- {
+ if ($resql) {
+ while ($obj = $this->db->fetch_object($resql)) {
$this->SupplierCategories[$obj->rowid] = $obj->label;
}
return 0;
@@ -3551,12 +3595,13 @@ class Societe extends CommonObject
public function AddFournisseurInCategory($categorie_id)
{
// phpcs:enable
- if ($categorie_id > 0 && $this->id > 0)
- {
+ if ($categorie_id > 0 && $this->id > 0) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) ";
$sql .= " VALUES (".$categorie_id.", ".$this->id.")";
- if ($resql = $this->db->query($sql)) return 0;
+ if ($resql = $this->db->query($sql)) {
+ return 0;
+ }
} else {
return 0;
}
@@ -3582,7 +3627,9 @@ class Societe extends CommonObject
dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
$name = $socname ? $socname : $member->societe;
- if (empty($name)) $name = $member->getFullName($langs);
+ if (empty($name)) {
+ $name = $member->getFullName($langs);
+ }
$alias = $socalias ? $socalias : '';
@@ -3608,15 +3655,13 @@ class Societe extends CommonObject
// Cree et positionne $this->id
$result = $this->create($user);
- if ($result >= 0)
- {
+ if ($result >= 0) {
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
$sql .= " SET fk_soc=".$this->id;
$sql .= " WHERE rowid=".$member->id;
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->db->commit();
return $this->id;
} else {
@@ -3658,12 +3703,10 @@ class Societe extends CommonObject
// We define country_id, country_code and country
$country_id = $country_code = $country_label = '';
- if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
- {
+ if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
$tmp = explode(':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
$country_id = $tmp[0];
- if (!empty($tmp[1])) // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
- {
+ if (!empty($tmp[1])) { // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
$country_code = $tmp[1];
$country_label = $tmp[2];
} else // For backward compatibility
@@ -3677,17 +3720,17 @@ class Societe extends CommonObject
$this->country_id = $country_id;
$this->country_code = $country_code;
$this->country = $country_label;
- if (is_object($langs)) $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label;
+ if (is_object($langs)) {
+ $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label;
+ }
//TODO This could be replicated for region but function `getRegion` didn't exist, so I didn't added it.
// We define state_id, state_code and state
$state_id = 0; $state_code = $state_label = '';
- if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE))
- {
+ if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) {
$tmp = explode(':', $conf->global->MAIN_INFO_SOCIETE_STATE);
$state_id = $tmp[0];
- if (!empty($tmp[1])) // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label"
- {
+ if (!empty($tmp[1])) { // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label"
$state_code = $tmp[1];
$state_label = $tmp[2];
} else // For backward compatibility
@@ -3701,7 +3744,9 @@ class Societe extends CommonObject
$this->state_id = $state_id;
$this->state_code = $state_code;
$this->state = $state_label;
- if (is_object($langs)) $this->state = ($langs->trans('State'.$state_code) != 'State'.$state_code) ? $langs->trans('State'.$state_code) : $state_label;
+ if (is_object($langs)) {
+ $this->state = ($langs->trans('State'.$state_code) != 'State'.$state_code) ? $langs->trans('State'.$state_code) : $state_label;
+ }
$this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ? '' : $conf->global->MAIN_INFO_SOCIETE_TEL;
$this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ? '' : $conf->global->MAIN_INFO_SOCIETE_FAX;
@@ -3715,12 +3760,24 @@ class Societe extends CommonObject
$this->youtube_url = empty($conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL) ? '' : $conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL;
$this->github_url = empty($conf->global->MAIN_INFO_SOCIETE_GITHUB_URL) ? '' : $conf->global->MAIN_INFO_SOCIETE_GITHUB_URL;
$this->socialnetworks = array();
- if (!empty($this->facebook_url)) $this->socialnetworks['facebook'] = $this->facebook_url;
- if (!empty($this->twitter_url)) $this->socialnetworks['twitter'] = $this->twitter_url;
- if (!empty($this->linkedin_url)) $this->socialnetworks['linkedin'] = $this->linkedin_url;
- if (!empty($this->instagram_url)) $this->socialnetworks['instagram'] = $this->instagram_url;
- if (!empty($this->youtube_url)) $this->socialnetworks['youtube'] = $this->youtube_url;
- if (!empty($this->github_url)) $this->socialnetworks['github'] = $this->github_url;
+ if (!empty($this->facebook_url)) {
+ $this->socialnetworks['facebook'] = $this->facebook_url;
+ }
+ if (!empty($this->twitter_url)) {
+ $this->socialnetworks['twitter'] = $this->twitter_url;
+ }
+ if (!empty($this->linkedin_url)) {
+ $this->socialnetworks['linkedin'] = $this->linkedin_url;
+ }
+ if (!empty($this->instagram_url)) {
+ $this->socialnetworks['instagram'] = $this->instagram_url;
+ }
+ if (!empty($this->youtube_url)) {
+ $this->socialnetworks['youtube'] = $this->youtube_url;
+ }
+ if (!empty($this->github_url)) {
+ $this->socialnetworks['github'] = $this->github_url;
+ }
// Id prof generiques
$this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ? '' : $conf->global->MAIN_INFO_SIREN;
@@ -3820,15 +3877,20 @@ class Societe extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
$sql .= " AND t.active = 1";
- if (empty($localTaxNum)) $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
- elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'";
- elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'";
+ if (empty($localTaxNum)) {
+ $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
+ } elseif ($localTaxNum == 1) {
+ $sql .= " AND t.localtax1_type <> '0'";
+ } elseif ($localTaxNum == 2) {
+ $sql .= " AND t.localtax2_type <> '0'";
+ }
$resql = $this->db->query($sql);
- if ($resql)
- {
- return ($this->db->num_rows($resql) > 0);
- } else return false;
+ if ($resql) {
+ return ($this->db->num_rows($resql) > 0);
+ } else {
+ return false;
+ }
}
/**
@@ -3845,10 +3907,11 @@ class Societe extends CommonObject
dol_syslog("useNPR", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
return ($this->db->num_rows($resql) > 0);
- } else return false;
+ } else {
+ return false;
+ }
}
/**
@@ -3866,10 +3929,9 @@ class Societe extends CommonObject
dol_syslog("useRevenueStamp", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$obj = $this->db->fetch_object($resql);
- return (($obj->nb > 0) ?true:false);
+ return (($obj->nb > 0) ?true:false);
} else {
$this->error = $this->db->lasterror();
return false;
@@ -3900,8 +3962,7 @@ class Societe extends CommonObject
$lib = $langs->trans("ProspectLevel".$fk_prospectlevel);
// If lib not found in language file, we get label from cache/databse
- if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
- {
+ if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel)) {
$lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label');
}
return $lib;
@@ -3955,30 +4016,45 @@ class Societe extends CommonObject
$langs->load('customers');
if ($mode == 2) {
- if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
- elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
- elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
- elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
- elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
- else {
+ if ($status == '-1' || $status == 'ST_NO') {
+ return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
+ } elseif ($status == '0' || $status == 'ST_NEVER') {
+ return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
+ } elseif ($status == '1' || $status == 'ST_TODO') {
+ return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
+ } elseif ($status == '2' || $status == 'ST_PEND') {
+ return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
+ } elseif ($status == '3' || $status == 'ST_DONE') {
+ return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
+ } else {
return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label);
}
} elseif ($mode == 3) {
- if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto);
- elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto);
- elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto);
- elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto);
- elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto);
- else {
+ if ($status == '-1' || $status == 'ST_NO') {
+ return img_action($langs->trans("StatusProspect-1"), -1, $picto);
+ } elseif ($status == '0' || $status == 'ST_NEVER') {
+ return img_action($langs->trans("StatusProspect0"), 0, $picto);
+ } elseif ($status == '1' || $status == 'ST_TODO') {
+ return img_action($langs->trans("StatusProspect1"), 1, $picto);
+ } elseif ($status == '2' || $status == 'ST_PEND') {
+ return img_action($langs->trans("StatusProspect2"), 2, $picto);
+ } elseif ($status == '3' || $status == 'ST_DONE') {
+ return img_action($langs->trans("StatusProspect3"), 3, $picto);
+ } else {
return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto);
}
} elseif ($mode == 4) {
- if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
- elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
- elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
- elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
- elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
- else {
+ if ($status == '-1' || $status == 'ST_NO') {
+ return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
+ } elseif ($status == '0' || $status == 'ST_NEVER') {
+ return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
+ } elseif ($status == '1' || $status == 'ST_TODO') {
+ return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
+ } elseif ($status == '2' || $status == 'ST_PEND') {
+ return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
+ } elseif ($status == '3' || $status == 'ST_DONE') {
+ return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
+ } else {
return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label);
}
}
@@ -4009,7 +4085,9 @@ class Societe extends CommonObject
public function getOutstandingProposals($mode = 'customer')
{
$table = 'propal';
- if ($mode == 'supplier') $table = 'supplier_proposal';
+ if ($mode == 'supplier') {
+ $table = 'supplier_proposal';
+ }
$sql = "SELECT rowid, total_ht, total as total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f";
$sql .= " WHERE fk_soc = ".$this->id;
@@ -4021,21 +4099,22 @@ class Societe extends CommonObject
dol_syslog("getOutstandingProposals", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$outstandingOpened = 0;
$outstandingTotal = 0;
$outstandingTotalIncTax = 0;
while ($obj = $this->db->fetch_object($resql)) {
$outstandingTotal += $obj->total_ht;
$outstandingTotalIncTax += $obj->total_ttc;
- if ($obj->status != 0) // Not a draft
- {
+ if ($obj->status != 0) {
+ // Not a draft
$outstandingOpened += $obj->total_ttc;
}
}
return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
- } else return array();
+ } else {
+ return array();
+ }
}
/**
@@ -4047,7 +4126,9 @@ class Societe extends CommonObject
public function getOutstandingOrders($mode = 'customer')
{
$table = 'commande';
- if ($mode == 'supplier') $table = 'commande_fournisseur';
+ if ($mode == 'supplier') {
+ $table = 'commande_fournisseur';
+ }
$sql = "SELECT rowid, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f";
$sql .= " WHERE fk_soc = ".$this->id;
@@ -4059,21 +4140,22 @@ class Societe extends CommonObject
dol_syslog("getOutstandingOrders", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$outstandingOpened = 0;
$outstandingTotal = 0;
$outstandingTotalIncTax = 0;
while ($obj = $this->db->fetch_object($resql)) {
$outstandingTotal += $obj->total_ht;
$outstandingTotalIncTax += $obj->total_ttc;
- if ($obj->status != 0) // Not a draft
- {
+ if ($obj->status != 0) {
+ // Not a draft
$outstandingOpened += $obj->total_ttc;
}
}
return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
- } else return array();
+ } else {
+ return array();
+ }
}
/**
@@ -4086,7 +4168,9 @@ class Societe extends CommonObject
public function getOutstandingBills($mode = 'customer', $late = 0)
{
$table = 'facture';
- if ($mode == 'supplier') $table = 'facture_fourn';
+ if ($mode == 'supplier') {
+ $table = 'facture_fourn';
+ }
/* Accurate value of remain to pay is to sum remaintopay for each invoice
$paiement = $invoice->getSommePaiement();
@@ -4095,8 +4179,11 @@ class Societe extends CommonObject
$alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
$remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
*/
- if ($mode == 'supplier') $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
- else $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
+ if ($mode == 'supplier') {
+ $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
+ } else {
+ $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
+ }
$sql .= " WHERE fk_soc = ".$this->id;
if (!empty($late)) {
$sql .= " AND date_lim_reglement < '".$this->db->idate(dol_now())."'";
@@ -4109,13 +4196,11 @@ class Societe extends CommonObject
dol_syslog("getOutstandingBills", LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$outstandingOpened = 0;
$outstandingTotal = 0;
$outstandingTotalIncTax = 0;
- if ($mode == 'supplier')
- {
+ if ($mode == 'supplier') {
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
$tmpobject = new FactureFournisseur($this->db);
} else {
@@ -4127,17 +4212,15 @@ class Societe extends CommonObject
if ($obj->status != $tmpobject::STATUS_DRAFT // Not a draft
&& !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code == 'replaced') // Not a replaced invoice
- )
- {
+ ) {
$outstandingTotal += $obj->total_ht;
$outstandingTotalIncTax += $obj->total_ttc;
}
if ($obj->paye == 0
&& $obj->status != $tmpobject::STATUS_DRAFT // Not a draft
&& $obj->status != $tmpobject::STATUS_ABANDONED // Not abandonned
- && $obj->status != $tmpobject::STATUS_CLOSED) // Not classified as paid
- //$sql .= " AND (status <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason
- {
+ && $obj->status != $tmpobject::STATUS_CLOSED) { // Not classified as paid
+ //$sql .= " AND (status <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason
$paiement = $tmpobject->getSommePaiement();
$creditnotes = $tmpobject->getSumCreditNotesUsed();
$deposits = $tmpobject->getSumDepositsUsed();
@@ -4147,8 +4230,7 @@ class Societe extends CommonObject
//if credit note is converted but not used
// TODO Do this also for customer ?
- if ($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $tmpobject->isCreditNoteUsed())
- {
+ if ($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $tmpobject->isCreditNoteUsed()) {
$outstandingOpened -= $tmpobject->getSumFromThisCreditNotesNotUsed();
}
}
@@ -4181,10 +4263,15 @@ class Societe extends CommonObject
global $langs;
$langs->load('companies');
- if ($status == 0) return $langs->trans("NorProspectNorCustomer");
- elseif ($status == 1) return $langs->trans("Customer");
- elseif ($status == 2) return $langs->trans("Prospect");
- elseif ($status == 3) return $langs->trans("ProspectCustomer");
+ if ($status == 0) {
+ return $langs->trans("NorProspectNorCustomer");
+ } elseif ($status == 1) {
+ return $langs->trans("Customer");
+ } elseif ($status == 2) {
+ return $langs->trans("Prospect");
+ } elseif ($status == 3) {
+ return $langs->trans("ProspectCustomer");
+ }
}
@@ -4203,21 +4290,20 @@ class Societe extends CommonObject
{
global $conf, $user, $langs;
- if (!empty($moreparams) && !empty($moreparams['use_companybankid']))
- {
+ if (!empty($moreparams) && !empty($moreparams['use_companybankid'])) {
$modelpath = "core/modules/bank/doc/";
include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
$companybankaccount = new CompanyBankAccount($this->db);
$result = $companybankaccount->fetch($moreparams['use_companybankid']);
- if (!$result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
+ if (!$result) {
+ dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
+ }
$result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
} else {
// Positionne le modele sur le nom du modele a utiliser
- if (!dol_strlen($modele))
- {
- if (!empty($conf->global->COMPANY_ADDON_PDF))
- {
+ if (!dol_strlen($modele)) {
+ if (!empty($conf->global->COMPANY_ADDON_PDF)) {
$modele = $conf->global->COMPANY_ADDON_PDF;
} else {
print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined");
@@ -4293,11 +4379,9 @@ class Societe extends CommonObject
}
}
foreach ($to_add as $add) {
- if ($c->fetch($add) > 0)
- {
+ if ($c->fetch($add) > 0) {
$result = $c->add_type($this, $type_categ);
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
$this->error = $c->error;
$this->errors = $c->errors;
@@ -4325,7 +4409,6 @@ class Societe extends CommonObject
$salesrep = array($salesrep);
}
-
$to_del = array(); // Nothing to delete
$to_add = $salesrep;
if ($onlyAdd === false) {
@@ -4347,8 +4430,7 @@ class Societe extends CommonObject
}
foreach ($to_add as $add) {
$result = $this->add_commercial($user, $add);
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
break;
}
@@ -4365,22 +4447,22 @@ class Societe extends CommonObject
*/
public function setThirdpartyType($typent_id)
{
- if ($this->id)
- {
+ if ($this->id) {
$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
$sql .= " SET fk_typent = ".($typent_id > 0 ? $typent_id : "null");
$sql .= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this).'::setThirdpartyType', LOG_DEBUG);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->typent_id = $typent_id;
- $this->typent_code = dol_getIdFromCode($db, $this->$typent_id, 'c_typent', 'id', 'code');
+ $this->typent_code = dol_getIdFromCode($this->db, $this->$typent_id, 'c_typent', 'id', 'code');
return 1;
} else {
return -1;
}
- } else return -1;
+ } else {
+ return -1;
+ }
}
/**
@@ -4394,8 +4476,7 @@ class Societe extends CommonObject
*/
public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
{
- if ($origin_id == $dest_id)
- {
+ if ($origin_id == $dest_id) {
dol_syslog('Error: Try to merge a thirdparty into itself');
return false;
}
diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php
index e6991388ad0..1c807b7b2b1 100644
--- a/htdocs/theme/eldy/global.inc.php
+++ b/htdocs/theme/eldy/global.inc.php
@@ -35,7 +35,7 @@
--oddevencolor: #202020;
--colorboxstatsborder: #e0e0e0;
--dolgraphbg: rgba(255,255,255,0);
- --fieldrequiredcolor: #804000;
+ --fieldrequiredcolor: #700040;
--colortextbacktab: #;
--colorboxiconbg: #eee;
--refidnocolor:#444;
diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php
index eb92bd51eb9..98e70cf66b7 100644
--- a/htdocs/user/class/user.class.php
+++ b/htdocs/user/class/user.class.php
@@ -2418,6 +2418,7 @@ class User extends CommonObject
}
$result = ''; $label = '';
+ $companylink = '';
if (!empty($this->photo)) {
$label .= '
';
diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php
index 5a8e6fb241c..7397b8ca2a6 100644
--- a/htdocs/webservices/server_invoice.php
+++ b/htdocs/webservices/server_invoice.php
@@ -288,7 +288,7 @@ $server->register(
*/
function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: getInvoice login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
@@ -363,7 +363,7 @@ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
'note_private' => $invoice->note_private ? $invoice->note_private : '',
'note_public' => $invoice->note_public ? $invoice->note_public : '',
'status' => $invoice->statut,
- 'project_id' => $invoic->fk_project,
+ 'project_id' => $invoice->fk_project,
'close_code' => $invoice->close_code ? $invoice->close_code : '',
'close_note' => $invoice->close_note ? $invoice->close_note : '',
'payment_mode_id' => $invoice->mode_reglement_id ? $invoice->mode_reglement_id : '',
@@ -399,7 +399,7 @@ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
*/
function getInvoicesForThirdParty($authentication, $idthirdparty)
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: getInvoicesForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty);
@@ -482,7 +482,7 @@ function getInvoicesForThirdParty($authentication, $idthirdparty)
'fk_user_valid' => $invoice->user_valid ? $invoice->user_valid : '',
'date' => $invoice->date ?dol_print_date($invoice->date, 'dayrfc') : '',
'date_due' => $invoice->date_lim_reglement ?dol_print_date($invoice->date_lim_reglement, 'dayrfc') : '',
- 'date_creation' => $invoice->date_creation ?dol_print_date($invoice->date_creation, 'dayhourrfc') : '',
+ 'date_creation' => $invoice->date_creation ?dol_print_date($invoice->date_creation, 'dayhourrfc') : '',
'date_validation' => $invoice->date_validation ?dol_print_date($invoice->date_creation, 'dayhourrfc') : '',
'date_modification' => $invoice->datem ?dol_print_date($invoice->datem, 'dayhourrfc') : '',
'type' => $invoice->type,
@@ -492,7 +492,7 @@ function getInvoicesForThirdParty($authentication, $idthirdparty)
'note_private' => $invoice->note_private ? $invoice->note_private : '',
'note_public' => $invoice->note_public ? $invoice->note_public : '',
'status'=> $invoice->statut,
- 'project_id' => $invoic->fk_project,
+ 'project_id' => $invoice->fk_project,
'close_code' => $invoice->close_code ? $invoice->close_code : '',
'close_note' => $invoice->close_note ? $invoice->close_note : '',
'payment_mode_id' => $invoice->mode_reglement_id ? $invoice->mode_reglement_id : '',
@@ -528,17 +528,16 @@ function getInvoicesForThirdParty($authentication, $idthirdparty)
* Create an invoice
*
* @param array $authentication Array of authentication information
- * @param Facture $invoice Invoice
+ * @param array $invoice Invoice
* @return array Array result
*/
function createInvoice($authentication, $invoice)
{
- global $db, $conf, $langs;
+ global $db, $conf;
$now = dol_now();
- dol_syslog("Function: createInvoice login=".$authentication['login']." id=".$invoice->id.
- ", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext);
+ dol_syslog("Function: createInvoice login=".$authentication['login']." id=".$invoice['id'].", ref=".$invoice['ref'].", ref_ext=".$invoice['ref_ext']);
if ($authentication['entity']) $conf->entity = $authentication['entity'];
@@ -580,22 +579,22 @@ function createInvoice($authentication, $invoice)
if (isset($invoice['lines']['line'][0])) $arrayoflines = $invoice['lines']['line'];
else $arrayoflines = $invoice['lines'];
- foreach ($arrayoflines as $key => $line)
+ foreach ($arrayoflines as $line)
{
// $key can be 'line' or '0','1',...
$newline = new FactureLigne($db);
$newline->product_type = $line['type'];
$newline->desc = $line['desc'];
- $newline->fk_product = $line['fk_product'];
- $newline->tva_tx = $line['vat_rate'];
+ $newline->fk_product = $line['product_id'];
+ $newline->tva_tx = isset($line['vat_rate']) ? $line['vat_rate'] : 0;
$newline->qty = $line['qty'];
- $newline->subprice = $line['unitprice'];
+ $newline->subprice = isset($line['unitprice']) ? $line['unitprice'] : null;
$newline->total_ht = $line['total_net'];
$newline->total_tva = $line['total_vat'];
$newline->total_ttc = $line['total'];
$newline->date_start = dol_stringtotime($line['date_start']);
$newline->date_end = dol_stringtotime($line['date_end']);
- $newline->fk_product = $line['product_id'];
+
$new_invoice->lines[] = $newline;
}
//var_dump($newobject->date_lim_reglement); exit;
@@ -654,10 +653,7 @@ function createInvoiceFromOrder($authentication, $id_order = '', $ref_order = ''
{
global $db, $conf;
- $now = dol_now();
-
- dol_syslog("Function: createInvoiceFromOrder login=".$authentication['login']." id=".$id_order.
- ", ref=".$ref_order.", ref_ext=".$ref_ext_order);
+ dol_syslog("Function: createInvoiceFromOrder login=".$authentication['login']." id=".$id_order.", ref=".$ref_order.", ref_ext=".$ref_ext_order);
if ($authentication['entity']) $conf->entity = $authentication['entity'];
@@ -781,12 +777,11 @@ function updateInvoice($authentication, $invoice)
$object->generateDocument($object->model_pdf, $outputlangs);
}
}
- if ($invoice['status'] == Facture::STATUS_CLOSED)
- {
- $result = $object->set_paid($fuser, $invoice->close_code, $invoice->close_note);
+ if ($invoice['status'] == Facture::STATUS_CLOSED) {
+ $result = $object->set_paid($fuser, $invoice['close_code'], $invoice['close_note']);
}
if ($invoice['status'] == Facture::STATUS_ABANDONED)
- $result = $object->set_canceled($fuser, $invoice->close_code, $invoice->close_note);
+ $result = $object->set_canceled($fuser, $invoice['close_code'], $invoice['close_note']);
}
}
diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php
index 30c105d7192..361b2a08f4a 100644
--- a/htdocs/webservices/server_order.php
+++ b/htdocs/webservices/server_order.php
@@ -354,7 +354,7 @@ $server->register(
*/
function getOrder($authentication, $id = '', $ref = '', $ref_ext = '')
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: getOrder login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
@@ -504,7 +504,7 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '')
*/
function getOrdersForThirdParty($authentication, $idthirdparty)
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: getOrdersForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty);
@@ -707,7 +707,7 @@ function createOrder($authentication, $order)
$extrafields->fetch_name_optionals_label($elementtype, true);
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
{
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
{
$key = 'options_'.$key;
$newobject->array_options[$key] = $order[$key];
@@ -813,7 +813,7 @@ function validOrder($authentication, $id = '', $id_warehouse = 0)
{
global $db, $conf, $langs;
- dol_syslog("Function: validOrder login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
+ dol_syslog("Function: validOrder login=".$authentication['login']." id=".$id." id_warehouse=".$id_warehouse);
// Init and check authentication
$objectresp = array();
@@ -830,7 +830,7 @@ function validOrder($authentication, $id = '', $id_warehouse = 0)
if ($fuser->rights->commande->lire)
{
$order = new Commande($db);
- $result = $order->fetch($id, $ref, $ref_ext);
+ $result = $order->fetch($id);
$order->fetch_thirdparty();
$db->begin();
@@ -889,8 +889,6 @@ function updateOrder($authentication, $order)
{
global $db, $conf, $langs;
- $now = dol_now();
-
dol_syslog("Function: updateOrder login=".$authentication['login']);
if ($authentication['entity']) $conf->entity = $authentication['entity'];
@@ -950,7 +948,7 @@ function updateOrder($authentication, $order)
$extrafields->fetch_name_optionals_label($elementtype, true);
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
{
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
{
$key = 'options_'.$key;
if (isset($order[$key]))
diff --git a/htdocs/webservices/server_other.php b/htdocs/webservices/server_other.php
index 71ee78d3c4d..61f53f7e275 100644
--- a/htdocs/webservices/server_other.php
+++ b/htdocs/webservices/server_other.php
@@ -145,7 +145,7 @@ $server->register(
*/
function getVersions($authentication)
{
- global $db, $conf, $langs;
+ global $conf;
dol_syslog("Function: getVersions login=".$authentication['login']);
@@ -188,7 +188,7 @@ function getVersions($authentication)
*/
function getDocument($authentication, $modulepart, $file, $refname = '')
{
- global $db, $conf, $langs, $mysoc;
+ global $db, $conf;
dol_syslog("Function: getDocument login=".$authentication['login'].' - modulepart='.$modulepart.' - file='.$file);
@@ -283,10 +283,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '')
{
if (file_exists($original_file))
{
- dol_syslog("Function: getDocument $original_file $filename content-type=$type");
-
- $file = $fileparams['fullname'];
- $filename = basename($file);
+ dol_syslog("Function: getDocument $original_file content-type=$type");
$f = fopen($original_file, 'r');
$content_file = fread($f, filesize($original_file));
diff --git a/htdocs/webservices/server_payment.php b/htdocs/webservices/server_payment.php
index 8a9b19d76d6..3fd3868a36a 100644
--- a/htdocs/webservices/server_payment.php
+++ b/htdocs/webservices/server_payment.php
@@ -45,6 +45,7 @@ $langs->load("main");
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
{
$langs->load("admin");
+
dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
print $langs->trans("WarningModuleNotActive", 'WebServices').'.
';
print $langs->trans("ToActivateModule");
@@ -139,7 +140,7 @@ $server->register(
*/
function createPayment($authentication, $payment)
{
- global $db, $conf, $langs;
+ global $db, $conf;
$now = dol_now();
@@ -165,7 +166,7 @@ function createPayment($authentication, $payment)
if (!$error)
{
$soc = new Societe($db);
- $res = $soc->fetch($payment['thirdparty_id']);
+ $soc->fetch($payment['thirdparty_id']);
$new_payment = new Paiement($db);
$new_payment->amount = doubleval($payment['amount']);
diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php
index bb068167b74..4368386c41e 100644
--- a/htdocs/webservices/server_productorservice.php
+++ b/htdocs/webservices/server_productorservice.php
@@ -1,6 +1,7 @@
* Copyright (C) 2012 JF FERRY
+ * Copyright (C) 2020 Frédéric France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,7 +24,9 @@
* \brief File that is entry point to call Dolibarr WebServices
*/
-if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
+if (!defined("NOCSRFCHECK")) {
+ define("NOCSRFCHECK", '1');
+}
require '../master.inc.php';
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
@@ -42,8 +45,7 @@ dol_syslog("Call Dolibarr webservices interfaces");
$langs->load("main");
// Enable and test if module web services is enabled
-if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
-{
+if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) {
$langs->load("admin");
dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
print $langs->trans("WarningModuleNotActive", 'WebServices').'.
';
@@ -142,19 +144,22 @@ $extrafield_array = null;
if (is_array($extrafields) && count($extrafields) > 0) {
$extrafield_array = array();
}
-if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
-{
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
- {
+if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
$type = $extrafields->attributes[$elementtype]['type'][$key];
- if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; }
- else {$type = 'xsd:string'; }
+ if ($type == 'date' || $type == 'datetime') {
+ $type = 'xsd:dateTime';
+ } else {
+ $type = 'xsd:string';
+ }
$extrafield_array['options_'.$key] = array('name'=>'options_'.$key, 'type'=>$type);
}
}
-if (is_array($extrafield_array)) $productorservice_fields = array_merge($productorservice_fields, $extrafield_array);
+if (is_array($extrafield_array)) {
+ $productorservice_fields = array_merge($productorservice_fields, $extrafield_array);
+}
// Define other specific objects
$server->wsdl->addComplexType(
@@ -236,7 +241,6 @@ $server->wsdl->addComplexType(
);
-
// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
@@ -349,44 +353,49 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = ''
$langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
$langs->setDefaultLang($langcode);
- if ($authentication['entity']) $conf->entity = $authentication['entity'];
+ if ($authentication['entity']) {
+ $conf->entity = $authentication['entity'];
+ }
// Init and check authentication
$objectresp = array();
- $errorcode = ''; $errorlabel = '';
+ $errorcode = '';
+ $errorlabel = '';
$error = 0;
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
// Check parameters
- if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
- {
+ if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
$error++;
$errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
}
- if (!$error)
- {
+ if (!$error) {
$langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
$langs->setDefaultLang($langcode);
$fuser->getrights();
$nbmax = 10;
- if ($fuser->rights->produit->lire || $fuser->rights->service->lire)
- {
+ if ($fuser->rights->produit->lire || $fuser->rights->service->lire) {
$product = new Product($db);
$result = $product->fetch($id, $ref, $ref_ext);
- if ($result > 0)
- {
+ if ($result > 0) {
$product->load_stock();
$dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output);
$pdir = get_exdir($product->id, 2, 0, 0, $product, 'product').$product->ref."/";
$dir = $dir.'/'.$pdir;
- if (!empty($product->multilangs[$langs->defaultlang]["label"])) $product->label = $product->multilangs[$langs->defaultlang]["label"];
- if (!empty($product->multilangs[$langs->defaultlang]["description"])) $product->description = $product->multilangs[$langs->defaultlang]["description"];
- if (!empty($product->multilangs[$langs->defaultlang]["note"])) $product->note = $product->multilangs[$langs->defaultlang]["note"];
+ if (!empty($product->multilangs[$langs->defaultlang]["label"])) {
+ $product->label = $product->multilangs[$langs->defaultlang]["label"];
+ }
+ if (!empty($product->multilangs[$langs->defaultlang]["description"])) {
+ $product->description = $product->multilangs[$langs->defaultlang]["description"];
+ }
+ if (!empty($product->multilangs[$langs->defaultlang]["note"])) {
+ $product->note = $product->multilangs[$langs->defaultlang]["note"];
+ }
$productorservice_result_fields = array(
'id' => $product->id,
@@ -436,10 +445,8 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = ''
//Get extrafield values
$product->fetch_optionals();
- if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
- {
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
- {
+ if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
$productorservice_result_fields = array_merge($productorservice_result_fields, array('options_'.$key => $product->array_options['options_'.$key]));
}
}
@@ -449,20 +456,17 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = ''
'result'=>array('result_code'=>'OK', 'result_label'=>''),
'product'=>$productorservice_result_fields
);
- }
- else {
+ } else {
$error++;
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
}
- }
- else {
+ } else {
$error++;
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
}
}
- if ($error)
- {
+ if ($error) {
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
//var_dump($objectresp);exit;
@@ -479,37 +483,41 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = ''
*/
function createProductOrService($authentication, $product)
{
- global $db, $conf, $langs;
+ global $db, $conf;
$now = dol_now();
dol_syslog("Function: createProductOrService login=".$authentication['login']);
- if ($authentication['entity']) $conf->entity = $authentication['entity'];
+ if ($authentication['entity']) {
+ $conf->entity = $authentication['entity'];
+ }
// Init and check authentication
$objectresp = array();
- $errorcode = ''; $errorlabel = '';
+ $errorcode = '';
+ $errorlabel = '';
$error = 0;
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
// Check parameters
if (empty($product['price_base_type'])) {
- if (isset($product['price_net']) && $product['price_net'] > 0) $product['price_base_type'] = 'HT';
- if (isset($product['price']) && $product['price'] > 0) $product['price_base_type'] = 'TTC';
+ if (isset($product['price_net']) && $product['price_net'] > 0) {
+ $product['price_base_type'] = 'HT';
+ }
+ if (isset($product['price']) && $product['price'] > 0) {
+ $product['price_base_type'] = 'TTC';
+ }
}
- if (isset($product['price_net']) && $product['price_net'] > 0 && isset($product['price']) && $product['price'] > 0)
- {
+ if (isset($product['price_net']) && $product['price_net'] > 0 && isset($product['price']) && $product['price'] > 0) {
$error++; $errorcode = 'KO'; $errorlabel = "You must choose between price or price_net to provide price.";
}
- if (!empty($product['barcode']) && empty($product['barcode_type']))
- {
+ if (!empty($product['barcode']) && empty($product['barcode_type'])) {
$error++; $errorcode = 'KO'; $errorlabel = "You must set a barcode type when setting a barcode.";
}
- if (!$error)
- {
+ if (!$error) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
$newobject = new Product($db);
@@ -528,34 +536,35 @@ function createProductOrService($authentication, $product)
$newobject->price_base_type = $product['price_base_type'];
$newobject->date_creation = $now;
- if (!empty($product['barcode']))
- {
+ if (!empty($product['barcode'])) {
$newobject->barcode = $product['barcode'];
$newobject->barcode_type = $product['barcode_type'];
}
$newobject->stock_reel = isset($product['stock_real']) ? $product['stock_real'] : null;
$newobject->pmp = isset($product['pmp']) ? $product['pmp'] : null;
- $newobject->seuil_stock_alert = isset($product['stock_alert']) ? $product['stock_alert'] : null;
+ $newobject->seuil_stock_alerte = isset($product['stock_alert']) ? $product['stock_alert'] : null;
$newobject->country_id = isset($product['country_id']) ? $product['country_id'] : 0;
- if (!empty($product['country_code'])) $newobject->country_id = getCountry($product['country_code'], 3);
+ if (!empty($product['country_code'])) {
+ $newobject->country_id = getCountry($product['country_code'], 3);
+ }
$newobject->customcode = isset($product['customcode']) ? $product['customcode'] : '';
$newobject->canvas = isset($product['canvas']) ? $product['canvas'] : '';
/*foreach($product['lines'] as $line)
- {
- $newline=new FactureLigne($db);
- $newline->type=$line['type'];
- $newline->desc=$line['desc'];
- $newline->fk_product=$line['fk_product'];
- $newline->total_ht=$line['total_net'];
- $newline->total_vat=$line['total_vat'];
- $newline->total_ttc=$line['total'];
- $newline->vat=$line['vat_rate'];
- $newline->qty=$line['qty'];
- $newline->fk_product=$line['product_id'];
- }*/
+ {
+ $newline=new FactureLigne($db);
+ $newline->type=$line['type'];
+ $newline->desc=$line['desc'];
+ $newline->fk_product=$line['fk_product'];
+ $newline->total_ht=$line['total_net'];
+ $newline->total_vat=$line['total_vat'];
+ $newline->total_ttc=$line['total'];
+ $newline->vat=$line['vat_rate'];
+ $newline->qty=$line['qty'];
+ $newline->fk_product=$line['product_id'];
+ }*/
//var_dump($product['ref_ext']);
//var_dump($product['lines'][0]['type']);
@@ -563,10 +572,8 @@ function createProductOrService($authentication, $product)
$extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label($elementtype, true);
- if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
- {
- foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
- {
+ if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
$key = 'options_'.$key;
$newobject->array_options[$key] = $product[$key];
}
@@ -575,43 +582,34 @@ function createProductOrService($authentication, $product)
$db->begin();
$result = $newobject->create($fuser, 0);
- if ($result <= 0)
- {
+ if ($result <= 0) {
$error++;
}
- if (!$error)
- {
+ if (!$error) {
// Update stock if stock count is provided and differs from database after creation or update
- if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled))
- {
+ if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) {
include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
$savstockreal = $newobject->stock_reel;
$newobject->load_stock('novirtual,nobatch'); // This overwrite ->stock_reel, surely 0 because we have just created product
$getstockreal = $newobject->stock_reel;
- if ($savstockreal != $getstockreal)
- {
+ if ($savstockreal != $getstockreal) {
$warehouse = new Entrepot($db);
$warehouse->fetch(0, $product['warehouse_ref']);
- if ($warehouse->id > 0)
- {
- if (($savstockreal - $getstockreal) > 0)
- {
+ if ($warehouse->id > 0) {
+ if (($savstockreal - $getstockreal) > 0) {
$result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog'));
}
- if (($savstockreal - $getstockreal) > 0)
- {
+ if (($savstockreal - $getstockreal) > 0) {
$result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog'));
}
- if ($result <= 0)
- {
+ if ($result <= 0) {
$error++;
$newobject->error = 'You set a different value for stock, but correction of stock count (before='.$getstockreal.', after='.$savstockreal.') fails with error '.$newobject->error;
}
- }
- else {
+ } else {
$error++;
$newobject->error = 'You set a different value for stock but we failed to find warehouse '.$product['warehouse_ref'].' to make correction.';
}
@@ -619,12 +617,10 @@ function createProductOrService($authentication, $product)
}
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref);
- }
- else {
+ } else {
$db->rollback();
$error++;
$errorcode = 'KO';
@@ -632,8 +628,7 @@ function createProductOrService($authentication, $product)
}
}
- if ($error)
- {
+ if ($error) {
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
@@ -650,43 +645,51 @@ function createProductOrService($authentication, $product)
*/
function updateProductOrService($authentication, $product)
{
- global $db, $conf, $langs;
+ global $db, $conf;
$now = dol_now();
dol_syslog("Function: updateProductOrService login=".$authentication['login']);
- if ($authentication['entity']) $conf->entity = $authentication['entity'];
+ if ($authentication['entity']) {
+ $conf->entity = $authentication['entity'];
+ }
// Init and check authentication
$objectresp = array();
- $errorcode = ''; $errorlabel = '';
+ $errorcode = '';
+ $errorlabel = '';
$error = 0;
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
// Check parameters
- if ($product['price_net'] > 0) $product['price_base_type'] = 'HT';
- if ($product['price'] > 0) $product['price_base_type'] = 'TTC';
+ if ($product['price_net'] > 0) {
+ $product['price_base_type'] = 'HT';
+ }
+ if ($product['price'] > 0) {
+ $product['price_base_type'] = 'TTC';
+ }
- if ($product['price_net'] > 0 && $product['price'] > 0)
- {
+ if ($product['price_net'] > 0 && $product['price'] > 0) {
$error++; $errorcode = 'KO'; $errorlabel = "You must choose between price or price_net to provide price.";
}
- if ($product['barcode'] && !$product['barcode_type'])
- {
+ if ($product['barcode'] && !$product['barcode_type']) {
$error++; $errorcode = 'KO'; $errorlabel = "You must set a barcode type when setting a barcode.";
}
- if (!$error)
- {
+ if (!$error) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
$newobject = new Product($db);
$newobject->fetch($product['id']);
- if (isset($product['ref'])) $newobject->ref = $product['ref'];
- if (isset($product['ref_ext'])) $newobject->ref_ext = $product['ref_ext'];
+ if (isset($product['ref'])) {
+ $newobject->ref = $product['ref'];
+ }
+ if (isset($product['ref_ext'])) {
+ $newobject->ref_ext = $product['ref_ext'];
+ }
$newobject->type = $product['type'];
$newobject->label = $product['label'];
$newobject->description = $product['description'];
@@ -699,30 +702,27 @@ function updateProductOrService($authentication, $product)
$newobject->price_base_type = $product['price_base_type'];
$newobject->date_creation = $now;
- if ($product['barcode'])
- {
+ if ($product['barcode']) {
$newobject->barcode = $product['barcode'];
$newobject->barcode_type = $product['barcode_type'];
}
- $newobject->stock_reel = $product['stock_real'];
- $newobject->pmp = $product['pmp'];
- $newobject->seuil_stock_alert = $product['stock_alert'];
+ $newobject->stock_reel = isset($product['stock_real']) ? $product['stock_real'] : null;
+ $newobject->pmp = isset($product['pmp']) ? $product['pmp'] : null;
+ $newobject->seuil_stock_alerte = isset($product['stock_alert']) ? $product['stock_alert'] : null;
- $newobject->country_id = $product['country_id'];
- if ($product['country_code']) $newobject->country_id = getCountry($product['country_code'], 3);
- $newobject->customcode = $product['customcode'];
+ $newobject->country_id = isset($product['country_id']) ? $product['country_id'] : 0;
+ if (!empty($product['country_code'])) $newobject->country_id = getCountry($product['country_code'], 3);
+ $newobject->customcode = isset($product['customcode']) ? $product['customcode'] : '';
- $newobject->canvas = $product['canvas'];
+ $newobject->canvas = isset($product['canvas']) ? $product['canvas'] : '';
$elementtype = 'product';
$extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label($elementtype, true);
- if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
- {
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
- {
+ if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
$key = 'options_'.$key;
$newobject->array_options[$key] = $product[$key];
}
@@ -731,41 +731,32 @@ function updateProductOrService($authentication, $product)
$db->begin();
$result = $newobject->update($newobject->id, $fuser);
- if ($result <= 0)
- {
+ if ($result <= 0) {
$error++;
- }
- else {
+ } else {
// Update stock if stock count is provided and differs from database after creation or update
- if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled))
- {
+ if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) {
include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
$savstockreal = $newobject->stock_reel;
$newobject->load_stock('novirtual,nobatch'); // This overwrite ->stock_reel
$getstockreal = $newobject->stock_reel;
- if ($savstockreal != $getstockreal)
- {
+ if ($savstockreal != $getstockreal) {
$warehouse = new Entrepot($db);
$warehouse->fetch(0, $product['warehouse_ref']);
- if ($warehouse->id > 0)
- {
- if (($savstockreal - $getstockreal) > 0)
- {
+ if ($warehouse->id > 0) {
+ if (($savstockreal - $getstockreal) > 0) {
$result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog'));
}
- if (($savstockreal - $getstockreal) > 0)
- {
+ if (($savstockreal - $getstockreal) > 0) {
$result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog'));
}
- if ($result <= 0)
- {
+ if ($result <= 0) {
$error++;
$newobject->error = 'You set a different value for stock, but correction of stock count (before='.$getstockreal.', after='.$savstockreal.') fails with error '.$newobject->error;
}
- }
- else {
+ } else {
$error++;
$newobject->error = 'You set a different value for stock but we failed to find warehouse '.$product['warehouse_ref'].' to make correction.';
}
@@ -773,32 +764,24 @@ function updateProductOrService($authentication, $product)
}
}
- if (!$error)
- {
- if ($newobject->price_base_type == 'HT')
- {
+ if (!$error) {
+ if ($newobject->price_base_type == 'HT') {
$result = $newobject->updatePrice($newobject->price, $newobject->price_base_type, $fuser);
- if ($result <= 0)
- {
+ if ($result <= 0) {
$error++;
}
- }
- elseif ($newobject->price_base_type == 'TTC')
- {
- $result = $newobject->updatePrice($newobject->price_ttc, $newobject->price_base_type);
- if ($result <= 0)
- {
+ } elseif ($newobject->price_base_type == 'TTC') {
+ $result = $newobject->updatePrice($newobject->price_ttc, $newobject->price_base_type, $fuser);
+ if ($result <= 0) {
$error++;
}
}
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref);
- }
- else {
+ } else {
$db->rollback();
$error++;
$errorcode = 'KO';
@@ -806,8 +789,7 @@ function updateProductOrService($authentication, $product)
}
}
- if ($error)
- {
+ if ($error) {
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
@@ -824,15 +806,18 @@ function updateProductOrService($authentication, $product)
*/
function deleteProductOrService($authentication, $listofidstring)
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: deleteProductOrService login=".$authentication['login']);
- if ($authentication['entity']) $conf->entity = $authentication['entity'];
+ if ($authentication['entity']) {
+ $conf->entity = $authentication['entity'];
+ }
// Init and check authentication
$objectresp = array();
- $errorcode = ''; $errorlabel = '';
+ $errorcode = '';
+ $errorlabel = '';
$error = 0;
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
@@ -844,32 +829,26 @@ function deleteProductOrService($authentication, $listofidstring)
$listofiddeleted = array();
// Check parameters
- if (count($listofid) == 0 || empty($listofid[0]))
- {
+ if (count($listofid) == 0 || empty($listofid[0])) {
$error++; $errorcode = 'KO'; $errorlabel = "List of Id of products or services to delete are required.";
}
- if (!$error)
- {
+ if (!$error) {
$firsterror = '';
$db->begin();
- foreach ($listofid as $key => $id)
- {
+ foreach ($listofid as $id) {
$newobject = new Product($db);
$result = $newobject->fetch($id);
- if ($result == 0)
- {
+ if ($result == 0) {
$error++;
$firsterror = 'Product or service with id '.$id.' not found';
break;
- }
- else {
+ } else {
$result = $newobject->delete($user);
- if ($result <= 0)
- {
+ if ($result <= 0) {
$error++;
$firsterror = $newobject->error;
break;
@@ -879,13 +858,11 @@ function deleteProductOrService($authentication, $listofidstring)
}
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
//$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'listofid'=>$listofiddeleted);
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'nbdeleted'=>count($listofiddeleted));
- }
- else {
+ } else {
$db->rollback();
$error++;
$errorcode = 'KO';
@@ -893,15 +870,12 @@ function deleteProductOrService($authentication, $listofidstring)
}
}
- if ($error)
- {
+ if ($error) {
//$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel), 'listofid'=>$listofiddeleted);
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel), 'nbdeleted'=>0);
- }
- elseif (count($listofiddeleted) == 0)
- {
- //$objectresp=array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',',$listofid).' found'), 'listofid'=>$listofiddeleted);
- $objectresp = array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',', $listofid).' found'), 'nbdeleted'=>0);
+ } elseif (count($listofiddeleted) == 0) {
+ //$objectresp=array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',',$listofid).' found'), 'listofid'=>$listofiddeleted);
+ $objectresp = array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',', $listofid).' found'), 'nbdeleted'=>0);
}
return $objectresp;
@@ -917,53 +891,56 @@ function deleteProductOrService($authentication, $listofidstring)
*/
function getListOfProductsOrServices($authentication, $filterproduct)
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: getListOfProductsOrServices login=".$authentication['login']);
- if ($authentication['entity']) $conf->entity = $authentication['entity'];
+ if ($authentication['entity']) {
+ $conf->entity = $authentication['entity'];
+ }
// Init and check authentication
$objectresp = array();
$arrayproducts = array();
- $errorcode = ''; $errorlabel = '';
+ $errorcode = '';
+ $errorlabel = '';
$error = 0;
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
// Check parameters
- if (!$error)
- {
+ if (!$error) {
$sql = "SELECT rowid, ref, ref_ext";
$sql .= " FROM ".MAIN_DB_PREFIX."product";
$sql .= " WHERE entity=".$conf->entity;
- foreach ($filterproduct as $key => $val)
- {
- if ($key == 'type' && $val >= 0) $sql .= " AND fk_product_type = ".$db->escape($val);
- if ($key == 'status_tosell') $sql .= " AND tosell = ".$db->escape($val);
- if ($key == 'status_tobuy') $sql .= " AND tobuy = ".$db->escape($val);
+ foreach ($filterproduct as $key => $val) {
+ if ($key == 'type' && $val >= 0) {
+ $sql .= " AND fk_product_type = ".$db->escape($val);
+ }
+ if ($key == 'status_tosell') {
+ $sql .= " AND tosell = ".$db->escape($val);
+ }
+ if ($key == 'status_tobuy') {
+ $sql .= " AND tobuy = ".$db->escape($val);
+ }
}
$resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
+ if ($resql) {
+ $num = $db->num_rows($resql);
- $i = 0;
- while ($i < $num)
- {
- $obj = $db->fetch_object($resql);
- $arrayproducts[] = array('id'=>$obj->rowid, 'ref'=>$obj->ref, 'ref_ext'=>$obj->ref_ext);
- $i++;
- }
- }
- else {
+ $i = 0;
+ while ($i < $num) {
+ $obj = $db->fetch_object($resql);
+ $arrayproducts[] = array('id'=>$obj->rowid, 'ref'=>$obj->ref, 'ref_ext'=>$obj->ref_ext);
+ $i++;
+ }
+ } else {
$error++;
$errorcode = $db->lasterrno();
$errorlabel = $db->lasterror();
}
}
- if ($error)
- {
+ if ($error) {
$objectresp = array(
'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel),
'products'=>$arrayproducts
@@ -996,7 +973,9 @@ function getProductsForCategory($authentication, $id, $lang = '')
dol_syslog("Function: getProductsForCategory login=".$authentication['login']." id=".$id);
- if ($authentication['entity']) $conf->entity = $authentication['entity'];
+ if ($authentication['entity']) {
+ $conf->entity = $authentication['entity'];
+ }
$objectresp = array();
$errorcode = ''; $errorlabel = '';
@@ -1005,27 +984,23 @@ function getProductsForCategory($authentication, $id, $lang = '')
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
- if (!$error && !$id)
- {
+ if (!$error && !$id) {
$error++;
$errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id must be provided.";
}
- if (!$error)
- {
+ if (!$error) {
$langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
$langs->setDefaultLang($langcode);
$fuser->getrights();
$nbmax = 10;
- if ($fuser->rights->produit->lire)
- {
+ if ($fuser->rights->produit->lire) {
$categorie = new Categorie($db);
$result = $categorie->fetch($id);
- if ($result > 0)
- {
+ if ($result > 0) {
$table = "product";
$field = "product";
$sql = "SELECT fk_".$field." FROM ".MAIN_DB_PREFIX."categorie_".$table;
@@ -1035,24 +1010,21 @@ function getProductsForCategory($authentication, $id, $lang = '')
dol_syslog("getProductsForCategory get id of product into category", LOG_DEBUG);
$res = $db->query($sql);
- if ($res)
- {
+ if ($res) {
$iProduct = 0;
$tmpproduct = new Product($db);
$products = array();
- while ($rec = $db->fetch_array($res))
- {
+ while ($rec = $db->fetch_array($res)) {
$tmpproduct->fetch($rec['fk_'.$field]);
- if ($tmpproduct->status > 0)
- {
+ if ($tmpproduct->status > 0) {
$dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output);
$pdir = get_exdir($tmpproduct->id, 2, 0, 0, $tmpproduct, 'product').$tmpproduct->id."/photos/";
$dir = $dir.'/'.$pdir;
$products[] = array(
'id' => $tmpproduct->id,
- 'ref' => $tmpproduct->ref,
- 'ref_ext' => $tmpproduct->ref_ext,
+ 'ref' => $tmpproduct->ref,
+ 'ref_ext' => $tmpproduct->ref_ext,
'label' => !empty($tmpproduct->multilangs[$langs->defaultlang]["label"]) ? $tmpproduct->multilangs[$langs->defaultlang]["label"] : $tmpproduct->label,
'description' => !empty($tmpproduct->multilangs[$langs->defaultlang]["description"]) ? $tmpproduct->multilangs[$langs->defaultlang]["description"] : $tmpproduct->description,
'date_creation' => dol_print_date($tmpproduct->date_creation, 'dayhourrfc'),
@@ -1090,10 +1062,8 @@ function getProductsForCategory($authentication, $id, $lang = '')
//Get extrafield values
$tmpproduct->fetch_optionals();
- if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
- {
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
- {
+ if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
$products[$iProduct] = array_merge($products[$iProduct], array('options_'.$key => $tmpproduct->array_options['options_'.$key]));
}
}
@@ -1107,26 +1077,22 @@ function getProductsForCategory($authentication, $id, $lang = '')
'result'=>array('result_code'=>'OK', 'result_label'=>''),
'products'=> $products
);
- }
- else {
+ } else {
$errorcode = 'NORECORDS_FOR_ASSOCIATION'; $errorlabel = 'No products associated'.$sql;
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
dol_syslog("getProductsForCategory:: ".$errorcode, LOG_DEBUG);
}
- }
- else {
+ } else {
$error++;
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id;
}
- }
- else {
+ } else {
$error++;
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
}
}
- if ($error)
- {
+ if ($error) {
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
diff --git a/htdocs/webservices/server_project.php b/htdocs/webservices/server_project.php
index 0817332c09f..8d76786df71 100644
--- a/htdocs/webservices/server_project.php
+++ b/htdocs/webservices/server_project.php
@@ -131,7 +131,7 @@ $server->wsdl->addComplexType(
);
$project_elements = array();
-foreach ($listofreferent as $key => $_)
+foreach ($listofreferent as $key => $label)
{
$project_elements[$key] = array('name'=>$key, 'type'=>'tns:elementsArray');
}
@@ -279,7 +279,7 @@ function createProject($authentication, $project)
$extrafields->fetch_name_optionals_label($elementtype, true);
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
{
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
{
$key = 'options_'.$key;
$newobject->array_options[$key] = $project[$key];
@@ -338,7 +338,7 @@ function createProject($authentication, $project)
*/
function getProject($authentication, $id = '', $ref = '')
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: getProject login=".$authentication['login']." id=".$id." ref=".$ref);
@@ -389,7 +389,7 @@ function getProject($authentication, $id = '', $ref = '')
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
{
$project->fetch_optionals();
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
{
$project_result_fields = array_merge($project_result_fields, array('options_'.$key => $project->array_options['options_'.$key]));
}
diff --git a/htdocs/webservices/server_supplier_invoice.php b/htdocs/webservices/server_supplier_invoice.php
index be90b60c36f..507095ac78b 100644
--- a/htdocs/webservices/server_supplier_invoice.php
+++ b/htdocs/webservices/server_supplier_invoice.php
@@ -225,7 +225,7 @@ $server->register(
*/
function getSupplierInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: getSupplierInvoice login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
@@ -333,7 +333,7 @@ function getSupplierInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
*/
function getSupplierInvoicesForThirdParty($authentication, $idthirdparty)
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: getSupplierInvoicesForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty);
@@ -344,6 +344,7 @@ function getSupplierInvoicesForThirdParty($authentication, $idthirdparty)
$errorcode = ''; $errorlabel = '';
$error = 0;
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
+
// Check parameters
if (!$error && empty($idthirdparty))
{
diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php
index 5bde94cc0d5..12b2d3315c8 100644
--- a/htdocs/webservices/server_thirdparty.php
+++ b/htdocs/webservices/server_thirdparty.php
@@ -132,7 +132,7 @@ if (is_array($extrafields) && count($extrafields) > 0) {
}
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
{
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
{
//$value=$object->array_options["options_".$key];
$type = $extrafields->attributes[$elementtype]['type'][$key];
@@ -290,7 +290,7 @@ $server->register(
*/
function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: getThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
@@ -367,7 +367,7 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
{
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
{
$thirdparty_result_fields = array_merge($thirdparty_result_fields, array('options_'.$key => $thirdparty->array_options['options_'.$key]));
}
@@ -408,7 +408,7 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
*/
function createThirdParty($authentication, $thirdparty)
{
- global $db, $conf, $langs;
+ global $db, $conf;
$now = dol_now();
@@ -483,7 +483,7 @@ function createThirdParty($authentication, $thirdparty)
$extrafields->fetch_name_optionals_label($elementtype, true);
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
{
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
{
$key = 'options_'.$key;
$newobject->array_options[$key] = $thirdparty[$key];
@@ -538,7 +538,7 @@ function createThirdParty($authentication, $thirdparty)
*/
function updateThirdParty($authentication, $thirdparty)
{
- global $db, $conf, $langs;
+ global $db, $conf;
$now = dol_now();
@@ -617,7 +617,7 @@ function updateThirdParty($authentication, $thirdparty)
$extrafields->fetch_name_optionals_label($elementtype, true);
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
{
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
{
$key = 'options_'.$key;
$object->array_options[$key] = $thirdparty[$key];
@@ -672,9 +672,7 @@ function updateThirdParty($authentication, $thirdparty)
*/
function getListOfThirdParties($authentication, $filterthirdparty)
{
- global $db, $conf, $langs;
-
- $now = dol_now();
+ global $db, $conf;
dol_syslog("Function: getListOfThirdParties login=".$authentication['login']);
@@ -725,7 +723,7 @@ function getListOfThirdParties($authentication, $filterthirdparty)
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
{
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
{
$extrafieldsOptions['options_'.$key] = $obj->{$key};
}
@@ -782,7 +780,7 @@ function getListOfThirdParties($authentication, $filterthirdparty)
*/
function deleteThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: deleteThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
diff --git a/htdocs/webservices/server_user.php b/htdocs/webservices/server_user.php
index 25cb2324412..8619a952ea1 100644
--- a/htdocs/webservices/server_user.php
+++ b/htdocs/webservices/server_user.php
@@ -195,7 +195,7 @@ if (is_array($extrafields) && count($extrafields) > 0) {
}
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
{
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
{
$type = $extrafields->attributes[$elementtype]['type'][$key];
if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; }
@@ -308,7 +308,7 @@ $server->register(
*/
function getUser($authentication, $id, $ref = '', $ref_ext = '')
{
- global $db, $conf, $langs;
+ global $db, $conf;
dol_syslog("Function: getUser login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
@@ -399,9 +399,7 @@ function getUser($authentication, $id, $ref = '', $ref_ext = '')
*/
function getListOfGroups($authentication)
{
- global $db, $conf, $langs;
-
- $now = dol_now();
+ global $db, $conf;
dol_syslog("Function: getListOfGroups login=".$authentication['login']);
@@ -477,7 +475,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
{
global $db, $conf, $langs;
- dol_syslog("Function: createUserFromThirdparty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
+ dol_syslog("Function: createUserFromThirdparty login=".$authentication['login']);
if ($authentication['entity']) $conf->entity = $authentication['entity'];
@@ -601,7 +599,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
$extrafields->fetch_name_optionals_label($elementtype, true);
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
{
- foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
+ foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
{
$key = 'contact_options_'.$key;
$key = substr($key, 8); // Remove 'contact_' prefix
@@ -644,7 +642,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
}
} else {
$error++;
- $errors = ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors);
+ $errorcode = join(', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
}
}
} else {
@@ -662,7 +660,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
{
$db->rollback();
$objectresp = array(
- 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)
+ 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)
);
}
@@ -680,9 +678,9 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
function setUserPassword($authentication, $shortuser)
{
- global $db, $conf, $langs;
+ global $db, $conf;
- dol_syslog("Function: setUserPassword login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
+ dol_syslog("Function: setUserPassword login=".$authentication['login']);
if ($authentication['entity']) $conf->entity = $authentication['entity'];
@@ -715,7 +713,6 @@ function setUserPassword($authentication, $shortuser)
{
$objectresp = array(
'result'=>array('result_code' => 'OK', 'result_label' => ''),
- 'groups'=>$arraygroups
);
}
else {
diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php
index 7cbb6af5955..8dc903642e0 100644
--- a/test/phpunit/FunctionsLibTest.php
+++ b/test/phpunit/FunctionsLibTest.php
@@ -131,6 +131,35 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
print __METHOD__."\n";
}
+ /**
+ * testIsValidEmail
+ *
+ * @return void
+ */
+ public function testIsValidEmail()
+ {
+ // Nb of line is same than entry text
+
+ $input="bidon@bademail";
+ $result=isValidEmail($input);
+ print __METHOD__." result=".$result."\n";
+ $this->assertFalse($result, 'Check isValidEmail '.$input);
+
+ $input="test@yahoo.com";
+ $result=isValidEmail($input);
+ print __METHOD__." result=".$result."\n";
+ $this->assertTrue($result, 'Check isValidEmail '.$input);
+
+ $input="The name of sender ";
+ $result=isValidEmail($input);
+ print __METHOD__." result=".$result."\n";
+ $this->assertFalse($result, 'Check isValidEmail '.$input);
+
+ $input="1234.abcdefg@domainame.com.br";
+ $result=isValidEmail($input);
+ print __METHOD__." result=".$result."\n";
+ $this->assertTrue($result, 'Check isValidEmail '.$input);
+ }
/**
* testIsValidMXRecord
diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php
index 650e391587b..6bedda43fa4 100644
--- a/test/phpunit/WebservicesInvoicesTest.php
+++ b/test/phpunit/WebservicesInvoicesTest.php
@@ -61,6 +61,9 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase
protected $ns = 'http://www.dolibarr.org/ns/';
+ protected $pass = 'admin';
+
+
/**
* Constructor
* We save global variables into local variables
@@ -102,6 +105,8 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase
{
global $conf,$user,$langs,$db;
+ $now = dol_now();
+
// create a third_party, needed to create an invoice
//
// The third party is created in setUpBeforeClass() and not in the
@@ -246,7 +251,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
'sourceapplication'=>'DEMO',
'login'=>'admin',
- 'password'=>'admin',
+ 'password'=>$this->pass,
'entity'=>'');
// Test URL
@@ -270,7 +275,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase
print "\n";
}
- print __METHOD__." result=".$result['result']['result_code']."\n";
+ print __METHOD__." result=".$result['result']['result_code']." ".$result['result']['result_label']."\n";
$this->assertEquals('OK', $result['result']['result_code']);
$this->assertEquals('ref-phpunit-2', $result['ref_ext']);
@@ -302,7 +307,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
'sourceapplication'=>'DEMO',
'login'=>'admin',
- 'password'=>'admin',
+ 'password'=>$this->pass,
'entity'=>'');
// Test URL
@@ -401,7 +406,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
'sourceapplication'=>'DEMO',
'login'=>'admin',
- 'password'=>'admin',
+ 'password'=>$this->pass,
'entity'=>'');
// Test URL