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 if ($this->db->num_rows($resql)) {
134 $objp = $this->db->fetch_object($resql);
135 $this->rowid = $objp->rowid;
136 $this->
id = $objp->rowid;
137 $this->fk_fichinter = $objp->fk_fichinter;
138 $this->date = $this->db->jdate($objp->date);
139 $this->datei = $this->db->jdate($objp->date);
140 $this->desc = $objp->description;
141 $this->duration = $objp->duree;
142 $this->rang = $objp->rang;
144 $this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
146 $this->db->free($resql);
155 $this->error = $this->db->error().
' sql='.$sql;
167 public function insert($user, $notrigger = 0)
171 dol_syslog(
"FichinterLigne::insert rang=".$this->rang);
173 if (empty($this->date) && !empty($this->datei)) {
174 $this->date = $this->datei;
179 $rangToUse = $this->rang;
180 if ($rangToUse == -1) {
182 $sql =
'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.
'fichinterdet';
183 $sql .=
' WHERE fk_fichinter = '.((int) $this->fk_fichinter);
184 $resql = $this->db->query($sql);
186 $obj = $this->db->fetch_object($resql);
187 $rangToUse = $obj->max + 1;
190 $this->db->rollback();
196 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'fichinterdet';
197 $sql .=
' (fk_fichinter, description, date, duree, rang)';
198 $sql .=
" VALUES (".((int) $this->fk_fichinter).
",";
199 $sql .=
" '".$this->db->escape($this->desc).
"',";
200 $sql .=
" '".$this->db->idate($this->date).
"',";
201 $sql .=
" ".((int) $this->duration).
",";
202 $sql .=
' '.((int) $rangToUse);
205 dol_syslog(
"FichinterLigne::insert", LOG_DEBUG);
206 $resql = $this->db->query($sql);
208 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'fichinterdet');
209 $this->rowid = $this->id;
222 $this->rang = $rangToUse;
226 $result = $this->
call_trigger(
'LINEFICHINTER_CREATE', $user);
238 $this->db->rollback();
242 $this->error = $this->db->error().
" sql=".$sql;
243 $this->db->rollback();
256 public function update($user, $notrigger = 0)
260 if (empty($this->date) && !empty($this->datei)) {
261 $this->date = $this->datei;
267 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinterdet SET";
268 $sql .=
" description = '".$this->db->escape($this->desc).
"',";
269 $sql .=
" date = '".$this->db->idate($this->date).
"',";
270 $sql .=
" duree = ".((int) $this->duration).
",";
271 $sql .=
" rang = ".((int) $this->rang);
272 $sql .=
" WHERE rowid = ".((int) $this->
id);
274 dol_syslog(
"FichinterLigne::update", LOG_DEBUG);
275 $resql = $this->db->query($sql);
288 $result = $this->
call_trigger(
'LINEFICHINTER_MODIFY', $user);
300 $this->error = $this->db->lasterror();
301 $this->db->rollback();
305 $this->error = $this->db->lasterror();
306 $this->db->rollback();
324 $sql =
"SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
325 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
326 $sql .=
" WHERE fk_fichinter=".((int) $this->fk_fichinter);
328 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
329 $resql = $this->db->query($sql);
331 $obj = $this->db->fetch_object($resql);
333 if (!empty($obj->total_duration)) {
334 $total_duration = $obj->total_duration;
337 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
338 $sql .=
" SET duree = ".((int) $total_duration);
339 $sql .=
" , dateo = ".(!empty($obj->dateo) ?
"'".$this->db->escape($obj->dateo).
"'" :
"null");
340 $sql .=
" , datee = ".(!empty($obj->datee) ?
"'".$this->db->escape($obj->datee).
"'" :
"null");
341 $sql .=
" WHERE rowid = ".((int) $this->fk_fichinter);
343 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
344 $resql = $this->db->query($sql);
349 $this->error = $this->db->error();
350 $this->db->rollback();
354 $this->error = $this->db->error();
355 $this->db->rollback();
371 dol_syslog(get_class($this).
"::deleteline lineid=".$this->
id);
378 $this->db->rollback();
382 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet WHERE rowid = ".((int) $this->
id);
383 $resql = $this->db->query($sql);
390 $result = $this->
call_trigger(
'LINEFICHINTER_DELETE', $user);
393 $this->db->rollback();
402 $this->db->rollback();
406 $this->error = $this->db->error().
" sql=".$sql;
407 $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...