25 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
35 public $element =
'establishment';
40 public $table_element =
'establishment';
45 public $table_element_line =
'';
50 public $fk_element =
'fk_establishment';
56 public $ismultientitymanaged = 1;
61 public $picto =
'building';
121 public $fk_user_author;
128 const STATUS_OPEN = 1;
129 const STATUS_CLOSED = 0;
132 public $fields = array(
133 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
134 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>15,
'index'=>1),
135 'ref' =>array(
'type'=>
'varchar(30)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>20),
136 'label' =>array(
'type'=>
'varchar(128)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'showoncombobox'=>1,
'position'=>22),
137 'address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Address',
'enabled'=>1,
'visible'=>-1,
'position'=>25),
138 'zip' =>array(
'type'=>
'varchar(25)',
'label'=>
'Zip',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
139 'town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Town',
'enabled'=>1,
'visible'=>-1,
'position'=>35),
140 'fk_state' =>array(
'type'=>
'integer',
'label'=>
'Fkstate',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
141 'fk_country' =>array(
'type'=>
'integer',
'label'=>
'Fkcountry',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
142 'profid1' =>array(
'type'=>
'varchar(20)',
'label'=>
'Profid1',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
143 'profid2' =>array(
'type'=>
'varchar(20)',
'label'=>
'Profid2',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
144 'profid3' =>array(
'type'=>
'varchar(20)',
'label'=>
'Profid3',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
145 'phone' =>array(
'type'=>
'varchar(20)',
'label'=>
'Phone',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
146 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fkuserauthor',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>70),
147 'fk_user_mod' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fkusermod',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
148 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>80),
149 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>85),
150 'status' =>array(
'type'=>
'integer',
'label'=>
'Status',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
172 global $conf, $langs;
178 $this->label = trim($this->label);
179 $this->address = trim($this->address);
180 $this->zip = trim($this->zip);
181 $this->town = trim($this->town);
183 if (empty($this->ref)) $this->ref =
'(PROV)';
187 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"establishment (";
194 $sql .=
", fk_country";
197 $sql .=
", fk_user_author";
198 $sql .=
", fk_user_mod";
199 $sql .=
") VALUES (";
200 $sql .=
"'".$this->db->escape($this->ref).
"'";
201 $sql .=
", '".$this->db->escape($this->label).
"'";
202 $sql .=
", '".$this->db->escape($this->address).
"'";
203 $sql .=
", '".$this->db->escape($this->zip).
"'";
204 $sql .=
", '".$this->db->escape($this->town).
"'";
205 $sql .=
", ".$this->country_id;
206 $sql .=
", ".$this->status;
207 $sql .=
", ".$conf->entity;
208 $sql .=
", '".$this->db->idate($now).
"'";
209 $sql .=
", ".$user->id;
210 $sql .=
", ".$user->id;
213 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
217 $this->errors[] =
"Error ".$this->db->lasterror();
222 foreach ($this->errors as $errmsg) {
223 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
224 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
226 $this->
db->rollback();
229 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
'establishment');
231 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"establishment SET ref = '".$this->
db->escape($this->
id).
"'";
232 $sql .=
" WHERE rowid = ".$this->id;
233 $this->
db->query($sql);
251 if (empty($this->label))
253 $this->error =
'ErrorBadParameter';
259 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"establishment";
260 $sql .=
" SET ref = '".$this->db->escape($this->ref).
"'";
261 $sql .=
", label = '".$this->db->escape($this->label).
"'";
262 $sql .=
", address = '".$this->db->escape($this->address).
"'";
263 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
264 $sql .=
", town = '".$this->db->escape($this->town).
"'";
265 $sql .=
", fk_country = ".($this->country_id > 0 ? $this->country_id :
'null');
266 $sql .=
", status = ".$this->db->escape($this->status);
267 $sql .=
", fk_user_mod = ".$user->id;
268 $sql .=
", entity = ".$this->entity;
269 $sql .=
" WHERE rowid = ".$this->id;
271 dol_syslog(get_class($this).
"::update sql=".$sql, LOG_DEBUG);
272 $result = $this->
db->query($sql);
277 $this->error = $this->
db->lasterror();
278 $this->
db->rollback();
291 $sql =
"SELECT e.rowid, e.ref, e.label, e.address, e.zip, e.town, e.status, e.fk_country as country_id, e.entity,";
292 $sql .=
' c.code as country_code, c.label as country';
293 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
294 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON e.fk_country = c.rowid';
295 $sql .=
" WHERE e.rowid = ".$id;
297 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
298 $result = $this->
db->query($sql);
301 $obj = $this->
db->fetch_object($result);
303 $this->
id = $obj->rowid;
304 $this->ref = $obj->ref;
305 $this->label = $obj->label;
306 $this->address = $obj->address;
307 $this->zip = $obj->zip;
308 $this->town = $obj->town;
309 $this->status = $obj->status;
310 $this->entity = $obj->entity;
312 $this->country_id = $obj->country_id;
313 $this->country_code = $obj->country_code;
314 $this->country = $obj->country;
318 $this->error = $this->
db->lasterror();
329 public function delete($id)
333 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"establishment WHERE rowid = ".$id;
335 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
336 $result = $this->
db->query($sql);
342 $this->error = $this->
db->lasterror();
343 $this->
db->rollback();
356 return $this->
LibStatut($this->status, $mode);
370 if (empty($this->labelStatus) || empty($this->labelStatusShort))
374 $this->labelStatus[self::STATUS_OPEN] = $langs->trans(
'Open');
375 $this->labelStatus[self::STATUS_CLOSED] = $langs->trans(
'Closed');
376 $this->labelStatusShort[self::STATUS_OPEN] = $langs->trans(
'Open');
377 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->trans(
'Closed');
380 $statusType =
'status'.$status;
381 if ($status == self::STATUS_OPEN) $statusType =
'status4';
382 if ($status == self::STATUS_CLOSED) $statusType =
'status6';
384 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
396 $sql =
'SELECT e.rowid, e.ref, e.datec, e.fk_user_author, e.tms, e.fk_user_mod, e.entity';
397 $sql .=
' FROM '.MAIN_DB_PREFIX.
'establishment as e';
398 $sql .=
' WHERE e.rowid = '.$id;
400 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
401 $result = $this->
db->query($sql);
405 if ($this->
db->num_rows($result))
407 $obj = $this->
db->fetch_object($result);
408 $this->
id = $obj->rowid;
410 $this->date_creation = $this->
db->jdate($obj->datec);
411 if ($obj->fk_user_author)
413 $cuser =
new User($this->
db);
414 $cuser->fetch($obj->fk_user_author);
415 $this->user_creation = $cuser;
417 if ($obj->fk_user_mod)
419 $muser =
new User($this->
db);
420 $muser->fetch($obj->fk_user_mod);
421 $this->user_modification = $muser;
423 $this->date_modification = $this->
db->jdate($obj->tms);
426 $this->
db->free($result);
444 $link =
'<a href="'.DOL_URL_ROOT.
'/hrm/establishment/card.php?id='.$this->
id.
'">';
449 $label =
'<u>'.$langs->trans(
"Establishment").
'</u>';
450 $label .=
'<br>'.$langs->trans(
"Label").
': '.$this->label;
452 if ($withpicto) $result .= ($link.img_object($label, $picto).$linkend);
453 if ($withpicto && $withpicto != 2) $result .=
' ';
454 if ($withpicto != 2) $result .= $link.$this->label.$linkend;
468 if (!empty($this->country_code))
return $this->country_code;
471 if (!empty($mysoc->country_code))
return $mysoc->country_code;
486 $this->label =
'Department AAA';
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
info($id)
Information on record.
$conf db
API class for accounts.
getCountryCode()
Return account country code.
__construct($db)
Constructor.
Class to manage establishments.
LibStatut($status, $mode=0)
Return the status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getLibStatut($mode=0)
Give a label from a status.
create($user)
Create object in database.
update($user)
Update record.
getNomUrl($withpicto=0)
Return clicable name (with picto eventually)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
fetch($id)
Load an object from database.