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";
456 $sql .=
") VALUES (";
457 $sql .= (!empty($this->entity) ? (int) $this->entity : (int)
$conf->entity);
458 $sql .=
", ".((int) $this->fk_project);
459 $sql .=
", ".(!empty($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
'null');
460 $sql .=
", ".((int) $this->fk_task_parent);
461 $sql .=
", '".$this->db->escape($this->label).
"'";
462 $sql .=
", '".$this->db->escape($this->
description).
"'";
463 $sql .=
", '".$this->db->escape($this->note_public).
"'";
464 $sql .=
", '".$this->db->escape($this->note_private).
"'";
465 $sql .=
", '".$this->db->idate($now).
"'";
466 $sql .=
", ".((int) $user->id);
467 $sql .=
", ".(isDolTms($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
'null');
468 $sql .=
", ".(isDolTms($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
'null');
469 $sql .=
", ".(($this->planned_workload !=
'' && $this->planned_workload >= 0) ? ((
int) $this->planned_workload) :
'null');
470 $sql .=
", ".(($this->progress !=
'' && $this->progress >= 0) ? ((
int) $this->progress) :
'null');
471 $sql .=
", ".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? ((
int) $this->budget_amount) :
'null');
472 $sql .=
", ".(($this->priority !=
'' && $this->priority >= 0) ? (
int) $this->priority :
'null');
473 $sql .=
", ".((int) $this->billable);
474 $sql .=
", ".((int) $this->
status);
479 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
480 $resql = $this->db->query($sql);
483 $this->errors[] =
"Error ".$this->db->lasterror();
487 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"projet_task");
508 foreach ($this->errors as $errmsg) {
509 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
510 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
512 $this->db->rollback();
529 public function fetch($id, $ref =
'', $loadparentdata = 0)
534 $sql .=
" t.entity,";
535 $sql .=
" t.fk_projet as fk_project,";
536 $sql .=
" t.fk_task_parent,";
538 $sql .=
" t.description,";
539 $sql .=
" t.duration_effective,";
540 $sql .=
" t.planned_workload,";
542 $sql .=
" t.dateo as date_start,";
543 $sql .=
" t.datee as date_end,";
544 $sql .=
" t.fk_user_creat,";
545 $sql .=
" t.fk_user_valid,";
546 $sql .=
" t.fk_statut as status,";
547 $sql .=
" t.progress,";
548 $sql .=
" t.budget_amount,";
549 $sql .=
" t.priority,";
550 $sql .=
" t.note_private,";
551 $sql .=
" t.note_public,";
553 $sql .=
" t.billable";
554 if (!empty($loadparentdata)) {
555 $sql .=
", t2.ref as task_parent_ref";
556 $sql .=
", t2.rang as task_parent_position";
558 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as t";
559 if (!empty($loadparentdata)) {
560 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t2 ON t.fk_task_parent = t2.rowid";
564 $sql .=
"entity IN (".getEntity(
'project').
")";
565 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
567 $sql .=
"t.rowid = ".((int) $id);
570 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
571 $resql = $this->db->query($sql);
573 $num_rows = $this->db->num_rows($resql);
576 $obj = $this->db->fetch_object($resql);
578 $this->
id = $obj->rowid;
579 $this->
ref = $obj->ref;
580 $this->entity = $obj->entity;
581 $this->fk_project = $obj->fk_project;
582 $this->fk_task_parent = $obj->fk_task_parent;
583 $this->label = $obj->label;
585 $this->duration_effective = $obj->duration_effective;
586 $this->planned_workload = $obj->planned_workload;
587 $this->date_c = $this->db->jdate($obj->datec);
588 $this->date_start = $this->db->jdate($obj->date_start);
589 $this->date_end = $this->db->jdate($obj->date_end);
590 $this->fk_user_creat = $obj->fk_user_creat;
591 $this->fk_user_valid = $obj->fk_user_valid;
592 $this->
status = $obj->status;
593 $this->progress = $obj->progress;
594 $this->budget_amount = $obj->budget_amount;
595 $this->priority = $obj->priority;
596 $this->note_private = $obj->note_private;
597 $this->note_public = $obj->note_public;
598 $this->rang = $obj->rang;
600 if (!empty($loadparentdata)) {
601 $this->task_parent_ref = $obj->task_parent_ref;
602 $this->task_parent_position = $obj->task_parent_position;
604 $this->billable = $obj->billable;
610 $this->db->free($resql);
618 $this->error =
"Error ".$this->db->lasterror();
631 public function update($user =
null, $notrigger = 0)
633 global
$conf, $langs;
637 if (isset($this->fk_project)) {
638 $this->fk_project = (int) $this->fk_project;
640 if (isset($this->
ref)) {
641 $this->
ref = trim($this->
ref);
643 if (isset($this->fk_task_parent)) {
644 $this->fk_task_parent = (int) $this->fk_task_parent;
646 if (isset($this->label)) {
647 $this->label = trim($this->label);
652 if (isset($this->note_public)) {
653 $this->note_public = trim($this->note_public);
655 if (isset($this->note_private)) {
656 $this->note_private = trim($this->note_private);
658 if (isset($this->duration_effective)) {
659 $this->duration_effective = trim($this->duration_effective);
661 if (isset($this->planned_workload)) {
662 $this->planned_workload = trim($this->planned_workload);
664 if (isset($this->budget_amount)) {
665 $this->budget_amount = (float) $this->budget_amount;
668 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
669 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
677 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
678 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
679 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"'".$this->db->escape((
string) $this->id).
"'").
",";
680 $sql .=
" fk_task_parent=".(isset($this->fk_task_parent) ? $this->fk_task_parent :
"null").
",";
681 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
682 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
683 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
684 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
685 $sql .=
" duration_effective=".(isset($this->duration_effective) ? $this->duration_effective :
"null").
",";
686 $sql .=
" planned_workload=".((isset($this->planned_workload) && $this->planned_workload !=
'') ? $this->planned_workload :
"null").
",";
687 $sql .=
" dateo=".(isDolTms($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
'null').
",";
688 $sql .=
" datee=".(isDolTms($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
'null').
",";
689 $sql .=
" progress=".(($this->progress !=
'' && $this->progress >= 0) ? $this->progress :
'null').
",";
690 $sql .=
" budget_amount=".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? $this->budget_amount :
'null').
",";
691 $sql .=
" rang=".((!empty($this->rang)) ? ((
int) $this->rang) :
"0").
",";
692 $sql .=
" priority=".((!empty($this->priority)) ? ((
int) $this->priority) :
"0").
",";
693 $sql .=
" billable=".((int) $this->billable).
",";
694 $sql .=
" fk_statut=".((int) $this->
status);
695 $sql .=
" WHERE rowid=".((int) $this->
id);
699 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
700 $resql = $this->db->query($sql);
703 $this->errors[] =
"Error ".$this->db->lasterror();
716 $project =
new Project($this->db);
717 if ($project->fetch($this->fk_project) > 0) {
719 $project->getLinesArray(
null);
720 $projectCompleted = array_reduce(
727 static function ($allTasksCompleted, $task) {
728 return $allTasksCompleted && $task->progress >= 100;
732 if ($projectCompleted) {
733 if ($project->setClose($user) <= 0) {
742 $this->errors[] = $project->error;
757 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
759 if (
$conf->project->dir_output) {
760 $project =
new Project($this->db);
761 $project->fetch($this->fk_project);
765 if (file_exists($olddir)) {
766 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
769 $langs->load(
"errors");
770 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
779 foreach ($this->errors as $errmsg) {
780 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
781 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
783 $this->db->rollback();
798 public function delete($user, $notrigger = 0)
801 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
808 dol_syslog(get_class($this).
"::delete Can't delete record as it has some sub tasks", LOG_WARNING);
809 $this->error =
'ErrorRecordHasSubTasks';
810 $this->db->rollback();
815 if (!empty($objectisused)) {
816 dol_syslog(get_class($this).
"::delete Can't delete record as it has some child", LOG_WARNING);
817 $this->error =
'ErrorRecordHasChildren';
818 $this->db->rollback();
826 $this->error =
'ErrorFailToDeleteLinkedContact';
828 $this->db->rollback();
834 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_time";
835 $sql .=
" WHERE fk_element = ".((int) $this->
id).
" AND elementtype = 'task'";
837 $resql = $this->db->query($sql);
840 $this->errors[] =
"Error ".$this->db->lasterror();
845 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_extrafields";
846 $sql .=
" WHERE fk_object = ".((int) $this->
id);
848 $resql = $this->db->query($sql);
851 $this->errors[] =
"Error ".$this->db->lasterror();
856 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task";
857 $sql .=
" WHERE rowid=".((int) $this->
id);
859 $resql = $this->db->query($sql);
862 $this->errors[] =
"Error ".$this->db->lasterror();
879 foreach ($this->errors as $errmsg) {
880 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
881 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
883 $this->db->rollback();
887 if (
$conf->project->dir_output) {
888 $projectstatic =
new Project($this->db);
889 $projectstatic->fetch($this->fk_project);
892 dol_syslog(get_class($this).
"::delete dir=".$dir, LOG_DEBUG);
893 if (file_exists($dir)) {
894 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
897 $this->error =
'ErrorFailToDeleteDir';
898 $this->db->rollback();
920 $sql =
"SELECT COUNT(*) as nb";
921 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task";
922 $sql .=
" WHERE fk_task_parent = ".((int) $this->
id);
924 dol_syslog(get_class($this).
"::hasChildren", LOG_DEBUG);
925 $resql = $this->db->query($sql);
928 $this->errors[] =
"Error ".$this->db->lasterror();
930 $obj = $this->db->fetch_object($resql);
934 $this->db->free($resql);
954 $sql =
"SELECT COUNT(*) as nb";
955 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time";
956 $sql .=
" WHERE fk_element = ".((int) $this->
id);
957 $sql .=
" AND elementtype = 'task'";
959 dol_syslog(get_class($this).
"::hasTimeSpent", LOG_DEBUG);
960 $resql = $this->db->query($sql);
963 $this->errors[] =
"Error ".$this->db->lasterror();
965 $obj = $this->db->fetch_object($resql);
969 $this->db->free($resql);
990 $langs->load(
'projects');
993 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Task").
'</u>';
994 if (!empty($this->
ref)) {
995 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
997 if (!empty($this->label)) {
998 $datas[
'label'] =
'<br><b>'.$langs->trans(
'LabelTask').
':</b> '.$this->label;
1000 if ($this->date_start || $this->date_end) {
1001 $datas[
'range'] =
"<br>".get_date_range($this->date_start, $this->date_end,
'', $langs, 0);
1019 public function getNomUrl($withpicto = 0, $option =
'', $mode =
'task', $addlabel = 0, $sep =
' - ', $notooltip = 0, $save_lastsearch_value = -1)
1021 global $action,
$conf, $hookmanager, $langs;
1023 if (!empty(
$conf->dol_no_mouse_hover)) {
1030 'objecttype' => $this->element,
1032 $classfortooltip =
'classfortooltip';
1035 $classfortooltip =
'classforajaxtooltip';
1036 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1042 $url = DOL_URL_ROOT.
'/projet/tasks/'.$mode.
'.php?id='.$this->
id.($option ==
'withproject' ?
'&withproject=1' :
'');
1044 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1045 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1046 $add_save_lastsearch_values = 1;
1048 if ($add_save_lastsearch_values) {
1049 $url .=
'&save_lastsearch_values=1';
1053 if (empty($notooltip)) {
1055 $label = $langs->trans(
"ShowTask");
1056 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1058 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1059 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' nowraponall"';
1061 $linkclose .=
' class="nowraponall"';
1064 $linkstart =
'<a href="'.$url.
'"';
1065 $linkstart .= $linkclose.
'>';
1068 $picto =
'projecttask';
1070 $result .= $linkstart;
1072 $result .=
img_object(($notooltip ?
'' : $label), $picto,
'class="paddingright"', 0, 0, $notooltip ? 0 : 1);
1074 if ($withpicto != 2) {
1075 if ($addlabel >= 0) {
1076 $result .= $this->ref;
1078 $result .= $this->label;
1081 $result .= $linkend;
1082 if ($withpicto != 2) {
1083 $result .= (($addlabel > 0 && $this->label) ?
'<span class="opacitymedium">'.$sep.dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)).
'</span>' :
'');
1086 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1087 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1089 $result = $hookmanager->resPrint;
1091 $result .= $hookmanager->resPrint;
1110 $this->fk_project = 0;
1111 $this->
ref =
'TK01';
1112 $this->fk_task_parent = 0;
1113 $this->label =
'Specimen task TK01';
1114 $this->duration_effective =
'';
1115 $this->fk_user_creat = $user->id;
1116 $this->progress = 25;
1118 $this->priority = 0;
1119 $this->note_private =
'This is a specimen private note';
1120 $this->note_public =
'This is a specimen public note';
1121 $this->billable = 1;
1149 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 =
'')
1151 global $hookmanager;
1159 if ($filteronprojuser > 0 || $filterontaskuser > 0) {
1160 $sql .=
" DISTINCT";
1162 $sql .=
" p.rowid as projectid, p.ref, p.title as plabel, p.public, p.fk_statut as projectstatus, p.usage_bill_time,";
1163 $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,";
1164 $sql .=
" t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang, t.priority,";
1165 $sql .=
" t.budget_amount, t.billable,";
1166 $sql .=
" t.note_public, t.note_private,";
1167 $sql .=
" s.rowid as thirdparty_id, s.nom as thirdparty_name, s.email as thirdparty_email,";
1168 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount as project_budget_amount";
1170 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1171 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1172 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key.
" as options_".$key :
'');
1175 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
1176 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
1177 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key.
" as options_".$key :
'');
1181 if ($includebilltime) {
1182 $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";
1185 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
1186 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1188 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_extrafields as efp ON (p.rowid = efp.fk_object)";
1192 if ($filteronprojuser > 0) {
1193 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1194 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1196 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
1198 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
1200 if ($includebilltime) {
1201 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype='task')";
1203 if ($filterontaskuser > 0) {
1204 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
1205 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
1207 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
1208 $sql .=
" AND t.fk_projet = p.rowid";
1209 } elseif ($mode == 1) {
1210 if ($filteronprojuser > 0) {
1211 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1212 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1214 if ($filterontaskuser > 0) {
1215 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
1216 if ($includebilltime) {
1217 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype='task')";
1219 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
1220 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
1222 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t on t.fk_projet = p.rowid";
1223 if ($includebilltime) {
1224 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_time as tt ON (tt.fk_element = t.rowid AND tt.elementtype = 'task')";
1227 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
1229 return 'BadValueForParameterMode';
1232 if ($filteronprojuser > 0) {
1233 $sql .=
" AND p.rowid = ec.element_id";
1234 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
1235 $sql .=
" AND ctc.element = 'project'";
1236 $sql .=
" AND ec.fk_socpeople = ".((int) $filteronprojuser);
1237 $sql .=
" AND ec.statut = 4";
1238 $sql .=
" AND ctc.source = 'internal'";
1240 if ($filterontaskuser > 0) {
1241 $sql .=
" AND t.fk_projet = p.rowid";
1242 $sql .=
" AND p.rowid = ec2.element_id";
1243 $sql .=
" AND ctc2.rowid = ec2.fk_c_type_contact";
1244 $sql .=
" AND ctc2.element = 'project_task'";
1245 $sql .=
" AND ec2.fk_socpeople = ".((int) $filterontaskuser);
1246 $sql .=
" AND ec2.statut = 4";
1247 $sql .=
" AND ctc2.source = 'internal'";
1250 $sql .=
" AND p.fk_soc = ".((int) $socid);
1253 $sql .=
" AND p.rowid IN (".$this->db->sanitize((
string) $projectid).
")";
1255 if ($filteronproj) {
1256 $sql .=
natural_search(array(
"p.ref",
"p.title"), $filteronproj);
1258 if ($filteronprojstatus && (
int) $filteronprojstatus !=
'-1') {
1259 $sql .=
" AND p.fk_statut IN (".$this->db->sanitize($filteronprojstatus).
")";
1261 if ($morewherefilter) {
1262 $sql .= $morewherefilter;
1266 $extrafieldsobjectkey =
'projet_task';
1267 $extrafieldsobjectprefix =
'efpt.';
1269 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
1272 $parameters = array();
1273 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
1274 $sql .= $hookmanager->resPrint;
1275 if ($includebilltime) {
1276 $sql .=
" GROUP BY p.rowid, p.ref, p.title, p.public, p.fk_statut, p.usage_bill_time,";
1277 $sql .=
" t.datec, t.dateo, t.datee, t.tms,";
1278 $sql .=
" t.rowid, t.ref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut,";
1279 $sql .=
" t.dateo, t.datee, t.planned_workload, t.rang, t.priority,";
1280 $sql .=
" t.budget_amount, t.billable,";
1281 $sql .=
" t.note_public, t.note_private,";
1282 $sql .=
" s.rowid, s.nom, s.email,";
1283 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount";
1285 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1286 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1287 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key :
'');
1290 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
1291 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
1292 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key :
'');
1298 if ($sortfield && $sortorder) {
1299 $sql .= $this->db->order($sortfield, $sortorder);
1301 $sql .=
" ORDER BY p.ref, t.rang, t.dateo";
1305 dol_syslog(get_class($this).
"::getTasksArray", LOG_DEBUG);
1306 $resql = $this->db->query($sql);
1308 $num = $this->db->num_rows($resql);
1314 $obj = $this->db->fetch_object($resql);
1316 if ($loadRoleMode) {
1317 if ((!$obj->public) && (is_object($userp))) {
1322 if (is_object($usert)) {
1330 $tasks[$i] =
new Task($this->db);
1331 $tasks[$i]->id = $obj->taskid;
1332 $tasks[$i]->ref = $obj->taskref;
1333 $tasks[$i]->fk_project = $obj->projectid;
1336 $tasks[$i]->projectref = $obj->ref;
1337 $tasks[$i]->projectlabel = $obj->plabel;
1338 $tasks[$i]->projectstatus = $obj->projectstatus;
1339 $tasks[$i]->fk_opp_status = $obj->fk_opp_status;
1340 $tasks[$i]->opp_amount = $obj->opp_amount;
1341 $tasks[$i]->opp_percent = $obj->opp_percent;
1342 $tasks[$i]->budget_amount = $obj->budget_amount;
1343 $tasks[$i]->project_budget_amount = $obj->project_budget_amount;
1344 $tasks[$i]->usage_bill_time = $obj->usage_bill_time;
1346 $tasks[$i]->label = $obj->label;
1347 $tasks[$i]->description = $obj->description;
1349 $tasks[$i]->fk_task_parent = $obj->fk_task_parent;
1350 $tasks[$i]->note_public = $obj->note_public;
1351 $tasks[$i]->note_private = $obj->note_private;
1352 $tasks[$i]->duration_effective = $obj->duration_effective;
1353 $tasks[$i]->planned_workload = $obj->planned_workload;
1355 if ($includebilltime) {
1357 $tasks[$i]->tobill = $obj->tobill;
1358 $tasks[$i]->billed = $obj->billed;
1361 $tasks[$i]->progress = $obj->progress;
1362 $tasks[$i]->fk_statut = $obj->status;
1363 $tasks[$i]->status = $obj->status;
1364 $tasks[$i]->public = $obj->public;
1365 $tasks[$i]->date_start = $this->db->jdate($obj->date_start);
1366 $tasks[$i]->date_end = $this->db->jdate($obj->date_end);
1367 $tasks[$i]->rang = $obj->rang;
1368 $tasks[$i]->priority = $obj->priority;
1370 $tasks[$i]->socid = $obj->thirdparty_id;
1371 $tasks[$i]->thirdparty_id = $obj->thirdparty_id;
1372 $tasks[$i]->thirdparty_name = $obj->thirdparty_name;
1373 $tasks[$i]->thirdparty_email = $obj->thirdparty_email;
1375 $tasks[$i]->billable = $obj->billable;
1378 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1379 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1380 if ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate') {
1381 $tmpvar =
'options_'.$key;
1382 $tasks[$i]->array_options_project[
'options_'.$key] = $obj->$tmpvar;
1389 $tasks[$i]->fetch_optionals();
1395 $this->db->free($resql);
1415 $arrayroles = array();
1417 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks userp=".json_encode(is_object($userp)).
" usert=".json_encode(is_object($usert)).
" projectid=".$projectid.
" taskid=".$taskid);
1420 if (empty($userp) && empty($usert)) {
1421 $this->error =
"CallWithWrongParameters";
1424 if (!empty($userp) && !empty($usert)) {
1425 $this->error =
"CallWithWrongParameters";
1432 $sql .=
" p.rowid as pid,";
1434 $sql .=
" pt.rowid as pid,";
1436 $sql .=
" ec.element_id, ctc.code, ctc.source";
1438 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
1440 if ($usert && $filteronprojstatus > -1) {
1441 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"projet_task as pt";
1443 if ($usert && $filteronprojstatus <= -1) {
1444 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as pt";
1446 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1447 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1449 $sql .=
" WHERE p.rowid = ec.element_id";
1451 $sql .=
" WHERE pt.rowid = ec.element_id";
1453 if ($userp && $filteronprojstatus > -1) {
1454 $sql .=
" AND p.fk_statut = ".((int) $filteronprojstatus);
1456 if ($usert && $filteronprojstatus > -1) {
1457 $sql .=
" AND pt.fk_projet = p.rowid AND p.fk_statut = ".((int) $filteronprojstatus);
1460 $sql .=
" AND ctc.element = 'project'";
1463 $sql .=
" AND ctc.element = 'project_task'";
1465 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
1467 $sql .=
" AND ec.fk_socpeople = ".((int) $userp->id);
1470 $sql .=
" AND ec.fk_socpeople = ".((int) $usert->id);
1472 $sql .=
" AND ec.statut = 4";
1473 $sql .=
" AND ctc.source = 'internal'";
1476 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectid).
")";
1479 $sql .=
" AND pt.fk_projet IN (".$this->db->sanitize($projectid).
")";
1484 $sql .=
" ERROR SHOULD NOT HAPPENS";
1487 $sql .=
" AND pt.rowid = ".((int) $taskid);
1492 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks execute request", LOG_DEBUG);
1493 $resql = $this->db->query($sql);
1495 $num = $this->db->num_rows($resql);
1498 $obj = $this->db->fetch_object($resql);
1499 if (empty($arrayroles[$obj->pid])) {
1500 $arrayroles[$obj->pid] = $obj->code;
1502 $arrayroles[$obj->pid] .=
','.$obj->code;
1506 $this->db->free($resql);
1523 $contactAlreadySelected = array();
1529 if ($source ==
'thirdparty') {
1530 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
1532 $contactAlreadySelected[$i] = $tab[$i][
'id'];
1536 return $contactAlreadySelected;
1549 $origintask =
new Task($this->db);
1550 $result = $origintask->fetch($origin_id);
1556 $arraycontactorigin = array_merge($origintask->liste_contact(-1,
'internal'), $origintask->liste_contact(-1,
'external'));
1557 if (is_array($arraycontactorigin)) {
1558 foreach ($arraycontactorigin as $key => $contact) {
1559 $result = $this->
add_contact($contact[
"id"], $contact[
"fk_c_type_contact"], $contact[
"source"]);
1581 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"element_time as et";
1582 $sql .=
" SET et.fk_element = ".((int) $dest_id);
1583 $sql .=
" WHERE et.elementtype = 'task'";
1584 $sql .=
" AND et.fk_element = ".((int) $origin_id);
1586 dol_syslog(get_class($this).
"::mergeTimeSpentTask", LOG_DEBUG);
1587 if (!$this->db->query($sql)) {
1588 $this->error = $this->db->lasterror();
1593 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1594 $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).
")";
1595 $sql .=
" WHERE rowid = ".((int) $dest_id);
1597 dol_syslog(get_class($this).
"::mergeTimeSpentTask update project_task", LOG_DEBUG);
1598 if (!$this->db->query($sql)) {
1599 $this->error = $this->db->lasterror();
1605 $this->db->commit();
1607 $this->db->rollback();
1623 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1629 if (!is_object($user)) {
1630 dol_print_error(
null,
"Method addTimeSpent was called with wrong parameter user");
1635 if (isset($this->timespent_note)) {
1636 $this->timespent_note = trim($this->timespent_note);
1638 if (empty($this->timespent_datehour) || ($this->timespent_date != $this->timespent_datehour)) {
1639 $this->timespent_datehour = $this->timespent_date;
1643 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1646 if ($this->timespent_date < $restrictBefore) {
1647 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack',
getDolGlobalString(
'PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS'));
1648 $this->errors[] = $this->error;
1656 $timespent->fk_element = $this->id;
1657 $timespent->elementtype =
'task';
1658 $timespent->element_date = $this->timespent_date;
1659 $timespent->element_datehour = $this->timespent_datehour;
1660 $timespent->element_date_withhour = $this->timespent_withhour;
1661 $timespent->element_duration = $this->timespent_duration;
1662 $timespent->fk_user = $this->timespent_fk_user;
1663 $timespent->fk_product = $this->timespent_fk_product;
1664 $timespent->note = $this->timespent_note;
1665 $timespent->datec = $now;
1667 $result = $timespent->create($user);
1670 $this->timespent_id = $result;
1674 $result = $this->
call_trigger(
'TASK_TIMESPENT_CREATE', $user);
1681 $this->error = $this->db->lasterror();
1687 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1688 $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).
")";
1689 if (isset($this->progress)) {
1690 $sql .=
", progress = ".((float) $this->progress);
1691 if ($this->progress == 100) {
1693 } elseif ($this->progress != 0) {
1698 $sql .=
", fk_statut = ".((int) $this->
status);
1701 $sql .=
", fk_statut = ".((int) $this->
status);
1703 $sql .=
" WHERE rowid = ".((int) $this->
id);
1705 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1706 if (!$this->db->query($sql)) {
1707 $this->error = $this->db->lasterror();
1712 $resql_thm_user = $this->db->query(
"SELECT thm FROM " . MAIN_DB_PREFIX .
"user WHERE rowid = " . ((
int) $timespent->fk_user));
1713 if (!empty($resql_thm_user)) {
1714 $obj_thm_user = $this->db->fetch_object($resql_thm_user);
1715 $timespent->thm = $obj_thm_user->thm;
1717 $res_update = $timespent->update($user);
1719 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1720 if ($res_update <= 0) {
1721 $this->error = $this->db->lasterror();
1727 $this->db->commit();
1729 $this->db->rollback();
1742 $arrayres = array();
1745 $sql .=
" s.rowid as socid,";
1746 $sql .=
" s.nom as thirdparty_name,";
1747 $sql .=
" s.email as thirdparty_email,";
1748 $sql .=
" ptt.rowid,";
1749 $sql .=
" ptt.ref_ext,";
1750 $sql .=
" ptt.fk_element as fk_task,";
1751 $sql .=
" ptt.element_date as task_date,";
1752 $sql .=
" ptt.element_datehour as task_datehour,";
1753 $sql .=
" ptt.element_date_withhour as task_date_withhour,";
1754 $sql .=
" ptt.element_duration as task_duration,";
1755 $sql .=
" ptt.fk_user,";
1756 $sql .=
" ptt.fk_product,";
1757 $sql .=
" ptt.note,";
1758 $sql .=
" ptt.thm,";
1759 $sql .=
" pt.rowid as task_id,";
1760 $sql .=
" pt.ref as task_ref,";
1761 $sql .=
" pt.label as task_label,";
1762 $sql .=
" p.rowid as project_id,";
1763 $sql .=
" p.ref as project_ref,";
1764 $sql .=
" p.title as project_label,";
1765 $sql .=
" p.public as public";
1766 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1767 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1768 $sql .=
" WHERE ptt.fk_element = pt.rowid AND pt.fk_projet = p.rowid";
1769 $sql .=
" AND ptt.elementtype = 'task'";
1770 $sql .=
" AND pt.rowid = ".((int) $this->
id);
1771 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1772 if ($morewherefilter) {
1773 $sql .= $morewherefilter;
1776 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1777 $resql = $this->db->query($sql);
1779 $num = $this->db->num_rows($resql);
1783 $obj = $this->db->fetch_object($resql);
1787 $newobj->socid = $obj->socid;
1788 $newobj->thirdparty_name = $obj->thirdparty_name;
1789 $newobj->thirdparty_email = $obj->thirdparty_email;
1791 $newobj->fk_project = $obj->project_id;
1792 $newobj->project_ref = $obj->project_ref;
1793 $newobj->project_label = $obj->project_label;
1794 $newobj->public = $obj->project_public;
1796 $newobj->fk_task = $obj->task_id;
1797 $newobj->task_ref = $obj->task_ref;
1798 $newobj->task_label = $obj->task_label;
1800 $newobj->timespent_line_id = $obj->rowid;
1801 $newobj->timespent_line_ref_ext = $obj->ref_ext;
1802 $newobj->timespent_line_date = $this->db->jdate($obj->task_date);
1803 $newobj->timespent_line_datehour = $this->db->jdate($obj->task_datehour);
1804 $newobj->timespent_line_withhour = $obj->task_date_withhour;
1805 $newobj->timespent_line_duration = $obj->task_duration;
1806 $newobj->timespent_line_fk_user = $obj->fk_user;
1807 $newobj->timespent_line_fk_product = $obj->fk_product;
1808 $newobj->timespent_line_thm = $obj->thm;
1809 $newobj->timespent_line_note = $obj->note;
1811 $arrayres[] = $newobj;
1816 $this->db->free($resql);
1818 $this->lines = $arrayres;
1822 $this->error =
"Error ".$this->db->lasterror();
1837 if (is_object($userobj)) {
1838 $userid = $userobj->id;
1844 if (empty($id) && empty($userid)) {
1845 dol_syslog(
"getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR);
1852 $sql .=
" MIN(t.element_datehour) as min_date,";
1853 $sql .=
" MAX(t.element_datehour) as max_date,";
1854 $sql .=
" SUM(t.element_duration) as total_duration,";
1855 $sql .=
" SUM(t.element_duration / 3600 * ".$this->db->ifsql(
"t.thm IS NULL",
'0',
"t.thm").
") as total_amount,";
1856 $sql .=
" COUNT(t.rowid) as nblines,";
1857 $sql .=
" SUM(".$this->db->ifsql(
"t.thm IS NULL",
'1',
'0').
") as nblinesnull";
1858 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as t";
1859 $sql .=
" WHERE t.elementtype='task'";
1860 if ($morewherefilter) {
1861 $sql .= $morewherefilter;
1864 $sql .=
" AND t.fk_element = ".((int) $id);
1867 $sql .=
" AND t.fk_user = ".((int) $userid);
1870 dol_syslog(get_class($this).
"::getSummaryOfTimeSpent", LOG_DEBUG);
1871 $resql = $this->db->query($sql);
1873 $obj = $this->db->fetch_object($resql);
1875 $result[
'min_date'] = $obj->min_date;
1876 $result[
'max_date'] = $obj->max_date;
1877 $result[
'total_duration'] = $obj->total_duration;
1879 $this->timespent_min_date = $this->db->jdate($obj->min_date);
1880 $this->timespent_max_date = $this->db->jdate($obj->max_date);
1881 $this->timespent_total_duration = $obj->total_duration;
1882 $this->timespent_total_amount = $obj->total_amount;
1883 $this->timespent_nblinesnull = ($obj->nblinesnull ? $obj->nblinesnull : 0);
1884 $this->timespent_nblines = ($obj->nblines ? $obj->nblines : 0);
1886 $this->db->free($resql);
1908 $sql .=
" SUM(t.element_duration) as nbseconds,";
1909 $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";
1910 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as t";
1911 $sql .=
" WHERE t.elementtype='task' AND t.fk_element = ".((int) $id);
1912 if (is_object($fuser) && $fuser->id > 0) {
1913 $sql .=
" AND fk_user = ".((int) $fuser->id);
1916 $datefieldname =
"element_datehour";
1917 $sql .=
" AND (".$datefieldname.
" >= '".$this->db->idate((
int) $dates).
"' OR ".$datefieldname.
" IS NULL)";
1920 $datefieldname =
"element_datehour";
1921 $sql .=
" AND (".$datefieldname.
" <= '".$this->db->idate((
int) $datee).
"' OR ".$datefieldname.
" IS NULL)";
1925 dol_syslog(get_class($this).
"::getSumOfAmount", LOG_DEBUG);
1926 $resql = $this->db->query($sql);
1928 $obj = $this->db->fetch_object($resql);
1930 $result[
'amount'] = $obj->amount;
1931 $result[
'nbseconds'] = $obj->nbseconds;
1932 $result[
'nblinesnull'] = $obj->nblinesnull;
1934 $this->db->free($resql);
1951 $timespent->fetch($id);
1953 dol_syslog(get_class($this).
"::fetchTimeSpent", LOG_DEBUG);
1955 if ($timespent->id > 0) {
1956 $this->timespent_id = $timespent->id;
1957 $this->
id = $timespent->fk_element;
1958 $this->timespent_date = $timespent->element_date;
1959 $this->timespent_datehour = $timespent->element_datehour;
1960 $this->timespent_withhour = $timespent->element_date_withhour;
1961 $this->timespent_duration = $timespent->element_duration;
1962 $this->timespent_fk_user = $timespent->fk_user;
1963 $this->timespent_fk_product = $timespent->fk_product;
1964 $this->timespent_thm = $timespent->thm;
1965 $this->timespent_note = $timespent->note;
1982 $arrayres = array();
1985 $sql .=
" s.rowid as socid,";
1986 $sql .=
" s.nom as thirdparty_name,";
1987 $sql .=
" s.email as thirdparty_email,";
1988 $sql .=
" ptt.rowid,";
1989 $sql .=
" ptt.fk_element as fk_task,";
1990 $sql .=
" ptt.element_date as task_date,";
1991 $sql .=
" ptt.element_datehour as task_datehour,";
1992 $sql .=
" ptt.element_date_withhour as task_date_withhour,";
1993 $sql .=
" ptt.element_duration as task_duration,";
1994 $sql .=
" ptt.fk_user,";
1995 $sql .=
" ptt.note,";
1996 $sql .=
" ptt.thm,";
1997 $sql .=
" pt.rowid as task_id,";
1998 $sql .=
" pt.ref as task_ref,";
1999 $sql .=
" pt.label as task_label,";
2000 $sql .=
" p.rowid as project_id,";
2001 $sql .=
" p.ref as project_ref,";
2002 $sql .=
" p.title as project_label,";
2003 $sql .=
" p.public as public";
2004 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
2005 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
2006 $sql .=
" WHERE ptt.fk_element = pt.rowid AND pt.fk_projet = p.rowid";
2007 $sql .=
" AND ptt.elementtype = 'task'";
2008 $sql .=
" AND ptt.fk_user = ".((int) $userobj->id);
2009 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
2010 if ($morewherefilter) {
2011 $sql .= $morewherefilter;
2014 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
2015 $resql = $this->db->query($sql);
2017 $num = $this->db->num_rows($resql);
2021 $obj = $this->db->fetch_object($resql);
2025 $newobj->socid = $obj->socid;
2026 $newobj->thirdparty_name = $obj->thirdparty_name;
2027 $newobj->thirdparty_email = $obj->thirdparty_email;
2029 $newobj->fk_project = $obj->project_id;
2030 $newobj->project_ref = $obj->project_ref;
2031 $newobj->project_label = $obj->project_label;
2032 $newobj->public = $obj->project_public;
2034 $newobj->fk_task = $obj->task_id;
2035 $newobj->task_ref = $obj->task_ref;
2036 $newobj->task_label = $obj->task_label;
2038 $newobj->timespent_id = $obj->rowid;
2039 $newobj->timespent_date = $this->db->jdate($obj->task_date);
2040 $newobj->timespent_datehour = $this->db->jdate($obj->task_datehour);
2041 $newobj->timespent_withhour = $obj->task_date_withhour;
2042 $newobj->timespent_duration = $obj->task_duration;
2043 $newobj->timespent_fk_user = $obj->fk_user;
2044 $newobj->timespent_thm = $obj->thm;
2045 $newobj->timespent_note = $obj->note;
2047 $arrayres[] = $newobj;
2052 $this->db->free($resql);
2055 $this->error =
"Error ".$this->db->lasterror();
2071 global
$conf, $langs;
2076 if ($this->timespent_date ==
'') {
2077 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date"));
2082 if (empty($this->timespent_datehour) || ($this->timespent_date != $this->timespent_datehour)) {
2083 $this->timespent_datehour = $this->timespent_date;
2085 if (isset($this->timespent_note)) {
2086 $this->timespent_note = trim($this->timespent_note);
2090 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2093 if ($this->timespent_date < $restrictBefore) {
2094 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack',
getDolGlobalString(
'PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS'));
2095 $this->errors[] = $this->error;
2103 $timespent->fetch($this->timespent_id);
2104 $old_fk_element = $timespent->fk_element;
2106 $timespent->element_date = $this->timespent_date;
2107 $timespent->element_datehour = $this->timespent_datehour;
2108 $timespent->element_date_withhour = $this->timespent_withhour;
2109 $timespent->element_duration = $this->timespent_duration;
2110 if ($this->timespent_fk_user > 0) {
2111 $timespent->fk_user = $this->timespent_fk_user;
2113 $timespent->fk_product = $this->timespent_fk_product;
2114 $timespent->fk_element = $this->id;
2115 $timespent->note = $this->timespent_note;
2116 $timespent->invoice_id = $this->timespent_invoiceid;
2117 $timespent->invoice_line_id = $this->timespent_invoicelineid;
2119 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
2120 if ($timespent->update($user) > 0) {
2123 $result = $this->
call_trigger(
'TASK_TIMESPENT_MODIFY', $user);
2125 $this->db->rollback();
2135 $this->error = $this->db->lasterror();
2136 $this->db->rollback();
2140 if ($ret == 1 && (($this->timespent_old_duration != $this->timespent_duration) ||
getDolGlobalString(
'TIMESPENT_ALWAYS_UPDATE_THM'))) {
2141 if ($this->timespent_old_duration != $this->timespent_duration) {
2143 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"projet_task";
2144 $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) .
")";
2145 if (isset($this->progress)) {
2146 $sql .=
", progress = " . ((float) $this->progress);
2148 $sql .=
" WHERE rowid = " . ((int) $this->
id);
2150 dol_syslog(get_class($this) .
"::updateTimeSpent", LOG_DEBUG);
2151 if (!$this->db->query($sql)) {
2152 $this->error = $this->db->lasterror();
2153 $this->db->rollback();
2161 $resql_thm_user = $this->db->query(
"SELECT thm FROM " . MAIN_DB_PREFIX .
"user WHERE rowid = " . ((
int) $timespent->fk_user));
2162 if (!empty($resql_thm_user)) {
2163 $obj_thm_user = $this->db->fetch_object($resql_thm_user);
2164 $timespent->thm = $obj_thm_user->thm;
2166 $res_update = $timespent->update($user);
2169 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
2170 if ($res_update <= 0) {
2171 $this->error = $this->db->lasterror();
2177 if ($ret == 1 && $old_fk_element != $this->
id) {
2179 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"projet_task";
2180 $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) .
")";
2181 $sql .=
" WHERE rowid = " . ((int) $old_fk_element);
2182 dol_syslog(get_class($this) .
"::updateTimeSpent update old task", LOG_DEBUG);
2183 if (!$this->db->query($sql)) {
2184 $this->error = $this->db->lasterror();
2185 $this->db->rollback();
2190 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"projet_task";
2191 $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) .
")";
2192 $sql .=
" WHERE rowid = " . ((int) $this->
id);
2193 dol_syslog(get_class($this) .
"::updateTimeSpent update new task", LOG_DEBUG);
2194 if (!$this->db->query($sql)) {
2195 $this->error = $this->db->lasterror();
2196 $this->db->rollback();
2203 $this->db->commit();
2217 global
$conf, $langs;
2222 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2225 if ($this->timespent_date < $restrictBefore) {
2226 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack',
getDolGlobalString(
'PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS'));
2227 $this->errors[] = $this->error;
2236 $result = $this->
call_trigger(
'TASK_TIMESPENT_DELETE', $user);
2245 $timespent->fetch($this->timespent_id);
2247 $res_del = $timespent->delete($user);
2251 $this->errors[] =
"Error ".$this->db->lasterror();
2256 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
2257 $sql .=
" SET duration_effective = duration_effective - ".$this->db->escape($this->timespent_duration ? (
string) $this->timespent_duration :
'0');
2258 $sql .=
" WHERE rowid = ".((int) $this->
id);
2260 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
2261 if ($this->db->query($sql)) {
2264 $this->error = $this->db->lasterror();
2271 foreach ($this->errors as $errmsg) {
2272 dol_syslog(get_class($this).
"::delTimeSpent ".$errmsg, LOG_ERR);
2273 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2275 $this->db->rollback();
2278 $this->db->commit();
2297 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)
2299 global $langs,
$conf;
2308 $clone_task =
new Task($this->db);
2309 $origin_task =
new Task($this->db);
2311 $clone_task->context[
'createfromclone'] =
'createfromclone';
2316 $clone_task->fetch($fromid);
2317 $clone_task->fetch_optionals();
2320 $origin_task->fetch($fromid);
2325 require_once DOL_DOCUMENT_ROOT.
"/core/modules/project/task/" .
getDolGlobalString(
'PROJECT_TASK_ADDON').
'.php';
2326 $modTask =
new $obj();
2327 '@phan-var-force ModeleNumRefTask $modTask';
2328 $defaultref = $modTask->getNextValue(
null, $clone_task);
2331 $ori_project_id = $clone_task->fk_project;
2333 $clone_task->id = 0;
2334 $clone_task->ref = $defaultref;
2335 $clone_task->fk_project = $project_id;
2336 $clone_task->fk_task_parent = $parent_task_id;
2337 $clone_task->date_c = $datec;
2338 $clone_task->planned_workload = $origin_task->planned_workload;
2339 $clone_task->rang = $origin_task->rang;
2340 $clone_task->priority = $origin_task->priority;
2343 if ($clone_change_dt) {
2344 $projectstatic =
new Project($this->db);
2345 $projectstatic->fetch($ori_project_id);
2348 $orign_project_dt_start = (!isset($projectstatic->date_start) || $projectstatic->date_start ==
'') ? $projectstatic->date_c : $projectstatic->date_start;
2351 if (!empty($clone_task->date_start)) {
2352 $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
2356 if (!empty($clone_task->date_end)) {
2357 $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
2362 $clone_task->progress = 0;
2366 $result = $clone_task->create($user);
2370 $this->error = $clone_task->error;
2377 $clone_task_id = $clone_task->id;
2378 $clone_task_ref = $clone_task->ref;
2382 $clone_task->note_private =
'';
2383 $clone_task->note_public =
'';
2386 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_public, ENT_QUOTES | ENT_HTML5),
'_public');
2388 $this->error .= $clone_task->error;
2390 $this->db->rollback();
2392 $this->db->commit();
2396 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_private, ENT_QUOTES | ENT_HTML5),
'_private');
2398 $this->error .= $clone_task->error;
2400 $this->db->rollback();
2402 $this->db->commit();
2408 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2411 $projectstatic =
new Project($this->db);
2412 $projectstatic->fetch($ori_project_id);
2413 $ori_project_ref = $projectstatic->ref;
2415 if ($ori_project_id != $project_id) {
2416 $projectstatic->fetch($project_id);
2417 $clone_project_ref = $projectstatic->ref;
2419 $clone_project_ref = $ori_project_ref;
2425 $filearray =
dol_dir_list($ori_task_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'', SORT_ASC, 1);
2426 foreach ($filearray as $file) {
2427 if (!file_exists($clone_task_dir)) {
2429 $this->error .= $langs->trans(
'ErrorInternalErrorDetected').
':dol_mkdir';
2434 $rescopy =
dol_copy($ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name'],
'0', 1);
2435 if (is_numeric($rescopy) && $rescopy < 0) {
2436 $this->error .= $langs->trans(
"ErrorFailToCopyFile", $ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name']);
2443 if ($clone_affectation) {
2444 $origin_task =
new Task($this->db);
2445 $origin_task->fetch($fromid);
2447 foreach (array(
'internal',
'external') as $source) {
2448 $tab = $origin_task->liste_contact(-1, $source);
2452 $clone_task->add_contact($tab[$i][
'id'], $tab[$i][
'code'], $tab[$i][
'source']);
2453 if ($clone_task->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2454 $langs->load(
"errors");
2455 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
2458 if ($clone_task->error !=
'') {
2459 $this->error .= $clone_task->error;
2473 unset($clone_task->context[
'createfromclone']);
2476 $this->db->commit();
2477 return $clone_task_id;
2479 $this->db->rollback();
2480 dol_syslog(get_class($this).
"::createFromClone nbError: ".$error.
" error : ".$this->error, LOG_ERR);
2511 return $langs->trans($this->labelStatus[$status]);
2512 } elseif ($mode == 1) {
2513 return $langs->trans($this->labelStatusShort[$status]);
2514 } elseif ($mode == 2) {
2517 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut0').
' '.$langs->trans($this->labelStatusShort[$status]);
2519 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut1').
' '.$langs->trans($this->labelStatusShort[$status]);
2521 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut3').
' '.$langs->trans($this->labelStatusShort[$status]);
2523 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6').
' '.$langs->trans($this->labelStatusShort[$status]);
2525 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6').
' '.$langs->trans($this->labelStatusShort[$status]);
2527 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut5').
' '.$langs->trans($this->labelStatusShort[$status]);
2529 } elseif ($mode == 3) {
2532 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut0');
2534 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut1');
2536 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut3');
2538 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6');
2540 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut6');
2542 return img_picto($langs->trans($this->labelStatusShort[$status]),
'statut5');
2544 } elseif ($mode == 4) {
2547 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status0', $mode);
2549 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status1', $mode);
2551 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status3', $mode);
2553 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status6', $mode);
2555 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status6', $mode);
2557 return dolGetStatus($langs->trans($this->labelStatus[$status]), $langs->trans($this->labelStatusShort[$status]),
'',
'status5', $mode);
2559 } elseif ($mode == 5) {
2569 } elseif ($mode == 6) {
2593 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2595 $outputlangs->load(
"projects");
2598 $modele =
'nodefault';
2600 if (!empty($this->model_pdf)) {
2601 $modele = $this->model_pdf;
2607 $modelpath =
"core/modules/project/task/doc/";
2609 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2623 global
$conf, $langs;
2629 $projectstatic =
new Project($this->db);
2630 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
2633 $sql =
"SELECT p.rowid as projectid, p.fk_statut as projectstatus,";
2634 $sql .=
" t.rowid as taskid, t.progress as progress, t.fk_statut as status,";
2635 $sql .=
" t.dateo as date_start, t.datee as date_end";
2636 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2639 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2640 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2641 $sql .=
" AND p.fk_statut = 1";
2642 $sql .=
" AND t.fk_projet = p.rowid";
2643 $sql .=
" AND (t.progress IS NULL OR t.progress < 100)";
2644 if (!$user->hasRight(
'projet',
'all',
'lire')) {
2645 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2653 $resql = $this->db->query($sql);
2655 $task_static =
new Task($this->db);
2658 $response->warning_delay =
$conf->project->task->warning_delay / 60 / 60 / 24;
2659 $response->label = $langs->trans(
"OpenedTasks");
2660 if ($user->hasRight(
"projet",
"all",
"lire")) {
2661 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mainmenu=project';
2663 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mode=mine&mainmenu=project';
2668 while ($obj = $this->db->fetch_object($resql)) {
2669 $response->nbtodo++;
2671 $task_static->projectstatus = $obj->projectstatus;
2672 $task_static->progress = $obj->progress;
2673 $task_static->fk_statut = $obj->status;
2674 $task_static->status = $obj->status;
2675 $task_static->date_start = $this->db->jdate($obj->date_start);
2676 $task_static->date_end = $this->db->jdate($obj->date_end);
2678 if ($task_static->hasDelay()) {
2679 $response->nbtodolate++;
2685 $this->error = $this->db->error();
2701 $socid = $user->socid;
2703 $projectstatic =
new Project($this->db);
2704 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $mine, 1, $socid);
2707 $sql =
"SELECT count(p.rowid) as nb";
2708 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2709 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
2710 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2711 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2713 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2714 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2715 $sql .=
" AND t.fk_projet = p.rowid";
2716 if ($mine || !$user->hasRight(
'projet',
'all',
'lire')) {
2717 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2722 $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).
")";
2724 if (!$user->hasRight(
'societe',
'client',
'voir')) {
2725 $sql .=
" AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).
") OR (s.rowid IS NULL))";
2728 $resql = $this->db->query($sql);
2731 while ($obj = $this->db->fetch_object($resql)) {
2732 $this->nb[
"tasks"] = $obj->nb;
2734 $this->db->free($resql);
2738 $this->error = $this->db->error();
2752 if (!($this->progress >= 0 && $this->progress < 100)) {
2758 $datetouse = ($this->date_end > 0) ? $this->date_end : ((isset($this->datee) && $this->datee > 0) ? $this->datee : 0);
2760 return ($datetouse > 0 && ($datetouse < ($now -
$conf->project->task->warning_delay)));
2772 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2774 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2775 $return .=
'<div class="info-box info-box-sm info-box-kanban">';
2776 $return .=
'<span class="info-box-icon bg-infobox-action">';
2779 $return .=
'</span>';
2780 $return .=
'<div class="info-box-content">';
2781 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
2782 if ($selected >= 0) {
2783 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2785 if (!empty($arraydata[
'projectlink'])) {
2788 $return .=
'<br><span class="info-box-status ">'.$arraydata[
'projectlink'].
'</span>';
2793 if (property_exists($this,
'duration_effective')) {
2794 $return .=
'<br><div class="info-box-label progressinkanban paddingtop">'.getTaskProgressView($this,
false,
true).
'</div>';
2796 $return .=
'</div>';
2797 $return .=
'</div>';
2798 $return .=
'</div>';
2812 global $langs, $hookmanager, $user, $action;
2815 $task_origin =
new Task($this->db);
2817 dol_syslog(
"mergeTask merge task id=".$task_origin_id.
" (will be deleted) into the task id=".$this->id);
2819 $langs->load(
'error');
2821 if (!$error && $task_origin->fetch($task_origin_id) < 1) {
2822 $this->error = $langs->trans(
'ErrorRecordNotFound');
2830 $listofproperties = array(
2831 'label',
'description',
'duration_effective',
'planned_workload',
'datec',
'date_start',
2832 'date_end',
'fk_user_creat',
'fk_user_valid',
'fk_statut',
'progress',
'budget_amount',
2833 'priority',
'rang',
'fk_projet',
'fk_task_parent'
2835 foreach ($listofproperties as $property) {
2836 if (empty($this->$property)) {
2837 $this->$property = $task_origin->$property;
2842 $listofproperties = array(
2843 'note_public',
'note_private'
2845 foreach ($listofproperties as $property) {
2846 $this->$property =
dol_concatdesc($this->$property, $task_origin->$property);
2850 if (is_array($task_origin->array_options)) {
2851 foreach ($task_origin->array_options as $key => $val) {
2852 if (empty($this->array_options[$key])) {
2853 $this->array_options[$key] = $val;
2859 $result = $this->
update($user);
2868 if ($result !=
true) {
2876 if ($result !=
true) {
2883 $parameters = array(
'task_origin' => $task_origin->id,
'task_dest' => $this->id);
2884 $reshook = $hookmanager->executeHooks(
'replaceThirdparty', $parameters, $this, $action);
2887 $this->error = $hookmanager->error;
2888 $this->errors = $hookmanager->errors;
2895 $this->context = array(
'merge' => 1,
'mergefromid' => $task_origin->id,
'mergefromref' => $task_origin->ref);
2907 if ($task_origin->delete($user) < 1) {
2908 $this->error = $task_origin->error;
2909 $this->errors = $task_origin->errors;
2915 $this->db->commit();
2918 $langs->load(
"errors");
2919 $this->error = $langs->trans(
'ErrorsTaskMerge');
2920 $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.
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_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...
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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...