26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $element =
'establishment';
41 public $table_element =
'establishment';
46 public $table_element_line =
'';
51 public $fk_element =
'fk_establishment';
56 public $picto =
'establishment';
111 public $fk_user_author;
118 const STATUS_OPEN = 1;
119 const STATUS_CLOSED = 0;
122 public $fields = array(
123 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
124 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 15,
'index' => 1),
125 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 20),
126 'label' => array(
'type' =>
'varchar(128)',
'label' =>
'Label',
'enabled' => 1,
'visible' => -1,
'showoncombobox' => 2,
'position' => 22),
127 'address' => array(
'type' =>
'varchar(255)',
'label' =>
'Address',
'enabled' => 1,
'visible' => -1,
'position' => 25),
128 'zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Zip',
'enabled' => 1,
'visible' => -1,
'position' => 30),
129 'town' => array(
'type' =>
'varchar(50)',
'label' =>
'Town',
'enabled' => 1,
'visible' => -1,
'position' => 35),
130 'fk_state' => array(
'type' =>
'integer',
'label' =>
'Fkstate',
'enabled' => 1,
'visible' => -1,
'position' => 40),
131 'fk_country' => array(
'type' =>
'integer',
'label' =>
'Fkcountry',
'enabled' => 1,
'visible' => -1,
'position' => 45),
132 'profid1' => array(
'type' =>
'varchar(20)',
'label' =>
'Profid1',
'enabled' => 1,
'visible' => -1,
'position' => 50),
133 'profid2' => array(
'type' =>
'varchar(20)',
'label' =>
'Profid2',
'enabled' => 1,
'visible' => -1,
'position' => 55),
134 'profid3' => array(
'type' =>
'varchar(20)',
'label' =>
'Profid3',
'enabled' => 1,
'visible' => -1,
'position' => 60),
135 'phone' => array(
'type' =>
'varchar(20)',
'label' =>
'Phone',
'enabled' => 1,
'visible' => -1,
'position' => 65),
136 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fkuserauthor',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 70),
137 'fk_user_mod' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fkusermod',
'enabled' => 1,
'visible' => -1,
'position' => 75),
138 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 80),
139 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 85),
140 'status' => array(
'type' =>
'integer',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'position' => 500),
153 $this->ismultientitymanaged = 1;
164 global
$conf, $langs;
170 $this->label = trim($this->label);
172 $this->zip = trim($this->zip);
173 $this->town = trim($this->town);
175 if (empty($this->
ref)) {
176 $this->
ref =
'(PROV)';
181 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"establishment (";
187 $sql .=
", fk_country";
191 $sql .=
", fk_user_author";
192 $sql .=
", fk_user_mod";
193 $sql .=
") VALUES (";
194 $sql .=
"'".$this->db->escape($this->
ref).
"'";
195 $sql .=
", '".$this->db->escape($this->label).
"'";
196 $sql .=
", '".$this->db->escape($this->
address).
"'";
197 $sql .=
", '".$this->db->escape($this->zip).
"'";
198 $sql .=
", '".$this->db->escape($this->town).
"'";
199 $sql .=
", ".((int) $this->country_id);
200 $sql .=
", ".((int) $this->
status);
201 $sql .=
", ".((int)
$conf->entity);
202 $sql .=
", '".$this->db->idate($now).
"'";
203 $sql .=
", ".((int) $user->id);
204 $sql .=
", ".((int) $user->id);
207 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
208 $resql = $this->db->query($sql);
211 $this->errors[] =
"Error ".$this->db->lasterror();
216 foreach ($this->errors as $errmsg) {
217 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
218 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
220 $this->db->rollback();
223 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'establishment');
225 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"establishment SET ref = '".$this->db->escape((
string) $this->id).
"'";
226 $sql .=
" WHERE rowid = ".((int) $this->
id);
227 $this->db->query($sql);
245 if (empty($this->label)) {
246 $this->error =
'ErrorBadParameter';
252 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"establishment";
253 $sql .=
" SET ref = '".$this->db->escape($this->
ref).
"'";
254 $sql .=
", label = '".$this->db->escape($this->label).
"'";
255 $sql .=
", address = '".$this->db->escape($this->
address).
"'";
256 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
257 $sql .=
", town = '".$this->db->escape($this->town).
"'";
258 $sql .=
", fk_country = ".($this->country_id > 0 ? $this->country_id :
'null');
259 $sql .=
", status = ".((int) $this->
status);
260 $sql .=
", fk_user_mod = ".((int) $user->id);
261 $sql .=
", entity = ".((int) $this->entity);
262 $sql .=
" WHERE rowid = ".((int) $this->
id);
264 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
265 $result = $this->db->query($sql);
270 $this->error = $this->db->lasterror();
271 $this->db->rollback();
284 $sql =
"SELECT e.rowid, e.ref, e.label, e.address, e.zip, e.town, e.status, e.fk_country as country_id, e.entity,";
285 $sql .=
' c.code as country_code, c.label as country';
286 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
287 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON e.fk_country = c.rowid';
288 $sql .=
" WHERE e.rowid = ".((int) $id);
290 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
291 $result = $this->db->query($sql);
293 $obj = $this->db->fetch_object($result);
295 $this->
id = $obj->rowid;
296 $this->
ref = $obj->ref;
297 $this->label = $obj->label;
298 $this->
address = $obj->address;
299 $this->zip = $obj->zip;
300 $this->town = $obj->town;
301 $this->
status = $obj->status;
302 $this->entity = $obj->entity;
304 $this->country_id = $obj->country_id;
305 $this->country_code = $obj->country_code;
306 $this->country = $obj->country;
313 $this->error = $this->db->lasterror();
324 public function delete($user)
328 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"establishment WHERE rowid = ".((int) $user->id);
330 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
332 $result = $this->db->query($sql);
337 $this->error = $this->db->lasterror();
338 $this->db->rollback();
365 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
368 $this->labelStatus[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Open');
369 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Closed');
370 $this->labelStatusShort[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Open');
371 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Closed');
374 $statusType =
'status'.$status;
375 if ($status == self::STATUS_OPEN) {
376 $statusType =
'status4';
378 if ($status == self::STATUS_CLOSED) {
379 $statusType =
'status6';
382 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
394 $sql =
'SELECT e.rowid, e.ref, e.datec, e.fk_user_author, e.tms as datem, e.fk_user_mod, e.entity';
395 $sql .=
' FROM '.MAIN_DB_PREFIX.
'establishment as e';
396 $sql .=
' WHERE e.rowid = '.((int) $id);
398 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
399 $result = $this->db->query($sql);
402 if ($this->db->num_rows($result)) {
403 $obj = $this->db->fetch_object($result);
405 $this->
id = $obj->rowid;
407 $this->user_creation_id = $obj->fk_user_author;
408 $this->user_modification_id = $obj->fk_user_mod;
409 $this->date_creation = $this->db->jdate($obj->datec);
410 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
412 $this->db->free($result);
428 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
430 global
$conf, $langs, $hookmanager;
432 if (!empty(
$conf->dol_no_mouse_hover)) {
438 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Establishment").
'</u>';
439 if (isset($this->
status)) {
440 $label .=
' '.$this->getLibStatut(5);
443 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
446 $label .=
'<b>'.$langs->trans(
'Residence').
':</b> '.$this->
address.
', '.$this->zip.
' '.$this->town;
448 $url = DOL_URL_ROOT.
'/hrm/establishment/card.php?id='.$this->id;
450 if ($option !=
'nolink') {
452 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
453 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
454 $add_save_lastsearch_values = 1;
456 if ($add_save_lastsearch_values) {
457 $url .=
'&save_lastsearch_values=1';
462 if (empty($notooltip)) {
464 $label = $langs->trans(
"Establishment");
465 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
467 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
468 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
470 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
473 if ($option ==
'nolink') {
474 $linkstart =
'<span';
476 $linkstart =
'<a href="'.$url.
'"';
478 $linkstart .= $linkclose.
'>';
479 if ($option ==
'nolink') {
480 $linkend =
'</span>';
485 $result .= $linkstart;
488 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
491 if ($withpicto != 2) {
492 $result .= $this->label;
498 global $action, $hookmanager;
499 $hookmanager->initHooks(array(
'establishmentdao'));
500 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
501 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
503 $result = $hookmanager->resPrint;
505 $result .= $hookmanager->resPrint;
521 if (!empty($this->country_code)) {
522 return $this->country_code;
526 if (!empty(
$mysoc->country_code)) {
527 return $mysoc->country_code;
543 $this->label =
'Department AAA';
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage establishments.
__construct($db)
Constructor.
getCountryCode()
Return account country code.
update($user)
Update record.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
LibStatut($status, $mode=0)
Return the status.
getLibStatut($mode=0)
Give a label from a status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
fetch($id)
Load an object from database.
create($user)
Create object in database.
info($id)
Information on record.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
div refaddress div address