29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
42 public $element =
'project_task';
47 public $table_element =
'projet_task';
52 public $fk_element =
'fk_task';
57 public $picto =
'projecttask';
62 protected $childtables = array(
63 'projet_task_time' => array(
'name' =>
'Task',
'parent' =>
'projet_task',
'parentkey' =>
'fk_task')
69 public $fk_task_parent = 0;
81 public $duration_effective;
82 public $planned_workload;
103 public $fk_user_creat;
108 public $fk_user_valid;
112 public $timespent_min_date;
113 public $timespent_max_date;
114 public $timespent_total_duration;
115 public $timespent_total_amount;
116 public $timespent_nblinesnull;
117 public $timespent_nblines;
121 public $timespent_id;
122 public $timespent_duration;
123 public $timespent_old_duration;
124 public $timespent_date;
125 public $timespent_datehour;
126 public $timespent_withhour;
127 public $timespent_fk_user;
128 public $timespent_thm;
129 public $timespent_note;
131 public $comments = array();
136 public $budget_amount;
141 public $project_budget_amount;
164 public function create($user, $notrigger = 0)
166 global $conf, $langs;
174 $this->label = trim($this->label);
177 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
178 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
186 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet_task (";
188 $sql .=
", fk_projet";
190 $sql .=
", fk_task_parent";
192 $sql .=
", description";
194 $sql .=
", fk_user_creat";
197 $sql .=
", planned_workload";
198 $sql .=
", progress";
199 $sql .=
", budget_amount";
200 $sql .=
") VALUES (";
201 $sql .= ((int) $conf->entity);
202 $sql .=
", ".((int) $this->fk_project);
203 $sql .=
", ".(!empty($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
'null');
204 $sql .=
", ".((int) $this->fk_task_parent);
205 $sql .=
", '".$this->db->escape($this->label).
"'";
206 $sql .=
", '".$this->db->escape($this->
description).
"'";
207 $sql .=
", '".$this->db->idate($now).
"'";
208 $sql .=
", ".((int) $user->id);
209 $sql .=
", ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
'null');
210 $sql .=
", ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
'null');
211 $sql .=
", ".(($this->planned_workload !=
'' && $this->planned_workload >= 0) ? ((
int) $this->planned_workload) :
'null');
212 $sql .=
", ".(($this->progress !=
'' && $this->progress >= 0) ? ((
int) $this->progress) :
'null');
213 $sql .=
", ".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? ((
int) $this->budget_amount) :
'null');
218 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
221 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
225 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"projet_task");
249 foreach ($this->errors as $errmsg) {
250 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
251 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
253 $this->
db->rollback();
270 public function fetch($id, $ref =
'', $loadparentdata = 0)
272 global $langs, $conf;
277 $sql .=
" t.fk_projet as fk_project,";
278 $sql .=
" t.fk_task_parent,";
280 $sql .=
" t.description,";
281 $sql .=
" t.duration_effective,";
282 $sql .=
" t.planned_workload,";
286 $sql .=
" t.fk_user_creat,";
287 $sql .=
" t.fk_user_valid,";
288 $sql .=
" t.fk_statut,";
289 $sql .=
" t.progress,";
290 $sql .=
" t.budget_amount,";
291 $sql .=
" t.priority,";
292 $sql .=
" t.note_private,";
293 $sql .=
" t.note_public,";
295 if (!empty($loadparentdata)) {
296 $sql .=
", t2.ref as task_parent_ref";
297 $sql .=
", t2.rang as task_parent_position";
299 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as t";
300 if (!empty($loadparentdata)) {
301 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t2 ON t.fk_task_parent = t2.rowid";
305 $sql .=
"entity IN (".getEntity(
'project').
")";
306 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
308 $sql .=
"t.rowid = ".((int) $id);
311 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
314 $num_rows = $this->
db->num_rows(
$resql);
317 $obj = $this->
db->fetch_object(
$resql);
319 $this->
id = $obj->rowid;
320 $this->
ref = $obj->ref;
321 $this->fk_project = $obj->fk_project;
322 $this->fk_task_parent = $obj->fk_task_parent;
323 $this->label = $obj->label;
325 $this->duration_effective = $obj->duration_effective;
326 $this->planned_workload = $obj->planned_workload;
327 $this->date_c = $this->
db->jdate($obj->datec);
328 $this->date_start = $this->
db->jdate($obj->dateo);
329 $this->date_end = $this->
db->jdate($obj->datee);
330 $this->fk_user_creat = $obj->fk_user_creat;
331 $this->fk_user_valid = $obj->fk_user_valid;
332 $this->fk_statut = $obj->fk_statut;
333 $this->progress = $obj->progress;
334 $this->budget_amount = $obj->budget_amount;
335 $this->priority = $obj->priority;
336 $this->note_private = $obj->note_private;
337 $this->note_public = $obj->note_public;
338 $this->rang = $obj->rang;
340 if (!empty($loadparentdata)) {
341 $this->task_parent_ref = $obj->task_parent_ref;
342 $this->task_parent_position = $obj->task_parent_position;
357 $this->error =
"Error ".$this->db->lasterror();
370 public function update($user = null, $notrigger = 0)
372 global $conf, $langs;
376 if (isset($this->fk_project)) {
377 $this->fk_project = trim($this->fk_project);
379 if (isset($this->
ref)) {
380 $this->
ref = trim($this->
ref);
382 if (isset($this->fk_task_parent)) {
383 $this->fk_task_parent = (int) $this->fk_task_parent;
385 if (isset($this->label)) {
386 $this->label = trim($this->label);
391 if (isset($this->duration_effective)) {
392 $this->duration_effective = trim($this->duration_effective);
394 if (isset($this->planned_workload)) {
395 $this->planned_workload = trim($this->planned_workload);
397 if (isset($this->budget_amount)) {
398 $this->budget_amount = trim($this->budget_amount);
401 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
402 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
410 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
411 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
412 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"'".$this->db->escape($this->
id).
"'").
",";
413 $sql .=
" fk_task_parent=".(isset($this->fk_task_parent) ? $this->fk_task_parent :
"null").
",";
414 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
415 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
416 $sql .=
" duration_effective=".(isset($this->duration_effective) ? $this->duration_effective :
"null").
",";
417 $sql .=
" planned_workload=".((isset($this->planned_workload) && $this->planned_workload !=
'') ? $this->planned_workload :
"null").
",";
418 $sql .=
" dateo=".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
'null').
",";
419 $sql .=
" datee=".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
'null').
",";
420 $sql .=
" progress=".(($this->progress !=
'' && $this->progress >= 0) ? $this->progress :
'null').
",";
421 $sql .=
" budget_amount=".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? $this->budget_amount :
'null').
",";
422 $sql .=
" rang=".((!empty($this->rang)) ? $this->rang :
"0");
423 $sql .=
" WHERE rowid=".((int) $this->
id);
427 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
430 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
441 if (!$error && !empty($conf->global->PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE)) {
444 if ($project->fetch($this->fk_project) > 0) {
446 $project->getLinesArray(null);
447 $projectCompleted = array_reduce(
449 function ($allTasksCompleted, $task) {
450 return $allTasksCompleted && $task->progress >= 100;
454 if ($projectCompleted) {
455 if ($project->setClose($user) <= 0) {
464 $this->errors[] = $project->error;
479 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
481 if ($conf->project->dir_output) {
483 $project->fetch($this->fk_project);
487 if (file_exists($olddir)) {
488 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
491 $langs->load(
"errors");
492 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
501 foreach ($this->errors as $errmsg) {
502 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
503 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
505 $this->
db->rollback();
521 public function delete($user, $notrigger = 0)
524 global $conf, $langs;
525 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
532 dol_syslog(get_class($this).
"::delete Can't delete record as it has some sub tasks", LOG_WARNING);
533 $this->error =
'ErrorRecordHasSubTasks';
534 $this->
db->rollback();
539 if (!empty($objectisused)) {
540 dol_syslog(get_class($this).
"::delete Can't delete record as it has some child", LOG_WARNING);
541 $this->error =
'ErrorRecordHasChildren';
542 $this->
db->rollback();
550 $this->error =
'ErrorFailToDeleteLinkedContact';
552 $this->
db->rollback();
558 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_time";
559 $sql .=
" WHERE fk_task = ".((int) $this->
id);
563 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
568 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_extrafields";
569 $sql .=
" WHERE fk_object = ".((int) $this->
id);
573 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
578 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task";
579 $sql .=
" WHERE rowid=".((int) $this->
id);
583 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
600 foreach ($this->errors as $errmsg) {
601 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
602 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
604 $this->
db->rollback();
608 if ($conf->project->dir_output) {
610 $projectstatic->fetch($this->fk_project);
613 dol_syslog(get_class($this).
"::delete dir=".$dir, LOG_DEBUG);
614 if (file_exists($dir)) {
615 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
618 $this->error =
'ErrorFailToDeleteDir';
619 $this->
db->rollback();
641 $sql =
"SELECT COUNT(*) as nb";
642 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task";
643 $sql .=
" WHERE fk_task_parent = ".((int) $this->
id);
645 dol_syslog(get_class($this).
"::hasChildren", LOG_DEBUG);
648 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
650 $obj = $this->
db->fetch_object(
$resql);
674 $sql =
"SELECT COUNT(*) as nb";
675 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time";
676 $sql .=
" WHERE fk_task = ".((int) $this->
id);
678 dol_syslog(get_class($this).
"::hasTimeSpent", LOG_DEBUG);
681 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
683 $obj = $this->
db->fetch_object(
$resql);
710 public function getNomUrl($withpicto = 0, $option =
'', $mode =
'task', $addlabel = 0, $sep =
' - ', $notooltip = 0, $save_lastsearch_value = -1)
712 global $conf, $langs, $user;
714 if (!empty($conf->dol_no_mouse_hover)) {
719 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Task").
'</u>';
720 if (!empty($this->
ref)) {
721 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
723 if (!empty($this->label)) {
724 $label .=
'<br><b>'.$langs->trans(
'LabelTask').
':</b> '.$this->label;
726 if ($this->date_start || $this->date_end) {
727 $label .=
"<br>".get_date_range($this->date_start, $this->date_end,
'', $langs, 0);
730 $url = DOL_URL_ROOT.
'/projet/tasks/'.$mode.
'.php?id='.$this->
id.($option ==
'withproject' ?
'&withproject=1' :
'');
732 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
733 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
734 $add_save_lastsearch_values = 1;
736 if ($add_save_lastsearch_values) {
737 $url .=
'&save_lastsearch_values=1';
741 if (empty($notooltip)) {
742 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
743 $label = $langs->trans(
"ShowTask");
744 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
746 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
747 $linkclose .=
' class="classfortooltip nowraponall"';
749 $linkclose .=
' class="nowraponall"';
752 $linkstart =
'<a href="'.$url.
'"';
753 $linkstart .= $linkclose.
'>';
756 $picto =
'projecttask';
758 $result .= $linkstart;
760 $result .=
img_object(($notooltip ?
'' : $label), $picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
762 if ($withpicto != 2) {
763 $result .= $this->ref;
766 if ($withpicto != 2) {
767 $result .= (($addlabel && $this->label) ? $sep.dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) :
'');
784 $this->fk_project =
'';
786 $this->fk_task_parent = null;
787 $this->label =
'Specimen task TK01';
788 $this->duration_effective =
'';
789 $this->fk_user_creat = null;
790 $this->progress =
'25';
791 $this->fk_statut = null;
792 $this->note =
'This is a specimen task not';
815 public function getTasksArray($usert = null, $userp = null, $projectid = 0, $socid = 0, $mode = 0, $filteronproj =
'', $filteronprojstatus =
'-1', $morewherefilter =
'', $filteronprojuser = 0, $filterontaskuser = 0, $extrafields = array(), $includebilltime = 0, $search_array_options = array(), $loadextras = 0)
817 global $conf, $hookmanager;
825 if ($filteronprojuser > 0 || $filterontaskuser > 0) {
828 $sql .=
" p.rowid as projectid, p.ref, p.title as plabel, p.public, p.fk_statut as projectstatus, p.usage_bill_time,";
829 $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,";
830 $sql .=
" t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang,";
831 $sql .=
" t.description, ";
832 $sql .=
" t.budget_amount, ";
833 $sql .=
" s.rowid as thirdparty_id, s.nom as thirdparty_name, s.email as thirdparty_email,";
834 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount as project_budget_amount";
835 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
836 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
837 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key.
" as options_".$key :
'');
840 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
841 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
842 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key.
" as options_".$key :
'');
845 if ($includebilltime) {
846 $sql .=
", SUM(tt.task_duration * ".$this->db->ifsql(
"invoice_id IS NULL",
"1",
"0").
") as tobill, SUM(tt.task_duration * ".$this->
db->ifsql(
"invoice_id IS NULL",
"0",
"1").
") as billed";
849 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
850 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
851 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_extrafields as efp ON (p.rowid = efp.fk_object)";
854 if ($filteronprojuser > 0) {
855 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
856 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
858 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
859 if ($includebilltime) {
860 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
862 if ($filterontaskuser > 0) {
863 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
864 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
866 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
867 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
868 $sql .=
" AND t.fk_projet = p.rowid";
869 } elseif ($mode == 1) {
870 if ($filteronprojuser > 0) {
871 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
872 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
874 if ($filterontaskuser > 0) {
875 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
876 if ($includebilltime) {
877 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
879 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
880 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
882 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t on t.fk_projet = p.rowid";
883 if ($includebilltime) {
884 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
887 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
888 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
890 return 'BadValueForParameterMode';
893 if ($filteronprojuser > 0) {
894 $sql .=
" AND p.rowid = ec.element_id";
895 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
896 $sql .=
" AND ctc.element = 'project'";
897 $sql .=
" AND ec.fk_socpeople = ".((int) $filteronprojuser);
898 $sql .=
" AND ec.statut = 4";
899 $sql .=
" AND ctc.source = 'internal'";
901 if ($filterontaskuser > 0) {
902 $sql .=
" AND t.fk_projet = p.rowid";
903 $sql .=
" AND p.rowid = ec2.element_id";
904 $sql .=
" AND ctc2.rowid = ec2.fk_c_type_contact";
905 $sql .=
" AND ctc2.element = 'project_task'";
906 $sql .=
" AND ec2.fk_socpeople = ".((int) $filterontaskuser);
907 $sql .=
" AND ec2.statut = 4";
908 $sql .=
" AND ctc2.source = 'internal'";
911 $sql .=
" AND p.fk_soc = ".((int) $socid);
914 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectid).
")";
919 if ($filteronprojstatus && $filteronprojstatus !=
'-1') {
920 $sql .=
" AND p.fk_statut IN (".$this->db->sanitize($filteronprojstatus).
")";
922 if ($morewherefilter) {
923 $sql .= $morewherefilter;
926 $extrafieldsobjectkey =
'projet_task';
927 $extrafieldsobjectprefix =
'efpt.';
929 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
931 $parameters = array();
932 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
933 $sql .= $hookmanager->resPrint;
934 if ($includebilltime) {
935 $sql .=
" GROUP BY p.rowid, p.ref, p.title, p.public, p.fk_statut, p.usage_bill_time,";
936 $sql .=
" t.datec, t.dateo, t.datee, t.tms,";
937 $sql .=
" t.rowid, t.ref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut,";
938 $sql .=
" t.dateo, t.datee, t.planned_workload, t.rang,";
939 $sql .=
" t.description, ";
940 $sql .=
" t.budget_amount, ";
941 $sql .=
" s.rowid, s.nom, s.email,";
942 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount";
943 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
944 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
945 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key :
'');
948 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
949 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
950 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key :
'');
956 $sql .=
" ORDER BY p.ref, t.rang, t.dateo";
959 dol_syslog(get_class($this).
"::getTasksArray", LOG_DEBUG);
968 $obj = $this->
db->fetch_object(
$resql);
970 if ((!$obj->public) && (is_object($userp))) {
975 if (is_object($usert)) {
982 $tasks[$i] =
new Task($this->
db);
983 $tasks[$i]->id = $obj->taskid;
984 $tasks[$i]->ref = $obj->taskref;
985 $tasks[$i]->fk_project = $obj->projectid;
986 $tasks[$i]->projectref = $obj->ref;
987 $tasks[$i]->projectlabel = $obj->plabel;
988 $tasks[$i]->projectstatus = $obj->projectstatus;
990 $tasks[$i]->fk_opp_status = $obj->fk_opp_status;
991 $tasks[$i]->opp_amount = $obj->opp_amount;
992 $tasks[$i]->opp_percent = $obj->opp_percent;
993 $tasks[$i]->budget_amount = $obj->budget_amount;
994 $tasks[$i]->project_budget_amount = $obj->project_budget_amount;
995 $tasks[$i]->usage_bill_time = $obj->usage_bill_time;
997 $tasks[$i]->label = $obj->label;
998 $tasks[$i]->description = $obj->description;
999 $tasks[$i]->fk_parent = $obj->fk_task_parent;
1000 $tasks[$i]->fk_task_parent = $obj->fk_task_parent;
1001 $tasks[$i]->duration = $obj->duration_effective;
1002 $tasks[$i]->planned_workload = $obj->planned_workload;
1004 if ($includebilltime) {
1005 $tasks[$i]->tobill = $obj->tobill;
1006 $tasks[$i]->billed = $obj->billed;
1009 $tasks[$i]->progress = $obj->progress;
1010 $tasks[$i]->fk_statut = $obj->status;
1011 $tasks[$i]->public = $obj->public;
1012 $tasks[$i]->date_start = $this->
db->jdate($obj->date_start);
1013 $tasks[$i]->date_end = $this->
db->jdate($obj->date_end);
1014 $tasks[$i]->rang = $obj->rang;
1016 $tasks[$i]->socid = $obj->thirdparty_id;
1017 $tasks[$i]->thirdparty_id = $obj->thirdparty_id;
1018 $tasks[$i]->thirdparty_name = $obj->thirdparty_name;
1019 $tasks[$i]->thirdparty_email = $obj->thirdparty_email;
1021 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1022 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1023 if ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate') {
1024 $tasks[$i]->{
'options_'.$key} = $obj->{
'options_'.$key};
1029 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
1030 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
1031 if ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate') {
1032 $tasks[$i]->{
'options_'.$key} = $obj->{
'options_'.$key};
1038 $tasks[$i]->fetch_optionals();
1064 $arrayroles = array();
1066 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks userp=".is_object($userp).
" usert=".is_object($usert).
" projectid=".$projectid.
" taskid=".$taskid);
1069 if (empty($userp) && empty($usert)) {
1070 $this->error =
"CallWithWrongParameters";
1073 if (!empty($userp) && !empty($usert)) {
1074 $this->error =
"CallWithWrongParameters";
1079 $sql =
"SELECT pt.rowid as pid, ec.element_id, ctc.code, ctc.source";
1081 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as pt";
1083 if ($usert && $filteronprojstatus > -1) {
1084 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"projet_task as pt";
1086 if ($usert && $filteronprojstatus <= -1) {
1087 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as pt";
1089 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1090 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1091 $sql .=
" WHERE pt.rowid = ec.element_id";
1092 if ($userp && $filteronprojstatus > -1) {
1093 $sql .=
" AND pt.fk_statut = ".((int) $filteronprojstatus);
1095 if ($usert && $filteronprojstatus > -1) {
1096 $sql .=
" AND pt.fk_projet = p.rowid AND p.fk_statut = ".((int) $filteronprojstatus);
1099 $sql .=
" AND ctc.element = 'project'";
1102 $sql .=
" AND ctc.element = 'project_task'";
1104 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
1106 $sql .=
" AND ec.fk_socpeople = ".((int) $userp->id);
1109 $sql .=
" AND ec.fk_socpeople = ".((int) $usert->id);
1111 $sql .=
" AND ec.statut = 4";
1112 $sql .=
" AND ctc.source = 'internal'";
1115 $sql .=
" AND pt.rowid IN (".$this->db->sanitize($projectid).
")";
1118 $sql .=
" AND pt.fk_projet IN (".$this->db->sanitize($projectid).
")";
1123 $sql .=
" ERROR SHOULD NOT HAPPENS";
1126 $sql .=
" AND pt.rowid = ".((int) $taskid);
1131 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks execute request", LOG_DEBUG);
1134 $num = $this->
db->num_rows(
$resql);
1137 $obj = $this->
db->fetch_object(
$resql);
1138 if (empty($arrayroles[$obj->pid])) {
1139 $arrayroles[$obj->pid] = $obj->code;
1141 $arrayroles[$obj->pid] .=
','.$obj->code;
1162 $contactAlreadySelected = array();
1163 $tab = $this->liste_contact(-1, $source);
1168 if ($source ==
'thirdparty') {
1169 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
1171 $contactAlreadySelected[$i] = $tab[$i][
'id'];
1175 return $contactAlreadySelected;
1188 global $conf, $langs;
1190 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1196 if (!is_object($user)) {
1197 dol_print_error(
'',
"Method addTimeSpent was called with wrong parameter user");
1202 if (isset($this->timespent_note)) {
1203 $this->timespent_note = trim($this->timespent_note);
1205 if (empty($this->timespent_datehour)) {
1206 $this->timespent_datehour = $this->timespent_date;
1209 if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1210 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1213 if ($this->timespent_date < $restrictBefore) {
1214 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1215 $this->errors[] = $this->error;
1223 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet_task_time (";
1225 $sql .=
", task_date";
1226 $sql .=
", task_datehour";
1227 $sql .=
", task_date_withhour";
1228 $sql .=
", task_duration";
1229 $sql .=
", fk_user";
1232 $sql .=
") VALUES (";
1233 $sql .= ((int) $this->
id);
1234 $sql .=
", '".$this->db->idate($this->timespent_date).
"'";
1235 $sql .=
", '".$this->db->idate($this->timespent_datehour).
"'";
1236 $sql .=
", ".(empty($this->timespent_withhour) ? 0 : 1);
1237 $sql .=
", ".((int) $this->timespent_duration);
1238 $sql .=
", ".((int) $this->timespent_fk_user);
1239 $sql .=
", ".(isset($this->timespent_note) ?
"'".$this->db->escape($this->timespent_note).
"'" :
"null");
1240 $sql .=
", '".$this->db->idate($now).
"'";
1245 $tasktime_id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"projet_task_time");
1246 $ret = $tasktime_id;
1247 $this->timespent_id = $ret;
1251 $result = $this->call_trigger(
'TASK_TIMESPENT_CREATE', $user);
1258 $this->error = $this->
db->lasterror();
1264 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1265 $sql .=
" SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt where ptt.fk_task = ".((int) $this->
id).
")";
1266 if (isset($this->progress)) {
1267 $sql .=
", progress = ".((float) $this->progress);
1269 $sql .=
" WHERE rowid = ".((int) $this->
id);
1271 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1272 if (!$this->
db->query($sql)) {
1273 $this->error = $this->
db->lasterror();
1278 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time";
1279 $sql .=
" SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX.
"user WHERE rowid = ".((int) $this->timespent_fk_user).
")";
1280 $sql .=
" WHERE rowid = ".((int) $tasktime_id);
1282 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1283 if (!$this->
db->query($sql)) {
1284 $this->error = $this->
db->lasterror();
1290 $this->
db->commit();
1292 $this->
db->rollback();
1307 $arrayres = array();
1310 $sql .=
" s.rowid as socid,";
1311 $sql .=
" s.nom as thirdparty_name,";
1312 $sql .=
" s.email as thirdparty_email,";
1313 $sql .=
" ptt.rowid,";
1314 $sql .=
" ptt.fk_task,";
1315 $sql .=
" ptt.task_date,";
1316 $sql .=
" ptt.task_datehour,";
1317 $sql .=
" ptt.task_date_withhour,";
1318 $sql .=
" ptt.task_duration,";
1319 $sql .=
" ptt.fk_user,";
1320 $sql .=
" ptt.note,";
1321 $sql .=
" ptt.thm,";
1322 $sql .=
" pt.rowid as task_id,";
1323 $sql .=
" pt.ref as task_ref,";
1324 $sql .=
" pt.label as task_label,";
1325 $sql .=
" p.rowid as project_id,";
1326 $sql .=
" p.ref as project_ref,";
1327 $sql .=
" p.title as project_label,";
1328 $sql .=
" p.public as public";
1329 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1330 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1331 $sql .=
" WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1332 $sql .=
" AND pt.rowid = ".((int) $this->
id);
1333 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1334 if ($morewherefilter) {
1335 $sql .= $morewherefilter;
1338 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1341 $num = $this->
db->num_rows(
$resql);
1345 $obj = $this->
db->fetch_object(
$resql);
1347 $newobj =
new stdClass();
1349 $newobj->socid = $obj->socid;
1350 $newobj->thirdparty_name = $obj->thirdparty_name;
1351 $newobj->thirdparty_email = $obj->thirdparty_email;
1353 $newobj->fk_project = $obj->project_id;
1354 $newobj->project_ref = $obj->project_ref;
1355 $newobj->project_label = $obj->project_label;
1356 $newobj->public = $obj->project_public;
1358 $newobj->fk_task = $obj->task_id;
1359 $newobj->task_ref = $obj->task_ref;
1360 $newobj->task_label = $obj->task_label;
1362 $newobj->timespent_line_id = $obj->rowid;
1363 $newobj->timespent_line_date = $this->
db->jdate($obj->task_date);
1364 $newobj->timespent_line_datehour = $this->
db->jdate($obj->task_datehour);
1365 $newobj->timespent_line_withhour = $obj->task_date_withhour;
1366 $newobj->timespent_line_duration = $obj->task_duration;
1367 $newobj->timespent_line_fk_user = $obj->fk_user;
1368 $newobj->timespent_line_thm = $obj->thm;
1369 $newobj->timespent_line_note = $obj->note;
1371 $arrayres[] = $newobj;
1378 $this->lines = $arrayres;
1382 $this->error =
"Error ".$this->db->lasterror();
1399 if (is_object($userobj)) {
1400 $userid = $userobj->id;
1406 if (empty($id) && empty($userid)) {
1407 dol_syslog(
"getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR);
1414 $sql .=
" MIN(t.task_datehour) as min_date,";
1415 $sql .=
" MAX(t.task_datehour) as max_date,";
1416 $sql .=
" SUM(t.task_duration) as total_duration,";
1417 $sql .=
" SUM(t.task_duration / 3600 * ".$this->db->ifsql(
"t.thm IS NULL", 0,
"t.thm").
") as total_amount,";
1418 $sql .=
" COUNT(t.rowid) as nblines,";
1419 $sql .=
" SUM(".$this->db->ifsql(
"t.thm IS NULL", 1, 0).
") as nblinesnull";
1420 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1421 $sql .=
" WHERE 1 = 1";
1422 if ($morewherefilter) {
1423 $sql .= $morewherefilter;
1426 $sql .=
" AND t.fk_task = ".((int) $id);
1429 $sql .=
" AND t.fk_user = ".((int) $userid);
1432 dol_syslog(get_class($this).
"::getSummaryOfTimeSpent", LOG_DEBUG);
1435 $obj = $this->
db->fetch_object(
$resql);
1437 $result[
'min_date'] = $obj->min_date;
1438 $result[
'max_date'] = $obj->max_date;
1439 $result[
'total_duration'] = $obj->total_duration;
1441 $this->timespent_min_date = $this->
db->jdate($obj->min_date);
1442 $this->timespent_max_date = $this->
db->jdate($obj->max_date);
1443 $this->timespent_total_duration = $obj->total_duration;
1444 $this->timespent_total_amount = $obj->total_amount;
1445 $this->timespent_nblinesnull = ($obj->nblinesnull ? $obj->nblinesnull : 0);
1446 $this->timespent_nblines = ($obj->nblines ? $obj->nblines : 0);
1474 $sql .=
" SUM(t.task_duration) as nbseconds,";
1475 $sql .=
" SUM(t.task_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";
1476 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1477 $sql .=
" WHERE t.fk_task = ".((int) $id);
1478 if (is_object($fuser) && $fuser->id > 0) {
1479 $sql .=
" AND fk_user = ".((int) $fuser->id);
1482 $datefieldname =
"task_datehour";
1483 $sql .=
" AND (".$datefieldname.
" >= '".$this->
db->idate($dates).
"' OR ".$datefieldname.
" IS NULL)";
1486 $datefieldname =
"task_datehour";
1487 $sql .=
" AND (".$datefieldname.
" <= '".$this->
db->idate($datee).
"' OR ".$datefieldname.
" IS NULL)";
1491 dol_syslog(get_class($this).
"::getSumOfAmount", LOG_DEBUG);
1494 $obj = $this->
db->fetch_object(
$resql);
1496 $result[
'amount'] = $obj->amount;
1497 $result[
'nbseconds'] = $obj->nbseconds;
1498 $result[
'nblinesnull'] = $obj->nblinesnull;
1519 $sql .=
" t.rowid,";
1520 $sql .=
" t.fk_task,";
1521 $sql .=
" t.task_date,";
1522 $sql .=
" t.task_datehour,";
1523 $sql .=
" t.task_date_withhour,";
1524 $sql .=
" t.task_duration,";
1525 $sql .=
" t.fk_user,";
1528 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1529 $sql .=
" WHERE t.rowid = ".((int) $id);
1531 dol_syslog(get_class($this).
"::fetchTimeSpent", LOG_DEBUG);
1535 $obj = $this->
db->fetch_object(
$resql);
1537 $this->timespent_id = $obj->rowid;
1538 $this->
id = $obj->fk_task;
1539 $this->timespent_date = $this->
db->jdate($obj->task_date);
1540 $this->timespent_datehour = $this->
db->jdate($obj->task_datehour);
1541 $this->timespent_withhour = $obj->task_date_withhour;
1542 $this->timespent_duration = $obj->task_duration;
1543 $this->timespent_fk_user = $obj->fk_user;
1544 $this->timespent_thm = $obj->thm;
1545 $this->timespent_note = $obj->note;
1552 $this->error =
"Error ".$this->db->lasterror();
1568 $arrayres = array();
1571 $sql .=
" s.rowid as socid,";
1572 $sql .=
" s.nom as thirdparty_name,";
1573 $sql .=
" s.email as thirdparty_email,";
1574 $sql .=
" ptt.rowid,";
1575 $sql .=
" ptt.fk_task,";
1576 $sql .=
" ptt.task_date,";
1577 $sql .=
" ptt.task_datehour,";
1578 $sql .=
" ptt.task_date_withhour,";
1579 $sql .=
" ptt.task_duration,";
1580 $sql .=
" ptt.fk_user,";
1581 $sql .=
" ptt.note,";
1582 $sql .=
" ptt.thm,";
1583 $sql .=
" pt.rowid as task_id,";
1584 $sql .=
" pt.ref as task_ref,";
1585 $sql .=
" pt.label as task_label,";
1586 $sql .=
" p.rowid as project_id,";
1587 $sql .=
" p.ref as project_ref,";
1588 $sql .=
" p.title as project_label,";
1589 $sql .=
" p.public as public";
1590 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1591 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1592 $sql .=
" WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1593 $sql .=
" AND ptt.fk_user = ".((int) $userobj->id);
1594 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1595 if ($morewherefilter) {
1596 $sql .= $morewherefilter;
1599 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1602 $num = $this->
db->num_rows(
$resql);
1606 $obj = $this->
db->fetch_object(
$resql);
1608 $newobj =
new stdClass();
1610 $newobj->socid = $obj->socid;
1611 $newobj->thirdparty_name = $obj->thirdparty_name;
1612 $newobj->thirdparty_email = $obj->thirdparty_email;
1614 $newobj->fk_project = $obj->project_id;
1615 $newobj->project_ref = $obj->project_ref;
1616 $newobj->project_label = $obj->project_label;
1617 $newobj->public = $obj->project_public;
1619 $newobj->fk_task = $obj->task_id;
1620 $newobj->task_ref = $obj->task_ref;
1621 $newobj->task_label = $obj->task_label;
1623 $newobj->timespent_id = $obj->rowid;
1624 $newobj->timespent_date = $this->
db->jdate($obj->task_date);
1625 $newobj->timespent_datehour = $this->
db->jdate($obj->task_datehour);
1626 $newobj->timespent_withhour = $obj->task_date_withhour;
1627 $newobj->timespent_duration = $obj->task_duration;
1628 $newobj->timespent_fk_user = $obj->fk_user;
1629 $newobj->timespent_thm = $obj->thm;
1630 $newobj->timespent_note = $obj->note;
1632 $arrayres[] = $newobj;
1640 $this->error =
"Error ".$this->db->lasterror();
1656 global $conf, $langs;
1661 if ($this->timespent_date ==
'') {
1662 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date"));
1665 if (!($this->timespent_fk_user > 0)) {
1666 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"User"));
1671 if (empty($this->timespent_datehour)) {
1672 $this->timespent_datehour = $this->timespent_date;
1674 if (isset($this->timespent_note)) {
1675 $this->timespent_note = trim($this->timespent_note);
1678 if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1679 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1682 if ($this->timespent_date < $restrictBefore) {
1683 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1684 $this->errors[] = $this->error;
1691 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time SET";
1692 $sql .=
" task_date = '".$this->db->idate($this->timespent_date).
"',";
1693 $sql .=
" task_datehour = '".$this->db->idate($this->timespent_datehour).
"',";
1694 $sql .=
" task_date_withhour = ".(empty($this->timespent_withhour) ? 0 : 1).
",";
1695 $sql .=
" task_duration = ".((int) $this->timespent_duration).
",";
1696 $sql .=
" fk_user = ".((int) $this->timespent_fk_user).
",";
1697 $sql .=
" note = ".(isset($this->timespent_note) ?
"'".$this->db->escape($this->timespent_note).
"'" :
"null");
1698 $sql .=
" WHERE rowid = ".((int) $this->timespent_id);
1700 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
1701 if ($this->
db->query($sql)) {
1704 $result = $this->call_trigger(
'TASK_TIMESPENT_MODIFY', $user);
1706 $this->
db->rollback();
1716 $this->error = $this->
db->lasterror();
1717 $this->
db->rollback();
1721 if ($ret == 1 && ($this->timespent_old_duration != $this->timespent_duration)) {
1723 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1724 $sql .=
" SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt where ptt.fk_task = ".((int) $this->
id).
")";
1725 if (isset($this->progress)) {
1726 $sql .=
", progress = ".((float) $this->progress);
1728 $sql .=
" WHERE rowid = ".((int) $this->
id);
1730 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
1731 if (!$this->
db->query($sql)) {
1732 $this->error = $this->
db->lasterror();
1733 $this->
db->rollback();
1738 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time";
1739 $sql .=
" SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX.
"user WHERE rowid = ".((int) $this->timespent_fk_user).
")";
1740 $sql .=
" WHERE (thm IS NULL OR thm = 0) AND rowid = ".((int) $this->timespent_id);
1742 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1743 if (!$this->
db->query($sql)) {
1744 $this->error = $this->
db->lasterror();
1750 $this->
db->commit();
1764 global $conf, $langs;
1768 if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1769 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1772 if ($this->timespent_date < $restrictBefore) {
1773 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1774 $this->errors[] = $this->error;
1783 $result = $this->call_trigger(
'TASK_TIMESPENT_DELETE', $user);
1791 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_time";
1792 $sql .=
" WHERE rowid = ".((int) $this->timespent_id);
1794 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
1797 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1802 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1803 $sql .=
" SET duration_effective = duration_effective - ".$this->db->escape($this->timespent_duration ? $this->timespent_duration : 0);
1804 $sql .=
" WHERE rowid = ".((int) $this->
id);
1806 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
1807 if ($this->
db->query($sql)) {
1810 $this->error = $this->
db->lasterror();
1817 foreach ($this->errors as $errmsg) {
1818 dol_syslog(get_class($this).
"::delTimeSpent ".$errmsg, LOG_ERR);
1819 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1821 $this->
db->rollback();
1824 $this->
db->commit();
1843 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)
1845 global $langs, $conf;
1854 $clone_task =
new Task($this->
db);
1855 $origin_task =
new Task($this->
db);
1857 $clone_task->context[
'createfromclone'] =
'createfromclone';
1862 $clone_task->fetch($fromid);
1863 $clone_task->fetch_optionals();
1866 $origin_task->fetch($fromid);
1869 $obj = empty($conf->global->PROJECT_TASK_ADDON) ?
'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
1870 if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT.
"/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.
".php")) {
1871 require_once DOL_DOCUMENT_ROOT.
"/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.
'.php';
1872 $modTask =
new $obj;
1873 $defaultref = $modTask->getNextValue(0, $clone_task);
1876 $ori_project_id = $clone_task->fk_project;
1878 $clone_task->id = 0;
1879 $clone_task->ref = $defaultref;
1880 $clone_task->fk_project = $project_id;
1881 $clone_task->fk_task_parent = $parent_task_id;
1882 $clone_task->date_c = $datec;
1883 $clone_task->planned_workload = $origin_task->planned_workload;
1884 $clone_task->rang = $origin_task->rang;
1887 if ($clone_change_dt) {
1888 $projectstatic =
new Project($this->
db);
1889 $projectstatic->fetch($ori_project_id);
1892 $orign_project_dt_start = $projectstatic->date_start;
1895 if (!empty($clone_task->date_start)) {
1896 $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
1900 if (!empty($clone_task->date_end)) {
1901 $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
1906 $clone_task->progress = 0;
1910 $result = $clone_task->create($user);
1914 $this->error = $clone_task->error;
1920 $clone_task_id = $clone_task->id;
1921 $clone_task_ref = $clone_task->ref;
1925 $clone_task->note_private =
'';
1926 $clone_task->note_public =
'';
1929 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_public, ENT_QUOTES | ENT_HTML5),
'_public');
1931 $this->error .= $clone_task->error;
1933 $this->
db->rollback();
1935 $this->
db->commit();
1939 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_private, ENT_QUOTES | ENT_HTML5),
'_private');
1941 $this->error .= $clone_task->error;
1943 $this->
db->rollback();
1945 $this->
db->commit();
1951 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1954 $projectstatic =
new Project($this->
db);
1955 $projectstatic->fetch($ori_project_id);
1956 $ori_project_ref = $projectstatic->ref;
1958 if ($ori_project_id != $project_id) {
1959 $projectstatic->fetch($project_id);
1960 $clone_project_ref = $projectstatic->ref;
1962 $clone_project_ref = $ori_project_ref;
1968 $filearray =
dol_dir_list($ori_task_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'', SORT_ASC, 1);
1969 foreach ($filearray as $key => $file) {
1970 if (!file_exists($clone_task_dir)) {
1972 $this->error .= $langs->trans(
'ErrorInternalErrorDetected').
':dol_mkdir';
1977 $rescopy =
dol_copy($ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name'], 0, 1);
1978 if (is_numeric($rescopy) && $rescopy < 0) {
1979 $this->error .= $langs->trans(
"ErrorFailToCopyFile", $ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name']);
1986 if ($clone_affectation) {
1987 $origin_task =
new Task($this->
db);
1988 $origin_task->fetch($fromid);
1990 foreach (array(
'internal',
'external') as $source) {
1991 $tab = $origin_task->liste_contact(-1, $source);
1995 $clone_task->add_contact($tab[$i][
'id'], $tab[$i][
'code'], $tab[$i][
'source']);
1996 if ($clone_task->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1997 $langs->load(
"errors");
1998 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
2001 if ($clone_task->error !=
'') {
2002 $this->error .= $clone_task->error;
2016 unset($clone_task->context[
'createfromclone']);
2019 $this->
db->commit();
2020 return $clone_task_id;
2022 $this->
db->rollback();
2023 dol_syslog(get_class($this).
"::createFromClone nbError: ".$error.
" error : ".$this->error, LOG_ERR);
2037 return $this->LibStatut($this->fk_statut, $mode);
2054 $this->statuts[0] =
'Draft';
2055 $this->statuts[1] =
'ToDo';
2056 $this->statuts[2] =
'Running';
2057 $this->statuts[3] =
'Finish';
2058 $this->statuts[4] =
'Transfered';
2059 $this->statuts_short[0] =
'Draft';
2060 $this->statuts_short[1] =
'ToDo';
2061 $this->statuts_short[2] =
'Running';
2062 $this->statuts_short[3] =
'Completed';
2063 $this->statuts_short[4] =
'Transfered';
2066 return $langs->trans($this->statuts[$status]);
2067 } elseif ($mode == 1) {
2068 return $langs->trans($this->statuts_short[$status]);
2069 } elseif ($mode == 2) {
2071 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts_short[$status]);
2072 } elseif ($status == 1) {
2073 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1').
' '.$langs->trans($this->statuts_short[$status]);
2074 } elseif ($status == 2) {
2075 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3').
' '.$langs->trans($this->statuts_short[$status]);
2076 } elseif ($status == 3) {
2077 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
2078 } elseif ($status == 4) {
2079 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
2080 } elseif ($status == 5) {
2081 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5').
' '.$langs->trans($this->statuts_short[$status]);
2083 } elseif ($mode == 3) {
2085 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0');
2086 } elseif ($status == 1) {
2087 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1');
2088 } elseif ($status == 2) {
2089 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3');
2090 } elseif ($status == 3) {
2091 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
2092 } elseif ($status == 4) {
2093 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
2094 } elseif ($status == 5) {
2095 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5');
2097 } elseif ($mode == 4) {
2099 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts[$status]);
2100 } elseif ($status == 1) {
2101 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1').
' '.$langs->trans($this->statuts[$status]);
2102 } elseif ($status == 2) {
2103 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3').
' '.$langs->trans($this->statuts[$status]);
2104 } elseif ($status == 3) {
2105 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
2106 } elseif ($status == 4) {
2107 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
2108 } elseif ($status == 5) {
2109 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5').
' '.$langs->trans($this->statuts[$status]);
2111 } elseif ($mode == 5) {
2121 } elseif ($mode == 6) {
2144 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2148 $outputlangs->load(
"projects");
2151 $modele =
'nodefault';
2153 if (!empty($this->model_pdf)) {
2154 $modele = $this->model_pdf;
2155 } elseif (!empty($this->modelpdf)) {
2156 $modele = $this->modelpdf;
2157 } elseif (!empty($conf->global->PROJECT_TASK_ADDON_PDF)) {
2158 $modele = $conf->global->PROJECT_TASK_ADDON_PDF;
2162 $modelpath =
"core/modules/project/task/doc/";
2164 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2178 global $conf, $langs;
2184 $projectstatic =
new Project($this->
db);
2185 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
2188 $sql =
"SELECT p.rowid as projectid, p.fk_statut as projectstatus,";
2189 $sql .=
" t.rowid as taskid, t.progress as progress, t.fk_statut as status,";
2190 $sql .=
" t.dateo as date_start, t.datee as datee";
2191 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2192 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
2194 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2195 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2196 $sql .=
" AND p.fk_statut = 1";
2197 $sql .=
" AND t.fk_projet = p.rowid";
2198 $sql .=
" AND (t.progress IS NULL OR t.progress < 100)";
2199 if (empty($user->rights->projet->all->lire)) {
2200 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2210 $task_static =
new Task($this->
db);
2213 $response->warning_delay = $conf->project->task->warning_delay / 60 / 60 / 24;
2214 $response->label = $langs->trans(
"OpenedTasks");
2215 if ($user->rights->projet->all->lire) {
2216 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mainmenu=project';
2218 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mode=mine&mainmenu=project';
2223 while ($obj = $this->
db->fetch_object(
$resql)) {
2224 $response->nbtodo++;
2226 $task_static->projectstatus = $obj->projectstatus;
2227 $task_static->progress = $obj->progress;
2228 $task_static->fk_statut = $obj->status;
2229 $task_static->date_end = $this->
db->jdate($obj->datee);
2231 if ($task_static->hasDelay()) {
2232 $response->nbtodolate++;
2238 $this->error = $this->
db->error();
2255 $mine = 0; $socid = $user->socid;
2257 $projectstatic =
new Project($this->
db);
2258 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $mine, 1, $socid);
2261 $sql =
"SELECT count(p.rowid) as nb";
2262 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2263 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
2264 if (empty($user->rights->societe->client->voir) && !$socid) {
2265 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2267 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2268 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2269 $sql .=
" AND t.fk_projet = p.rowid";
2270 if ($mine || empty($user->rights->projet->all->lire)) {
2271 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2276 $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).
")";
2278 if (empty($user->rights->societe->client->voir) && !$socid) {
2279 $sql .=
" AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).
") OR (s.rowid IS NULL))";
2285 while ($obj = $this->
db->fetch_object(
$resql)) {
2286 $this->nb[
"tasks"] = $obj->nb;
2292 $this->error = $this->
db->error();
2306 if (!($this->progress >= 0 && $this->progress < 100)) {
2312 $datetouse = ($this->date_end > 0) ? $this->date_end : ((isset($this->datee) && $this->datee > 0) ? $this->datee : 0);
2314 return ($datetouse > 0 && ($datetouse < ($now - $conf->project->task->warning_delay)));
hasTimeSpent()
Return nb of time spent.
fetchTimeSpent($id)
Load properties of timespent of a task from the time spent ID.
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...
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
getLibStatut($mode=0)
Return status label of object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
update($user=null, $notrigger=0)
Update database.
dol_mkdir($dir, $dataroot= '', $newmask= '')
Creation of a directory (this can create recursive subdir)
$conf db
API class for accounts.
updateTimeSpent($user, $notrigger=0)
Update time spent.
dol_html_entity_decode($a, $b, $c= 'UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_now($mode= 'auto')
Return date for now.
delete_linked_contact($source= '', $code= '')
Delete all links between an object $this and all its contacts.
Class to manage Dolibarr users.
getNomUrl($withpicto=0, $option= '', $mode= 'task', $addlabel=0, $sep= '- ', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
isObjectUsed($id=0, $entity=0)
Function to check if an object is used by others.
create($user, $notrigger=0)
Create into database.
addTimeSpent($user, $notrigger=0)
Add time spent.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
const STATUS_VALIDATED
Open/Validated status.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
initAsSpecimen()
Initialise an instance with random values.
Class to manage projects.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
fetchAllTimeSpent(User $userobj, $morewherefilter= '')
Load all records of time spent.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
hasDelay()
Is the task delayed?
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
hasChildren()
Return nb of children.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getTasksArray($usert=null, $userp=null, $projectid=0, $socid=0, $mode=0, $filteronproj= '', $filteronprojstatus= '-1', $morewherefilter= '', $filteronprojuser=0, $filterontaskuser=0, $extrafields=array(), $includebilltime=0, $search_array_options=array(), $loadextras=0)
Return list of tasks for all projects or for one particular project Sort order is on project...
getSumOfAmount($fuser= '', $dates= '', $datee= '')
Calculate quantity and value of time consumed using the thm (hourly amount value of work for user ent...
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
__construct($db)
Constructor.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create an intervention document on disk using template defined into PROJECT_TASK_ADDON_PDF.
dol_move_dir($srcdir, $destdir, $overwriteifexists=1, $indexdatabase=1, $renamedircontent=1)
Move a directory into another name.
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_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
getListContactId($source= 'internal')
Return list of id of contacts of 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...
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
getSummaryOfTimeSpent($userobj=null, $morewherefilter= '')
Calculate total of time spent for task.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
LibStatut($status, $mode=0)
Return status label for an object.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
delTimeSpent($user, $notrigger=0)
Delete time spent.
fetch($id, $ref= '', $loadparentdata=0)
Load object in memory from database.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
fetchTimeSpentOnTask($morewherefilter= '')
Fetch records of time spent of this task.
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.