Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion htdocs/admin/company.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,22 @@
/*}*/
}


// TODO Must be in trigger
if( isModEnabled('multicompany')) {
$linked_soc = GETPOST('linked_soc', 'int');
if($linked_soc) {
$sql = 'SELECT fk_entity FROM '.MAIN_DB_PREFIX.'entity_thirdparty WHERE fk_entity ='. $conf->entity;
$resql = $db->query($sql);
if(!$resql || $db->num_rows($resql) == 0) {
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'entity_thirdparty (entity, fk_entity, fk_thirdparty) VALUES ( 0, ' . $conf->entity . ', ' . $linked_soc . ')';
} else {
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'entity_thirdparty SET fk_soc = ' . $linked_soc . ' WHERE fk_entity = ' . $conf->entity;
}
$resql = $db->query($sql);
}
}

dolibarr_set_const($db, "MAIN_INFO_SOCIETE_MANAGERS", GETPOST("MAIN_INFO_SOCIETE_MANAGERS", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_INFO_GDPR", GETPOST("MAIN_INFO_GDPR", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_INFO_CAPITAL", GETPOST("capital", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
Expand Down Expand Up @@ -605,7 +621,41 @@
print '<textarea class="flat quatrevingtpercent" name="note" id="note" rows="'.ROWS_5.'">'.(GETPOSTISSET('note') ? GETPOST('note', 'restricthtml') : (getDolGlobalString('MAIN_INFO_SOCIETE_NOTE') ? $conf->global->MAIN_INFO_SOCIETE_NOTE : '')).'</textarea></td></tr>';
print '</td></tr>';

print '</table>';
// Society/Third party
// TODO We need to add a check to see thirdparty association is allowed. --> Some const checks to add
// !dolibarr_get_const($this->db, 'MULTICOMPANY_LINK_THIRDPARTY_ENTITY',
if (isModEnabled('multicompany')) {
// TODO Trad not loaded
print '<tr class="oddeven"><td><label for="linked_soc">'.$langs->trans("ThirdPartyAssociated").'</label></td><td>';

// Get current society associated to the company (if any)
// TODO Code to be improved
$linked_soc = 0;
$sql = 'SELECT fk_soc FROM '.MAIN_DB_PREFIX.'entity_thirdparty WHERE fk_entity = ' . $entity;
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
$linked_soc = $obj->fk_soc;
}

// TODO Get all thirdparty list from the database
print $form->select_company($linked_soc, 'linked_soc', '', $langs->trans("ThirdParty"), 0, 0, array(), 0, 'minwidth100', '', '', 1, array(), false, array(), 0, true);
print '</td></tr>';
print '<tr class="oddeven"><td><label for="force_soc_info">'.$langs->trans("forceUpdateFromSoc").'</label>';
print info_admin($langs->trans("DANGERZONE"), 1);
print '</td>';
print '<td><input type="checkbox" name="forceUpdateFromSoc" id="forceUpdateFromSoc"></td></tr>' ."\n";
}

$parameters=array();
$reshook=$hookmanager->executeHooks('hookantho',$parameters,$object,$action); // See description below



print '</table>';


print('Module context: '.join(',', $object->contextarray));

print $form->buttonsSaveCancel("Save", '', array(), false, 'reposition');

Expand Down
28 changes: 24 additions & 4 deletions htdocs/core/class/html.form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ public function select_type_fees($selected = '', $htmlname = 'type', $showempty
* @param int $showcode Show code
* @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(), $showcode = 0)
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, $searchInAllEntities = false)
{
// phpcs:enable
global $conf, $user, $langs;
Expand Down Expand Up @@ -1365,7 +1365,7 @@ public function select_company($selected = '', $htmlname = 'socid', $filter = ''
$out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
} else {
// Immediate load of all database
$out .= $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
$out .= $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode, $searchInAllEntities);
}

return $out;
Expand Down Expand Up @@ -1396,7 +1396,7 @@ public function select_company($selected = '', $htmlname = 'socid', $filter = ''
* @param int $showcode Show code in list
* @return array|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(), $showcode = 0)
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, $searchInAllEntities = false)
{
// phpcs:enable
global $conf, $user, $langs;
Expand Down Expand Up @@ -1446,14 +1446,29 @@ public function select_thirdparty_list($selected = '', $htmlname = 'socid', $fil
$sql .= ", s.address, s.zip, s.town";
$sql .= ", dictp.code as country_code";
}

if ($searchInAllEntities && isModEnabled('multicompany') && $conf->entity == 1 && $user->admin) {
$sql .= ", e.label as entity_label";
}


$sql .= " FROM " . $this->db->prefix() . "societe as s";
if (getDolGlobalString('COMPANY_SHOW_ADDRESS_SELECTLIST')) {
$sql .= " LEFT JOIN " . $this->db->prefix() . "c_country as dictp ON dictp.rowid = s.fk_pays";
}
if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
$sql .= ", " . $this->db->prefix() . "societe_commerciaux as sc";
}
$sql .= " WHERE s.entity IN (" . getEntity('societe') . ")";

// If multicompany is enabled and user is admin and in master entity, search societe in all entities
// TODO must be improved, like in select_user function
if ($searchInAllEntities && isModEnabled('multicompany') && $conf->entity == 1 && $user->admin) {
$sql .= " JOIN " . $this->db->prefix() . "entity as e ON s.entity = e.rowid";
$sql .= " WHERE s.entity IS NOT NULL";
} else {
$sql .= " WHERE s.entity IN (" . getEntity('societe') . ")";
}

if (!empty($user->socid)) {
$sql .= " AND s.rowid = " . ((int) $user->socid);
}
Expand Down Expand Up @@ -1559,6 +1574,11 @@ public function select_thirdparty_list($selected = '', $htmlname = 'socid', $fil
$label .= ' - '.$obj->tva_intra;
}

// Add entity label when soc are searched in all entities
if ($searchInAllEntities && isModEnabled('multicompany') && $conf->entity == 1 && $user->admin) {
$label .= ' (' . $obj->entity_label . ')';
}

$labelhtml = $label;

if ($showtype) {
Expand Down