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;
392 $this->labelStatus = array(
399 $this->labelStatusShort = array(
416 public function create($user, $notrigger = 0)
418 global $conf, $langs;
426 $this->label = trim($this->label);
428 $this->note_public = trim($this->note_public);
429 $this->note_private = trim($this->note_private);
431 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
432 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
437 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet_task (";
439 $sql .=
", fk_projet";
441 $sql .=
", fk_task_parent";
443 $sql .=
", description";
444 $sql .=
", note_public";
445 $sql .=
", note_private";
447 $sql .=
", fk_user_creat";
450 $sql .=
", planned_workload";
451 $sql .=
", progress";
452 $sql .=
", budget_amount";
453 $sql .=
", priority";
454 $sql .=
", billable";
455 $sql .=
", fk_statut";
457 $sql .=
") VALUES (";
458 $sql .= (!empty($this->entity) ? (int) $this->entity : (int) $conf->entity);
459 $sql .=
", ".((int) $this->fk_project);
460 $sql .=
", ".(!empty($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
'null');
461 $sql .=
", ".((int) $this->fk_task_parent);
462 $sql .=
", '".$this->db->escape($this->label).
"'";
463 $sql .=
", '".$this->db->escape($this->
description).
"'";
464 $sql .=
", '".$this->db->escape($this->note_public).
"'";
465 $sql .=
", '".$this->db->escape($this->note_private).
"'";
466 $sql .=
", '".$this->db->idate($now).
"'";
467 $sql .=
", ".((int) $user->id);
468 $sql .=
", ".(isDolTms($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
'null');
469 $sql .=
", ".(isDolTms($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
'null');
470 $sql .=
", ".(($this->planned_workload !=
'' && $this->planned_workload >= 0) ? ((
int) $this->planned_workload) :
'null');
471 $sql .=
", ".(($this->progress !=
'' && $this->progress >= 0) ? ((
int) $this->progress) :
'null');
472 $sql .=
", ".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? ((
int) $this->budget_amount) :
'null');
473 $sql .=
", ".(($this->priority !=
'' && $this->priority >= 0) ? (
int) $this->priority :
'null');
474 $sql .=
", ".((int) $this->billable);
475 $sql .=
", ".((int) $this->
status);
476 $sql .=
", ".((!empty($this->rang)) ? ((
int) $this->rang) :
"0");
481 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
482 $resql = $this->db->query($sql);
485 $this->errors[] =
"Error ".$this->db->lasterror();
489 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"projet_task");
500 $result = $this->call_trigger(
'TASK_CREATE', $user);
510 foreach ($this->errors as $errmsg) {
511 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
512 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
514 $this->db->rollback();
531 public function fetch($id, $ref =
'', $loadparentdata = 0)
536 $sql .=
" t.entity,";
537 $sql .=
" t.fk_projet as fk_project,";
538 $sql .=
" t.fk_task_parent,";
540 $sql .=
" t.description,";
541 $sql .=
" t.duration_effective,";
542 $sql .=
" t.planned_workload,";
544 $sql .=
" t.dateo as date_start,";
545 $sql .=
" t.datee as date_end,";
546 $sql .=
" t.fk_user_creat,";
547 $sql .=
" t.fk_user_valid,";
548 $sql .=
" t.fk_statut as status,";
549 $sql .=
" t.progress,";
550 $sql .=
" t.budget_amount,";
551 $sql .=
" t.priority,";
552 $sql .=
" t.note_private,";
553 $sql .=
" t.note_public,";
555 $sql .=
" t.billable";
556 if (!empty($loadparentdata)) {
557 $sql .=
", t2.ref as task_parent_ref";
558 $sql .=
", t2.rang as task_parent_position";
560 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as t";
561 if (!empty($loadparentdata)) {
562 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t2 ON t.fk_task_parent = t2.rowid";
566 $sql .=
"entity IN (".getEntity(
'project').
")";
567 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
569 $sql .=
"t.rowid = ".((int) $id);
572 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
573 $resql = $this->db->query($sql);
575 $num_rows = $this->db->num_rows($resql);
578 $obj = $this->db->fetch_object($resql);
580 $this->
id = $obj->rowid;
581 $this->
ref = $obj->ref;
582 $this->entity = $obj->entity;
583 $this->fk_project = $obj->fk_project;
584 $this->fk_task_parent = $obj->fk_task_parent;
585 $this->label = $obj->label;
587 $this->duration_effective = $obj->duration_effective;
588 $this->planned_workload = $obj->planned_workload;
589 $this->date_c = $this->db->jdate($obj->datec);
590 $this->date_start = $this->db->jdate($obj->date_start);
591 $this->date_end = $this->db->jdate($obj->date_end);
592 $this->fk_user_creat = $obj->fk_user_creat;
593 $this->fk_user_valid = $obj->fk_user_valid;
594 $this->
status = $obj->status;
595 $this->progress = $obj->progress;
596 $this->budget_amount = $obj->budget_amount;
597 $this->priority = $obj->priority;
598 $this->note_private = $obj->note_private;
599 $this->note_public = $obj->note_public;
600 $this->rang = $obj->rang;
602 if (!empty($loadparentdata)) {
603 $this->task_parent_ref = $obj->task_parent_ref;
604 $this->task_parent_position = $obj->task_parent_position;
606 $this->billable = $obj->billable;
612 $this->db->free($resql);
620 $this->error =
"Error ".$this->db->lasterror();
633 public function update($user =
null, $notrigger = 0)
635 global $conf, $langs;
639 if (isset($this->fk_project)) {
640 $this->fk_project = (int) $this->fk_project;
642 if (isset($this->
ref)) {
643 $this->
ref = trim($this->
ref);
645 if (isset($this->fk_task_parent)) {
646 $this->fk_task_parent = (int) $this->fk_task_parent;
648 if (isset($this->label)) {
649 $this->label = trim($this->label);
654 if (isset($this->note_public)) {
655 $this->note_public = trim($this->note_public);
657 if (isset($this->note_private)) {
658 $this->note_private = trim($this->note_private);
660 if (isset($this->duration_effective)) {
661 $this->duration_effective = trim($this->duration_effective);
663 if (isset($this->planned_workload)) {
664 $this->planned_workload = trim($this->planned_workload);
666 if (isset($this->budget_amount)) {
667 $this->budget_amount = (float) $this->budget_amount;
670 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
671 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
679 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
680 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
681 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"'".$this->db->escape((
string) $this->id).
"'").
",";
682 $sql .=
" fk_task_parent=".(isset($this->fk_task_parent) ? $this->fk_task_parent :
"null").
",";
683 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
684 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
685 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
686 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
687 $sql .=
" duration_effective=".(isset($this->duration_effective) ? $this->duration_effective :
"null").
",";
688 $sql .=
" planned_workload=".((isset($this->planned_workload) && $this->planned_workload !=
'') ? $this->planned_workload :
"null").
",";
689 $sql .=
" datec=".(isDolTms($this->date_c) ?
"'".$this->db->idate($this->date_c).
"'" :
'null').
",";
690 $sql .=
" dateo=".(isDolTms($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
'null').
",";
691 $sql .=
" datee=".(isDolTms($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
'null').
",";
692 $sql .=
" progress=".(($this->progress !=
'' && $this->progress >= 0) ? $this->progress :
'null').
",";
693 $sql .=
" budget_amount=".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? $this->budget_amount :
'null').
",";
694 $sql .=
" rang=".((!empty($this->rang)) ? ((
int) $this->rang) :
"0").
",";
695 $sql .=
" priority=".((!empty($this->priority)) ? ((
int) $this->priority) :
"0").
",";
696 $sql .=
" billable=".((int) $this->billable).
",";
697 $sql .=
" fk_statut=".((int) $this->
status);
698 $sql .=
" WHERE rowid=".((int) $this->
id);
702 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
703 $resql = $this->db->query($sql);
706 $this->errors[] =
"Error ".$this->db->lasterror();
719 $project =
new Project($this->db);
720 if ($project->fetch($this->fk_project) > 0) {
722 $project->getLinesArray(
null);
723 $projectCompleted = array_reduce(
730 static function ($allTasksCompleted, $task) {
731 return $allTasksCompleted && $task->progress >= 100;
735 if ($projectCompleted) {
736 if ($project->setClose($user) <= 0) {
745 $this->errors[] = $project->error;
752 $result = $this->call_trigger(
'TASK_MODIFY', $user);
760 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
762 if ($conf->project->dir_output) {
763 $project =
new Project($this->db);
764 $project->fetch($this->fk_project);
768 if (file_exists($olddir)) {
769 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
772 $langs->load(
"errors");
773 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
782 foreach ($this->errors as $errmsg) {
783 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
784 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
786 $this->db->rollback();
801 public function delete($user, $notrigger = 0)
804 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
811 dol_syslog(get_class($this).
"::delete Can't delete record as it has some sub tasks", LOG_WARNING);
812 $this->error =
'ErrorRecordHasSubTasks';
813 $this->db->rollback();
818 if (!empty($objectisused)) {
819 dol_syslog(get_class($this).
"::delete Can't delete record as it has some child", LOG_WARNING);
820 $this->error =
'ErrorRecordHasChildren';
821 $this->db->rollback();
829 $this->error =
'ErrorFailToDeleteLinkedContact';
831 $this->db->rollback();
837 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_time";
838 $sql .=
" WHERE fk_element = ".((int) $this->
id).
" AND elementtype = 'task'";
840 $resql = $this->db->query($sql);
843 $this->errors[] =
"Error ".$this->db->lasterror();
848 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_extrafields";
849 $sql .=
" WHERE fk_object = ".((int) $this->
id);
851 $resql = $this->db->query($sql);
854 $this->errors[] =
"Error ".$this->db->lasterror();
859 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task";
860 $sql .=
" WHERE rowid=".((int) $this->
id);
862 $resql = $this->db->query($sql);
865 $this->errors[] =
"Error ".$this->db->lasterror();
872 $result = $this->call_trigger(
'TASK_DELETE', $user);
882 foreach ($this->errors as $errmsg) {
883 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
884 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
886 $this->db->rollback();
890 if ($conf->project->dir_output) {
891 $projectstatic =
new Project($this->db);
892 $projectstatic->fetch($this->fk_project);
895 dol_syslog(get_class($this).
"::delete dir=".$dir, LOG_DEBUG);
896 if (file_exists($dir)) {
897 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
900 $this->error =
'ErrorFailToDeleteDir';
901 $this->db->rollback();
923 $sql =
"SELECT COUNT(*) as nb";
924 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task";
925 $sql .=
" WHERE fk_task_parent = ".((int) $this->
id);
927 dol_syslog(get_class($this).
"::hasChildren", LOG_DEBUG);
928 $resql = $this->db->query($sql);
931 $this->errors[] =
"Error ".$this->db->lasterror();
933 $obj = $this->db->fetch_object($resql);
937 $this->db->free($resql);
957 $sql =
"SELECT COUNT(*) as nb";
958 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time";
959 $sql .=
" WHERE fk_element = ".((int) $this->
id);
960 $sql .=
" AND elementtype = 'task'";
962 dol_syslog(get_class($this).
"::hasTimeSpent", LOG_DEBUG);
963 $resql = $this->db->query($sql);
966 $this->errors[] =
"Error ".$this->db->lasterror();
968 $obj = $this->db->fetch_object($resql);
972 $this->db->free($resql);
993 $langs->load(
'projects');
996 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Task").
'</u>';
997 if (!empty($this->
ref)) {
998 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1000 if (!empty($this->label)) {
1001 $datas[
'label'] =
'<br><b>'.$langs->trans(
'LabelTask').
':</b> '.$this->label;
1003 if ($this->date_start || $this->date_end) {
1004 $datas[
'range'] =
"<br>".get_date_range($this->date_start, $this->date_end,
'', $langs, 0);
1022 public function getNomUrl($withpicto = 0, $option =
'', $mode =
'task', $addlabel = 0, $sep =
' - ', $notooltip = 0, $save_lastsearch_value = -1)
1024 global $action, $conf, $hookmanager, $langs;
1026 if (!empty($conf->dol_no_mouse_hover)) {
1033 'objecttype' => $this->element,
1035 $classfortooltip =
'classfortooltip';
1038 $classfortooltip =
'classforajaxtooltip';
1039 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1045 $url = DOL_URL_ROOT.
'/projet/tasks/'.$mode.
'.php?id='.$this->
id.($option ==
'withproject' ?
'&withproject=1' :
'');
1047 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1048 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1049 $add_save_lastsearch_values = 1;
1051 if ($add_save_lastsearch_values) {
1052 $url .=
'&save_lastsearch_values=1';
1056 if (empty($notooltip)) {
1058 $label = $langs->trans(
"ShowTask");
1059 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1061 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1062 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' nowraponall"';
1064 $linkclose .=
' class="nowraponall"';
1067 $linkstart =
'<a href="'.$url.
'"';
1068 $linkstart .= $linkclose.
'>';
1071 $picto =
'projecttask';
1073 $result .= $linkstart;
1075 $result .=
img_object(($notooltip ?
'' : $label), $picto,
'class="paddingright"', 0, 0, $notooltip ? 0 : 1);
1077 if ($withpicto != 2) {
1078 if ($addlabel >= 0) {
1079 $result .= $this->ref;
1081 $result .= $this->label;
1084 $result .= $linkend;
1085 if ($withpicto != 2) {
1086 $result .= (($addlabel > 0 && $this->label) ?
'<span class="opacitymedium">'.$sep.dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)).
'</span>' :
'');
1089 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1090 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1092 $result = $hookmanager->resPrint;
1094 $result .= $hookmanager->resPrint;
1113 $this->fk_project = 0;
1114 $this->
ref =
'TK01';
1115 $this->fk_task_parent = 0;
1116 $this->label =
'Specimen task TK01';
1117 $this->duration_effective =
'';
1118 $this->fk_user_creat = $user->id;
1119 $this->progress = 25;
1121 $this->priority = 0;
1122 $this->note_private =
'This is a specimen private note';
1123 $this->note_public =
'This is a specimen public note';
1124 $this->billable = 1;
1152 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 =
'')
1154 global $hookmanager;
1162 if ($filteronprojuser > 0 || $filterontaskuser > 0) {
1163 $sql .=
" DISTINCT";
1165 $sql .=
" p.rowid as projectid, p.ref, p.title as plabel, p.public, p.fk_statut as projectstatus, p.usage_bill_time,";
1166 $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,";
1167 $sql .=
" t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang, t.priority,";
1168 $sql .=
" t.budget_amount, t.billable,";
1169 $sql .=
" t.note_public, t.note_private,";
1170 $sql .=
" s.rowid as thirdparty_id, s.nom as thirdparty_name, s.email as thirdparty_email,";
1171 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount as project_budget_amount";
1173 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1174 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1175 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key.
" as options_".$key :
'');
1178 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
1179 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
1180 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key.
" as options_".$key :
'');
1184 if ($includebilltime) {
1185 $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";
1188 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
1189 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1191 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_extrafields as efp ON (p.rowid = efp.fk_object)";
1195 if ($filteronprojuser > 0) {
1196 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1197 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1199 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
1201 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
1203 if ($includebilltime) {
1204 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype='task')";
1206 if ($filterontaskuser > 0) {
1207 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
1208 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
1210 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
1211 $sql .=
" AND t.fk_projet = p.rowid";
1212 } elseif ($mode == 1) {
1213 if ($filteronprojuser > 0) {
1214 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1215 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1217 if ($filterontaskuser > 0) {
1218 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
1219 if ($includebilltime) {
1220 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype='task')";
1222 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
1223 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
1225 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t on t.fk_projet = p.rowid";
1226 if ($includebilltime) {
1227 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype = 'task')";
1230 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
1232 return 'BadValueForParameterMode';
1235 if ($filteronprojuser > 0) {
1236 $sql .=
" AND p.rowid = ec.element_id";
1237 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
1238 $sql .=
" AND ctc.element = 'project'";
1239 $sql .=
" AND ec.fk_socpeople = ".((int) $filteronprojuser);
1240 $sql .=
" AND ec.statut = 4";
1241 $sql .=
" AND ctc.source = 'internal'";
1243 if ($filterontaskuser > 0) {
1244 $sql .=
" AND t.fk_projet = p.rowid";
1245 $sql .=
" AND p.rowid = ec2.element_id";
1246 $sql .=
" AND ctc2.rowid = ec2.fk_c_type_contact";
1247 $sql .=
" AND ctc2.element = 'project_task'";
1248 $sql .=
" AND ec2.fk_socpeople = ".((int) $filterontaskuser);
1249 $sql .=
" AND ec2.statut = 4";
1250 $sql .=
" AND ctc2.source = 'internal'";
1253 $sql .=
" AND p.fk_soc = ".((int) $socid);
1256 $sql .=
" AND p.rowid IN (".$this->db->sanitize((
string) $projectid).
")";
1258 if ($filteronproj) {
1259 $sql .=
natural_search(array(
"p.ref",
"p.title"), $filteronproj);
1261 if ($filteronprojstatus && (
int) $filteronprojstatus !=
'-1') {
1262 $sql .=
" AND p.fk_statut IN (".$this->db->sanitize($filteronprojstatus).
")";
1264 if ($morewherefilter) {
1265 $sql .= $morewherefilter;
1269 $extrafieldsobjectkey =
'projet_task';
1270 $extrafieldsobjectprefix =
'efpt.';
1271 $search_options_pattern =
'search_task_options_';
1273 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
1276 $parameters = array();
1277 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
1278 $sql .= $hookmanager->resPrint;
1279 if ($includebilltime) {
1280 $sql .=
" GROUP BY p.rowid, p.ref, p.title, p.public, p.fk_statut, p.usage_bill_time,";
1281 $sql .=
" t.datec, t.dateo, t.datee, t.tms,";
1282 $sql .=
" t.rowid, t.ref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut,";
1283 $sql .=
" t.dateo, t.datee, t.planned_workload, t.rang, t.priority,";
1284 $sql .=
" t.budget_amount, t.billable,";
1285 $sql .=
" t.note_public, t.note_private,";
1286 $sql .=
" s.rowid, s.nom, s.email,";
1287 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount";
1289 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1290 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1291 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key :
'');
1294 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
1295 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
1296 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key :
'');
1302 if ($sortfield && $sortorder) {
1303 $sql .= $this->db->order($sortfield, $sortorder);
1305 $sql .=
" ORDER BY p.ref, t.rang, t.dateo";
1309 dol_syslog(get_class($this).
"::getTasksArray", LOG_DEBUG);
1310 $resql = $this->db->query($sql);
1312 $num = $this->db->num_rows($resql);
1318 $obj = $this->db->fetch_object($resql);
1320 if ($loadRoleMode) {
1321 if ((!$obj->public) && (is_object($userp))) {
1326 if (is_object($usert)) {
1334 $tasks[$i] =
new Task($this->db);
1335 $tasks[$i]->id = $obj->taskid;
1336 $tasks[$i]->ref = $obj->taskref;
1337 $tasks[$i]->fk_project = $obj->projectid;
1340 $tasks[$i]->projectref = $obj->ref;
1341 $tasks[$i]->projectlabel = $obj->plabel;
1342 $tasks[$i]->projectstatus = $obj->projectstatus;
1343 $tasks[$i]->fk_opp_status = $obj->fk_opp_status;
1344 $tasks[$i]->opp_amount = $obj->opp_amount;
1345 $tasks[$i]->opp_percent = $obj->opp_percent;
1346 $tasks[$i]->budget_amount = $obj->budget_amount;
1347 $tasks[$i]->project_budget_amount = $obj->project_budget_amount;
1348 $tasks[$i]->usage_bill_time = $obj->usage_bill_time;
1350 $tasks[$i]->label = $obj->label;
1351 $tasks[$i]->description = $obj->description;
1353 $tasks[$i]->fk_task_parent = $obj->fk_task_parent;
1354 $tasks[$i]->note_public = $obj->note_public;
1355 $tasks[$i]->note_private = $obj->note_private;
1356 $tasks[$i]->duration_effective = $obj->duration_effective;
1357 $tasks[$i]->planned_workload = $obj->planned_workload;
1359 if ($includebilltime) {
1361 $tasks[$i]->tobill = $obj->tobill;
1362 $tasks[$i]->billed = $obj->billed;
1365 $tasks[$i]->progress = $obj->progress;
1366 $tasks[$i]->fk_statut = $obj->status;
1367 $tasks[$i]->status = $obj->status;
1368 $tasks[$i]->public = $obj->public;
1369 $tasks[$i]->date_start = $this->db->jdate($obj->date_start);
1370 $tasks[$i]->date_end = $this->db->jdate($obj->date_end);
1371 $tasks[$i]->rang = $obj->rang;
1372 $tasks[$i]->priority = $obj->priority;
1374 $tasks[$i]->socid = $obj->thirdparty_id;
1375 $tasks[$i]->thirdparty_id = $obj->thirdparty_id;
1376 $tasks[$i]->thirdparty_name = $obj->thirdparty_name;
1377 $tasks[$i]->thirdparty_email = $obj->thirdparty_email;
1379 $tasks[$i]->billable = $obj->billable;
1382 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1383 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1384 if ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate') {
1385 $tmpvar =
'options_'.$key;
1386 $tasks[$i]->array_options_project[
'options_'.$key] = $obj->$tmpvar;
1393 $tasks[$i]->fetch_optionals();
1399 $this->db->free($resql);
1419 $arrayroles = array();
1421 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks userp=".json_encode(is_object($userp)).
" usert=".json_encode(is_object($usert)).
" projectid=".$projectid.
" taskid=".$taskid);
1424 if (empty($userp) && empty($usert)) {
1425 $this->error =
"CallWithWrongParameters";
1428 if (!empty($userp) && !empty($usert)) {
1429 $this->error =
"CallWithWrongParameters";
1436 $sql .=
" p.rowid as pid,";
1438 $sql .=
" pt.rowid as pid,";
1440 $sql .=
" ec.element_id, ctc.code, ctc.source";
1442 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
1444 if ($usert && $filteronprojstatus > -1) {
1445 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"projet_task as pt";
1447 if ($usert && $filteronprojstatus <= -1) {
1448 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as pt";
1450 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1451 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1453 $sql .=
" WHERE p.rowid = ec.element_id";
1455 $sql .=
" WHERE pt.rowid = ec.element_id";
1457 if ($userp && $filteronprojstatus > -1) {
1458 $sql .=
" AND p.fk_statut = ".((int) $filteronprojstatus);
1460 if ($usert && $filteronprojstatus > -1) {
1461 $sql .=
" AND pt.fk_projet = p.rowid AND p.fk_statut = ".((int) $filteronprojstatus);
1464 $sql .=
" AND ctc.element = 'project'";
1467 $sql .=
" AND ctc.element = 'project_task'";
1469 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
1471 $sql .=
" AND ec.fk_socpeople = ".((int) $userp->id);
1474 $sql .=
" AND ec.fk_socpeople = ".((int) $usert->id);
1476 $sql .=
" AND ec.statut = 4";
1477 $sql .=
" AND ctc.source = 'internal'";
1480 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectid).
")";
1483 $sql .=
" AND pt.fk_projet IN (".$this->db->sanitize($projectid).
")";
1488 $sql .=
" ERROR SHOULD NOT HAPPENS";
1491 $sql .=
" AND pt.rowid = ".((int) $taskid);
1496 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks execute request", LOG_DEBUG);
1497 $resql = $this->db->query($sql);
1499 $num = $this->db->num_rows($resql);
1502 $obj = $this->db->fetch_object($resql);
1503 if (empty($arrayroles[$obj->pid])) {
1504 $arrayroles[$obj->pid] = $obj->code;
1506 $arrayroles[$obj->pid] .=
','.$obj->code;
1510 $this->db->free($resql);
1527 $contactAlreadySelected = array();
1533 if ($source ==
'thirdparty') {
1534 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
1536 $contactAlreadySelected[$i] = $tab[$i][
'id'];
1540 return $contactAlreadySelected;
1553 $origintask =
new Task($this->db);
1554 $result = $origintask->fetch($origin_id);
1560 $arraycontactorigin = array_merge($origintask->liste_contact(-1,
'internal'), $origintask->liste_contact(-1,
'external'));
1561 if (is_array($arraycontactorigin)) {
1562 foreach ($arraycontactorigin as $key => $contact) {
1563 $result = $this->
add_contact($contact[
"id"], $contact[
"fk_c_type_contact"], $contact[
"source"]);
1585 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"element_time as et";
1586 $sql .=
" SET et.fk_element = ".((int) $dest_id);
1587 $sql .=
" WHERE et.elementtype = 'task'";
1588 $sql .=
" AND et.fk_element = ".((int) $origin_id);
1590 dol_syslog(get_class($this).
"::mergeTimeSpentTask", LOG_DEBUG);
1591 if (!$this->db->query($sql)) {
1592 $this->error = $this->db->lasterror();
1597 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1598 $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).
")";
1599 $sql .=
" WHERE rowid = ".((int) $dest_id);
1601 dol_syslog(get_class($this).
"::mergeTimeSpentTask update project_task", LOG_DEBUG);
1602 if (!$this->db->query($sql)) {
1603 $this->error = $this->db->lasterror();
1609 $this->db->commit();
1611 $this->db->rollback();
1627 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1633 if (!is_object($user)) {
1634 dol_print_error(
null,
"Method addTimeSpent was called with wrong parameter user");
1639 if (isset($this->timespent_note)) {
1640 $this->timespent_note = trim($this->timespent_note);
1642 if (empty($this->timespent_datehour) || ($this->timespent_date != $this->timespent_datehour)) {
1643 $this->timespent_datehour = $this->timespent_date;
1647 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1650 if ($this->timespent_date < $restrictBefore) {
1651 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack',
getDolGlobalString(
'PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS'));
1652 $this->errors[] = $this->error;
1660 $timespent->fk_element = $this->id;
1661 $timespent->elementtype =
'task';
1662 $timespent->element_date = $this->timespent_date;
1663 $timespent->element_datehour = $this->timespent_datehour;
1664 $timespent->element_date_withhour = $this->timespent_withhour;
1665 $timespent->element_duration = $this->timespent_duration;
1666 $timespent->fk_user = $this->timespent_fk_user;
1667 $timespent->fk_product = $this->timespent_fk_product;
1668 $timespent->note = $this->timespent_note;
1669 $timespent->datec = $now;
1671 $result = $timespent->create($user);
1674 $this->timespent_id = $result;
1678 $result = $this->call_trigger(
'TASK_TIMESPENT_CREATE', $user);
1685 $this->error = $this->db->lasterror();
1692 if ($ret <= 0 && empty($this->error) && !empty($this->errors)) {
1693 foreach ($this->errors as $errmsg) {
1694 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1695 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1701 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1702 $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).
")";
1703 if (isset($this->progress)) {
1704 $sql .=
", progress = ".((float) $this->progress);
1705 if ($this->progress == 100) {
1707 } elseif ($this->progress != 0) {
1712 $sql .=
", fk_statut = ".((int) $this->
status);
1715 $sql .=
", fk_statut = ".((int) $this->
status);
1717 $sql .=
" WHERE rowid = ".((int) $this->
id);
1719 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1720 if (!$this->db->query($sql)) {
1721 $this->error = $this->db->lasterror();
1726 $resql_thm_user = $this->db->query(
"SELECT thm FROM " . MAIN_DB_PREFIX .
"user WHERE rowid = " . ((
int) $timespent->fk_user));
1727 if (!empty($resql_thm_user)) {
1728 $obj_thm_user = $this->db->fetch_object($resql_thm_user);
1729 $timespent->thm = $obj_thm_user->thm;
1731 $res_update = $timespent->update($user);
1733 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1734 if ($res_update <= 0) {
1735 $this->error = $this->db->lasterror();
1741 $this->db->commit();
1743 $this->db->rollback();
1756 $arrayres = array();
1759 $sql .=
" s.rowid as socid,";
1760 $sql .=
" s.nom as thirdparty_name,";
1761 $sql .=
" s.email as thirdparty_email,";
1762 $sql .=
" ptt.rowid,";
1763 $sql .=
" ptt.ref_ext,";
1764 $sql .=
" ptt.fk_element as fk_task,";
1765 $sql .=
" ptt.element_date as task_date,";
1766 $sql .=
" ptt.element_datehour as task_datehour,";
1767 $sql .=
" ptt.element_date_withhour as task_date_withhour,";
1768 $sql .=
" ptt.element_duration as task_duration,";
1769 $sql .=
" ptt.fk_user,";
1770 $sql .=
" ptt.fk_product,";
1771 $sql .=
" ptt.note,";
1772 $sql .=
" ptt.thm,";
1773 $sql .=
" pt.rowid as task_id,";
1774 $sql .=
" pt.ref as task_ref,";
1775 $sql .=
" pt.label as task_label,";
1776 $sql .=
" p.rowid as project_id,";
1777 $sql .=
" p.ref as project_ref,";
1778 $sql .=
" p.title as project_label,";
1779 $sql .=
" p.public as project_public";
1780 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1781 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1782 $sql .=
" WHERE ptt.fk_element = pt.rowid AND pt.fk_projet = p.rowid";
1783 $sql .=
" AND ptt.elementtype = 'task'";
1784 $sql .=
" AND pt.rowid = ".((int) $this->
id);
1785 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1786 if ($morewherefilter) {
1787 $sql .= $morewherefilter;
1790 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1791 $resql = $this->db->query($sql);
1793 $num = $this->db->num_rows($resql);
1797 $obj = $this->db->fetch_object($resql);
1801 $newobj->socid = $obj->socid;
1802 $newobj->thirdparty_name = $obj->thirdparty_name;
1803 $newobj->thirdparty_email = $obj->thirdparty_email;
1805 $newobj->fk_project = $obj->project_id;
1806 $newobj->project_ref = $obj->project_ref;
1807 $newobj->project_label = $obj->project_label;
1808 $newobj->project_public = $obj->project_public;
1809 $newobj->public = $obj->project_public;
1811 $newobj->fk_task = $obj->task_id;
1812 $newobj->task_ref = $obj->task_ref;
1813 $newobj->task_label = $obj->task_label;
1815 $newobj->timespent_line_id = $obj->rowid;
1816 $newobj->timespent_line_ref_ext = $obj->ref_ext;
1817 $newobj->timespent_line_date = $this->db->jdate($obj->task_date);
1818 $newobj->timespent_line_datehour = $this->db->jdate($obj->task_datehour);
1819 $newobj->timespent_line_withhour = $obj->task_date_withhour;
1820 $newobj->timespent_line_duration = $obj->task_duration;
1821 $newobj->timespent_line_fk_user = $obj->fk_user;
1822 $newobj->timespent_line_fk_product = $obj->fk_product;
1823 $newobj->timespent_line_thm = $obj->thm;
1824 $newobj->timespent_line_note = $obj->note;
1826 $arrayres[] = $newobj;
1831 $this->db->free($resql);
1833 $this->lines = $arrayres;
1837 $this->error =
"Error ".$this->db->lasterror();
1852 if (is_object($userobj)) {
1853 $userid = $userobj->id;
1859 if (empty($id) && empty($userid)) {
1860 dol_syslog(
"getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR);
1867 $sql .=
" MIN(t.element_datehour) as min_date,";
1868 $sql .=
" MAX(t.element_datehour) as max_date,";
1869 $sql .=
" SUM(t.element_duration) as total_duration,";
1870 $sql .=
" SUM(t.element_duration / 3600 * ".$this->db->ifsql(
"t.thm IS NULL",
'0',
"t.thm").
") as total_amount,";
1871 $sql .=
" COUNT(t.rowid) as nblines,";
1872 $sql .=
" SUM(".$this->db->ifsql(
"t.thm IS NULL",
'1',
'0').
") as nblinesnull";
1873 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as t";
1874 $sql .=
" WHERE t.elementtype='task'";
1875 if ($morewherefilter) {
1876 $sql .= $morewherefilter;
1879 $sql .=
" AND t.fk_element = ".((int) $id);
1882 $sql .=
" AND t.fk_user = ".((int) $userid);
1885 dol_syslog(get_class($this).
"::getSummaryOfTimeSpent", LOG_DEBUG);
1886 $resql = $this->db->query($sql);
1888 $obj = $this->db->fetch_object($resql);
1890 $result[
'min_date'] = $obj->min_date;
1891 $result[
'max_date'] = $obj->max_date;
1892 $result[
'total_duration'] = $obj->total_duration;
1894 $this->timespent_min_date = $this->db->jdate($obj->min_date);
1895 $this->timespent_max_date = $this->db->jdate($obj->max_date);
1896 $this->timespent_total_duration = $obj->total_duration;
1897 $this->timespent_total_amount = $obj->total_amount;
1898 $this->timespent_nblinesnull = ($obj->nblinesnull ? $obj->nblinesnull : 0);
1899 $this->timespent_nblines = ($obj->nblines ? $obj->nblines : 0);
1901 $this->db->free($resql);
1923 $sql .=
" SUM(t.element_duration) as nbseconds,";
1924 $sql .=
" SUM(".$this->db->ifsql(
"u.thm IS NULL",
'1',
'0').
") as nbuserthmnull,";
1925 $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";
1926 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as t";
1927 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = t.fk_user";
1928 $sql .=
" WHERE t.elementtype='task' AND t.fk_element = ".((int) $id);
1929 if (is_object($fuser) && $fuser->id > 0) {
1930 $sql .=
" AND fk_user = ".((int) $fuser->id);
1933 $datefieldname =
"element_datehour";
1934 $sql .=
" AND (".$datefieldname.
" >= '".$this->db->idate((
int) $dates).
"' OR ".$datefieldname.
" IS NULL)";
1937 $datefieldname =
"element_datehour";
1938 $sql .=
" AND (".$datefieldname.
" <= '".$this->db->idate((
int) $datee).
"' OR ".$datefieldname.
" IS NULL)";
1942 dol_syslog(get_class($this).
"::getSumOfAmount", LOG_DEBUG);
1943 $resql = $this->db->query($sql);
1945 $obj = $this->db->fetch_object($resql);
1947 $result[
'amount'] = $obj->amount;
1948 $result[
'nbseconds'] = $obj->nbseconds;
1949 $result[
'nblinesnull'] = $obj->nblinesnull;
1950 $result[
'nbuserthmnull'] = $obj->nbuserthmnull;
1952 $this->db->free($resql);
1969 $timespent->fetch($id);
1971 dol_syslog(get_class($this).
"::fetchTimeSpent", LOG_DEBUG);
1973 if ($timespent->id > 0) {
1974 $this->timespent_id = $timespent->id;
1975 $this->
id = $timespent->fk_element;
1976 $this->timespent_date = $timespent->element_date;
1977 $this->timespent_datehour = $timespent->element_datehour;
1978 $this->timespent_withhour = $timespent->element_date_withhour;
1979 $this->timespent_duration = $timespent->element_duration;
1980 $this->timespent_fk_user = $timespent->fk_user;
1981 $this->timespent_fk_product = $timespent->fk_product;
1982 $this->timespent_thm = $timespent->thm;
1983 $this->timespent_note = $timespent->note;
2000 $arrayres = array();
2003 $sql .=
" s.rowid as socid,";
2004 $sql .=
" s.nom as thirdparty_name,";
2005 $sql .=
" s.email as thirdparty_email,";
2006 $sql .=
" ptt.rowid,";
2007 $sql .=
" ptt.fk_element as fk_task,";
2008 $sql .=
" ptt.element_date as task_date,";
2009 $sql .=
" ptt.element_datehour as task_datehour,";
2010 $sql .=
" ptt.element_date_withhour as task_date_withhour,";
2011 $sql .=
" ptt.element_duration as task_duration,";
2012 $sql .=
" ptt.fk_user,";
2013 $sql .=
" ptt.note,";
2014 $sql .=
" ptt.thm,";
2015 $sql .=
" pt.rowid as task_id,";
2016 $sql .=
" pt.ref as task_ref,";
2017 $sql .=
" pt.label as task_label,";
2018 $sql .=
" p.rowid as project_id,";
2019 $sql .=
" p.ref as project_ref,";
2020 $sql .=
" p.title as project_label,";
2021 $sql .=
" p.public as public";
2022 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
2023 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
2024 $sql .=
" WHERE ptt.fk_element = pt.rowid AND pt.fk_projet = p.rowid";
2025 $sql .=
" AND ptt.elementtype = 'task'";
2026 $sql .=
" AND ptt.fk_user = ".((int) $userobj->id);
2027 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
2028 if ($morewherefilter) {
2029 $sql .= $morewherefilter;
2032 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
2033 $resql = $this->db->query($sql);
2035 $num = $this->db->num_rows($resql);
2039 $obj = $this->db->fetch_object($resql);
2043 $newobj->socid = $obj->socid;
2044 $newobj->thirdparty_name = $obj->thirdparty_name;
2045 $newobj->thirdparty_email = $obj->thirdparty_email;
2047 $newobj->fk_project = $obj->project_id;
2048 $newobj->project_ref = $obj->project_ref;
2049 $newobj->project_label = $obj->project_label;
2050 $newobj->public = $obj->project_public;
2052 $newobj->fk_task = $obj->task_id;
2053 $newobj->task_ref = $obj->task_ref;
2054 $newobj->task_label = $obj->task_label;
2056 $newobj->timespent_id = $obj->rowid;
2057 $newobj->timespent_date = $this->db->jdate($obj->task_date);
2058 $newobj->timespent_datehour = $this->db->jdate($obj->task_datehour);
2059 $newobj->timespent_withhour = $obj->task_date_withhour;
2060 $newobj->timespent_duration = $obj->task_duration;
2061 $newobj->timespent_fk_user = $obj->fk_user;
2062 $newobj->timespent_thm = $obj->thm;
2063 $newobj->timespent_note = $obj->note;
2065 $arrayres[] = $newobj;
2070 $this->db->free($resql);
2073 $this->error =
"Error ".$this->db->lasterror();
2089 global $conf, $langs;
2094 if ($this->timespent_date ==
'') {
2095 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date"));
2100 if (empty($this->timespent_datehour) || ($this->timespent_date != $this->timespent_datehour)) {
2101 $this->timespent_datehour = $this->timespent_date;
2103 if (isset($this->timespent_note)) {
2104 $this->timespent_note = trim($this->timespent_note);
2108 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2111 if ($this->timespent_date < $restrictBefore) {
2112 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack',
getDolGlobalString(
'PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS'));
2113 $this->errors[] = $this->error;
2121 $timespent->fetch($this->timespent_id);
2122 $old_fk_element = $timespent->fk_element;
2124 $timespent->element_date = $this->timespent_date;
2125 $timespent->element_datehour = $this->timespent_datehour;
2127 $timespent->element_date_withhour = $this->timespent_withhour;
2128 $timespent->element_duration = $this->timespent_duration;
2129 if ($this->timespent_fk_user > 0) {
2130 $timespent->fk_user = $this->timespent_fk_user;
2132 $timespent->fk_product = $this->timespent_fk_product;
2133 $timespent->fk_element = $this->id;
2134 $timespent->note = $this->timespent_note;
2135 $timespent->invoice_id = $this->timespent_invoiceid;
2136 $timespent->invoice_line_id = $this->timespent_invoicelineid;
2138 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
2140 $resupdate = $timespent->update($user);
2141 if ($resupdate > 0) {
2144 $result = $this->call_trigger(
'TASK_TIMESPENT_MODIFY', $user);
2146 $this->db->rollback();
2156 $this->error = $this->db->lasterror();
2157 $this->db->rollback();
2164 if ($ret < 0 && empty($this->error) && !empty($this->errors)) {
2165 foreach ($this->errors as $errmsg) {
2166 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2167 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2171 if ($ret == 1 && (($this->timespent_old_duration != $this->timespent_duration) ||
getDolGlobalString(
'TIMESPENT_ALWAYS_UPDATE_THM'))) {
2172 if ($this->timespent_old_duration != $this->timespent_duration) {
2174 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"projet_task";
2175 $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) .
")";
2176 if (isset($this->progress)) {
2177 $sql .=
", progress = " . ((float) $this->progress);
2179 $sql .=
" WHERE rowid = " . ((int) $this->
id);
2181 dol_syslog(get_class($this) .
"::updateTimeSpent", LOG_DEBUG);
2182 if (!$this->db->query($sql)) {
2183 $this->error = $this->db->lasterror();
2184 $this->db->rollback();
2192 $resql_thm_user = $this->db->query(
"SELECT thm FROM " . MAIN_DB_PREFIX .
"user WHERE rowid = " . ((
int) $timespent->fk_user));
2193 if (!empty($resql_thm_user)) {
2194 $obj_thm_user = $this->db->fetch_object($resql_thm_user);
2195 $timespent->thm = $obj_thm_user->thm;
2197 $res_update = $timespent->update($user);
2200 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
2201 if ($res_update <= 0) {
2202 $this->error = $this->db->lasterror();
2208 if ($ret == 1 && $old_fk_element != $this->
id) {
2210 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"projet_task";
2211 $sql .=
" SET duration_effective = (SELECT COALESCE(SUM(element_duration), 0) FROM " . MAIN_DB_PREFIX .
"element_time as ptt where ptt.elementtype = 'task' AND ptt.fk_element = " . ((int) $old_fk_element) .
")";
2212 $sql .=
" WHERE rowid = " . ((int) $old_fk_element);
2213 dol_syslog(get_class($this) .
"::updateTimeSpent update old task", LOG_DEBUG);
2214 if (!$this->db->query($sql)) {
2215 $this->error = $this->db->lasterror();
2216 $this->db->rollback();
2221 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"projet_task";
2222 $sql .=
" SET duration_effective = (SELECT COALESCE(SUM(element_duration), 0) FROM " . MAIN_DB_PREFIX .
"element_time as ptt where ptt.elementtype = 'task' AND ptt.fk_element = " . ((int) $this->
id) .
")";
2223 $sql .=
" WHERE rowid = " . ((int) $this->
id);
2224 dol_syslog(get_class($this) .
"::updateTimeSpent update new task", LOG_DEBUG);
2225 if (!$this->db->query($sql)) {
2226 $this->error = $this->db->lasterror();
2227 $this->db->rollback();
2234 $this->db->commit();
2248 global $conf, $langs;
2253 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2256 if ($this->timespent_date < $restrictBefore) {
2257 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack',
getDolGlobalString(
'PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS'));
2258 $this->errors[] = $this->error;
2267 $result = $this->call_trigger(
'TASK_TIMESPENT_DELETE', $user);
2276 $timespent->fetch($this->timespent_id);
2278 $res_del = $timespent->delete($user);
2282 $this->errors[] =
"Error ".$this->db->lasterror();
2287 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
2288 $sql .=
" SET duration_effective = duration_effective - ".$this->db->escape($this->timespent_duration ? (
string) $this->timespent_duration :
'0');
2289 $sql .=
" WHERE rowid = ".((int) $this->
id);
2291 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
2292 if ($this->db->query($sql)) {
2295 $this->error = $this->db->lasterror();
2302 foreach ($this->errors as $errmsg) {
2303 dol_syslog(get_class($this).
"::delTimeSpent ".$errmsg, LOG_ERR);
2304 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2306 $this->db->rollback();
2309 $this->db->commit();
2328 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)
2330 global $langs, $conf;
2339 $clone_task =
new Task($this->db);
2340 $origin_task =
new Task($this->db);
2342 $clone_task->context[
'createfromclone'] =
'createfromclone';
2347 $clone_task->fetch($fromid);
2348 $clone_task->fetch_optionals();
2351 $origin_task->fetch($fromid);
2354 $obj = !
getDolGlobalString(
'PROJECT_TASK_ADDON') ?
'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
2356 require_once DOL_DOCUMENT_ROOT.
"/core/modules/project/task/" .
getDolGlobalString(
'PROJECT_TASK_ADDON').
'.php';
2357 $modTask =
new $obj();
2358 '@phan-var-force ModeleNumRefTask $modTask';
2359 $defaultref = $modTask->getNextValue(
null, $clone_task);
2362 $ori_project_id = $clone_task->fk_project;
2364 $clone_task->id = 0;
2365 $clone_task->ref = $defaultref;
2366 $clone_task->fk_project = $project_id;
2367 $clone_task->fk_task_parent = $parent_task_id;
2368 $clone_task->date_c = $datec;
2369 $clone_task->planned_workload = $origin_task->planned_workload;
2370 $clone_task->rang = $origin_task->rang;
2371 $clone_task->priority = $origin_task->priority;
2374 if ($clone_change_dt) {
2375 $projectstatic =
new Project($this->db);
2376 $projectstatic->fetch($ori_project_id);
2379 $orign_project_dt_start = (!isset($projectstatic->date_start) || $projectstatic->date_start ==
'') ? $projectstatic->date_c : $projectstatic->date_start;
2382 if (!empty($clone_task->date_start)) {
2383 $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
2387 if (!empty($clone_task->date_end)) {
2388 $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
2393 $clone_task->progress = 0;
2397 $result = $clone_task->create($user);
2401 $this->error = $clone_task->error;
2408 $clone_task_id = $clone_task->id;
2409 $clone_task_ref = $clone_task->ref;
2413 $clone_task->note_private =
'';
2414 $clone_task->note_public =
'';
2417 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_public, ENT_QUOTES | ENT_HTML5),
'_public');
2419 $this->error .= $clone_task->error;
2421 $this->db->rollback();
2423 $this->db->commit();
2427 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_private, ENT_QUOTES | ENT_HTML5),
'_private');
2429 $this->error .= $clone_task->error;
2431 $this->db->rollback();
2433 $this->db->commit();
2439 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2442 $projectstatic =
new Project($this->db);
2443 $projectstatic->fetch($ori_project_id);
2444 $ori_project_ref = $projectstatic->ref;
2446 if ($ori_project_id != $project_id) {
2447 $projectstatic->fetch($project_id);
2448 $clone_project_ref = $projectstatic->ref;
2450 $clone_project_ref = $ori_project_ref;
2456 $filearray =
dol_dir_list($ori_task_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'', SORT_ASC, 1);
2457 foreach ($filearray as $file) {
2458 if (!file_exists($clone_task_dir)) {
2460 $this->error .= $langs->trans(
'ErrorInternalErrorDetected').
':dol_mkdir';
2465 $rescopy =
dol_copy($ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name'],
'0', 1);
2466 if (is_numeric($rescopy) && $rescopy < 0) {
2467 $this->error .= $langs->trans(
"ErrorFailToCopyFile", $ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name']);
2474 if ($clone_affectation) {
2475 $origin_task =
new Task($this->db);
2476 $origin_task->fetch($fromid);
2478 foreach (array(
'internal',
'external') as $source) {
2479 $tab = $origin_task->liste_contact(-1, $source);
2483 $clone_task->add_contact($tab[$i][
'id'], $tab[$i][
'code'], $tab[$i][
'source']);
2484 if ($clone_task->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2485 $langs->load(
"errors");
2486 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
2489 if ($clone_task->error !=
'') {
2490 $this->error .= $clone_task->error;
2504 unset($clone_task->context[
'createfromclone']);
2507 $this->db->commit();
2508 return $clone_task_id;
2510 $this->db->rollback();
2511 dol_syslog(get_class($this).
"::createFromClone nbError: ".$error.
" error : ".$this->error, LOG_ERR);
2542 return $langs->trans($this->labelStatus[$status]);
2543 } elseif ($mode == 1) {
2544 return $langs->trans($this->labelStatusShort[$status]);
2545 } elseif ($mode == 2) {
2548 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut0').
' '.$langs->trans($this->labelStatusShort[$status]);
2550 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut1').
' '.$langs->trans($this->labelStatusShort[$status]);
2552 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut3').
' '.$langs->trans($this->labelStatusShort[$status]);
2554 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6').
' '.$langs->trans($this->labelStatusShort[$status]);
2556 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6').
' '.$langs->trans($this->labelStatusShort[$status]);
2558 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut5').
' '.$langs->trans($this->labelStatusShort[$status]);
2560 } elseif ($mode == 3) {
2563 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut0');
2565 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut1');
2567 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut3');
2569 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6');
2571 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6');
2573 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut5');
2575 } elseif ($mode == 4) {
2578 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status0', $mode);
2580 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status1', $mode);
2582 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status3', $mode);
2584 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status6', $mode);
2586 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status6', $mode);
2588 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status5', $mode);
2590 } elseif ($mode == 5) {
2600 } elseif ($mode == 6) {
2624 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2626 $outputlangs->load(
"projects");
2629 $modele =
'nodefault';
2631 if (!empty($this->model_pdf)) {
2632 $modele = $this->model_pdf;
2638 $modelpath =
"core/modules/project/task/doc/";
2640 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2654 global $conf, $langs;
2660 $projectstatic =
new Project($this->db);
2661 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
2664 $sql =
"SELECT p.rowid as projectid, p.fk_statut as projectstatus,";
2665 $sql .=
" t.rowid as taskid, t.progress as progress, t.fk_statut as status,";
2666 $sql .=
" t.dateo as date_start, t.datee as date_end";
2667 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2670 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2671 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2672 $sql .=
" AND p.fk_statut = 1";
2673 $sql .=
" AND t.fk_projet = p.rowid";
2674 $sql .=
" AND (t.progress IS NULL OR t.progress < 100)";
2675 if (!$user->hasRight(
'projet',
'all',
'lire')) {
2676 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2684 $resql = $this->db->query($sql);
2686 $task_static =
new Task($this->db);
2689 $response->warning_delay = $conf->project->task->warning_delay / 60 / 60 / 24;
2690 $response->label = $langs->trans(
"OpenedTasks");
2691 if ($user->hasRight(
"projet",
"all",
"lire")) {
2692 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mainmenu=project';
2694 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mode=mine&mainmenu=project';
2699 while ($obj = $this->db->fetch_object($resql)) {
2700 $response->nbtodo++;
2702 $task_static->projectstatus = $obj->projectstatus;
2703 $task_static->progress = $obj->progress;
2704 $task_static->fk_statut = $obj->status;
2705 $task_static->status = $obj->status;
2706 $task_static->date_start = $this->db->jdate($obj->date_start);
2707 $task_static->date_end = $this->db->jdate($obj->date_end);
2709 if ($task_static->hasDelay()) {
2710 $response->nbtodolate++;
2716 $this->error = $this->db->error();
2732 $socid = $user->socid;
2734 $projectstatic =
new Project($this->db);
2735 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $mine, 1, $socid);
2738 $sql =
"SELECT count(p.rowid) as nb";
2739 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2740 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
2741 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2742 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2744 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2745 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2746 $sql .=
" AND t.fk_projet = p.rowid";
2747 if ($mine || !$user->hasRight(
'projet',
'all',
'lire')) {
2748 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2753 $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).
")";
2755 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2756 $sql .=
" AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).
") OR (s.rowid IS NULL))";
2759 $resql = $this->db->query($sql);
2762 while ($obj = $this->db->fetch_object($resql)) {
2763 $this->nb[
"tasks"] = $obj->nb;
2765 $this->db->free($resql);
2769 $this->error = $this->db->error();
2783 if (!($this->progress >= 0 && $this->progress < 100)) {
2789 $datetouse = ($this->date_end > 0) ? $this->date_end : ((isset($this->datee) && $this->datee > 0) ? $this->datee : 0);
2791 return ($datetouse > 0 && ($datetouse < ($now - $conf->project->task->warning_delay)));
2803 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2805 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2806 $return .=
'<div class="info-box info-box-sm info-box-kanban">';
2807 $return .=
'<span class="info-box-icon bg-infobox-action">';
2810 $return .=
'</span>';
2811 $return .=
'<div class="info-box-content">';
2812 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
2813 if ($selected >= 0) {
2814 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2816 if (!empty($arraydata[
'projectlink'])) {
2819 $return .=
'<br><span class="info-box-status ">'.$arraydata[
'projectlink'].
'</span>';
2824 if (property_exists($this,
'duration_effective')) {
2825 $return .=
'<br><div class="info-box-label progressinkanban paddingtop">'.getTaskProgressView($this,
false,
true).
'</div>';
2827 $return .=
'</div>';
2828 $return .=
'</div>';
2829 $return .=
'</div>';
2843 global $langs, $hookmanager, $user, $action;
2846 $task_origin =
new Task($this->db);
2848 dol_syslog(
"mergeTask merge task id=".$task_origin_id.
" (will be deleted) into the task id=".$this->id);
2850 $langs->load(
'error');
2852 if (!$error && $task_origin->fetch($task_origin_id) < 1) {
2853 $this->error = $langs->trans(
'ErrorRecordNotFound');
2861 $listofproperties = array(
2862 'label',
'description',
'duration_effective',
'planned_workload',
'datec',
'date_start',
2863 'date_end',
'fk_user_creat',
'fk_user_valid',
'fk_statut',
'progress',
'budget_amount',
2864 'priority',
'rang',
'fk_projet',
'fk_task_parent'
2866 foreach ($listofproperties as $property) {
2867 if (empty($this->$property)) {
2868 $this->$property = $task_origin->$property;
2873 $listofproperties = array(
2874 'note_public',
'note_private'
2876 foreach ($listofproperties as $property) {
2877 $this->$property =
dol_concatdesc($this->$property, $task_origin->$property);
2881 if (is_array($task_origin->array_options)) {
2882 foreach ($task_origin->array_options as $key => $val) {
2883 if (empty($this->array_options[$key])) {
2884 $this->array_options[$key] = $val;
2890 $result = $this->
update($user);
2899 if ($result !=
true) {
2907 if ($result !=
true) {
2914 $parameters = array(
'task_origin' => $task_origin->id,
'task_dest' => $this->id);
2915 $reshook = $hookmanager->executeHooks(
'replaceThirdparty', $parameters, $this, $action);
2918 $this->error = $hookmanager->error;
2919 $this->errors = $hookmanager->errors;
2926 $this->context = array(
'merge' => 1,
'mergefromid' => $task_origin->id,
'mergefromref' => $task_origin->ref);
2929 $result = $this->call_trigger(
'TASK_MODIFY', $user);
2938 if ($task_origin->delete($user) < 1) {
2939 $this->error = $task_origin->error;
2940 $this->errors = $task_origin->errors;
2946 $this->db->commit();
2949 $langs->load(
"errors");
2950 $this->error = $langs->trans(
'ErrorsTaskMerge');
2951 $this->db->rollback();
2971 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2972 return parent::setCategoriesCommon($categories, Categorie::TYPE_PROJECT_TASK);
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.
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.
setCategories($categories)
Sets object to task categories.
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.
const STATUS_ONGOING
Ongoing status (In progress).
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_now($mode='gmt')
Return date for now.
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)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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...
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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)