29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $element =
'deplacement';
44 public $table_element =
'deplacement';
49 public $table_element_line =
'';
54 public $fk_element =
'';
86 public $fk_user_author;
110 public $extraparams = array();
137 $this->ismultientitymanaged = 0;
152 if (empty($this->
type) || $this->
type < 0) {
153 $this->error =
'ErrorBadParameter';
156 if (empty($this->fk_user) || $this->fk_user < 0) {
157 $this->error =
'ErrorBadParameter';
165 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"deplacement (";
169 $sql .=
", fk_user_author";
172 $sql .=
", note_private";
173 $sql .=
", note_public";
174 $sql .=
", fk_projet";
176 $sql .=
") VALUES (";
177 $sql .=
" '".$this->db->idate($now).
"'";
178 $sql .=
", ".((int)
$conf->entity);
179 $sql .=
", ".((int) $user->id);
180 $sql .=
", ".((int) $this->fk_user);
181 $sql .=
", '".$this->db->escape($this->
type).
"'";
182 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
183 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
184 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
185 $sql .=
", ".($this->fk_soc > 0 ? ((int) $this->fk_soc) :
"null");
188 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
189 $result = $this->db->query($sql);
191 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"deplacement");
194 $result = $this->
call_trigger(
'DEPLACEMENT_CREATE', $user);
196 $this->db->rollback();
201 $result = $this->
update($user);
206 $this->error = $this->db->error();
207 $this->db->rollback();
211 $this->error = $this->db->error().
" sql=".$sql;
212 $this->db->rollback();
226 $this->km = (float)
price2num($this->km);
229 if (!is_numeric($this->km)) {
232 if (empty($this->date)) {
233 $this->error =
'ErrorBadParameter';
236 if (empty($this->
type) || $this->
type < 0) {
237 $this->error =
'ErrorBadParameter';
240 if (empty($this->fk_user) || $this->fk_user < 0) {
241 $this->error =
'ErrorBadParameter';
247 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"deplacement ";
248 $sql .=
" SET km = ".((float) $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 = ".((int) $this->fk_user);
253 $sql .=
" , fk_user_modif = ".((int) $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 = ".((int) $this->
id);
260 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
261 $result = $this->db->query($sql);
266 $this->error = $this->db->lasterror();
267 $this->db->rollback();
279 public function fetch($id, $ref =
'')
281 $sql =
"SELECT rowid, fk_user, type, fk_statut, km, fk_soc, dated, note_private, note_public, fk_projet as fk_project, extraparams";
282 $sql .=
" FROM ".MAIN_DB_PREFIX.
"deplacement";
283 $sql .=
" WHERE entity IN (".getEntity(
'deplacement').
")";
285 $sql .=
" AND ref ='".$this->db->escape($ref).
"'";
287 $sql .=
" AND 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->rowid;
297 $this->date = $this->db->jdate($obj->dated);
298 $this->fk_user = $obj->fk_user;
299 $this->socid = $obj->fk_soc;
300 $this->km = $obj->km;
301 $this->
type = $obj->type;
302 $this->statut = $obj->fk_statut;
303 $this->note_private = $obj->note_private;
304 $this->note_public = $obj->note_public;
305 $this->fk_project = $obj->fk_project;
307 $this->extraparams = (array) json_decode($obj->extraparams,
true);
311 $this->error = $this->db->error();
322 public function delete($user)
328 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"deplacement WHERE rowid = ".((int) $id);
330 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
331 $result = $this->db->query($sql);
336 $this->error = $this->db->error();
337 $this->db->rollback();
351 return $this->
LibStatut($this->statut, $mode);
367 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
378 $status_logo = array(0 =>
'status0', 1 =>
'status4', 2 =>
'status1', 4 =>
'status6', 5 =>
'status4', 6 =>
'status6', 99 =>
'status5');
379 $statusType = $status_logo[$status];
381 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
395 $label = $langs->trans(
"Show").
': '.$this->ref;
397 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/deplacement/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
404 $result .= ($link.img_object($label, $picto,
'class="classfortooltip"').$linkend);
406 if ($withpicto && $withpicto != 2) {
409 if ($withpicto != 2) {
410 $result .= $link.$this->ref.$linkend;
428 $sql =
"SELECT id, code, label";
429 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees";
430 $sql .=
" WHERE active = ".((int) $active);
432 dol_syslog(get_class($this).
"::listOfTypes", LOG_DEBUG);
433 $result = $this->db->query($sql);
435 $num = $this->db->num_rows($result);
438 $obj = $this->db->fetch_object($result);
439 $ret[$obj->code] = (($langs->trans($obj->code) != $obj->code) ? $langs->trans($obj->code) : $obj->label);
457 $sql =
'SELECT c.rowid, c.datec, c.fk_user_author, c.fk_user_modif,';
458 $sql .=
' c.tms as datem';
459 $sql .=
' FROM '.MAIN_DB_PREFIX.
'deplacement as c';
460 $sql .=
' WHERE c.rowid = '.((int) $id);
462 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
463 $result = $this->db->query($sql);
466 if ($this->db->num_rows($result)) {
467 $obj = $this->db->fetch_object($result);
469 $this->
id = $obj->rowid;
471 $this->user_creation_id = $obj->fk_user_author;
472 $this->user_modification_id = $obj->fk_user_modif;
473 $this->date_creation = $this->db->jdate($obj->datec);
474 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
476 $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 clickable 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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type