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 $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
|
* 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 = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."establishment as e";
|
$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->order($sortfield, $sortorder);
|
||||||
$sql.= $db->plimit($limit+1, $offset);
|
$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 .= ", fk_country = ".($this->country_id > 0 ? $this->country_id : 'null');
|
||||||
$sql .= ", status = ".$this->db->escape($this->status);
|
$sql .= ", status = ".$this->db->escape($this->status);
|
||||||
$sql .= ", fk_user_mod = " . $user->id;
|
$sql .= ", fk_user_mod = " . $user->id;
|
||||||
|
$sql .= ", entity = " . $this->entity;
|
||||||
$sql .= " WHERE rowid = ".$this->id;
|
$sql .= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
|
dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
|
||||||
@ -230,7 +231,7 @@ class Establishment extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function fetch($id)
|
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.= ' c.code as country_code, c.label as country';
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."establishment as e";
|
$sql.= " FROM ".MAIN_DB_PREFIX."establishment as e";
|
||||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON e.fk_country = c.rowid';
|
$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->zip = $obj->zip;
|
||||||
$this->town = $obj->town;
|
$this->town = $obj->town;
|
||||||
$this->status = $obj->status;
|
$this->status = $obj->status;
|
||||||
|
$this->entity = $obj->entity;
|
||||||
|
|
||||||
$this->country_id = $obj->country_id;
|
$this->country_id = $obj->country_id;
|
||||||
$this->country_code = $obj->country_code;
|
$this->country_code = $obj->country_code;
|
||||||
@ -352,7 +354,7 @@ class Establishment extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function info($id)
|
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.= ' FROM '.MAIN_DB_PREFIX.'establishment as e';
|
||||||
$sql.= ' WHERE e.rowid = '.$id;
|
$sql.= ' WHERE e.rowid = '.$id;
|
||||||
|
|
||||||
@ -390,6 +392,37 @@ class Establishment extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
* Return clicable name (with picto eventually)
|
||||||
*
|
*
|
||||||
@ -415,6 +448,34 @@ class Establishment extends CommonObject
|
|||||||
return $result;
|
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
|
* Return account country code
|
||||||
*
|
*
|
||||||
|
|||||||
@ -92,8 +92,7 @@ elseif ($action == 'add')
|
|||||||
$object->status = GETPOST('status', 'int');
|
$object->status = GETPOST('status', 'int');
|
||||||
$object->fk_user_author = $user->id;
|
$object->fk_user_author = $user->id;
|
||||||
$object->datec = dol_now();
|
$object->datec = dol_now();
|
||||||
|
$object->entity = GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity;
|
||||||
|
|
||||||
|
|
||||||
$id = $object->create($user);
|
$id = $object->create($user);
|
||||||
|
|
||||||
@ -141,6 +140,7 @@ elseif ($action == 'update')
|
|||||||
$object->country_id = GETPOST('country_id', 'int');
|
$object->country_id = GETPOST('country_id', 'int');
|
||||||
$object->fk_user_mod = $user->id;
|
$object->fk_user_mod = $user->id;
|
||||||
$object->status = GETPOST('status', 'int');
|
$object->status = GETPOST('status', 'int');
|
||||||
|
$object->entity = GETPOST('entity', 'int')>0?GETPOST('entity', 'int'):$conf->entity;
|
||||||
|
|
||||||
$result = $object->update($user);
|
$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 '<td><input name="name" id="name" size="32" value="' . GETPOST("name", "alpha") . '"></td>';
|
||||||
print '</tr>';
|
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
|
// Address
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
|
print '<td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
|
||||||
@ -202,7 +210,7 @@ if ($action == 'create')
|
|||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td>';
|
print '<td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print $formcompany->select_ziptown(
|
print $formcompany->select_ziptown(
|
||||||
GETPOST('zipcode', 'alpha'),
|
GETPOST('zipcode', 'alpha'),
|
||||||
'zipcode',
|
'zipcode',
|
||||||
array (
|
array (
|
||||||
@ -218,7 +226,7 @@ print $formcompany->select_ziptown(
|
|||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td>';
|
print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print $formcompany->select_ziptown(GETPOST('town', 'alpha'), 'town', array (
|
print $formcompany->select_ziptown(GETPOST('town', 'alpha'), 'town', array (
|
||||||
'zipcode',
|
'zipcode',
|
||||||
'selectcountry_id'
|
'selectcountry_id'
|
||||||
));
|
));
|
||||||
@ -284,6 +292,12 @@ if (($id || $ref) && $action == 'edit')
|
|||||||
print '<input name="name" id="name" class="flat" size="32" value="'.$object->name.'">';
|
print '<input name="name" id="name" class="flat" size="32" value="'.$object->name.'">';
|
||||||
print '</td></tr>';
|
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
|
// Address
|
||||||
print '<tr><td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
|
print '<tr><td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
@ -292,12 +306,12 @@ if (($id || $ref) && $action == 'edit')
|
|||||||
|
|
||||||
// Zipcode / Town
|
// Zipcode / Town
|
||||||
print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
|
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',
|
'town',
|
||||||
'selectcountry_id'
|
'selectcountry_id'
|
||||||
), 6) . '</tr>';
|
), 6) . '</tr>';
|
||||||
print '<tr><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
|
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',
|
'zipcode',
|
||||||
'selectcountry_id'
|
'selectcountry_id'
|
||||||
)) . '</td></tr>';
|
)) . '</td></tr>';
|
||||||
@ -367,6 +381,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
print '<td>'.$object->name.'</td>';
|
print '<td>'.$object->name.'</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
|
// Parent
|
||||||
|
print '<tr>';
|
||||||
|
print '<td class="titlefield">'.$langs->trans("Parent").'</td>';
|
||||||
|
print '<td>'.$object->getNomUrlParent($object->entity).'</td>';
|
||||||
|
print '</tr>';
|
||||||
|
|
||||||
// Address
|
// Address
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>'.$langs->trans("Address").'</td>';
|
print '<td>'.$langs->trans("Address").'</td>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user