32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
93 public $element =
'fichinterdet';
98 public $table_element =
'fichinterdet';
103 public $fk_element =
'fk_fichinter';
125 dol_syslog(
"FichinterLigne::fetch", LOG_DEBUG);
127 $sql =
'SELECT ft.rowid, ft.fk_fichinter, ft.description, ft.duree, ft.rang, ft.date, ft.extraparams';
128 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinterdet as ft';
129 $sql .=
' WHERE ft.rowid = '.((int) $rowid);
131 $resql = $this->db->query($sql);
133 $objp = $this->db->fetch_object($resql);
134 $this->rowid = $objp->rowid;
135 $this->
id = $objp->rowid;
136 $this->fk_fichinter = $objp->fk_fichinter;
137 $this->date = $this->db->jdate($objp->date);
138 $this->datei = $this->db->jdate($objp->date);
139 $this->desc = $objp->description;
140 $this->duration = $objp->duree;
141 $this->rang = $objp->rang;
143 $this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
145 $this->db->free($resql);
151 $this->error = $this->db->error().
' sql='.$sql;
163 public function insert($user, $notrigger = 0)
167 dol_syslog(
"FichinterLigne::insert rang=".$this->rang);
169 if (empty($this->date) && !empty($this->datei)) {
170 $this->date = $this->datei;
175 $rangToUse = $this->rang;
176 if ($rangToUse == -1) {
178 $sql =
'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.
'fichinterdet';
179 $sql .=
' WHERE fk_fichinter = '.((int) $this->fk_fichinter);
180 $resql = $this->db->query($sql);
182 $obj = $this->db->fetch_object($resql);
183 $rangToUse = $obj->max + 1;
186 $this->db->rollback();
192 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'fichinterdet';
193 $sql .=
' (fk_fichinter, description, date, duree, rang)';
194 $sql .=
" VALUES (".((int) $this->fk_fichinter).
",";
195 $sql .=
" '".$this->db->escape($this->desc).
"',";
196 $sql .=
" '".$this->db->idate($this->date).
"',";
197 $sql .=
" ".((int) $this->duration).
",";
198 $sql .=
' '.((int) $rangToUse);
201 dol_syslog(
"FichinterLigne::insert", LOG_DEBUG);
202 $resql = $this->db->query($sql);
204 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'fichinterdet');
205 $this->rowid = $this->id;
218 $this->rang = $rangToUse;
222 $result = $this->
call_trigger(
'LINEFICHINTER_CREATE', $user);
234 $this->db->rollback();
238 $this->error = $this->db->error().
" sql=".$sql;
239 $this->db->rollback();
252 public function update($user, $notrigger = 0)
256 if (empty($this->date) && !empty($this->datei)) {
257 $this->date = $this->datei;
263 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinterdet SET";
264 $sql .=
" description = '".$this->db->escape($this->desc).
"',";
265 $sql .=
" date = '".$this->db->idate($this->date).
"',";
266 $sql .=
" duree = ".((int) $this->duration).
",";
267 $sql .=
" rang = ".((int) $this->rang);
268 $sql .=
" WHERE rowid = ".((int) $this->
id);
270 dol_syslog(
"FichinterLigne::update", LOG_DEBUG);
271 $resql = $this->db->query($sql);
284 $result = $this->
call_trigger(
'LINEFICHINTER_MODIFY', $user);
296 $this->error = $this->db->lasterror();
297 $this->db->rollback();
301 $this->error = $this->db->lasterror();
302 $this->db->rollback();
320 $sql =
"SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
321 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
322 $sql .=
" WHERE fk_fichinter=".((int) $this->fk_fichinter);
324 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
325 $resql = $this->db->query($sql);
327 $obj = $this->db->fetch_object($resql);
329 if (!empty($obj->total_duration)) {
330 $total_duration = $obj->total_duration;
333 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
334 $sql .=
" SET duree = ".((int) $total_duration);
335 $sql .=
" , dateo = ".(!empty($obj->dateo) ?
"'".$this->db->escape($obj->dateo).
"'" :
"null");
336 $sql .=
" , datee = ".(!empty($obj->datee) ?
"'".$this->db->escape($obj->datee).
"'" :
"null");
337 $sql .=
" WHERE rowid = ".((int) $this->fk_fichinter);
339 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
340 $resql = $this->db->query($sql);
345 $this->error = $this->db->error();
346 $this->db->rollback();
350 $this->error = $this->db->error();
351 $this->db->rollback();
367 dol_syslog(get_class($this).
"::deleteline lineid=".$this->
id);
374 $this->db->rollback();
378 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet WHERE rowid = ".((int) $this->
id);
379 $resql = $this->db->query($sql);
386 $result = $this->
call_trigger(
'LINEFICHINTER_DELETE', $user);
389 $this->db->rollback();
398 $this->db->rollback();
402 $this->error = $this->db->error().
" sql=".$sql;
403 $this->db->rollback();
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage intervention lines.
deleteLine($user, $notrigger=0)
Delete a intervention line.
fetch($rowid)
Retrieve the line of intervention.
update_total()
Update total duration into llx_fichinter.
update($user, $notrigger=0)
Update intervention into database.
__construct($db)
Constructor.
insert($user, $notrigger=0)
Insert the line into database.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...