Merge pull request #10698 from wdammak/patch-32
Add parent establishment
This commit is contained in:
commit
836eff1233
@ -3682,6 +3682,75 @@ class Form
|
||||
return $num;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a HTML select list of establishment
|
||||
*
|
||||
* @param string $selected Id establishment pre-selected
|
||||
* @param string $htmlname Name of select zone
|
||||
* @param int $statut Status of searched establishment (0=open, 1=closed, 2=both)
|
||||
* @param string $filtre To filter list
|
||||
* @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries.
|
||||
* @param string $moreattrib To add more attribute on select
|
||||
* @return int <0 if error, Num of establishment found if OK (0, 1, 2, ...)
|
||||
*/
|
||||
function selectEstablishments($selected = '', $htmlname = 'entity', $statut = 0, $filtre = '', $useempty = 0, $moreattrib = '')
|
||||
{
|
||||
// phpcs:enable
|
||||
global $langs, $conf;
|
||||
|
||||
$langs->load("admin");
|
||||
$num = 0;
|
||||
|
||||
$sql = "SELECT rowid, name, fk_country, status, entity";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."establishment";
|
||||
$sql.= " WHERE 1=1";
|
||||
if ($statut != 2) $sql.= " AND status = '".$statut."'";
|
||||
if ($filtre) $sql.=" AND ".$filtre;
|
||||
$sql.= " ORDER BY name";
|
||||
|
||||
dol_syslog(get_class($this)."::select_establishment", LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
if ($num)
|
||||
{
|
||||
print '<select id="select'.$htmlname.'" class="flat selectestablishment" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
|
||||
if ($useempty == 1 || ($useempty == 2 && $num > 1))
|
||||
{
|
||||
print '<option value="-1"> </option>';
|
||||
}
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
if ($selected == $obj->rowid)
|
||||
{
|
||||
print '<option value="'.$obj->rowid.'" selected>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<option value="'.$obj->rowid.'">';
|
||||
}
|
||||
print trim($obj->name);
|
||||
if ($statut == 2 && $obj->status == 1) print ' ('.$langs->trans("Closed").')';
|
||||
print '</option>';
|
||||
$i++;
|
||||
}
|
||||
print "</select>";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($statut == 0) print '<span class="opacitymedium">'.$langs->trans("NoActiveEstablishmentDefined").'</span>';
|
||||
else print '<span class="opacitymedium">'.$langs->trans("NoEstablishmentFound").'</span>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form to select bank account
|
||||
*
|
||||
|
||||
@ -78,7 +78,7 @@ dol_fiche_head($head, 'establishments', $langs->trans("HRM"), -1, "user");
|
||||
|
||||
$sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."establishment as e";
|
||||
$sql.= " WHERE e.entity = ".$conf->entity;
|
||||
$sql.= " WHERE e.entity IN (".getEntity('establishment').')';
|
||||
$sql.= $db->order($sortfield, $sortorder);
|
||||
$sql.= $db->plimit($limit+1, $offset);
|
||||
|
||||
|
||||
@ -208,6 +208,7 @@ class Establishment extends CommonObject
|
||||
$sql .= ", fk_country = ".($this->country_id > 0 ? $this->country_id : 'null');
|
||||
$sql .= ", status = ".$this->db->escape($this->status);
|
||||
$sql .= ", fk_user_mod = " . $user->id;
|
||||
$sql .= ", entity = " . $this->entity;
|
||||
$sql .= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
|
||||
@ -230,7 +231,7 @@ class Establishment extends CommonObject
|
||||
*/
|
||||
function fetch($id)
|
||||
{
|
||||
$sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status, e.fk_country as country_id,";
|
||||
$sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status, e.fk_country as country_id, e.entity,";
|
||||
$sql.= ' c.code as country_code, c.label as country';
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."establishment as e";
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON e.fk_country = c.rowid';
|
||||
@ -249,6 +250,7 @@ class Establishment extends CommonObject
|
||||
$this->zip = $obj->zip;
|
||||
$this->town = $obj->town;
|
||||
$this->status = $obj->status;
|
||||
$this->entity = $obj->entity;
|
||||
|
||||
$this->country_id = $obj->country_id;
|
||||
$this->country_code = $obj->country_code;
|
||||
@ -352,7 +354,7 @@ class Establishment extends CommonObject
|
||||
*/
|
||||
function info($id)
|
||||
{
|
||||
$sql = 'SELECT e.rowid, e.datec, e.fk_user_author, e.tms, e.fk_user_mod';
|
||||
$sql = 'SELECT e.rowid, e.datec, e.fk_user_author, e.tms, e.fk_user_mod, e.entity';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'establishment as e';
|
||||
$sql.= ' WHERE e.rowid = '.$id;
|
||||
|
||||
@ -389,6 +391,37 @@ class Establishment extends CommonObject
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get on record Establishment
|
||||
*
|
||||
* @param int $id Id of record
|
||||
* @return obj
|
||||
*/
|
||||
function getEstablishment($id)
|
||||
{
|
||||
$sql = 'SELECT e.rowid, e.name, e.datec, e.fk_user_author, e.tms, e.fk_user_mod, e.entity';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'establishment as e';
|
||||
$sql.= ' WHERE e.rowid = '.$id;
|
||||
|
||||
dol_syslog(get_class($this)."::fetch info", LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
if ($this->db->num_rows($result))
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
}
|
||||
$this->db->free($result);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return clicable name (with picto eventually)
|
||||
@ -414,6 +447,34 @@ class Establishment extends CommonObject
|
||||
if ($withpicto != 2) $result.=$link.$this->name.$linkend;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return clicable name (with picto eventually)
|
||||
*
|
||||
* @param int $id Id of record
|
||||
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
|
||||
* @return string String with URL
|
||||
*/
|
||||
function getNomUrlParent($id = 0, $withpicto = 0)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$result='';
|
||||
|
||||
$obj = $this->getEstablishment(($id>0)?$id:$conf->entity);
|
||||
|
||||
$link = '<a href="'.DOL_URL_ROOT.'/hrm/establishment/card.php?id='.$obj->rowid.'">';
|
||||
$linkend='</a>';
|
||||
|
||||
$picto='building';
|
||||
|
||||
$label=$langs->trans("Show").': '.$obj->name;
|
||||
|
||||
if ($withpicto) $result.=($link.img_object($label, $picto).$linkend);
|
||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||
if ($withpicto != 2) $result.=$link.$obj->name.$linkend;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return account country code
|
||||
|
||||
@ -92,8 +92,7 @@ elseif ($action == 'add')
|
||||
$object->status = GETPOST('status', 'int');
|
||||
$object->fk_user_author = $user->id;
|
||||
$object->datec = dol_now();
|
||||
|
||||
|
||||
$object->entity = GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity;
|
||||
|
||||
$id = $object->create($user);
|
||||
|
||||
@ -141,6 +140,7 @@ elseif ($action == 'update')
|
||||
$object->country_id = GETPOST('country_id', 'int');
|
||||
$object->fk_user_mod = $user->id;
|
||||
$object->status = GETPOST('status', 'int');
|
||||
$object->entity = GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity;
|
||||
|
||||
$result = $object->update($user);
|
||||
|
||||
@ -190,6 +190,14 @@ if ($action == 'create')
|
||||
print '<td><input name="name" id="name" size="32" value="' . GETPOST("name", "alpha") . '"></td>';
|
||||
print '</tr>';
|
||||
|
||||
// Parent
|
||||
print '<tr>';
|
||||
print '<td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
|
||||
print '<td class="maxwidthonsmartphone">';
|
||||
print $form->selectEstablishments(GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity, 'entity', 1);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Address
|
||||
print '<tr>';
|
||||
print '<td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
|
||||
@ -202,7 +210,7 @@ if ($action == 'create')
|
||||
print '<tr>';
|
||||
print '<td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td>';
|
||||
print '<td>';
|
||||
print $formcompany->select_ziptown(
|
||||
print $formcompany->select_ziptown(
|
||||
GETPOST('zipcode', 'alpha'),
|
||||
'zipcode',
|
||||
array (
|
||||
@ -218,7 +226,7 @@ print $formcompany->select_ziptown(
|
||||
print '<tr>';
|
||||
print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td>';
|
||||
print '<td>';
|
||||
print $formcompany->select_ziptown(GETPOST('town', 'alpha'), 'town', array (
|
||||
print $formcompany->select_ziptown(GETPOST('town', 'alpha'), 'town', array (
|
||||
'zipcode',
|
||||
'selectcountry_id'
|
||||
));
|
||||
@ -282,6 +290,12 @@ if (($id || $ref) && $action == 'edit')
|
||||
// Name
|
||||
print '<tr><td>'.$form->editfieldkey('Name', 'name', '', $object, 0, 'string', '', 1).'</td><td>';
|
||||
print '<input name="name" id="name" class="flat" size="32" value="'.$object->name.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
// Parent
|
||||
print '<tr><td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
|
||||
print '<td class="maxwidthonsmartphone">';
|
||||
print $form->selectEstablishments($object->entity>0?$object->entity:$conf->entity, 'entity', 1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Address
|
||||
@ -292,12 +306,12 @@ if (($id || $ref) && $action == 'edit')
|
||||
|
||||
// Zipcode / Town
|
||||
print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
|
||||
print $formcompany->select_ziptown($object->zip, 'zipcode', array (
|
||||
print $formcompany->select_ziptown($object->zip, 'zipcode', array (
|
||||
'town',
|
||||
'selectcountry_id'
|
||||
), 6) . '</tr>';
|
||||
print '<tr><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
|
||||
print $formcompany->select_ziptown($object->town, 'town', array (
|
||||
print $formcompany->select_ziptown($object->town, 'town', array (
|
||||
'zipcode',
|
||||
'selectcountry_id'
|
||||
)) . '</td></tr>';
|
||||
@ -366,6 +380,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
print '<td class="titlefield">'.$langs->trans("Name").'</td>';
|
||||
print '<td>'.$object->name.'</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Parent
|
||||
print '<tr>';
|
||||
print '<td class="titlefield">'.$langs->trans("Parent").'</td>';
|
||||
print '<td>'.$object->getNomUrlParent($object->entity).'</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Address
|
||||
print '<tr>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user