companycard-directedit-typent

This commit is contained in:
Stephane Lesage 2020-12-13 19:50:35 +01:00
parent acb73966f7
commit 5e4cc7fcfd
3 changed files with 104 additions and 37 deletions

View File

@ -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 .= '<form method="post" action="'.$page.'">';
$out .= '<input type="hidden" name="action" value="set_thirdpartytype">';
$out .= '<input type="hidden" name="token" value="'.newToken().'">';
$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 .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans("Modify").'">';
$out .= '</form>';
} else {
if ($selected)
{
$arr = $this->typent_array(0);
$typent = $arr[$selected];
$out .= $typent;
} else {
$out .= "&nbsp;";
}
}
if ($nooutput) return $out;
else print $out;
}
}

View File

@ -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 '&nbsp;';
}
print '</td>';
print '</tr>';
print '</td></tr>';
// Type + Workforce/Staff
$arr = $formcompany->typent_array(1);
$object->typent = $arr[$object->typent_code];
print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>'.$object->typent.'</td>';
// Third-Party Type
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ThirdPartyType').'</td>';
if ($action != 'editthirdpartytype' && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editthirdpartytype&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
print '</tr></table>';
print '</td><td>';
$html_name = ($action == 'editthirdpartytype') ? 'typent_id' : 'none';
$formcompany->formThirdpartyType($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->typent_id, $html_name, '');
print '</td></tr>';
// Workforce/Staff
print '<tr><td>'.$langs->trans("Workforce").'</td><td>'.$object->effectif.'</td></tr>';
print '</table>';
print '</div>';
print '<div class="fichehalfright"><div class="ficheaddleft">';
print '<div class="underbanner clearboth"></div>';
@ -2518,14 +2531,10 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
if (!empty($conf->incoterm->enabled))
{
print '<tr><td>';
print '<table width="100%" class="nobordernopadding"><tr><td>';
print $langs->trans('IncotermLabel');
print '<td><td class="right">';
if ($user->rights->societe->creer) print '<a class="editfielda" href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('', 1).'</a>';
else print '&nbsp;';
print '</td></tr></table>';
print '</td>';
print '<td colspan="3">';
print '<table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans('IncotermLabel').'</td>';
if ($action != 'editincoterm' && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=editincoterm">'.img_edit('', 1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
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 '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('ParentCompany');
print '</td>';
if ($action != 'editparentcompany') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ParentCompany').'</td>';
if ($action != 'editparentcompany' && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
print '</tr></table>';
print '</td><td>';
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 '</td>';
print '</tr>';
$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 '</td></tr>';
}
// Sales representative
@ -2587,8 +2589,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
} else {
print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
}
print '</td>';
print "</tr>\n";
print "</td></tr>\n";
}
// Webservices url/key

View File

@ -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.