28 require_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();
128 $this->statuts_short = array(0 =>
'Draft', 1 =>
'Validated', 2 =>
'Refunded');
129 $this->statuts = array(0 =>
'Draft', 1 =>
'Validated', 2 =>
'Refunded');
144 if (empty($this->
type) || $this->
type < 0)
146 $this->error =
'ErrorBadParameter';
149 if (empty($this->fk_user) || $this->fk_user < 0)
151 $this->error =
'ErrorBadParameter';
159 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"deplacement (";
163 $sql .=
", fk_user_author";
166 $sql .=
", note_private";
167 $sql .=
", note_public";
168 $sql .=
", fk_projet";
170 $sql .=
") VALUES (";
171 $sql .=
" '".$this->db->idate($now).
"'";
172 $sql .=
", ".$conf->entity;
173 $sql .=
", ".$user->id;
174 $sql .=
", ".$this->fk_user;
175 $sql .=
", '".$this->db->escape($this->
type).
"'";
176 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
177 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
178 $sql .=
", ".($this->fk_project > 0 ? $this->fk_project : 0);
179 $sql .=
", ".($this->fk_soc > 0 ? $this->fk_soc :
"null");
182 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
183 $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);
192 $this->
db->rollback();
197 $result = $this->
update($user);
203 $this->error = $this->
db->error();
204 $this->
db->rollback();
208 $this->error = $this->
db->error().
" sql=".$sql;
209 $this->
db->rollback();
228 if (!is_numeric($this->km)) $this->km = 0;
229 if (empty($this->date))
231 $this->error =
'ErrorBadParameter';
234 if (empty($this->
type) || $this->
type < 0)
236 $this->error =
'ErrorBadParameter';
239 if (empty($this->fk_user) || $this->fk_user < 0)
241 $this->error =
'ErrorBadParameter';
247 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"deplacement ";
248 $sql .=
" SET km = ".$this->km;
249 $sql .=
" , dated = '".$this->db->idate($this->date).
"'";
250 $sql .=
" , type = '".$this->db->escape($this->
type).
"'";
251 $sql .=
" , fk_statut = '".$this->db->escape($this->
statut).
"'";
252 $sql .=
" , fk_user = ".$this->fk_user;
253 $sql .=
" , fk_user_modif = ".$user->id;
254 $sql .=
" , fk_soc = ".($this->socid > 0 ? $this->socid :
'null');
255 $sql .=
" , note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
256 $sql .=
" , note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
257 $sql .=
" , fk_projet = ".($this->fk_project > 0 ? $this->fk_project : 0);
258 $sql .=
" WHERE rowid = ".$this->id;
260 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
261 $result = $this->
db->query($sql);
267 $this->error = $this->
db->lasterror();
268 $this->
db->rollback();
280 public function fetch($id, $ref =
'')
282 $sql =
"SELECT rowid, fk_user, type, fk_statut, km, fk_soc, dated, note_private, note_public, fk_projet as fk_project, extraparams";
283 $sql .=
" FROM ".MAIN_DB_PREFIX.
"deplacement";
284 $sql .=
" WHERE entity IN (".getEntity(
'deplacement').
")";
285 if ($ref) $sql .=
" AND ref ='".$this->db->escape($ref).
"'";
286 else $sql .=
" AND rowid = ".$id;
288 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
289 $result = $this->
db->query($sql);
292 $obj = $this->
db->fetch_object($result);
294 $this->
id = $obj->rowid;
295 $this->ref = $obj->rowid;
296 $this->date = $this->
db->jdate($obj->dated);
297 $this->fk_user = $obj->fk_user;
298 $this->socid = $obj->fk_soc;
299 $this->km = $obj->km;
300 $this->
type = $obj->type;
301 $this->
statut = $obj->fk_statut;
302 $this->note_private = $obj->note_private;
303 $this->note_public = $obj->note_public;
304 $this->fk_project = $obj->fk_project;
306 $this->extraparams = (array) json_decode($obj->extraparams,
true);
310 $this->error = $this->
db->error();
321 public function delete($id)
325 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"deplacement WHERE rowid = ".$id;
327 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
328 $result = $this->
db->query($sql);
334 $this->error = $this->
db->error();
335 $this->
db->rollback();
367 return $langs->trans($this->statuts[$status]);
368 } elseif ($mode == 1)
370 return $langs->trans($this->statuts_short[$status]);
371 } elseif ($mode == 2)
373 if ($status == 0)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts_short[$status]);
374 elseif ($status == 1)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut4').
' '.$langs->trans($this->statuts_short[$status]);
375 elseif ($status == 2)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
376 } elseif ($mode == 3)
378 if ($status == 0 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut0');
379 elseif ($status == 1 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut4');
380 elseif ($status == 2 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
381 } elseif ($mode == 4)
383 if ($status == 0 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts[$status]);
384 elseif ($status == 1 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut4').
' '.$langs->trans($this->statuts[$status]);
385 elseif ($status == 2 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
386 } elseif ($mode == 5)
388 if ($status == 0 && !empty($this->statuts_short[$status]))
return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut0');
389 elseif ($status == 1 && !empty($this->statuts_short[$status]))
return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut4');
390 elseif ($status == 2 && !empty($this->statuts_short[$status]))
return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
405 $label = $langs->trans(
"Show").
': '.$this->ref;
407 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/deplacement/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
413 if ($withpicto) $result .= ($link.img_object($label, $picto,
'class="classfortooltip"').$linkend);
414 if ($withpicto && $withpicto != 2) $result .=
' ';
415 if ($withpicto != 2) $result .= $link.$this->ref.$linkend;
432 $sql =
"SELECT id, code, label";
433 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees";
434 $sql .=
" WHERE active = ".$active;
436 dol_syslog(get_class($this).
"::listOfTypes", LOG_DEBUG);
437 $result = $this->
db->query($sql);
440 $num = $this->
db->num_rows($result);
444 $obj = $this->
db->fetch_object($result);
445 $ret[$obj->code] = (($langs->trans($obj->code) != $obj->code) ? $langs->trans($obj->code) : $obj->label);
463 $sql =
'SELECT c.rowid, c.datec, c.fk_user_author, c.fk_user_modif,';
465 $sql .=
' FROM '.MAIN_DB_PREFIX.
'deplacement as c';
466 $sql .=
' WHERE c.rowid = '.$id;
468 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
469 $result = $this->
db->query($sql);
473 if ($this->
db->num_rows($result))
475 $obj = $this->
db->fetch_object($result);
476 $this->
id = $obj->rowid;
477 if ($obj->fk_user_author)
479 $cuser =
new User($this->
db);
480 $cuser->fetch($obj->fk_user_author);
481 $this->user_creation = $cuser;
483 if ($obj->fk_user_modif)
485 $muser =
new User($this->
db);
486 $muser->fetch($obj->fk_user_modif);
487 $this->user_modification = $muser;
489 $this->date_creation = $this->
db->jdate($obj->datec);
490 $this->date_modification = $this->
db->jdate($obj->tms);
492 $this->
db->free($result);
const STATUS_DRAFT
Draft status.
Class to manage trips and working credit notes.
create($user)
Create object in database TODO Add ref number.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
const STATUS_REFUNDED
Refunded status.
const STATUS_VALIDATED
Validated status.
dol_now($mode= 'auto')
Return date for now.
listOfTypes($active=1)
List of types.
Class to manage Dolibarr users.
$conf db
API class for accounts.
__construct($db)
Constructor.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
call_trigger($triggerName, $user)
Call trigger based on this instance.
fetch($id, $ref= '')
Load an object from database.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getNomUrl($withpicto=0)
Return clicable name (with picto eventually)
getLibStatut($mode=0)
Retourne le libelle du statut.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
info($id)
Information on record.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
update($user)
Update record.