Fix nature of thirdparty must use the picto

This commit is contained in:
Laurent Destailleur 2022-06-29 21:55:31 +02:00
parent 3bd5ed3782
commit d13bd3eaa6
3 changed files with 37 additions and 19 deletions

View File

@ -1257,9 +1257,10 @@ class Form
* @param array $ajaxoptions Options for ajax_autocompleter * @param array $ajaxoptions Options for ajax_autocompleter
* @param bool $multiple add [] in the name of element and add 'multiple' attribut (not working with ajax_autocompleter) * @param bool $multiple add [] in the name of element and add 'multiple' attribut (not working with ajax_autocompleter)
* @param array $excludeids Exclude IDs from the select combo * @param array $excludeids Exclude IDs from the select combo
* @param int $showcode Show code
* @return string HTML string with select box for thirdparty. * @return string HTML string with select box for thirdparty.
*/ */
public function select_company($selected = '', $htmlname = 'socid', $filter = '', $showempty = '', $showtype = 0, $forcecombo = 0, $events = array(), $limit = 0, $morecss = 'minwidth100', $moreparam = '', $selected_input_value = '', $hidelabel = 1, $ajaxoptions = array(), $multiple = false, $excludeids = array()) public function select_company($selected = '', $htmlname = 'socid', $filter = '', $showempty = '', $showtype = 0, $forcecombo = 0, $events = array(), $limit = 0, $morecss = 'minwidth100', $moreparam = '', $selected_input_value = '', $hidelabel = 1, $ajaxoptions = array(), $multiple = false, $excludeids = array(), $showcode = 0)
{ {
// phpcs:enable // phpcs:enable
global $conf, $user, $langs; global $conf, $user, $langs;
@ -1303,7 +1304,7 @@ class Form
$out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
} else { } else {
// Immediate load of all database // Immediate load of all database
$out .= $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit, $morecss, $moreparam, $multiple, $excludeids); $out .= $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
} }
return $out; return $out;
@ -1328,9 +1329,10 @@ class Form
* @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container
* @param bool $multiple add [] in the name of element and add 'multiple' attribut * @param bool $multiple add [] in the name of element and add 'multiple' attribut
* @param array $excludeids Exclude IDs from the select combo * @param array $excludeids Exclude IDs from the select combo
* @param int $showcode Show code in list
* @return string HTML string with * @return string HTML string with
*/ */
public function select_thirdparty_list($selected = '', $htmlname = 'socid', $filter = '', $showempty = '', $showtype = 0, $forcecombo = 0, $events = array(), $filterkey = '', $outputmode = 0, $limit = 0, $morecss = 'minwidth100', $moreparam = '', $multiple = false, $excludeids = array()) public function select_thirdparty_list($selected = '', $htmlname = 'socid', $filter = '', $showempty = '', $showtype = 0, $forcecombo = 0, $events = array(), $filterkey = '', $outputmode = 0, $limit = 0, $morecss = 'minwidth100', $moreparam = '', $multiple = false, $excludeids = array(), $showcode = 0)
{ {
// phpcs:enable // phpcs:enable
global $conf, $user, $langs; global $conf, $user, $langs;
@ -1442,13 +1444,15 @@ class Form
$out .= '<option value="-1" data-html="'.dol_escape_htmltag('<span class="opacitymedium">'.($textifempty ? $textifempty : '&nbsp;').'</span>').'">'.$textifempty.'</option>'."\n"; $out .= '<option value="-1" data-html="'.dol_escape_htmltag('<span class="opacitymedium">'.($textifempty ? $textifempty : '&nbsp;').'</span>').'">'.$textifempty.'</option>'."\n";
} }
$companytemp = new Societe($this->db);
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
if ($num) { if ($num) {
while ($i < $num) { while ($i < $num) {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$label = ''; $label = '';
if ($conf->global->SOCIETE_ADD_REF_IN_LIST) { if ($showcode || !empty($conf->global->SOCIETE_ADD_REF_IN_LIST)) {
if (($obj->client) && (!empty($obj->code_client))) { if (($obj->client) && (!empty($obj->code_client))) {
$label = $obj->code_client.' - '; $label = $obj->code_client.' - ';
} }
@ -1468,7 +1472,17 @@ class Form
$label .= ' - '.$obj->tva_intra.''; $label .= ' - '.$obj->tva_intra.'';
} }
$labelhtml = $label;
if ($showtype) { if ($showtype) {
$companytemp->id = $obj->rowid;
$companytemp->client = $obj->client;
$companytemp->fournisseur = $obj->fournisseur;
$tmptype = $companytemp->getTypeUrl(1, '', 0, 'span');
if ($tmptype) {
$labelhtml .= ' '.$tmptype;
}
if ($obj->client || $obj->fournisseur) { if ($obj->client || $obj->fournisseur) {
$label .= ' ('; $label .= ' (';
} }
@ -1487,20 +1501,22 @@ class Form
} }
if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) { if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
$label .= ($obj->address ? ' - '.$obj->address : '').($obj->zip ? ' - '.$obj->zip : '').($obj->town ? ' '.$obj->town : ''); $s = ($obj->address ? ' - '.$obj->address : '').($obj->zip ? ' - '.$obj->zip : '').($obj->town ? ' '.$obj->town : '');
if (!empty($obj->country_code)) { if (!empty($obj->country_code)) {
$label .= ', '.$langs->trans('Country'.$obj->country_code); $s .= ', '.$langs->trans('Country'.$obj->country_code);
} }
$label .= $s;
$labelhtml .= $s;
} }
if (empty($outputmode)) { if (empty($outputmode)) {
if (in_array($obj->rowid, $selected)) { if (in_array($obj->rowid, $selected)) {
$out .= '<option value="'.$obj->rowid.'" selected>'.$label.'</option>'; $out .= '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($labelhtml).'">'.$label.'</option>';
} else { } else {
$out .= '<option value="'.$obj->rowid.'">'.$label.'</option>'; $out .= '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($labelhtml).'">'.$label.'</option>';
} }
} else { } else {
array_push($outarray, array('key'=>$obj->rowid, 'value'=>$label, 'label'=>$label)); array_push($outarray, array('key'=>$obj->rowid, 'value'=>$label, 'label'=>$label, 'labelhtml'=>$labelhtml));
} }
$i++; $i++;

View File

@ -50,7 +50,8 @@ $outjson = (GETPOST('outjson', 'int') ? GETPOST('outjson', 'int') : 0);
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$excludeids = GETPOST('excludeids', 'intcomma'); $excludeids = GETPOST('excludeids', 'intcomma');
$showtype = GETPOST('showtype', 'int'); $showtype = GETPOSTINT('showtype', 'int');
$showcode = GETPOSTINT('showcode', 'int');
$object = new Societe($db); $object = new Societe($db);
if ($id > 0) { if ($id > 0) {
@ -123,7 +124,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) {
$excludeids = array(); $excludeids = array();
} }
$arrayresult = $form->select_thirdparty_list(0, $htmlname, $filter, 1, $showtype, 0, null, $searchkey, $outjson, 0, 'minwidth100', '', false, $excludeids); $arrayresult = $form->select_thirdparty_list(0, $htmlname, $filter, 1, $showtype, 0, null, $searchkey, $outjson, 0, 'minwidth100', '', false, $excludeids, $showcode);
$db->close(); $db->close();

View File

@ -2787,26 +2787,27 @@ class Societe extends CommonObject
* @param int $withpicto Add picto into link (0=No picto, 1=Include picto with link, 2=Picto only) * @param int $withpicto Add picto into link (0=No picto, 1=Include picto with link, 2=Picto only)
* @param string $option ''=All * @param string $option ''=All
* @param int $notooltip 1=Disable tooltip * @param int $notooltip 1=Disable tooltip
* @param string $tag Tag 'a' or 'span'
* @return string String with URL * @return string String with URL
*/ */
public function getTypeUrl($withpicto = 0, $option = '', $notooltip = 0) public function getTypeUrl($withpicto = 0, $option = '', $notooltip = 0, $tag = 'a')
{ {
global $conf, $langs; global $conf, $langs;
$s = ''; $s = '';
if (empty($option) || preg_match('/prospect/', $option)) { if (empty($option) || preg_match('/prospect/', $option)) {
if (($this->client == 2 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) { if (($this->client == 2 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
$s .= '<a class="customer-back opacitymedium" title="'.$langs->trans("Prospect").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id.'">'.dol_substr($langs->trans("Prospect"), 0, 1).'</a>'; $s .= '<'.$tag.' class="customer-back opacitymedium" title="'.$langs->trans("Prospect").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id.'">'.dol_substr($langs->trans("Prospect"), 0, 1).'</'.$tag.'>';
} }
} }
if (empty($option) || preg_match('/customer/', $option)) { if (empty($option) || preg_match('/customer/', $option)) {
if (($this->client == 1 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) { if (($this->client == 1 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
$s .= '<a class="customer-back" title="'.$langs->trans("Customer").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id.'">'.dol_substr($langs->trans("Customer"), 0, 1).'</a>'; $s .= '<'.$tag.' class="customer-back" title="'.$langs->trans("Customer").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id.'">'.dol_substr($langs->trans("Customer"), 0, 1).'</'.$tag.'>';
} }
} }
if (empty($option) || preg_match('/supplier/', $option)) { if (empty($option) || preg_match('/supplier/', $option)) {
if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $this->fournisseur) { if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $this->fournisseur) {
$s .= '<a class="vendor-back" title="'.$langs->trans("Supplier").'" href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id.'">'.dol_substr($langs->trans("Supplier"), 0, 1).'</a>'; $s .= '<'.$tag.' class="vendor-back" title="'.$langs->trans("Supplier").'" href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id.'">'.dol_substr($langs->trans("Supplier"), 0, 1).'</'.$tag.'>';
} }
} }
return $s; return $s;