diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 0b4c4e499e3..1cd2ed5315c 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -1008,4 +1008,45 @@ class FormCompany extends Form return $out; } + + /** + * Output html select to select third-party type + * + * @param string $page Page + * @param string $selected Id preselected + * @param string $htmlname Name of HTML select + * @param string $filter optional filters criteras + * @param int $nooutput No print output. Return it only. + * @return void|string + */ + public function formThirdpartyType($page, $selected = '', $htmlname = 'socid', $filter = '', $nooutput = 0) + { + // phpcs:enable + global $langs; + + $out = ''; + if ($htmlname != "none") + { + $out .= '
'; + $out .= ''; + $out .= ''; + $sortparam = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label. + $out .= $this->selectarray($htmlname, $this->typent_array(0, $filter), $selected, 0, 0, 0, '', 0, 0, 0, $sortparam, '', 1); + $out .= ''; + $out .= '
'; + } else { + if ($selected) + { + $arr = $this->typent_array(0); + $typent = $arr[$selected]; + $out .= $typent; + } else { + $out .= " "; + } + } + + if ($nooutput) return $out; + else print $out; + } + } diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index ab2cddb940d..e1b77c8dfb2 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -838,18 +838,25 @@ if (empty($reshook)) } } + // Set third-party type + if ($action == 'set_thirdpartytype' && $user->rights->societe->creer) + { + $object->fetch($socid); + $result = $object->setThirdpartyType(GETPOST('typent_id', 'int')); + } + + // Set incoterm + if ($action == 'set_incoterms' && $user->rights->societe->creer && !empty($conf->incoterm->enabled)) + { + $object->fetch($socid); + $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); + } + // Set parent company if ($action == 'set_thirdparty' && $user->rights->societe->creer) { $object->fetch($socid); - $result = $object->set_parent(GETPOST('editparentcompany', 'int')); - } - - // Set incoterm - if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) - { - $object->fetch($socid); - $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); + $result = $object->set_parent(GETPOST('parent_id', 'int')); } // Set sales representatives @@ -2455,18 +2462,24 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } else { print ' '; } - print ''; - print ''; + print ''; - // Type + Workforce/Staff - $arr = $formcompany->typent_array(1); - $object->typent = $arr[$object->typent_code]; - print ''.$langs->trans("ThirdPartyType").''.$object->typent.''; + // Third-Party Type + print ''; + print ''; + if ($action != 'editthirdpartytype' && $user->rights->societe->creer) print ''; + print '
'.$langs->trans('ThirdPartyType').'id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'
'; + print ''; + $html_name = ($action == 'editthirdpartytype') ? 'typent_id' : 'none'; + $formcompany->formThirdpartyType($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->typent_id, $html_name, ''); + print ''; + + // Workforce/Staff print ''.$langs->trans("Workforce").''.$object->effectif.''; print ''; - print ''; + print '
'; print '
'; @@ -2518,14 +2531,10 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) if (!empty($conf->incoterm->enabled)) { print ''; - print '
'; - print $langs->trans('IncotermLabel'); - print ''; - if ($user->rights->societe->creer) print ''.img_edit('', 1).''; - else print ' '; - print '
'; - print ''; - print ''; + print ''; + if ($action != 'editincoterm' && $user->rights->societe->creer) print ''; + print '
'.$langs->trans('IncotermLabel').''.img_edit('', 1).'
'; + print ''; if ($action != 'editincoterm') { print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); @@ -2553,20 +2562,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) { print ''; - print ''; - if ($action != 'editparentcompany') print ''; + print '
'; - print $langs->trans('ParentCompany'); - print 'id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'
'; + if ($action != 'editparentcompany' && $user->rights->societe->creer) print ''; print '
'.$langs->trans('ParentCompany').'id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'
'; print ''; - if ($action == 'editparentcompany') - { - $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'editparentcompany', 's.rowid <> '.$object->id, 1); - } else { - $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'none', 's.rowid <> '.$object->id, 1); - } - print ''; - print ''; + $html_name = ($action == 'editparentcompany') ? 'parent_id' : 'none'; + $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, $html_name, 's.rowid <> '.$object->id, 1); + print ''; } // Sales representative @@ -2587,8 +2589,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } else { print ''.$langs->trans("ThirdpartyNotLinkedToMember").''; } - print ''; - print "\n"; + print "\n"; } // Webservices url/key diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index f18a6e1b9a8..f8796739701 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4355,6 +4355,31 @@ class Societe extends CommonObject return $error ? -1 : 1; } + /** + * Define third-party type of current company + * + * @param int $typent_id third party type rowid in llx_c_typent + * @return int <0 if KO, >0 if OK + */ + public function setThirdpartyType($typent_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) + { + $this->typent_id = $typent_id; + $this->typent_code = dol_getIdFromCode($db, $this->$typent_id, 'c_typent', 'id', 'code'); + return 1; + } else { + return -1; + } + } else return -1; + } /** * Function used to replace a thirdparty id with another one.