32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/timespent.class.php';
46 public $element =
'project_task';
51 public $table_element =
'projet_task';
56 public $fk_element =
'fk_element';
61 public $picto =
'projecttask';
66 protected $childtables = array(
67 'element_time' => array(
'name' =>
'Task',
'parent' =>
'projet_task',
'parentkey' =>
'fk_element',
'parenttypefield' =>
'elementtype',
'parenttypevalue' =>
'task')
73 public $fk_task_parent = 0;
88 public $duration_effective;
93 public $planned_workload;
152 public $fk_user_creat;
157 public $fk_user_valid;
167 public $timespent_min_date;
171 public $timespent_max_date;
175 public $timespent_total_duration;
179 public $timespent_total_amount;
183 public $timespent_nblinesnull;
187 public $timespent_nblines;
194 public $timespent_id;
198 public $timespent_duration;
202 public $timespent_old_duration;
206 public $timespent_date;
210 public $timespent_datehour;
215 public $timespent_withhour;
220 public $timespent_fk_user;
224 public $timespent_thm;
228 public $timespent_note;
232 public $timespent_fk_product;
236 public $timespent_invoiceid;
240 public $timespent_invoicelineid;
242 public $comments = array();
264 public $projectstatus;
269 public $projectlabel;
284 public $fk_opp_status;
289 public $usage_bill_time;
299 public $array_options_project;
313 public $thirdparty_id;
318 public $thirdparty_name;
323 public $thirdparty_email;
329 public $task_parent_ref;
334 public $task_parent_position;
340 public $billable = 1;
345 public $budget_amount;
350 public $project_budget_amount;
396 public function create($user, $notrigger = 0)
398 global
$conf, $langs;
406 $this->label = trim($this->label);
408 $this->note_public = trim($this->note_public);
409 $this->note_private = trim($this->note_private);
411 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
412 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
417 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet_task (";
419 $sql .=
", fk_projet";
421 $sql .=
", fk_task_parent";
423 $sql .=
", description";
424 $sql .=
", note_public";
425 $sql .=
", note_private";
427 $sql .=
", fk_user_creat";
430 $sql .=
", planned_workload";
431 $sql .=
", progress";
432 $sql .=
", budget_amount";
433 $sql .=
", priority";
434 $sql .=
", billable";
435 $sql .=
") VALUES (";
436 $sql .= (!empty($this->entity) ? (int) $this->entity : (int)
$conf->entity);
437 $sql .=
", ".((int) $this->fk_project);
438 $sql .=
", ".(!empty($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
'null');
439 $sql .=
", ".((int) $this->fk_task_parent);
440 $sql .=
", '".$this->db->escape($this->label).
"'";
441 $sql .=
", '".$this->db->escape($this->
description).
"'";
442 $sql .=
", '".$this->db->escape($this->note_public).
"'";
443 $sql .=
", '".$this->db->escape($this->note_private).
"'";
444 $sql .=
", '".$this->db->idate($now).
"'";
445 $sql .=
", ".((int) $user->id);
446 $sql .=
", ".(isDolTms($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
'null');
447 $sql .=
", ".(isDolTms($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
'null');
448 $sql .=
", ".(($this->planned_workload !=
'' && $this->planned_workload >= 0) ? ((
int) $this->planned_workload) :
'null');
449 $sql .=
", ".(($this->progress !=
'' && $this->progress >= 0) ? ((
int) $this->progress) :
'null');
450 $sql .=
", ".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? ((
int) $this->budget_amount) :
'null');
451 $sql .=
", ".(($this->priority !=
'' && $this->priority >= 0) ? (
int) $this->priority :
'null');
452 $sql .=
", ".((int) $this->billable);
457 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
458 $resql = $this->db->query($sql);
461 $this->errors[] =
"Error ".$this->db->lasterror();
465 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"projet_task");
486 foreach ($this->errors as $errmsg) {
487 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
488 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
490 $this->db->rollback();
507 public function fetch($id, $ref =
'', $loadparentdata = 0)
512 $sql .=
" t.entity,";
513 $sql .=
" t.fk_projet as fk_project,";
514 $sql .=
" t.fk_task_parent,";
516 $sql .=
" t.description,";
517 $sql .=
" t.duration_effective,";
518 $sql .=
" t.planned_workload,";
520 $sql .=
" t.dateo as date_start,";
521 $sql .=
" t.datee as date_end,";
522 $sql .=
" t.fk_user_creat,";
523 $sql .=
" t.fk_user_valid,";
524 $sql .=
" t.fk_statut as status,";
525 $sql .=
" t.progress,";
526 $sql .=
" t.budget_amount,";
527 $sql .=
" t.priority,";
528 $sql .=
" t.note_private,";
529 $sql .=
" t.note_public,";
531 $sql .=
" t.billable";
532 if (!empty($loadparentdata)) {
533 $sql .=
", t2.ref as task_parent_ref";
534 $sql .=
", t2.rang as task_parent_position";
536 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as t";
537 if (!empty($loadparentdata)) {
538 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t2 ON t.fk_task_parent = t2.rowid";
542 $sql .=
"entity IN (".getEntity(
'project').
")";
543 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
545 $sql .=
"t.rowid = ".((int) $id);
548 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
549 $resql = $this->db->query($sql);
551 $num_rows = $this->db->num_rows($resql);
554 $obj = $this->db->fetch_object($resql);
556 $this->
id = $obj->rowid;
557 $this->
ref = $obj->ref;
558 $this->entity = $obj->entity;
559 $this->fk_project = $obj->fk_project;
560 $this->fk_task_parent = $obj->fk_task_parent;
561 $this->label = $obj->label;
563 $this->duration_effective = $obj->duration_effective;
564 $this->planned_workload = $obj->planned_workload;
565 $this->date_c = $this->db->jdate($obj->datec);
566 $this->date_start = $this->db->jdate($obj->date_start);
567 $this->date_end = $this->db->jdate($obj->date_end);
568 $this->fk_user_creat = $obj->fk_user_creat;
569 $this->fk_user_valid = $obj->fk_user_valid;
570 $this->fk_statut = $obj->status;
571 $this->
status = $obj->status;
572 $this->progress = $obj->progress;
573 $this->budget_amount = $obj->budget_amount;
574 $this->priority = $obj->priority;
575 $this->note_private = $obj->note_private;
576 $this->note_public = $obj->note_public;
577 $this->rang = $obj->rang;
579 if (!empty($loadparentdata)) {
580 $this->task_parent_ref = $obj->task_parent_ref;
581 $this->task_parent_position = $obj->task_parent_position;
583 $this->billable = $obj->billable;
589 $this->db->free($resql);
597 $this->error =
"Error ".$this->db->lasterror();
610 public function update($user =
null, $notrigger = 0)
612 global
$conf, $langs;
616 if (isset($this->fk_project)) {
617 $this->fk_project = (int) $this->fk_project;
619 if (isset($this->
ref)) {
620 $this->
ref = trim($this->
ref);
622 if (isset($this->fk_task_parent)) {
623 $this->fk_task_parent = (int) $this->fk_task_parent;
625 if (isset($this->label)) {
626 $this->label = trim($this->label);
631 if (isset($this->note_public)) {
632 $this->note_public = trim($this->note_public);
634 if (isset($this->note_private)) {
635 $this->note_private = trim($this->note_private);
637 if (isset($this->duration_effective)) {
638 $this->duration_effective = trim($this->duration_effective);
640 if (isset($this->planned_workload)) {
641 $this->planned_workload = trim($this->planned_workload);
643 if (isset($this->budget_amount)) {
644 $this->budget_amount = (float) $this->budget_amount;
647 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
648 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
656 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
657 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
658 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"'".$this->db->escape($this->
id).
"'").
",";
659 $sql .=
" fk_task_parent=".(isset($this->fk_task_parent) ? $this->fk_task_parent :
"null").
",";
660 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
661 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
662 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
663 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
664 $sql .=
" duration_effective=".(isset($this->duration_effective) ? $this->duration_effective :
"null").
",";
665 $sql .=
" planned_workload=".((isset($this->planned_workload) && $this->planned_workload !=
'') ? $this->planned_workload :
"null").
",";
666 $sql .=
" dateo=".(isDolTms($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
'null').
",";
667 $sql .=
" datee=".(isDolTms($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
'null').
",";
668 $sql .=
" progress=".(($this->progress !=
'' && $this->progress >= 0) ? $this->progress :
'null').
",";
669 $sql .=
" budget_amount=".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? $this->budget_amount :
'null').
",";
670 $sql .=
" rang=".((!empty($this->rang)) ? ((
int) $this->rang) :
"0").
",";
671 $sql .=
" priority=".((!empty($this->priority)) ? ((
int) $this->priority) :
"0").
",";
672 $sql .=
" billable=".((int) $this->billable);
673 $sql .=
" WHERE rowid=".((int) $this->
id);
677 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
678 $resql = $this->db->query($sql);
681 $this->errors[] =
"Error ".$this->db->lasterror();
694 $project =
new Project($this->db);
695 if ($project->fetch($this->fk_project) > 0) {
697 $project->getLinesArray(
null);
698 $projectCompleted = array_reduce(
705 static function ($allTasksCompleted, $task) {
706 return $allTasksCompleted && $task->progress >= 100;
710 if ($projectCompleted) {
711 if ($project->setClose($user) <= 0) {
720 $this->errors[] = $project->error;
735 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
737 if (
$conf->project->dir_output) {
738 $project =
new Project($this->db);
739 $project->fetch($this->fk_project);
743 if (file_exists($olddir)) {
744 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
747 $langs->load(
"errors");
748 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
757 foreach ($this->errors as $errmsg) {
758 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
759 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
761 $this->db->rollback();
777 public function delete($user, $notrigger = 0)
780 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
787 dol_syslog(get_class($this).
"::delete Can't delete record as it has some sub tasks", LOG_WARNING);
788 $this->error =
'ErrorRecordHasSubTasks';
789 $this->db->rollback();
794 if (!empty($objectisused)) {
795 dol_syslog(get_class($this).
"::delete Can't delete record as it has some child", LOG_WARNING);
796 $this->error =
'ErrorRecordHasChildren';
797 $this->db->rollback();
805 $this->error =
'ErrorFailToDeleteLinkedContact';
807 $this->db->rollback();
813 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_time";
814 $sql .=
" WHERE fk_element = ".((int) $this->
id).
" AND elementtype = 'task'";
816 $resql = $this->db->query($sql);
819 $this->errors[] =
"Error ".$this->db->lasterror();
824 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_extrafields";
825 $sql .=
" WHERE fk_object = ".((int) $this->
id);
827 $resql = $this->db->query($sql);
830 $this->errors[] =
"Error ".$this->db->lasterror();
835 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task";
836 $sql .=
" WHERE rowid=".((int) $this->
id);
838 $resql = $this->db->query($sql);
841 $this->errors[] =
"Error ".$this->db->lasterror();
858 foreach ($this->errors as $errmsg) {
859 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
860 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
862 $this->db->rollback();
866 if (
$conf->project->dir_output) {
867 $projectstatic =
new Project($this->db);
868 $projectstatic->fetch($this->fk_project);
871 dol_syslog(get_class($this).
"::delete dir=".$dir, LOG_DEBUG);
872 if (file_exists($dir)) {
873 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
876 $this->error =
'ErrorFailToDeleteDir';
877 $this->db->rollback();
899 $sql =
"SELECT COUNT(*) as nb";
900 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task";
901 $sql .=
" WHERE fk_task_parent = ".((int) $this->
id);
903 dol_syslog(get_class($this).
"::hasChildren", LOG_DEBUG);
904 $resql = $this->db->query($sql);
907 $this->errors[] =
"Error ".$this->db->lasterror();
909 $obj = $this->db->fetch_object($resql);
913 $this->db->free($resql);
933 $sql =
"SELECT COUNT(*) as nb";
934 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time";
935 $sql .=
" WHERE fk_element = ".((int) $this->
id);
936 $sql .=
" AND elementtype = 'task'";
938 dol_syslog(get_class($this).
"::hasTimeSpent", LOG_DEBUG);
939 $resql = $this->db->query($sql);
942 $this->errors[] =
"Error ".$this->db->lasterror();
944 $obj = $this->db->fetch_object($resql);
948 $this->db->free($resql);
969 $langs->load(
'projects');
972 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Task").
'</u>';
973 if (!empty($this->
ref)) {
974 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
976 if (!empty($this->label)) {
977 $datas[
'label'] =
'<br><b>'.$langs->trans(
'LabelTask').
':</b> '.$this->label;
979 if ($this->date_start || $this->date_end) {
980 $datas[
'range'] =
"<br>".get_date_range($this->date_start, $this->date_end,
'', $langs, 0);
998 public function getNomUrl($withpicto = 0, $option =
'', $mode =
'task', $addlabel = 0, $sep =
' - ', $notooltip = 0, $save_lastsearch_value = -1)
1000 global $action,
$conf, $hookmanager, $langs;
1002 if (!empty(
$conf->dol_no_mouse_hover)) {
1009 'objecttype' => $this->element,
1011 $classfortooltip =
'classfortooltip';
1014 $classfortooltip =
'classforajaxtooltip';
1015 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1021 $url = DOL_URL_ROOT.
'/projet/tasks/'.$mode.
'.php?id='.$this->
id.($option ==
'withproject' ?
'&withproject=1' :
'');
1023 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1024 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1025 $add_save_lastsearch_values = 1;
1027 if ($add_save_lastsearch_values) {
1028 $url .=
'&save_lastsearch_values=1';
1032 if (empty($notooltip)) {
1034 $label = $langs->trans(
"ShowTask");
1035 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1037 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1038 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' nowraponall"';
1040 $linkclose .=
' class="nowraponall"';
1043 $linkstart =
'<a href="'.$url.
'"';
1044 $linkstart .= $linkclose.
'>';
1047 $picto =
'projecttask';
1049 $result .= $linkstart;
1051 $result .=
img_object(($notooltip ?
'' : $label), $picto,
'class="paddingright"', 0, 0, $notooltip ? 0 : 1);
1053 if ($withpicto != 2) {
1054 $result .= $this->ref;
1056 $result .= $linkend;
1057 if ($withpicto != 2) {
1058 $result .= (($addlabel && $this->label) ? $sep.dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) :
'');
1061 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1062 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1064 $result = $hookmanager->resPrint;
1066 $result .= $hookmanager->resPrint;
1085 $this->fk_project = 0;
1086 $this->
ref =
'TK01';
1087 $this->fk_task_parent = 0;
1088 $this->label =
'Specimen task TK01';
1089 $this->duration_effective =
'';
1090 $this->fk_user_creat = $user->id;
1091 $this->progress = 25;
1093 $this->priority = 0;
1094 $this->note_private =
'This is a specimen private note';
1095 $this->note_public =
'This is a specimen public note';
1096 $this->billable = 1;
1124 public function getTasksArray($usert =
null, $userp =
null, $projectid = 0, $socid = 0, $mode = 0, $filteronproj =
'', $filteronprojstatus =
'-1', $morewherefilter =
'', $filteronprojuser = 0, $filterontaskuser = 0, $extrafields =
null, $includebilltime = 0, $search_array_options = array(), $loadextras = 0, $loadRoleMode = 1, $sortfield =
'', $sortorder =
'')
1126 global $hookmanager;
1134 if ($filteronprojuser > 0 || $filterontaskuser > 0) {
1135 $sql .=
" DISTINCT";
1137 $sql .=
" p.rowid as projectid, p.ref, p.title as plabel, p.public, p.fk_statut as projectstatus, p.usage_bill_time,";
1138 $sql .=
" t.rowid as taskid, t.ref as taskref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut as status,";
1139 $sql .=
" t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang, t.priority,";
1140 $sql .=
" t.budget_amount, t.billable,";
1141 $sql .=
" t.note_public, t.note_private,";
1142 $sql .=
" s.rowid as thirdparty_id, s.nom as thirdparty_name, s.email as thirdparty_email,";
1143 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount as project_budget_amount";
1145 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1146 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1147 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key.
" as options_".$key :
'');
1150 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
1151 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
1152 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key.
" as options_".$key :
'');
1156 if ($includebilltime) {
1157 $sql .=
", SUM(tt.element_duration * ".$this->db->ifsql(
"invoice_id IS NULL",
"1",
"0").
") as tobill, SUM(tt.element_duration * ".$this->db->ifsql(
"invoice_id IS NULL",
"0",
"1").
") as billed";
1160 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
1161 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1163 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_extrafields as efp ON (p.rowid = efp.fk_object)";
1167 if ($filteronprojuser > 0) {
1168 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1169 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1171 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
1173 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
1175 if ($includebilltime) {
1176 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype='task')";
1178 if ($filterontaskuser > 0) {
1179 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
1180 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
1182 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
1183 $sql .=
" AND t.fk_projet = p.rowid";
1184 } elseif ($mode == 1) {
1185 if ($filteronprojuser > 0) {
1186 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1187 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1189 if ($filterontaskuser > 0) {
1190 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
1191 if ($includebilltime) {
1192 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype='task')";
1194 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
1195 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
1197 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t on t.fk_projet = p.rowid";
1198 if ($includebilltime) {
1199 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype = 'task')";
1202 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
1204 return 'BadValueForParameterMode';
1207 if ($filteronprojuser > 0) {
1208 $sql .=
" AND p.rowid = ec.element_id";
1209 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
1210 $sql .=
" AND ctc.element = 'project'";
1211 $sql .=
" AND ec.fk_socpeople = ".((int) $filteronprojuser);
1212 $sql .=
" AND ec.statut = 4";
1213 $sql .=
" AND ctc.source = 'internal'";
1215 if ($filterontaskuser > 0) {
1216 $sql .=
" AND t.fk_projet = p.rowid";
1217 $sql .=
" AND p.rowid = ec2.element_id";
1218 $sql .=
" AND ctc2.rowid = ec2.fk_c_type_contact";
1219 $sql .=
" AND ctc2.element = 'project_task'";
1220 $sql .=
" AND ec2.fk_socpeople = ".((int) $filterontaskuser);
1221 $sql .=
" AND ec2.statut = 4";
1222 $sql .=
" AND ctc2.source = 'internal'";
1225 $sql .=
" AND p.fk_soc = ".((int) $socid);
1228 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectid).
")";
1230 if ($filteronproj) {
1231 $sql .=
natural_search(array(
"p.ref",
"p.title"), $filteronproj);
1233 if ($filteronprojstatus && (
int) $filteronprojstatus !=
'-1') {
1234 $sql .=
" AND p.fk_statut IN (".$this->db->sanitize($filteronprojstatus).
")";
1236 if ($morewherefilter) {
1237 $sql .= $morewherefilter;
1241 $extrafieldsobjectkey =
'projet_task';
1242 $extrafieldsobjectprefix =
'efpt.';
1244 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
1247 $parameters = array();
1248 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
1249 $sql .= $hookmanager->resPrint;
1250 if ($includebilltime) {
1251 $sql .=
" GROUP BY p.rowid, p.ref, p.title, p.public, p.fk_statut, p.usage_bill_time,";
1252 $sql .=
" t.datec, t.dateo, t.datee, t.tms,";
1253 $sql .=
" t.rowid, t.ref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut,";
1254 $sql .=
" t.dateo, t.datee, t.planned_workload, t.rang, t.priority,";
1255 $sql .=
" t.budget_amount, t.billable,";
1256 $sql .=
" t.note_public, t.note_private,";
1257 $sql .=
" s.rowid, s.nom, s.email,";
1258 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount";
1260 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1261 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1262 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key :
'');
1265 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
1266 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
1267 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key :
'');
1273 if ($sortfield && $sortorder) {
1274 $sql .= $this->db->order($sortfield, $sortorder);
1276 $sql .=
" ORDER BY p.ref, t.rang, t.dateo";
1280 dol_syslog(get_class($this).
"::getTasksArray", LOG_DEBUG);
1281 $resql = $this->db->query($sql);
1283 $num = $this->db->num_rows($resql);
1289 $obj = $this->db->fetch_object($resql);
1291 if ($loadRoleMode) {
1292 if ((!$obj->public) && (is_object($userp))) {
1297 if (is_object($usert)) {
1305 $tasks[$i] =
new Task($this->db);
1306 $tasks[$i]->id = $obj->taskid;
1307 $tasks[$i]->ref = $obj->taskref;
1308 $tasks[$i]->fk_project = $obj->projectid;
1311 $tasks[$i]->projectref = $obj->ref;
1312 $tasks[$i]->projectlabel = $obj->plabel;
1313 $tasks[$i]->projectstatus = $obj->projectstatus;
1314 $tasks[$i]->fk_opp_status = $obj->fk_opp_status;
1315 $tasks[$i]->opp_amount = $obj->opp_amount;
1316 $tasks[$i]->opp_percent = $obj->opp_percent;
1317 $tasks[$i]->budget_amount = $obj->budget_amount;
1318 $tasks[$i]->project_budget_amount = $obj->project_budget_amount;
1319 $tasks[$i]->usage_bill_time = $obj->usage_bill_time;
1321 $tasks[$i]->label = $obj->label;
1322 $tasks[$i]->description = $obj->description;
1324 $tasks[$i]->fk_task_parent = $obj->fk_task_parent;
1325 $tasks[$i]->note_public = $obj->note_public;
1326 $tasks[$i]->note_private = $obj->note_private;
1327 $tasks[$i]->duration_effective = $obj->duration_effective;
1328 $tasks[$i]->planned_workload = $obj->planned_workload;
1330 if ($includebilltime) {
1332 $tasks[$i]->tobill = $obj->tobill;
1333 $tasks[$i]->billed = $obj->billed;
1336 $tasks[$i]->progress = $obj->progress;
1337 $tasks[$i]->fk_statut = $obj->status;
1338 $tasks[$i]->status = $obj->status;
1339 $tasks[$i]->public = $obj->public;
1340 $tasks[$i]->date_start = $this->db->jdate($obj->date_start);
1341 $tasks[$i]->date_end = $this->db->jdate($obj->date_end);
1342 $tasks[$i]->rang = $obj->rang;
1343 $tasks[$i]->priority = $obj->priority;
1345 $tasks[$i]->socid = $obj->thirdparty_id;
1346 $tasks[$i]->thirdparty_id = $obj->thirdparty_id;
1347 $tasks[$i]->thirdparty_name = $obj->thirdparty_name;
1348 $tasks[$i]->thirdparty_email = $obj->thirdparty_email;
1350 $tasks[$i]->billable = $obj->billable;
1353 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1354 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1355 if ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate') {
1356 $tmpvar =
'options_'.$key;
1357 $tasks[$i]->array_options_project[
'options_'.$key] = $obj->$tmpvar;
1364 $tasks[$i]->fetch_optionals();
1370 $this->db->free($resql);
1390 $arrayroles = array();
1392 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks userp=".json_encode(is_object($userp)).
" usert=".json_encode(is_object($usert)).
" projectid=".$projectid.
" taskid=".$taskid);
1395 if (empty($userp) && empty($usert)) {
1396 $this->error =
"CallWithWrongParameters";
1399 if (!empty($userp) && !empty($usert)) {
1400 $this->error =
"CallWithWrongParameters";
1407 $sql .=
" p.rowid as pid,";
1409 $sql .=
" pt.rowid as pid,";
1411 $sql .=
" ec.element_id, ctc.code, ctc.source";
1413 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
1415 if ($usert && $filteronprojstatus > -1) {
1416 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"projet_task as pt";
1418 if ($usert && $filteronprojstatus <= -1) {
1419 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as pt";
1421 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1422 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1424 $sql .=
" WHERE p.rowid = ec.element_id";
1426 $sql .=
" WHERE pt.rowid = ec.element_id";
1428 if ($userp && $filteronprojstatus > -1) {
1429 $sql .=
" AND p.fk_statut = ".((int) $filteronprojstatus);
1431 if ($usert && $filteronprojstatus > -1) {
1432 $sql .=
" AND pt.fk_projet = p.rowid AND p.fk_statut = ".((int) $filteronprojstatus);
1435 $sql .=
" AND ctc.element = 'project'";
1438 $sql .=
" AND ctc.element = 'project_task'";
1440 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
1442 $sql .=
" AND ec.fk_socpeople = ".((int) $userp->id);
1445 $sql .=
" AND ec.fk_socpeople = ".((int) $usert->id);
1447 $sql .=
" AND ec.statut = 4";
1448 $sql .=
" AND ctc.source = 'internal'";
1451 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectid).
")";
1454 $sql .=
" AND pt.fk_projet IN (".$this->db->sanitize($projectid).
")";
1459 $sql .=
" ERROR SHOULD NOT HAPPENS";
1462 $sql .=
" AND pt.rowid = ".((int) $taskid);
1467 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks execute request", LOG_DEBUG);
1468 $resql = $this->db->query($sql);
1470 $num = $this->db->num_rows($resql);
1473 $obj = $this->db->fetch_object($resql);
1474 if (empty($arrayroles[$obj->pid])) {
1475 $arrayroles[$obj->pid] = $obj->code;
1477 $arrayroles[$obj->pid] .=
','.$obj->code;
1481 $this->db->free($resql);
1498 $contactAlreadySelected = array();
1504 if ($source ==
'thirdparty') {
1505 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
1507 $contactAlreadySelected[$i] = $tab[$i][
'id'];
1511 return $contactAlreadySelected;
1524 $origintask =
new Task($this->db);
1525 $result = $origintask->fetch($origin_id);
1531 $arraycontactorigin = array_merge($origintask->liste_contact(-1,
'internal'), $origintask->liste_contact(-1,
'external'));
1532 if (is_array($arraycontactorigin)) {
1533 foreach ($arraycontactorigin as $key => $contact) {
1534 $result = $this->
add_contact($contact[
"id"], $contact[
"fk_c_type_contact"], $contact[
"source"]);
1556 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"element_time as et";
1557 $sql .=
" SET et.fk_element = ".((int) $dest_id);
1558 $sql .=
" WHERE et.elementtype = 'task'";
1559 $sql .=
" AND et.fk_element = ".((int) $origin_id);
1561 dol_syslog(get_class($this).
"::mergeTimeSpentTask", LOG_DEBUG);
1562 if (!$this->db->query($sql)) {
1563 $this->error = $this->db->lasterror();
1568 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1569 $sql .=
" SET duration_effective = (SELECT SUM(element_duration) FROM ".MAIN_DB_PREFIX.
"element_time as ptt where ptt.elementtype = 'task' AND ptt.fk_element = ".((int) $dest_id).
")";
1570 $sql .=
" WHERE rowid = ".((int) $dest_id);
1572 dol_syslog(get_class($this).
"::mergeTimeSpentTask update project_task", LOG_DEBUG);
1573 if (!$this->db->query($sql)) {
1574 $this->error = $this->db->lasterror();
1580 $this->db->commit();
1582 $this->db->rollback();
1598 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1604 if (!is_object($user)) {
1605 dol_print_error(
null,
"Method addTimeSpent was called with wrong parameter user");
1610 if (isset($this->timespent_note)) {
1611 $this->timespent_note = trim($this->timespent_note);
1613 if (empty($this->timespent_datehour) || ($this->timespent_date != $this->timespent_datehour)) {
1614 $this->timespent_datehour = $this->timespent_date;
1618 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1621 if ($this->timespent_date < $restrictBefore) {
1622 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack',
getDolGlobalString(
'PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS'));
1623 $this->errors[] = $this->error;
1631 $timespent->fk_element = $this->id;
1632 $timespent->elementtype =
'task';
1633 $timespent->element_date = $this->timespent_date;
1634 $timespent->element_datehour = $this->timespent_datehour;
1635 $timespent->element_date_withhour = $this->timespent_withhour;
1636 $timespent->element_duration = $this->timespent_duration;
1637 $timespent->fk_user = $this->timespent_fk_user;
1638 $timespent->fk_product = $this->timespent_fk_product;
1639 $timespent->note = $this->timespent_note;
1640 $timespent->datec = $now;
1642 $result = $timespent->create($user);
1645 $this->timespent_id = $result;
1649 $result = $this->
call_trigger(
'TASK_TIMESPENT_CREATE', $user);
1656 $this->error = $this->db->lasterror();
1662 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1663 $sql .=
" SET duration_effective = (SELECT SUM(element_duration) FROM ".MAIN_DB_PREFIX.
"element_time as ptt where ptt.elementtype = 'task' AND ptt.fk_element = ".((int) $this->
id).
")";
1664 if (isset($this->progress)) {
1665 $sql .=
", progress = ".((float) $this->progress);
1667 $sql .=
" WHERE rowid = ".((int) $this->
id);
1669 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1670 if (!$this->db->query($sql)) {
1671 $this->error = $this->db->lasterror();
1676 $resql_thm_user = $this->db->query(
"SELECT thm FROM " . MAIN_DB_PREFIX .
"user WHERE rowid = " . ((
int) $timespent->fk_user));
1677 if (!empty($resql_thm_user)) {
1678 $obj_thm_user = $this->db->fetch_object($resql_thm_user);
1679 $timespent->thm = $obj_thm_user->thm;
1681 $res_update = $timespent->update($user);
1683 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1684 if ($res_update <= 0) {
1685 $this->error = $this->db->lasterror();
1691 $this->db->commit();
1693 $this->db->rollback();
1706 $arrayres = array();
1709 $sql .=
" s.rowid as socid,";
1710 $sql .=
" s.nom as thirdparty_name,";
1711 $sql .=
" s.email as thirdparty_email,";
1712 $sql .=
" ptt.rowid,";
1713 $sql .=
" ptt.ref_ext,";
1714 $sql .=
" ptt.fk_element as fk_task,";
1715 $sql .=
" ptt.element_date as task_date,";
1716 $sql .=
" ptt.element_datehour as task_datehour,";
1717 $sql .=
" ptt.element_date_withhour as task_date_withhour,";
1718 $sql .=
" ptt.element_duration as task_duration,";
1719 $sql .=
" ptt.fk_user,";
1720 $sql .=
" ptt.note,";
1721 $sql .=
" ptt.thm,";
1722 $sql .=
" pt.rowid as task_id,";
1723 $sql .=
" pt.ref as task_ref,";
1724 $sql .=
" pt.label as task_label,";
1725 $sql .=
" p.rowid as project_id,";
1726 $sql .=
" p.ref as project_ref,";
1727 $sql .=
" p.title as project_label,";
1728 $sql .=
" p.public as public";
1729 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1730 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1731 $sql .=
" WHERE ptt.fk_element = pt.rowid AND pt.fk_projet = p.rowid";
1732 $sql .=
" AND ptt.elementtype = 'task'";
1733 $sql .=
" AND pt.rowid = ".((int) $this->
id);
1734 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1735 if ($morewherefilter) {
1736 $sql .= $morewherefilter;
1739 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1740 $resql = $this->db->query($sql);
1742 $num = $this->db->num_rows($resql);
1746 $obj = $this->db->fetch_object($resql);
1750 $newobj->socid = $obj->socid;
1751 $newobj->thirdparty_name = $obj->thirdparty_name;
1752 $newobj->thirdparty_email = $obj->thirdparty_email;
1754 $newobj->fk_project = $obj->project_id;
1755 $newobj->project_ref = $obj->project_ref;
1756 $newobj->project_label = $obj->project_label;
1757 $newobj->public = $obj->project_public;
1759 $newobj->fk_task = $obj->task_id;
1760 $newobj->task_ref = $obj->task_ref;
1761 $newobj->task_label = $obj->task_label;
1763 $newobj->timespent_line_id = $obj->rowid;
1764 $newobj->timespent_line_ref_ext = $obj->ref_ext;
1765 $newobj->timespent_line_date = $this->db->jdate($obj->task_date);
1766 $newobj->timespent_line_datehour = $this->db->jdate($obj->task_datehour);
1767 $newobj->timespent_line_withhour = $obj->task_date_withhour;
1768 $newobj->timespent_line_duration = $obj->task_duration;
1769 $newobj->timespent_line_fk_user = $obj->fk_user;
1770 $newobj->timespent_line_thm = $obj->thm;
1771 $newobj->timespent_line_note = $obj->note;
1773 $arrayres[] = $newobj;
1778 $this->db->free($resql);
1780 $this->lines = $arrayres;
1784 $this->error =
"Error ".$this->db->lasterror();
1799 if (is_object($userobj)) {
1800 $userid = $userobj->id;
1806 if (empty($id) && empty($userid)) {
1807 dol_syslog(
"getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR);
1814 $sql .=
" MIN(t.element_datehour) as min_date,";
1815 $sql .=
" MAX(t.element_datehour) as max_date,";
1816 $sql .=
" SUM(t.element_duration) as total_duration,";
1817 $sql .=
" SUM(t.element_duration / 3600 * ".$this->db->ifsql(
"t.thm IS NULL", 0,
"t.thm").
") as total_amount,";
1818 $sql .=
" COUNT(t.rowid) as nblines,";
1819 $sql .=
" SUM(".$this->db->ifsql(
"t.thm IS NULL", 1, 0).
") as nblinesnull";
1820 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as t";
1821 $sql .=
" WHERE t.elementtype='task'";
1822 if ($morewherefilter) {
1823 $sql .= $morewherefilter;
1826 $sql .=
" AND t.fk_element = ".((int) $id);
1829 $sql .=
" AND t.fk_user = ".((int) $userid);
1832 dol_syslog(get_class($this).
"::getSummaryOfTimeSpent", LOG_DEBUG);
1833 $resql = $this->db->query($sql);
1835 $obj = $this->db->fetch_object($resql);
1837 $result[
'min_date'] = $obj->min_date;
1838 $result[
'max_date'] = $obj->max_date;
1839 $result[
'total_duration'] = $obj->total_duration;
1841 $this->timespent_min_date = $this->db->jdate($obj->min_date);
1842 $this->timespent_max_date = $this->db->jdate($obj->max_date);
1843 $this->timespent_total_duration = $obj->total_duration;
1844 $this->timespent_total_amount = $obj->total_amount;
1845 $this->timespent_nblinesnull = ($obj->nblinesnull ? $obj->nblinesnull : 0);
1846 $this->timespent_nblines = ($obj->nblines ? $obj->nblines : 0);
1848 $this->db->free($resql);
1870 $sql .=
" SUM(t.element_duration) as nbseconds,";
1871 $sql .=
" SUM(t.element_duration / 3600 * ".$this->db->ifsql(
"t.thm IS NULL", 0,
"t.thm").
") as amount, SUM(".$this->db->ifsql(
"t.thm IS NULL", 1, 0).
") as nblinesnull";
1872 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as t";
1873 $sql .=
" WHERE t.elementtype='task' AND t.fk_element = ".((int) $id);
1874 if (is_object($fuser) && $fuser->id > 0) {
1875 $sql .=
" AND fk_user = ".((int) $fuser->id);
1878 $datefieldname =
"element_datehour";
1879 $sql .=
" AND (".$datefieldname.
" >= '".$this->db->idate($dates).
"' OR ".$datefieldname.
" IS NULL)";
1882 $datefieldname =
"element_datehour";
1883 $sql .=
" AND (".$datefieldname.
" <= '".$this->db->idate($datee).
"' OR ".$datefieldname.
" IS NULL)";
1887 dol_syslog(get_class($this).
"::getSumOfAmount", LOG_DEBUG);
1888 $resql = $this->db->query($sql);
1890 $obj = $this->db->fetch_object($resql);
1892 $result[
'amount'] = $obj->amount;
1893 $result[
'nbseconds'] = $obj->nbseconds;
1894 $result[
'nblinesnull'] = $obj->nblinesnull;
1896 $this->db->free($resql);
1913 $timespent->fetch($id);
1915 dol_syslog(get_class($this).
"::fetchTimeSpent", LOG_DEBUG);
1917 if ($timespent->id > 0) {
1918 $this->timespent_id = $timespent->id;
1919 $this->
id = $timespent->fk_element;
1920 $this->timespent_date = $timespent->element_date;
1921 $this->timespent_datehour = $timespent->element_datehour;
1922 $this->timespent_withhour = $timespent->element_date_withhour;
1923 $this->timespent_duration = $timespent->element_duration;
1924 $this->timespent_fk_user = $timespent->fk_user;
1925 $this->timespent_fk_product = $timespent->fk_product;
1926 $this->timespent_thm = $timespent->thm;
1927 $this->timespent_note = $timespent->note;
1944 $arrayres = array();
1947 $sql .=
" s.rowid as socid,";
1948 $sql .=
" s.nom as thirdparty_name,";
1949 $sql .=
" s.email as thirdparty_email,";
1950 $sql .=
" ptt.rowid,";
1951 $sql .=
" ptt.fk_element as fk_task,";
1952 $sql .=
" ptt.element_date as task_date,";
1953 $sql .=
" ptt.element_datehour as task_datehour,";
1954 $sql .=
" ptt.element_date_withhour as task_date_withhour,";
1955 $sql .=
" ptt.element_duration as task_duration,";
1956 $sql .=
" ptt.fk_user,";
1957 $sql .=
" ptt.note,";
1958 $sql .=
" ptt.thm,";
1959 $sql .=
" pt.rowid as task_id,";
1960 $sql .=
" pt.ref as task_ref,";
1961 $sql .=
" pt.label as task_label,";
1962 $sql .=
" p.rowid as project_id,";
1963 $sql .=
" p.ref as project_ref,";
1964 $sql .=
" p.title as project_label,";
1965 $sql .=
" p.public as public";
1966 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1967 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1968 $sql .=
" WHERE ptt.fk_element = pt.rowid AND pt.fk_projet = p.rowid";
1969 $sql .=
" AND ptt.elementtype = 'task'";
1970 $sql .=
" AND ptt.fk_user = ".((int) $userobj->id);
1971 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1972 if ($morewherefilter) {
1973 $sql .= $morewherefilter;
1976 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1977 $resql = $this->db->query($sql);
1979 $num = $this->db->num_rows($resql);
1983 $obj = $this->db->fetch_object($resql);
1987 $newobj->socid = $obj->socid;
1988 $newobj->thirdparty_name = $obj->thirdparty_name;
1989 $newobj->thirdparty_email = $obj->thirdparty_email;
1991 $newobj->fk_project = $obj->project_id;
1992 $newobj->project_ref = $obj->project_ref;
1993 $newobj->project_label = $obj->project_label;
1994 $newobj->public = $obj->project_public;
1996 $newobj->fk_task = $obj->task_id;
1997 $newobj->task_ref = $obj->task_ref;
1998 $newobj->task_label = $obj->task_label;
2000 $newobj->timespent_id = $obj->rowid;
2001 $newobj->timespent_date = $this->db->jdate($obj->task_date);
2002 $newobj->timespent_datehour = $this->db->jdate($obj->task_datehour);
2003 $newobj->timespent_withhour = $obj->task_date_withhour;
2004 $newobj->timespent_duration = $obj->task_duration;
2005 $newobj->timespent_fk_user = $obj->fk_user;
2006 $newobj->timespent_thm = $obj->thm;
2007 $newobj->timespent_note = $obj->note;
2009 $arrayres[] = $newobj;
2014 $this->db->free($resql);
2017 $this->error =
"Error ".$this->db->lasterror();
2033 global
$conf, $langs;
2038 if ($this->timespent_date ==
'') {
2039 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date"));
2044 if (empty($this->timespent_datehour)) {
2045 $this->timespent_datehour = $this->timespent_date;
2047 if (isset($this->timespent_note)) {
2048 $this->timespent_note = trim($this->timespent_note);
2052 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2055 if ($this->timespent_date < $restrictBefore) {
2056 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack',
getDolGlobalString(
'PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS'));
2057 $this->errors[] = $this->error;
2065 $timespent->fetch($this->timespent_id);
2067 $timespent->element_date = $this->timespent_date;
2068 $timespent->element_datehour = $this->timespent_datehour;
2069 $timespent->element_date_withhour = $this->timespent_withhour;
2070 $timespent->element_duration = $this->timespent_duration;
2071 if ($this->timespent_fk_user > 0) {
2072 $timespent->fk_user = $this->timespent_fk_user;
2074 $timespent->fk_product = $this->timespent_fk_product;
2075 $timespent->note = $this->timespent_note;
2076 $timespent->invoice_id = $this->timespent_invoiceid;
2077 $timespent->invoice_line_id = $this->timespent_invoicelineid;
2079 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
2080 if ($timespent->update($user) > 0) {
2083 $result = $this->
call_trigger(
'TASK_TIMESPENT_MODIFY', $user);
2085 $this->db->rollback();
2095 $this->error = $this->db->lasterror();
2096 $this->db->rollback();
2100 if ($ret == 1 && (($this->timespent_old_duration != $this->timespent_duration) ||
getDolGlobalString(
'TIMESPENT_ALWAYS_UPDATE_THM'))) {
2101 if ($this->timespent_old_duration != $this->timespent_duration) {
2103 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"projet_task";
2104 $sql .=
" SET duration_effective = (SELECT SUM(element_duration) FROM " . MAIN_DB_PREFIX .
"element_time as ptt where ptt.elementtype = 'task' AND ptt.fk_element = " . ((int) $this->
id) .
")";
2105 if (isset($this->progress)) {
2106 $sql .=
", progress = " . ((float) $this->progress);
2108 $sql .=
" WHERE rowid = " . ((int) $this->
id);
2110 dol_syslog(get_class($this) .
"::updateTimeSpent", LOG_DEBUG);
2111 if (!$this->db->query($sql)) {
2112 $this->error = $this->db->lasterror();
2113 $this->db->rollback();
2121 $resql_thm_user = $this->db->query(
"SELECT thm FROM " . MAIN_DB_PREFIX .
"user WHERE rowid = " . ((
int) $timespent->fk_user));
2122 if (!empty($resql_thm_user)) {
2123 $obj_thm_user = $this->db->fetch_object($resql_thm_user);
2124 $timespent->thm = $obj_thm_user->thm;
2126 $res_update = $timespent->update($user);
2129 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
2130 if ($res_update <= 0) {
2131 $this->error = $this->db->lasterror();
2137 $this->db->commit();
2151 global
$conf, $langs;
2156 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2159 if ($this->timespent_date < $restrictBefore) {
2160 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack',
getDolGlobalString(
'PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS'));
2161 $this->errors[] = $this->error;
2170 $result = $this->
call_trigger(
'TASK_TIMESPENT_DELETE', $user);
2179 $timespent->fetch($this->timespent_id);
2181 $res_del = $timespent->delete($user);
2185 $this->errors[] =
"Error ".$this->db->lasterror();
2190 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
2191 $sql .=
" SET duration_effective = duration_effective - ".$this->db->escape($this->timespent_duration ? $this->timespent_duration : 0);
2192 $sql .=
" WHERE rowid = ".((int) $this->
id);
2194 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
2195 if ($this->db->query($sql)) {
2198 $this->error = $this->db->lasterror();
2205 foreach ($this->errors as $errmsg) {
2206 dol_syslog(get_class($this).
"::delTimeSpent ".$errmsg, LOG_ERR);
2207 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2209 $this->db->rollback();
2212 $this->db->commit();
2231 public function createFromClone(
User $user, $fromid, $project_id, $parent_task_id, $clone_change_dt =
false, $clone_affectation =
false, $clone_time =
false, $clone_file =
false, $clone_note =
false, $clone_prog =
false)
2233 global $langs,
$conf;
2242 $clone_task =
new Task($this->db);
2243 $origin_task =
new Task($this->db);
2245 $clone_task->context[
'createfromclone'] =
'createfromclone';
2250 $clone_task->fetch($fromid);
2251 $clone_task->fetch_optionals();
2254 $origin_task->fetch($fromid);
2259 require_once DOL_DOCUMENT_ROOT.
"/core/modules/project/task/" .
getDolGlobalString(
'PROJECT_TASK_ADDON').
'.php';
2260 $modTask =
new $obj();
2261 '@phan-var-force ModeleNumRefTask $modTask';
2262 $defaultref = $modTask->getNextValue(0, $clone_task);
2265 $ori_project_id = $clone_task->fk_project;
2267 $clone_task->id = 0;
2268 $clone_task->ref = $defaultref;
2269 $clone_task->fk_project = $project_id;
2270 $clone_task->fk_task_parent = $parent_task_id;
2271 $clone_task->date_c = $datec;
2272 $clone_task->planned_workload = $origin_task->planned_workload;
2273 $clone_task->rang = $origin_task->rang;
2274 $clone_task->priority = $origin_task->priority;
2277 if ($clone_change_dt) {
2278 $projectstatic =
new Project($this->db);
2279 $projectstatic->fetch($ori_project_id);
2282 $orign_project_dt_start = (!isset($projectstatic->date_start) || $projectstatic->date_start ==
'') ? $projectstatic->date_c : $projectstatic->date_start;
2285 if (!empty($clone_task->date_start)) {
2286 $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
2290 if (!empty($clone_task->date_end)) {
2291 $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
2296 $clone_task->progress = 0;
2300 $result = $clone_task->create($user);
2304 $this->error = $clone_task->error;
2311 $clone_task_id = $clone_task->id;
2312 $clone_task_ref = $clone_task->ref;
2316 $clone_task->note_private =
'';
2317 $clone_task->note_public =
'';
2320 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_public, ENT_QUOTES | ENT_HTML5),
'_public');
2322 $this->error .= $clone_task->error;
2324 $this->db->rollback();
2326 $this->db->commit();
2330 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_private, ENT_QUOTES | ENT_HTML5),
'_private');
2332 $this->error .= $clone_task->error;
2334 $this->db->rollback();
2336 $this->db->commit();
2342 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2345 $projectstatic =
new Project($this->db);
2346 $projectstatic->fetch($ori_project_id);
2347 $ori_project_ref = $projectstatic->ref;
2349 if ($ori_project_id != $project_id) {
2350 $projectstatic->fetch($project_id);
2351 $clone_project_ref = $projectstatic->ref;
2353 $clone_project_ref = $ori_project_ref;
2359 $filearray =
dol_dir_list($ori_task_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'', SORT_ASC, 1);
2360 foreach ($filearray as $file) {
2361 if (!file_exists($clone_task_dir)) {
2363 $this->error .= $langs->trans(
'ErrorInternalErrorDetected').
':dol_mkdir';
2368 $rescopy =
dol_copy($ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name'],
'0', 1);
2369 if (is_numeric($rescopy) && $rescopy < 0) {
2370 $this->error .= $langs->trans(
"ErrorFailToCopyFile", $ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name']);
2377 if ($clone_affectation) {
2378 $origin_task =
new Task($this->db);
2379 $origin_task->fetch($fromid);
2381 foreach (array(
'internal',
'external') as $source) {
2382 $tab = $origin_task->liste_contact(-1, $source);
2386 $clone_task->add_contact($tab[$i][
'id'], $tab[$i][
'code'], $tab[$i][
'source']);
2387 if ($clone_task->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2388 $langs->load(
"errors");
2389 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
2392 if ($clone_task->error !=
'') {
2393 $this->error .= $clone_task->error;
2407 unset($clone_task->context[
'createfromclone']);
2410 $this->db->commit();
2411 return $clone_task_id;
2413 $this->db->rollback();
2414 dol_syslog(get_class($this).
"::createFromClone nbError: ".$error.
" error : ".$this->error, LOG_ERR);
2445 $this->labelStatus[0] =
'Draft';
2446 $this->labelStatus[1] =
'ToDo';
2447 $this->labelStatus[2] =
'Running';
2448 $this->labelStatus[3] =
'Finish';
2449 $this->labelStatus[4] =
'Transfered';
2450 $this->labelStatusShort[0] =
'Draft';
2451 $this->labelStatusShort[1] =
'ToDo';
2452 $this->labelStatusShort[2] =
'Running';
2453 $this->labelStatusShort[3] =
'Completed';
2454 $this->labelStatusShort[4] =
'Transfered';
2457 return $langs->trans($this->labelStatus[$status]);
2458 } elseif ($mode == 1) {
2459 return $langs->trans($this->labelStatusShort[$status]);
2460 } elseif ($mode == 2) {
2462 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut0').
' '.$langs->trans($this->labelStatusShort[$status]);
2463 } elseif ($status == 1) {
2464 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut1').
' '.$langs->trans($this->labelStatusShort[$status]);
2465 } elseif ($status == 2) {
2466 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut3').
' '.$langs->trans($this->labelStatusShort[$status]);
2467 } elseif ($status == 3) {
2468 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6').
' '.$langs->trans($this->labelStatusShort[$status]);
2469 } elseif ($status == 4) {
2470 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6').
' '.$langs->trans($this->labelStatusShort[$status]);
2471 } elseif ($status == 5) {
2472 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut5').
' '.$langs->trans($this->labelStatusShort[$status]);
2474 } elseif ($mode == 3) {
2476 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut0');
2477 } elseif ($status == 1) {
2478 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut1');
2479 } elseif ($status == 2) {
2480 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut3');
2481 } elseif ($status == 3) {
2482 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6');
2483 } elseif ($status == 4) {
2484 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6');
2485 } elseif ($status == 5) {
2486 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut5');
2488 } elseif ($mode == 4) {
2490 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut0').
' '.$langs->trans($this->labelStatus[$status]);
2491 } elseif ($status == 1) {
2492 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut1').
' '.$langs->trans($this->labelStatus[$status]);
2493 } elseif ($status == 2) {
2494 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut3').
' '.$langs->trans($this->labelStatus[$status]);
2495 } elseif ($status == 3) {
2496 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6').
' '.$langs->trans($this->labelStatus[$status]);
2497 } elseif ($status == 4) {
2498 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6').
' '.$langs->trans($this->labelStatus[$status]);
2499 } elseif ($status == 5) {
2500 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut5').
' '.$langs->trans($this->labelStatus[$status]);
2502 } elseif ($mode == 5) {
2512 } elseif ($mode == 6) {
2536 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2538 $outputlangs->load(
"projects");
2541 $modele =
'nodefault';
2543 if (!empty($this->model_pdf)) {
2544 $modele = $this->model_pdf;
2550 $modelpath =
"core/modules/project/task/doc/";
2552 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2566 global
$conf, $langs;
2572 $projectstatic =
new Project($this->db);
2573 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
2576 $sql =
"SELECT p.rowid as projectid, p.fk_statut as projectstatus,";
2577 $sql .=
" t.rowid as taskid, t.progress as progress, t.fk_statut as status,";
2578 $sql .=
" t.dateo as date_start, t.datee as date_end";
2579 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2582 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2583 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2584 $sql .=
" AND p.fk_statut = 1";
2585 $sql .=
" AND t.fk_projet = p.rowid";
2586 $sql .=
" AND (t.progress IS NULL OR t.progress < 100)";
2587 if (!$user->hasRight(
'projet',
'all',
'lire')) {
2588 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2596 $resql = $this->db->query($sql);
2598 $task_static =
new Task($this->db);
2601 $response->warning_delay =
$conf->project->task->warning_delay / 60 / 60 / 24;
2602 $response->label = $langs->trans(
"OpenedTasks");
2603 if ($user->hasRight(
"projet",
"all",
"lire")) {
2604 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mainmenu=project';
2606 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mode=mine&mainmenu=project';
2611 while ($obj = $this->db->fetch_object($resql)) {
2612 $response->nbtodo++;
2614 $task_static->projectstatus = $obj->projectstatus;
2615 $task_static->progress = $obj->progress;
2616 $task_static->fk_statut = $obj->status;
2617 $task_static->status = $obj->status;
2618 $task_static->date_start = $this->db->jdate($obj->date_start);
2619 $task_static->date_end = $this->db->jdate($obj->date_end);
2621 if ($task_static->hasDelay()) {
2622 $response->nbtodolate++;
2628 $this->error = $this->db->error();
2644 $socid = $user->socid;
2646 $projectstatic =
new Project($this->db);
2647 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $mine, 1, $socid);
2650 $sql =
"SELECT count(p.rowid) as nb";
2651 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2652 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
2653 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2654 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2656 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2657 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2658 $sql .=
" AND t.fk_projet = p.rowid";
2659 if ($mine || !$user->hasRight(
'projet',
'all',
'lire')) {
2660 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2665 $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).
")";
2667 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2668 $sql .=
" AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).
") OR (s.rowid IS NULL))";
2671 $resql = $this->db->query($sql);
2674 while ($obj = $this->db->fetch_object($resql)) {
2675 $this->nb[
"tasks"] = $obj->nb;
2677 $this->db->free($resql);
2681 $this->error = $this->db->error();
2695 if (!($this->progress >= 0 && $this->progress < 100)) {
2701 $datetouse = ($this->date_end > 0) ? $this->date_end : ((isset($this->datee) && $this->datee > 0) ? $this->datee : 0);
2703 return ($datetouse > 0 && ($datetouse < ($now -
$conf->project->task->warning_delay)));
2715 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2717 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2718 $return .=
'<div class="info-box info-box-sm info-box-kanban">';
2719 $return .=
'<span class="info-box-icon bg-infobox-action">';
2722 $return .=
'</span>';
2723 $return .=
'<div class="info-box-content">';
2724 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
2725 if ($selected >= 0) {
2726 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2728 if (!empty($arraydata[
'projectlink'])) {
2731 $return .=
'<br><span class="info-box-status ">'.$arraydata[
'projectlink'].
'</span>';
2736 if (property_exists($this,
'duration_effective')) {
2737 $return .=
'<br><div class="info-box-label progressinkanban paddingtop">'.getTaskProgressView($this,
false,
true).
'</div>';
2739 $return .=
'</div>';
2740 $return .=
'</div>';
2741 $return .=
'</div>';
2755 global $langs, $hookmanager, $user, $action;
2758 $task_origin =
new Task($this->db);
2760 dol_syslog(
"mergeTask merge task id=".$task_origin_id.
" (will be deleted) into the task id=".$this->id);
2762 $langs->load(
'error');
2764 if (!$error && $task_origin->fetch($task_origin_id) < 1) {
2765 $this->error = $langs->trans(
'ErrorRecordNotFound');
2773 $listofproperties = array(
2774 'label',
'description',
'duration_effective',
'planned_workload',
'datec',
'date_start',
2775 'date_end',
'fk_user_creat',
'fk_user_valid',
'fk_statut',
'progress',
'budget_amount',
2776 'priority',
'rang',
'fk_projet',
'fk_task_parent'
2778 foreach ($listofproperties as $property) {
2779 if (empty($this->$property)) {
2780 $this->$property = $task_origin->$property;
2785 $listofproperties = array(
2786 'note_public',
'note_private'
2788 foreach ($listofproperties as $property) {
2789 $this->$property =
dol_concatdesc($this->$property, $task_origin->$property);
2793 if (is_array($task_origin->array_options)) {
2794 foreach ($task_origin->array_options as $key => $val) {
2795 if (empty($this->array_options[$key])) {
2796 $this->array_options[$key] = $val;
2802 $result = $this->
update($user);
2811 if ($result !=
true) {
2819 if ($result !=
true) {
2826 $parameters = array(
'task_origin' => $task_origin->id,
'task_dest' => $this->id);
2827 $reshook = $hookmanager->executeHooks(
'replaceThirdparty', $parameters, $this, $action);
2830 $this->error = $hookmanager->error;
2831 $this->errors = $hookmanager->errors;
2838 $this->context = array(
'merge' => 1,
'mergefromid' => $task_origin->id,
'mergefromref' => $task_origin->ref);
2850 if ($task_origin->delete($user) < 1) {
2851 $this->error = $task_origin->error;
2852 $this->errors = $task_origin->errors;
2858 $this->db->commit();
2861 $langs->load(
"errors");
2862 $this->error = $langs->trans(
'ErrorsTaskMerge');
2863 $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...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
liste_contact($statusoflink=-1, $source='external', $list=0, $code='', $status=-1, $arrayoftcids=array())
Get array of all contacts for an object.
isObjectUsed($id=0, $entity=0)
Function to check if an object is used by others (by children).
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
call_trigger($triggerName, $user)
Call trigger based on this instance.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage projects.
const STATUS_VALIDATED
Open/Validated status.
create($user, $notrigger=0)
Create into database.
fetch($id, $ref='', $loadparentdata=0)
Load object in memory from database.
getLibStatut($mode=0)
Return status label of object.
mergeContactTask($origin_id, $dest_id)
Merge contact of tasks.
const STATUS_TRANSFERRED
Transferred status.
getSumOfAmount($fuser='', $dates='', $datee='')
Calculate quantity and value of time consumed using the thm (hourly amount value of work for user ent...
mergeTask($task_origin_id)
Merge a task with another one, deleting the given task.
__construct($db)
Constructor.
fetchTimeSpentOnTask($morewherefilter='')
Fetch records of time spent of this task.
const STATUS_VALIDATED
Validated status (To do).
hasTimeSpent()
Return nb of time spent.
getNomUrl($withpicto=0, $option='', $mode='task', $addlabel=0, $sep=' - ', $notooltip=0, $save_lastsearch_value=-1)
Return clickable name (with picto eventually)
getListContactId($source='internal')
Return list of id of contacts of task.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
delTimeSpent($user, $notrigger=0)
Delete time spent.
mergeTimeSpentTask($origin_id, $dest_id)
Merge time spent of tasks.
const STATUS_DRAFT
Draft status.
fetchAllTimeSpent(User $userobj, $morewherefilter='')
Load all records of time spent.
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
getUserRolesForProjectsOrTasks($userp, $usert, $projectid='', $taskid=0, $filteronprojstatus=-1)
Return list of roles for a user for each projects or each tasks (or a particular project or a particu...
update($user=null, $notrigger=0)
Update database.
getSummaryOfTimeSpent($userobj=null, $morewherefilter='')
Calculate total of time spent for task.
getTooltipContentArray($params)
getTooltipContentArray
const STATUS_CANCELED
status canceled
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create an intervention document on disk using template defined into PROJECT_TASK_ADDON_PDF.
fetchTimeSpent($id)
Load properties of timespent of a task from the time spent ID.
updateTimeSpent($user, $notrigger=0)
Update time spent line with id $this->timespent_id.
createFromClone(User $user, $fromid, $project_id, $parent_task_id, $clone_change_dt=false, $clone_affectation=false, $clone_time=false, $clone_file=false, $clone_note=false, $clone_prog=false)
Load an object from its id and create a new one in database.
loadStateBoard()
Load indicators this->nb for state board.
initAsSpecimen()
Initialise an instance with random values.
getTasksArray($usert=null, $userp=null, $projectid=0, $socid=0, $mode=0, $filteronproj='', $filteronprojstatus='-1', $morewherefilter='', $filteronprojuser=0, $filterontaskuser=0, $extrafields=null, $includebilltime=0, $search_array_options=array(), $loadextras=0, $loadRoleMode=1, $sortfield='', $sortorder='')
Return list of tasks for all projects or for one particular project Sort order is on project,...
addTimeSpent($user, $notrigger=0)
Add time spent.
hasDelay()
Is the task delayed?
LibStatut($status, $mode=0)
Return status label for an object.
const STATUS_CLOSED
Finished status.
hasChildren()
Return nb of children.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_move_dir($srcdir, $destdir, $overwriteifexists=1, $indexdatabase=1, $renamedircontent=1)
Move a directory into another name.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...