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';
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->db->free($resql);
149 $this->error = $this->db->error().
' sql='.$sql;
161 public function insert($user, $notrigger = 0)
165 dol_syslog(
"FichinterLigne::insert rang=".$this->rang);
167 if (empty($this->date) && !empty($this->datei)) {
168 $this->date = $this->datei;
173 $rangToUse = $this->rang;
174 if ($rangToUse == -1) {
176 $sql =
'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.
'fichinterdet';
177 $sql .=
' WHERE fk_fichinter = '.((int) $this->fk_fichinter);
178 $resql = $this->db->query($sql);
180 $obj = $this->db->fetch_object($resql);
181 $rangToUse = $obj->max + 1;
184 $this->db->rollback();
190 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'fichinterdet';
191 $sql .=
' (fk_fichinter, description, date, duree, rang)';
192 $sql .=
" VALUES (".((int) $this->fk_fichinter).
",";
193 $sql .=
" '".$this->db->escape($this->desc).
"',";
194 $sql .=
" '".$this->db->idate($this->date).
"',";
195 $sql .=
" ".((int) $this->duration).
",";
196 $sql .=
' '.((int) $rangToUse);
199 dol_syslog(
"FichinterLigne::insert", LOG_DEBUG);
200 $resql = $this->db->query($sql);
202 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'fichinterdet');
203 $this->rowid = $this->id;
216 $this->rang = $rangToUse;
220 $result = $this->
call_trigger(
'LINEFICHINTER_CREATE', $user);
232 $this->db->rollback();
236 $this->error = $this->db->error().
" sql=".$sql;
237 $this->db->rollback();
250 public function update($user, $notrigger = 0)
254 if (empty($this->date) && !empty($this->datei)) {
255 $this->date = $this->datei;
261 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinterdet SET";
262 $sql .=
" description = '".$this->db->escape($this->desc).
"',";
263 $sql .=
" date = '".$this->db->idate($this->date).
"',";
264 $sql .=
" duree = ".((int) $this->duration).
",";
265 $sql .=
" rang = ".((int) $this->rang);
266 $sql .=
" WHERE rowid = ".((int) $this->
id);
268 dol_syslog(
"FichinterLigne::update", LOG_DEBUG);
269 $resql = $this->db->query($sql);
282 $result = $this->
call_trigger(
'LINEFICHINTER_MODIFY', $user);
294 $this->error = $this->db->lasterror();
295 $this->db->rollback();
299 $this->error = $this->db->lasterror();
300 $this->db->rollback();
318 $sql =
"SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
319 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
320 $sql .=
" WHERE fk_fichinter=".((int) $this->fk_fichinter);
322 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
323 $resql = $this->db->query($sql);
325 $obj = $this->db->fetch_object($resql);
327 if (!empty($obj->total_duration)) {
328 $total_duration = $obj->total_duration;
331 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
332 $sql .=
" SET duree = ".((int) $total_duration);
333 $sql .=
" , dateo = ".(!empty($obj->dateo) ?
"'".$this->db->escape($obj->dateo).
"'" :
"null");
334 $sql .=
" , datee = ".(!empty($obj->datee) ?
"'".$this->db->escape($obj->datee).
"'" :
"null");
335 $sql .=
" WHERE rowid = ".((int) $this->fk_fichinter);
337 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
338 $resql = $this->db->query($sql);
343 $this->error = $this->db->error();
344 $this->db->rollback();
348 $this->error = $this->db->error();
349 $this->db->rollback();
365 dol_syslog(get_class($this).
"::deleteline lineid=".$this->
id);
372 $this->db->rollback();
376 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet WHERE rowid = ".((int) $this->
id);
377 $resql = $this->db->query($sql);
384 $result = $this->
call_trigger(
'LINEFICHINTER_DELETE', $user);
387 $this->db->rollback();
396 $this->db->rollback();
400 $this->error = $this->db->error().
" sql=".$sql;
401 $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.