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;
83 public $fk_user_author;
104 public $extraparams = array();
144 if (empty($this->
type) || $this->
type < 0) {
145 $this->error =
'ErrorBadParameter';
148 if (empty($this->fk_user) || $this->fk_user < 0) {
149 $this->error =
'ErrorBadParameter';
157 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"deplacement (";
161 $sql .=
", fk_user_author";
164 $sql .=
", note_private";
165 $sql .=
", note_public";
166 $sql .=
", fk_projet";
168 $sql .=
") VALUES (";
169 $sql .=
" '".$this->db->idate($now).
"'";
170 $sql .=
", ".((int) $conf->entity);
171 $sql .=
", ".((int) $user->id);
172 $sql .=
", ".((int) $this->fk_user);
173 $sql .=
", '".$this->db->escape($this->
type).
"'";
174 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
175 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
176 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
177 $sql .=
", ".($this->fk_soc > 0 ? ((int) $this->fk_soc) :
"null");
180 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
181 $result = $this->db->query($sql);
183 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"deplacement");
186 $result = $this->
call_trigger(
'DEPLACEMENT_CREATE', $user);
188 $this->db->rollback();
193 $result = $this->
update($user);
198 $this->error = $this->db->error();
199 $this->db->rollback();
203 $this->error = $this->db->error().
" sql=".$sql;
204 $this->db->rollback();
221 if (!is_numeric($this->km)) {
224 if (empty($this->date)) {
225 $this->error =
'ErrorBadParameter';
228 if (empty($this->
type) || $this->
type < 0) {
229 $this->error =
'ErrorBadParameter';
232 if (empty($this->fk_user) || $this->fk_user < 0) {
233 $this->error =
'ErrorBadParameter';
239 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"deplacement ";
240 $sql .=
" SET km = ".((float) $this->km);
241 $sql .=
" , dated = '".$this->db->idate($this->date).
"'";
242 $sql .=
" , type = '".$this->db->escape($this->
type).
"'";
243 $sql .=
" , fk_statut = '".$this->db->escape($this->
statut).
"'";
244 $sql .=
" , fk_user = ".((int) $this->fk_user);
245 $sql .=
" , fk_user_modif = ".((int) $user->id);
246 $sql .=
" , fk_soc = ".($this->socid > 0 ? $this->socid :
'null');
247 $sql .=
" , note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
248 $sql .=
" , note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
249 $sql .=
" , fk_projet = ".($this->fk_project > 0 ? $this->fk_project : 0);
250 $sql .=
" WHERE rowid = ".((int) $this->
id);
252 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
253 $result = $this->db->query($sql);
258 $this->error = $this->db->lasterror();
259 $this->db->rollback();
271 public function fetch($id, $ref =
'')
273 $sql =
"SELECT rowid, fk_user, type, fk_statut, km, fk_soc, dated, note_private, note_public, fk_projet as fk_project, extraparams";
274 $sql .=
" FROM ".MAIN_DB_PREFIX.
"deplacement";
275 $sql .=
" WHERE entity IN (".getEntity(
'deplacement').
")";
277 $sql .=
" AND ref ='".$this->db->escape($ref).
"'";
279 $sql .=
" AND rowid = ".((int) $id);
282 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
283 $result = $this->db->query($sql);
285 $obj = $this->db->fetch_object($result);
287 $this->
id = $obj->rowid;
288 $this->
ref = $obj->rowid;
289 $this->date = $this->db->jdate($obj->dated);
290 $this->fk_user = $obj->fk_user;
291 $this->socid = $obj->fk_soc;
292 $this->km = $obj->km;
293 $this->
type = $obj->type;
294 $this->
statut = $obj->fk_statut;
295 $this->note_private = $obj->note_private;
296 $this->note_public = $obj->note_public;
297 $this->fk_project = $obj->fk_project;
299 $this->extraparams = (array) json_decode($obj->extraparams,
true);
303 $this->error = $this->db->error();
314 public function delete($user)
320 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"deplacement WHERE rowid = ".((int) $id);
322 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
323 $result = $this->db->query($sql);
328 $this->error = $this->db->error();
329 $this->db->rollback();
359 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
370 $status_logo = array(0 =>
'status0', 1=>
'status4', 2 =>
'status1', 4 =>
'status6', 5 =>
'status4', 6 =>
'status6', 99 =>
'status5');
371 $statusType = $status_logo[$status];
373 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
387 $label = $langs->trans(
"Show").
': '.$this->ref;
389 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/deplacement/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
396 $result .= ($link.img_object($label, $picto,
'class="classfortooltip"').$linkend);
398 if ($withpicto && $withpicto != 2) {
401 if ($withpicto != 2) {
402 $result .= $link.$this->ref.$linkend;
420 $sql =
"SELECT id, code, label";
421 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees";
422 $sql .=
" WHERE active = ".((int) $active);
424 dol_syslog(get_class($this).
"::listOfTypes", LOG_DEBUG);
425 $result = $this->db->query($sql);
427 $num = $this->db->num_rows($result);
430 $obj = $this->db->fetch_object($result);
431 $ret[$obj->code] = (($langs->trans($obj->code) != $obj->code) ? $langs->trans($obj->code) : $obj->label);
449 $sql =
'SELECT c.rowid, c.datec, c.fk_user_author, c.fk_user_modif,';
450 $sql .=
' c.tms as datem';
451 $sql .=
' FROM '.MAIN_DB_PREFIX.
'deplacement as c';
452 $sql .=
' WHERE c.rowid = '.((int) $id);
454 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
455 $result = $this->db->query($sql);
458 if ($this->db->num_rows($result)) {
459 $obj = $this->db->fetch_object($result);
461 $this->
id = $obj->rowid;
463 $this->user_creation_id = $obj->fk_user_author;
464 $this->user_modification_id = $obj->fk_user_modif;
465 $this->date_creation = $this->db->jdate($obj->datec);
466 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
468 $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.
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...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type