28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $element =
'deplacement';
43 public $table_element =
'deplacement';
48 public $table_element_line =
'';
53 public $fk_element =
'';
59 public $ismultientitymanaged = 0;
78 public $fk_user_author;
99 public $extraparams = array();
101 public $statuts = array();
102 public $statuts_short = array();
103 public $statuts_logo = array();
130 $this->statuts_short = array(0 =>
'Draft', 1 =>
'Validated', 2 =>
'Refunded');
131 $this->statuts = array(0 =>
'Draft', 1 =>
'Validated', 2 =>
'Refunded');
132 $this->statuts_logo = array(0 =>
'status0', 1=>
'status4', 2 =>
'status1', 4 =>
'status6', 5 =>
'status4', 6 =>
'status6', 99 =>
'status5');
147 if (empty($this->
type) || $this->
type < 0) {
148 $this->error =
'ErrorBadParameter';
151 if (empty($this->fk_user) || $this->fk_user < 0) {
152 $this->error =
'ErrorBadParameter';
160 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"deplacement (";
164 $sql .=
", fk_user_author";
167 $sql .=
", note_private";
168 $sql .=
", note_public";
169 $sql .=
", fk_projet";
171 $sql .=
") VALUES (";
172 $sql .=
" '".$this->db->idate($now).
"'";
173 $sql .=
", ".((int) $conf->entity);
174 $sql .=
", ".((int) $user->id);
175 $sql .=
", ".((int) $this->fk_user);
176 $sql .=
", '".$this->db->escape($this->
type).
"'";
177 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
178 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
179 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
180 $sql .=
", ".($this->fk_soc > 0 ? ((int) $this->fk_soc) :
"null");
183 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
184 $result = $this->db->query($sql);
186 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"deplacement");
189 $result = $this->
call_trigger(
'DEPLACEMENT_CREATE', $user);
191 $this->db->rollback();
196 $result = $this->
update($user);
201 $this->error = $this->db->error();
202 $this->db->rollback();
206 $this->error = $this->db->error().
" sql=".$sql;
207 $this->db->rollback();
226 if (!is_numeric($this->km)) {
229 if (empty($this->date)) {
230 $this->error =
'ErrorBadParameter';
233 if (empty($this->
type) || $this->
type < 0) {
234 $this->error =
'ErrorBadParameter';
237 if (empty($this->fk_user) || $this->fk_user < 0) {
238 $this->error =
'ErrorBadParameter';
244 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"deplacement ";
245 $sql .=
" SET km = ".((float) $this->km);
246 $sql .=
" , dated = '".$this->db->idate($this->date).
"'";
247 $sql .=
" , type = '".$this->db->escape($this->
type).
"'";
248 $sql .=
" , fk_statut = '".$this->db->escape($this->
statut).
"'";
249 $sql .=
" , fk_user = ".((int) $this->fk_user);
250 $sql .=
" , fk_user_modif = ".((int) $user->id);
251 $sql .=
" , fk_soc = ".($this->socid > 0 ? $this->socid :
'null');
252 $sql .=
" , note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
253 $sql .=
" , note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
254 $sql .=
" , fk_projet = ".($this->fk_project > 0 ? $this->fk_project : 0);
255 $sql .=
" WHERE rowid = ".((int) $this->
id);
257 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
258 $result = $this->db->query($sql);
263 $this->error = $this->db->lasterror();
264 $this->db->rollback();
276 public function fetch($id, $ref =
'')
278 $sql =
"SELECT rowid, fk_user, type, fk_statut, km, fk_soc, dated, note_private, note_public, fk_projet as fk_project, extraparams";
279 $sql .=
" FROM ".MAIN_DB_PREFIX.
"deplacement";
280 $sql .=
" WHERE entity IN (".getEntity(
'deplacement').
")";
282 $sql .=
" AND ref ='".$this->db->escape($ref).
"'";
284 $sql .=
" AND rowid = ".((int) $id);
287 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
288 $result = $this->db->query($sql);
290 $obj = $this->db->fetch_object($result);
292 $this->
id = $obj->rowid;
293 $this->
ref = $obj->rowid;
294 $this->date = $this->db->jdate($obj->dated);
295 $this->fk_user = $obj->fk_user;
296 $this->socid = $obj->fk_soc;
297 $this->km = $obj->km;
298 $this->
type = $obj->type;
299 $this->
statut = $obj->fk_statut;
300 $this->note_private = $obj->note_private;
301 $this->note_public = $obj->note_public;
302 $this->fk_project = $obj->fk_project;
304 $this->extraparams = (array) json_decode($obj->extraparams,
true);
308 $this->error = $this->db->error();
319 public function delete($user)
325 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"deplacement WHERE rowid = ".((int) $id);
327 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
328 $result = $this->db->query($sql);
333 $this->error = $this->db->error();
334 $this->db->rollback();
364 $labelStatus = $langs->transnoentitiesnoconv($this->statuts[$status]);
365 $labelStatusShort = $langs->transnoentitiesnoconv($this->statuts_short[$status]);
367 $statusType = $this->statuts_logo[$status];
369 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
383 $label = $langs->trans(
"Show").
': '.$this->ref;
385 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/deplacement/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
392 $result .= ($link.img_object($label, $picto,
'class="classfortooltip"').$linkend);
394 if ($withpicto && $withpicto != 2) {
397 if ($withpicto != 2) {
398 $result .= $link.$this->ref.$linkend;
416 $sql =
"SELECT id, code, label";
417 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees";
418 $sql .=
" WHERE active = ".((int) $active);
420 dol_syslog(get_class($this).
"::listOfTypes", LOG_DEBUG);
421 $result = $this->db->query($sql);
423 $num = $this->db->num_rows($result);
426 $obj = $this->db->fetch_object($result);
427 $ret[$obj->code] = (($langs->trans($obj->code) != $obj->code) ? $langs->trans($obj->code) : $obj->label);
445 $sql =
'SELECT c.rowid, c.datec, c.fk_user_author, c.fk_user_modif,';
446 $sql .=
' c.tms as datem';
447 $sql .=
' FROM '.MAIN_DB_PREFIX.
'deplacement as c';
448 $sql .=
' WHERE c.rowid = '.((int) $id);
450 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
451 $result = $this->db->query($sql);
454 if ($this->db->num_rows($result)) {
455 $obj = $this->db->fetch_object($result);
456 $this->
id = $obj->rowid;
458 $this->user_creation_id = $obj->fk_user_author;
459 $this->user_modification_id = $obj->fk_user_modif;
460 $this->date_creation = $this->db->jdate($obj->datec);
461 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
463 $this->db->free($result);
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage trips and working credit notes.
listOfTypes($active=1)
List of types.
const STATUS_DRAFT
Draft status.
getNomUrl($withpicto=0)
Return clicable name (with picto eventually)
info($id)
Information on record.
update($user)
Update record.
create($user)
Create object in database TODO Add ref number.
const STATUS_REFUNDED
Refunded status.
fetch($id, $ref='')
Load an object from database.
__construct(DoliDB $db)
Constructor.
LibStatut($status, $mode=0)
Return the label of a given status.
getLibStatut($mode=0)
Return the label of the status.
const STATUS_VALIDATED
Validated status.
Class to manage Dolibarr database access.
print $langs trans("Ref").' m m m statut
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type