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;
130 public $timespent_fk_product;
132 public $comments = array();
137 public $budget_amount;
142 public $project_budget_amount;
165 public function create($user, $notrigger = 0)
167 global $conf, $langs;
175 $this->label = trim($this->label);
178 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
179 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
187 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet_task (";
189 $sql .=
", fk_projet";
191 $sql .=
", fk_task_parent";
193 $sql .=
", description";
195 $sql .=
", fk_user_creat";
198 $sql .=
", planned_workload";
199 $sql .=
", progress";
200 $sql .=
", budget_amount";
201 $sql .=
") VALUES (";
202 $sql .= ((int) $conf->entity);
203 $sql .=
", ".((int) $this->fk_project);
204 $sql .=
", ".(!empty($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
'null');
205 $sql .=
", ".((int) $this->fk_task_parent);
206 $sql .=
", '".$this->db->escape($this->label).
"'";
207 $sql .=
", '".$this->db->escape($this->
description).
"'";
208 $sql .=
", '".$this->db->idate($now).
"'";
209 $sql .=
", ".((int) $user->id);
210 $sql .=
", ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
'null');
211 $sql .=
", ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
'null');
212 $sql .=
", ".(($this->planned_workload !=
'' && $this->planned_workload >= 0) ? ((
int) $this->planned_workload) :
'null');
213 $sql .=
", ".(($this->progress !=
'' && $this->progress >= 0) ? ((
int) $this->progress) :
'null');
214 $sql .=
", ".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? ((
int) $this->budget_amount) :
'null');
219 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
222 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
226 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"projet_task");
250 foreach ($this->errors as $errmsg) {
251 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
252 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
254 $this->
db->rollback();
271 public function fetch($id, $ref =
'', $loadparentdata = 0)
273 global $langs, $conf;
278 $sql .=
" t.fk_projet as fk_project,";
279 $sql .=
" t.fk_task_parent,";
281 $sql .=
" t.description,";
282 $sql .=
" t.duration_effective,";
283 $sql .=
" t.planned_workload,";
287 $sql .=
" t.fk_user_creat,";
288 $sql .=
" t.fk_user_valid,";
289 $sql .=
" t.fk_statut,";
290 $sql .=
" t.progress,";
291 $sql .=
" t.budget_amount,";
292 $sql .=
" t.priority,";
293 $sql .=
" t.note_private,";
294 $sql .=
" t.note_public,";
296 if (!empty($loadparentdata)) {
297 $sql .=
", t2.ref as task_parent_ref";
298 $sql .=
", t2.rang as task_parent_position";
300 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as t";
301 if (!empty($loadparentdata)) {
302 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t2 ON t.fk_task_parent = t2.rowid";
306 $sql .=
"entity IN (".getEntity(
'project').
")";
307 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
309 $sql .=
"t.rowid = ".((int) $id);
312 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
315 $num_rows = $this->
db->num_rows(
$resql);
318 $obj = $this->
db->fetch_object(
$resql);
320 $this->
id = $obj->rowid;
321 $this->
ref = $obj->ref;
322 $this->fk_project = $obj->fk_project;
323 $this->fk_task_parent = $obj->fk_task_parent;
324 $this->label = $obj->label;
326 $this->duration_effective = $obj->duration_effective;
327 $this->planned_workload = $obj->planned_workload;
328 $this->date_c = $this->
db->jdate($obj->datec);
329 $this->date_start = $this->
db->jdate($obj->dateo);
330 $this->date_end = $this->
db->jdate($obj->datee);
331 $this->fk_user_creat = $obj->fk_user_creat;
332 $this->fk_user_valid = $obj->fk_user_valid;
333 $this->fk_statut = $obj->fk_statut;
334 $this->progress = $obj->progress;
335 $this->budget_amount = $obj->budget_amount;
336 $this->priority = $obj->priority;
337 $this->note_private = $obj->note_private;
338 $this->note_public = $obj->note_public;
339 $this->rang = $obj->rang;
341 if (!empty($loadparentdata)) {
342 $this->task_parent_ref = $obj->task_parent_ref;
343 $this->task_parent_position = $obj->task_parent_position;
358 $this->error =
"Error ".$this->db->lasterror();
371 public function update($user =
null, $notrigger = 0)
373 global $conf, $langs;
377 if (isset($this->fk_project)) {
378 $this->fk_project = trim($this->fk_project);
380 if (isset($this->
ref)) {
381 $this->
ref = trim($this->
ref);
383 if (isset($this->fk_task_parent)) {
384 $this->fk_task_parent = (int) $this->fk_task_parent;
386 if (isset($this->label)) {
387 $this->label = trim($this->label);
392 if (isset($this->duration_effective)) {
393 $this->duration_effective = trim($this->duration_effective);
395 if (isset($this->planned_workload)) {
396 $this->planned_workload = trim($this->planned_workload);
398 if (isset($this->budget_amount)) {
399 $this->budget_amount = trim($this->budget_amount);
402 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
403 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
411 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
412 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
413 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"'".$this->db->escape($this->
id).
"'").
",";
414 $sql .=
" fk_task_parent=".(isset($this->fk_task_parent) ? $this->fk_task_parent :
"null").
",";
415 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
416 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
417 $sql .=
" duration_effective=".(isset($this->duration_effective) ? $this->duration_effective :
"null").
",";
418 $sql .=
" planned_workload=".((isset($this->planned_workload) && $this->planned_workload !=
'') ? $this->planned_workload :
"null").
",";
419 $sql .=
" dateo=".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
'null').
",";
420 $sql .=
" datee=".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
'null').
",";
421 $sql .=
" progress=".(($this->progress !=
'' && $this->progress >= 0) ? $this->progress :
'null').
",";
422 $sql .=
" budget_amount=".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? $this->budget_amount :
'null').
",";
423 $sql .=
" rang=".((!empty($this->rang)) ? $this->rang :
"0");
424 $sql .=
" WHERE rowid=".((int) $this->
id);
428 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
431 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
442 if (!$error && !empty($conf->global->PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE)) {
445 if ($project->fetch($this->fk_project) > 0) {
447 $project->getLinesArray(
null);
448 $projectCompleted = array_reduce(
450 function ($allTasksCompleted, $task) {
451 return $allTasksCompleted && $task->progress >= 100;
455 if ($projectCompleted) {
456 if ($project->setClose($user) <= 0) {
465 $this->errors[] = $project->error;
480 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
482 if ($conf->project->dir_output) {
484 $project->fetch($this->fk_project);
488 if (file_exists($olddir)) {
489 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
492 $langs->load(
"errors");
493 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
502 foreach ($this->errors as $errmsg) {
503 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
504 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
506 $this->
db->rollback();
522 public function delete($user, $notrigger = 0)
525 global $conf, $langs;
526 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
533 dol_syslog(get_class($this).
"::delete Can't delete record as it has some sub tasks", LOG_WARNING);
534 $this->error =
'ErrorRecordHasSubTasks';
535 $this->
db->rollback();
540 if (!empty($objectisused)) {
541 dol_syslog(get_class($this).
"::delete Can't delete record as it has some child", LOG_WARNING);
542 $this->error =
'ErrorRecordHasChildren';
543 $this->
db->rollback();
551 $this->error =
'ErrorFailToDeleteLinkedContact';
553 $this->
db->rollback();
559 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_time";
560 $sql .=
" WHERE fk_task = ".((int) $this->
id);
564 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
569 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_extrafields";
570 $sql .=
" WHERE fk_object = ".((int) $this->
id);
574 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
579 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task";
580 $sql .=
" WHERE rowid=".((int) $this->
id);
584 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
601 foreach ($this->errors as $errmsg) {
602 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
603 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
605 $this->
db->rollback();
609 if ($conf->project->dir_output) {
611 $projectstatic->fetch($this->fk_project);
614 dol_syslog(get_class($this).
"::delete dir=".$dir, LOG_DEBUG);
615 if (file_exists($dir)) {
616 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
619 $this->error =
'ErrorFailToDeleteDir';
620 $this->
db->rollback();
642 $sql =
"SELECT COUNT(*) as nb";
643 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task";
644 $sql .=
" WHERE fk_task_parent = ".((int) $this->
id);
646 dol_syslog(get_class($this).
"::hasChildren", LOG_DEBUG);
649 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
651 $obj = $this->
db->fetch_object(
$resql);
675 $sql =
"SELECT COUNT(*) as nb";
676 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time";
677 $sql .=
" WHERE fk_task = ".((int) $this->
id);
679 dol_syslog(get_class($this).
"::hasTimeSpent", LOG_DEBUG);
682 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
684 $obj = $this->
db->fetch_object(
$resql);
711 public function getNomUrl($withpicto = 0, $option =
'', $mode =
'task', $addlabel = 0, $sep =
' - ', $notooltip = 0, $save_lastsearch_value = -1)
713 global $conf, $langs, $user;
715 if (!empty($conf->dol_no_mouse_hover)) {
720 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Task").
'</u>';
721 if (!empty($this->
ref)) {
722 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
724 if (!empty($this->label)) {
725 $label .=
'<br><b>'.$langs->trans(
'LabelTask').
':</b> '.$this->label;
727 if ($this->date_start || $this->date_end) {
728 $label .=
"<br>".get_date_range($this->date_start, $this->date_end,
'', $langs, 0);
731 $url = DOL_URL_ROOT.
'/projet/tasks/'.$mode.
'.php?id='.$this->
id.($option ==
'withproject' ?
'&withproject=1' :
'');
733 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
734 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
735 $add_save_lastsearch_values = 1;
737 if ($add_save_lastsearch_values) {
738 $url .=
'&save_lastsearch_values=1';
742 if (empty($notooltip)) {
743 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
744 $label = $langs->trans(
"ShowTask");
745 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
747 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
748 $linkclose .=
' class="classfortooltip nowraponall"';
750 $linkclose .=
' class="nowraponall"';
753 $linkstart =
'<a href="'.$url.
'"';
754 $linkstart .= $linkclose.
'>';
757 $picto =
'projecttask';
759 $result .= $linkstart;
761 $result .=
img_object(($notooltip ?
'' : $label), $picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
763 if ($withpicto != 2) {
764 $result .= $this->ref;
767 if ($withpicto != 2) {
768 $result .= (($addlabel && $this->label) ? $sep.dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) :
'');
785 $this->fk_project =
'';
787 $this->fk_task_parent =
null;
788 $this->label =
'Specimen task TK01';
789 $this->duration_effective =
'';
790 $this->fk_user_creat =
null;
791 $this->progress =
'25';
792 $this->fk_statut =
null;
793 $this->note =
'This is a specimen task not';
817 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, $loadRoleMode = 1)
819 global $conf, $hookmanager;
827 if ($filteronprojuser > 0 || $filterontaskuser > 0) {
830 $sql .=
" p.rowid as projectid, p.ref, p.title as plabel, p.public, p.fk_statut as projectstatus, p.usage_bill_time,";
831 $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,";
832 $sql .=
" t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang,";
833 $sql .=
" t.description, ";
834 $sql .=
" t.budget_amount, ";
835 $sql .=
" s.rowid as thirdparty_id, s.nom as thirdparty_name, s.email as thirdparty_email,";
836 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount as project_budget_amount";
837 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
838 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
839 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key.
" as options_".$key :
'');
842 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
843 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
844 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key.
" as options_".$key :
'');
847 if ($includebilltime) {
848 $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";
851 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
852 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
853 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_extrafields as efp ON (p.rowid = efp.fk_object)";
856 if ($filteronprojuser > 0) {
857 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
858 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
860 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
861 if ($includebilltime) {
862 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
864 if ($filterontaskuser > 0) {
865 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
866 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
868 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
869 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
870 $sql .=
" AND t.fk_projet = p.rowid";
871 } elseif ($mode == 1) {
872 if ($filteronprojuser > 0) {
873 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
874 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
876 if ($filterontaskuser > 0) {
877 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
878 if ($includebilltime) {
879 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
881 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
882 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
884 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t on t.fk_projet = p.rowid";
885 if ($includebilltime) {
886 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
889 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
890 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
892 return 'BadValueForParameterMode';
895 if ($filteronprojuser > 0) {
896 $sql .=
" AND p.rowid = ec.element_id";
897 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
898 $sql .=
" AND ctc.element = 'project'";
899 $sql .=
" AND ec.fk_socpeople = ".((int) $filteronprojuser);
900 $sql .=
" AND ec.statut = 4";
901 $sql .=
" AND ctc.source = 'internal'";
903 if ($filterontaskuser > 0) {
904 $sql .=
" AND t.fk_projet = p.rowid";
905 $sql .=
" AND p.rowid = ec2.element_id";
906 $sql .=
" AND ctc2.rowid = ec2.fk_c_type_contact";
907 $sql .=
" AND ctc2.element = 'project_task'";
908 $sql .=
" AND ec2.fk_socpeople = ".((int) $filterontaskuser);
909 $sql .=
" AND ec2.statut = 4";
910 $sql .=
" AND ctc2.source = 'internal'";
913 $sql .=
" AND p.fk_soc = ".((int) $socid);
916 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectid).
")";
921 if ($filteronprojstatus && $filteronprojstatus !=
'-1') {
922 $sql .=
" AND p.fk_statut IN (".$this->db->sanitize($filteronprojstatus).
")";
924 if ($morewherefilter) {
925 $sql .= $morewherefilter;
928 $extrafieldsobjectkey =
'projet_task';
929 $extrafieldsobjectprefix =
'efpt.';
931 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
933 $parameters = array();
934 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
935 $sql .= $hookmanager->resPrint;
936 if ($includebilltime) {
937 $sql .=
" GROUP BY p.rowid, p.ref, p.title, p.public, p.fk_statut, p.usage_bill_time,";
938 $sql .=
" t.datec, t.dateo, t.datee, t.tms,";
939 $sql .=
" t.rowid, t.ref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut,";
940 $sql .=
" t.dateo, t.datee, t.planned_workload, t.rang,";
941 $sql .=
" t.description, ";
942 $sql .=
" t.budget_amount, ";
943 $sql .=
" s.rowid, s.nom, s.email,";
944 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount";
945 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
946 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
947 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key :
'');
950 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
951 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
952 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key :
'');
958 $sql .=
" ORDER BY p.ref, t.rang, t.dateo";
961 dol_syslog(get_class($this).
"::getTasksArray", LOG_DEBUG);
970 $obj = $this->
db->fetch_object(
$resql);
973 if ((!$obj->public) && (is_object($userp))) {
978 if (is_object($usert)) {
986 $tasks[$i] =
new Task($this->
db);
987 $tasks[$i]->id = $obj->taskid;
988 $tasks[$i]->ref = $obj->taskref;
989 $tasks[$i]->fk_project = $obj->projectid;
990 $tasks[$i]->projectref = $obj->ref;
991 $tasks[$i]->projectlabel = $obj->plabel;
992 $tasks[$i]->projectstatus = $obj->projectstatus;
994 $tasks[$i]->fk_opp_status = $obj->fk_opp_status;
995 $tasks[$i]->opp_amount = $obj->opp_amount;
996 $tasks[$i]->opp_percent = $obj->opp_percent;
997 $tasks[$i]->budget_amount = $obj->budget_amount;
998 $tasks[$i]->project_budget_amount = $obj->project_budget_amount;
999 $tasks[$i]->usage_bill_time = $obj->usage_bill_time;
1001 $tasks[$i]->label = $obj->label;
1002 $tasks[$i]->description = $obj->description;
1003 $tasks[$i]->fk_parent = $obj->fk_task_parent;
1004 $tasks[$i]->fk_task_parent = $obj->fk_task_parent;
1005 $tasks[$i]->duration = $obj->duration_effective;
1006 $tasks[$i]->planned_workload = $obj->planned_workload;
1008 if ($includebilltime) {
1009 $tasks[$i]->tobill = $obj->tobill;
1010 $tasks[$i]->billed = $obj->billed;
1013 $tasks[$i]->progress = $obj->progress;
1014 $tasks[$i]->fk_statut = $obj->status;
1015 $tasks[$i]->public = $obj->public;
1016 $tasks[$i]->date_start = $this->
db->jdate($obj->date_start);
1017 $tasks[$i]->date_end = $this->
db->jdate($obj->date_end);
1018 $tasks[$i]->rang = $obj->rang;
1020 $tasks[$i]->socid = $obj->thirdparty_id;
1021 $tasks[$i]->thirdparty_id = $obj->thirdparty_id;
1022 $tasks[$i]->thirdparty_name = $obj->thirdparty_name;
1023 $tasks[$i]->thirdparty_email = $obj->thirdparty_email;
1025 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1026 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1027 if ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate') {
1028 $tmpvar =
'options_'.$key;
1029 $tasks[$i]->{
'options_'.$key} = $obj->$tmpvar;
1034 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
1035 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
1036 if ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate') {
1037 $tmpvar =
'options_'.$key;
1038 $tasks[$i]->{
'options_'.$key} = $obj->$tmpvar;
1044 $tasks[$i]->fetch_optionals();
1070 $arrayroles = array();
1072 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks userp=".is_object($userp).
" usert=".is_object($usert).
" projectid=".$projectid.
" taskid=".$taskid);
1075 if (empty($userp) && empty($usert)) {
1076 $this->error =
"CallWithWrongParameters";
1079 if (!empty($userp) && !empty($usert)) {
1080 $this->error =
"CallWithWrongParameters";
1085 $sql =
"SELECT pt.rowid as pid, ec.element_id, ctc.code, ctc.source";
1087 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as pt";
1089 if ($usert && $filteronprojstatus > -1) {
1090 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"projet_task as pt";
1092 if ($usert && $filteronprojstatus <= -1) {
1093 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as pt";
1095 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1096 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1097 $sql .=
" WHERE pt.rowid = ec.element_id";
1098 if ($userp && $filteronprojstatus > -1) {
1099 $sql .=
" AND pt.fk_statut = ".((int) $filteronprojstatus);
1101 if ($usert && $filteronprojstatus > -1) {
1102 $sql .=
" AND pt.fk_projet = p.rowid AND p.fk_statut = ".((int) $filteronprojstatus);
1105 $sql .=
" AND ctc.element = 'project'";
1108 $sql .=
" AND ctc.element = 'project_task'";
1110 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
1112 $sql .=
" AND ec.fk_socpeople = ".((int) $userp->id);
1115 $sql .=
" AND ec.fk_socpeople = ".((int) $usert->id);
1117 $sql .=
" AND ec.statut = 4";
1118 $sql .=
" AND ctc.source = 'internal'";
1121 $sql .=
" AND pt.rowid IN (".$this->db->sanitize($projectid).
")";
1124 $sql .=
" AND pt.fk_projet IN (".$this->db->sanitize($projectid).
")";
1129 $sql .=
" ERROR SHOULD NOT HAPPENS";
1132 $sql .=
" AND pt.rowid = ".((int) $taskid);
1137 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks execute request", LOG_DEBUG);
1140 $num = $this->
db->num_rows(
$resql);
1143 $obj = $this->
db->fetch_object(
$resql);
1144 if (empty($arrayroles[$obj->pid])) {
1145 $arrayroles[$obj->pid] = $obj->code;
1147 $arrayroles[$obj->pid] .=
','.$obj->code;
1168 $contactAlreadySelected = array();
1169 $tab = $this->liste_contact(-1, $source);
1174 if ($source ==
'thirdparty') {
1175 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
1177 $contactAlreadySelected[$i] = $tab[$i][
'id'];
1181 return $contactAlreadySelected;
1194 global $conf, $langs;
1196 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1202 if (!is_object($user)) {
1203 dol_print_error(
'',
"Method addTimeSpent was called with wrong parameter user");
1208 if (isset($this->timespent_note)) {
1209 $this->timespent_note = trim($this->timespent_note);
1211 if (empty($this->timespent_datehour)) {
1212 $this->timespent_datehour = $this->timespent_date;
1215 if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1216 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1219 if ($this->timespent_date < $restrictBefore) {
1220 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1221 $this->errors[] = $this->error;
1229 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet_task_time (";
1231 $sql .=
", task_date";
1232 $sql .=
", task_datehour";
1233 $sql .=
", task_date_withhour";
1234 $sql .=
", task_duration";
1235 $sql .=
", fk_user";
1236 $sql .=
", fk_product";
1239 $sql .=
") VALUES (";
1240 $sql .= ((int) $this->
id);
1241 $sql .=
", '".$this->db->idate($this->timespent_date).
"'";
1242 $sql .=
", '".$this->db->idate($this->timespent_datehour).
"'";
1243 $sql .=
", ".(empty($this->timespent_withhour) ? 0 : 1);
1244 $sql .=
", ".((int) $this->timespent_duration);
1245 $sql .=
", ".((int) $this->timespent_fk_user);
1246 $sql .=
", ".((int) $this->timespent_fk_product);
1247 $sql .=
", ".(isset($this->timespent_note) ?
"'".$this->db->escape($this->timespent_note).
"'" :
"null");
1248 $sql .=
", '".$this->db->idate($now).
"'";
1253 $tasktime_id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"projet_task_time");
1254 $ret = $tasktime_id;
1255 $this->timespent_id = $ret;
1259 $result = $this->call_trigger(
'TASK_TIMESPENT_CREATE', $user);
1266 $this->error = $this->
db->lasterror();
1272 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1273 $sql .=
" SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt where ptt.fk_task = ".((int) $this->
id).
")";
1274 if (isset($this->progress)) {
1275 $sql .=
", progress = ".((float) $this->progress);
1277 $sql .=
" WHERE rowid = ".((int) $this->
id);
1279 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1280 if (!$this->
db->query($sql)) {
1281 $this->error = $this->
db->lasterror();
1286 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time";
1287 $sql .=
" SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX.
"user WHERE rowid = ".((int) $this->timespent_fk_user).
")";
1288 $sql .=
" WHERE rowid = ".((int) $tasktime_id);
1290 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1291 if (!$this->
db->query($sql)) {
1292 $this->error = $this->
db->lasterror();
1298 $this->
db->commit();
1300 $this->
db->rollback();
1315 $arrayres = array();
1318 $sql .=
" s.rowid as socid,";
1319 $sql .=
" s.nom as thirdparty_name,";
1320 $sql .=
" s.email as thirdparty_email,";
1321 $sql .=
" ptt.rowid,";
1322 $sql .=
" ptt.fk_task,";
1323 $sql .=
" ptt.task_date,";
1324 $sql .=
" ptt.task_datehour,";
1325 $sql .=
" ptt.task_date_withhour,";
1326 $sql .=
" ptt.task_duration,";
1327 $sql .=
" ptt.fk_user,";
1328 $sql .=
" ptt.note,";
1329 $sql .=
" ptt.thm,";
1330 $sql .=
" pt.rowid as task_id,";
1331 $sql .=
" pt.ref as task_ref,";
1332 $sql .=
" pt.label as task_label,";
1333 $sql .=
" p.rowid as project_id,";
1334 $sql .=
" p.ref as project_ref,";
1335 $sql .=
" p.title as project_label,";
1336 $sql .=
" p.public as public";
1337 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1338 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1339 $sql .=
" WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1340 $sql .=
" AND pt.rowid = ".((int) $this->
id);
1341 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1342 if ($morewherefilter) {
1343 $sql .= $morewherefilter;
1346 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1349 $num = $this->
db->num_rows(
$resql);
1353 $obj = $this->
db->fetch_object(
$resql);
1355 $newobj =
new stdClass();
1357 $newobj->socid = $obj->socid;
1358 $newobj->thirdparty_name = $obj->thirdparty_name;
1359 $newobj->thirdparty_email = $obj->thirdparty_email;
1361 $newobj->fk_project = $obj->project_id;
1362 $newobj->project_ref = $obj->project_ref;
1363 $newobj->project_label = $obj->project_label;
1364 $newobj->public = $obj->project_public;
1366 $newobj->fk_task = $obj->task_id;
1367 $newobj->task_ref = $obj->task_ref;
1368 $newobj->task_label = $obj->task_label;
1370 $newobj->timespent_line_id = $obj->rowid;
1371 $newobj->timespent_line_date = $this->
db->jdate($obj->task_date);
1372 $newobj->timespent_line_datehour = $this->
db->jdate($obj->task_datehour);
1373 $newobj->timespent_line_withhour = $obj->task_date_withhour;
1374 $newobj->timespent_line_duration = $obj->task_duration;
1375 $newobj->timespent_line_fk_user = $obj->fk_user;
1376 $newobj->timespent_line_thm = $obj->thm;
1377 $newobj->timespent_line_note = $obj->note;
1379 $arrayres[] = $newobj;
1386 $this->lines = $arrayres;
1390 $this->error =
"Error ".$this->db->lasterror();
1405 if (is_object($userobj)) {
1406 $userid = $userobj->id;
1412 if (empty($id) && empty($userid)) {
1413 dol_syslog(
"getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR);
1420 $sql .=
" MIN(t.task_datehour) as min_date,";
1421 $sql .=
" MAX(t.task_datehour) as max_date,";
1422 $sql .=
" SUM(t.task_duration) as total_duration,";
1423 $sql .=
" SUM(t.task_duration / 3600 * ".$this->db->ifsql(
"t.thm IS NULL", 0,
"t.thm").
") as total_amount,";
1424 $sql .=
" COUNT(t.rowid) as nblines,";
1425 $sql .=
" SUM(".$this->db->ifsql(
"t.thm IS NULL", 1, 0).
") as nblinesnull";
1426 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1427 $sql .=
" WHERE 1 = 1";
1428 if ($morewherefilter) {
1429 $sql .= $morewherefilter;
1432 $sql .=
" AND t.fk_task = ".((int) $id);
1435 $sql .=
" AND t.fk_user = ".((int) $userid);
1438 dol_syslog(get_class($this).
"::getSummaryOfTimeSpent", LOG_DEBUG);
1441 $obj = $this->
db->fetch_object(
$resql);
1443 $result[
'min_date'] = $obj->min_date;
1444 $result[
'max_date'] = $obj->max_date;
1445 $result[
'total_duration'] = $obj->total_duration;
1447 $this->timespent_min_date = $this->
db->jdate($obj->min_date);
1448 $this->timespent_max_date = $this->
db->jdate($obj->max_date);
1449 $this->timespent_total_duration = $obj->total_duration;
1450 $this->timespent_total_amount = $obj->total_amount;
1451 $this->timespent_nblinesnull = ($obj->nblinesnull ? $obj->nblinesnull : 0);
1452 $this->timespent_nblines = ($obj->nblines ? $obj->nblines : 0);
1480 $sql .=
" SUM(t.task_duration) as nbseconds,";
1481 $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";
1482 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1483 $sql .=
" WHERE t.fk_task = ".((int) $id);
1484 if (is_object($fuser) && $fuser->id > 0) {
1485 $sql .=
" AND fk_user = ".((int) $fuser->id);
1488 $datefieldname =
"task_datehour";
1489 $sql .=
" AND (".$datefieldname.
" >= '".$this->
db->idate($dates).
"' OR ".$datefieldname.
" IS NULL)";
1492 $datefieldname =
"task_datehour";
1493 $sql .=
" AND (".$datefieldname.
" <= '".$this->
db->idate($datee).
"' OR ".$datefieldname.
" IS NULL)";
1497 dol_syslog(get_class($this).
"::getSumOfAmount", LOG_DEBUG);
1500 $obj = $this->
db->fetch_object(
$resql);
1502 $result[
'amount'] = $obj->amount;
1503 $result[
'nbseconds'] = $obj->nbseconds;
1504 $result[
'nblinesnull'] = $obj->nblinesnull;
1525 $sql .=
" t.rowid,";
1526 $sql .=
" t.fk_task,";
1527 $sql .=
" t.task_date,";
1528 $sql .=
" t.task_datehour,";
1529 $sql .=
" t.task_date_withhour,";
1530 $sql .=
" t.task_duration,";
1531 $sql .=
" t.fk_user,";
1532 $sql .=
" t.fk_product,";
1535 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1536 $sql .=
" WHERE t.rowid = ".((int) $id);
1538 dol_syslog(get_class($this).
"::fetchTimeSpent", LOG_DEBUG);
1542 $obj = $this->
db->fetch_object(
$resql);
1544 $this->timespent_id = $obj->rowid;
1545 $this->
id = $obj->fk_task;
1546 $this->timespent_date = $this->
db->jdate($obj->task_date);
1547 $this->timespent_datehour = $this->
db->jdate($obj->task_datehour);
1548 $this->timespent_withhour = $obj->task_date_withhour;
1549 $this->timespent_duration = $obj->task_duration;
1550 $this->timespent_fk_user = $obj->fk_user;
1551 $this->timespent_fk_product = $obj->fk_product;
1552 $this->timespent_thm = $obj->thm;
1553 $this->timespent_note = $obj->note;
1560 $this->error =
"Error ".$this->db->lasterror();
1574 $arrayres = array();
1577 $sql .=
" s.rowid as socid,";
1578 $sql .=
" s.nom as thirdparty_name,";
1579 $sql .=
" s.email as thirdparty_email,";
1580 $sql .=
" ptt.rowid,";
1581 $sql .=
" ptt.fk_task,";
1582 $sql .=
" ptt.task_date,";
1583 $sql .=
" ptt.task_datehour,";
1584 $sql .=
" ptt.task_date_withhour,";
1585 $sql .=
" ptt.task_duration,";
1586 $sql .=
" ptt.fk_user,";
1587 $sql .=
" ptt.note,";
1588 $sql .=
" ptt.thm,";
1589 $sql .=
" pt.rowid as task_id,";
1590 $sql .=
" pt.ref as task_ref,";
1591 $sql .=
" pt.label as task_label,";
1592 $sql .=
" p.rowid as project_id,";
1593 $sql .=
" p.ref as project_ref,";
1594 $sql .=
" p.title as project_label,";
1595 $sql .=
" p.public as public";
1596 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1597 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1598 $sql .=
" WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1599 $sql .=
" AND ptt.fk_user = ".((int) $userobj->id);
1600 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1601 if ($morewherefilter) {
1602 $sql .= $morewherefilter;
1605 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1608 $num = $this->
db->num_rows(
$resql);
1612 $obj = $this->
db->fetch_object(
$resql);
1614 $newobj =
new stdClass();
1616 $newobj->socid = $obj->socid;
1617 $newobj->thirdparty_name = $obj->thirdparty_name;
1618 $newobj->thirdparty_email = $obj->thirdparty_email;
1620 $newobj->fk_project = $obj->project_id;
1621 $newobj->project_ref = $obj->project_ref;
1622 $newobj->project_label = $obj->project_label;
1623 $newobj->public = $obj->project_public;
1625 $newobj->fk_task = $obj->task_id;
1626 $newobj->task_ref = $obj->task_ref;
1627 $newobj->task_label = $obj->task_label;
1629 $newobj->timespent_id = $obj->rowid;
1630 $newobj->timespent_date = $this->
db->jdate($obj->task_date);
1631 $newobj->timespent_datehour = $this->
db->jdate($obj->task_datehour);
1632 $newobj->timespent_withhour = $obj->task_date_withhour;
1633 $newobj->timespent_duration = $obj->task_duration;
1634 $newobj->timespent_fk_user = $obj->fk_user;
1635 $newobj->timespent_thm = $obj->thm;
1636 $newobj->timespent_note = $obj->note;
1638 $arrayres[] = $newobj;
1646 $this->error =
"Error ".$this->db->lasterror();
1662 global $conf, $langs;
1667 if ($this->timespent_date ==
'') {
1668 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date"));
1671 if (!($this->timespent_fk_user > 0)) {
1672 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"User"));
1677 if (empty($this->timespent_datehour)) {
1678 $this->timespent_datehour = $this->timespent_date;
1680 if (isset($this->timespent_note)) {
1681 $this->timespent_note = trim($this->timespent_note);
1684 if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1685 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1688 if ($this->timespent_date < $restrictBefore) {
1689 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1690 $this->errors[] = $this->error;
1697 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time SET";
1698 $sql .=
" task_date = '".$this->db->idate($this->timespent_date).
"',";
1699 $sql .=
" task_datehour = '".$this->db->idate($this->timespent_datehour).
"',";
1700 $sql .=
" task_date_withhour = ".(empty($this->timespent_withhour) ? 0 : 1).
",";
1701 $sql .=
" task_duration = ".((int) $this->timespent_duration).
",";
1702 $sql .=
" fk_user = ".((int) $this->timespent_fk_user).
",";
1703 $sql .=
" fk_product = ".((int) $this->timespent_fk_product).
",";
1704 $sql .=
" note = ".(isset($this->timespent_note) ?
"'".$this->db->escape($this->timespent_note).
"'" :
"null");
1705 $sql .=
" WHERE rowid = ".((int) $this->timespent_id);
1707 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
1708 if ($this->
db->query($sql)) {
1711 $result = $this->call_trigger(
'TASK_TIMESPENT_MODIFY', $user);
1713 $this->
db->rollback();
1723 $this->error = $this->
db->lasterror();
1724 $this->
db->rollback();
1728 if ($ret == 1 && (($this->timespent_old_duration != $this->timespent_duration) || !empty($conf->global->TIMESPENT_ALWAYS_UPDATE_THM))) {
1729 if ($this->timespent_old_duration != $this->timespent_duration) {
1731 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"projet_task";
1732 $sql .=
" SET duration_effective = (SELECT SUM(task_duration) FROM " . MAIN_DB_PREFIX .
"projet_task_time as ptt where ptt.fk_task = " . ((int) $this->
id) .
")";
1733 if (isset($this->progress)) {
1734 $sql .=
", progress = " . ((
float) $this->progress);
1736 $sql .=
" WHERE rowid = " . ((int) $this->
id);
1738 dol_syslog(get_class($this) .
"::updateTimeSpent", LOG_DEBUG);
1739 if (!$this->
db->query($sql)) {
1740 $this->error = $this->
db->lasterror();
1741 $this->
db->rollback();
1747 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time";
1748 $sql .=
" SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX.
"user WHERE rowid = ".((int) $this->timespent_fk_user).
")";
1749 $sql .=
" WHERE rowid = ".((int) $this->timespent_id);
1750 if (empty($conf->global->TIMESPENT_ALWAYS_UPDATE_THM)) {
1751 $sql .=
" AND (thm IS NULL OR thm = 0)";
1754 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1755 if (!$this->
db->query($sql)) {
1756 $this->error = $this->
db->lasterror();
1762 $this->
db->commit();
1776 global $conf, $langs;
1780 if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1781 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1784 if ($this->timespent_date < $restrictBefore) {
1785 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1786 $this->errors[] = $this->error;
1795 $result = $this->call_trigger(
'TASK_TIMESPENT_DELETE', $user);
1803 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_time";
1804 $sql .=
" WHERE rowid = ".((int) $this->timespent_id);
1806 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
1809 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1814 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1815 $sql .=
" SET duration_effective = duration_effective - ".$this->db->escape($this->timespent_duration ? $this->timespent_duration : 0);
1816 $sql .=
" WHERE rowid = ".((int) $this->
id);
1818 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
1819 if ($this->
db->query($sql)) {
1822 $this->error = $this->
db->lasterror();
1829 foreach ($this->errors as $errmsg) {
1830 dol_syslog(get_class($this).
"::delTimeSpent ".$errmsg, LOG_ERR);
1831 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1833 $this->
db->rollback();
1836 $this->
db->commit();
1855 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)
1857 global $langs, $conf;
1866 $clone_task =
new Task($this->
db);
1867 $origin_task =
new Task($this->
db);
1869 $clone_task->context[
'createfromclone'] =
'createfromclone';
1874 $clone_task->fetch($fromid);
1875 $clone_task->fetch_optionals();
1878 $origin_task->fetch($fromid);
1881 $obj = empty($conf->global->PROJECT_TASK_ADDON) ?
'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
1882 if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT.
"/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.
".php")) {
1883 require_once DOL_DOCUMENT_ROOT.
"/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.
'.php';
1884 $modTask =
new $obj;
1885 $defaultref = $modTask->getNextValue(0, $clone_task);
1888 $ori_project_id = $clone_task->fk_project;
1890 $clone_task->id = 0;
1891 $clone_task->ref = $defaultref;
1892 $clone_task->fk_project = $project_id;
1893 $clone_task->fk_task_parent = $parent_task_id;
1894 $clone_task->date_c = $datec;
1895 $clone_task->planned_workload = $origin_task->planned_workload;
1896 $clone_task->rang = $origin_task->rang;
1899 if ($clone_change_dt) {
1900 $projectstatic =
new Project($this->
db);
1901 $projectstatic->fetch($ori_project_id);
1904 $orign_project_dt_start = $projectstatic->date_start;
1907 if (!empty($clone_task->date_start)) {
1908 $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
1912 if (!empty($clone_task->date_end)) {
1913 $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
1918 $clone_task->progress = 0;
1922 $result = $clone_task->create($user);
1926 $this->error = $clone_task->error;
1932 $clone_task_id = $clone_task->id;
1933 $clone_task_ref = $clone_task->ref;
1937 $clone_task->note_private =
'';
1938 $clone_task->note_public =
'';
1941 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_public, ENT_QUOTES | ENT_HTML5),
'_public');
1943 $this->error .= $clone_task->error;
1945 $this->
db->rollback();
1947 $this->
db->commit();
1951 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_private, ENT_QUOTES | ENT_HTML5),
'_private');
1953 $this->error .= $clone_task->error;
1955 $this->
db->rollback();
1957 $this->
db->commit();
1963 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1966 $projectstatic =
new Project($this->
db);
1967 $projectstatic->fetch($ori_project_id);
1968 $ori_project_ref = $projectstatic->ref;
1970 if ($ori_project_id != $project_id) {
1971 $projectstatic->fetch($project_id);
1972 $clone_project_ref = $projectstatic->ref;
1974 $clone_project_ref = $ori_project_ref;
1980 $filearray =
dol_dir_list($ori_task_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'', SORT_ASC, 1);
1981 foreach ($filearray as $key => $file) {
1982 if (!file_exists($clone_task_dir)) {
1984 $this->error .= $langs->trans(
'ErrorInternalErrorDetected').
':dol_mkdir';
1989 $rescopy =
dol_copy($ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name'], 0, 1);
1990 if (is_numeric($rescopy) && $rescopy < 0) {
1991 $this->error .= $langs->trans(
"ErrorFailToCopyFile", $ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name']);
1998 if ($clone_affectation) {
1999 $origin_task =
new Task($this->
db);
2000 $origin_task->fetch($fromid);
2002 foreach (array(
'internal',
'external') as $source) {
2003 $tab = $origin_task->liste_contact(-1, $source);
2007 $clone_task->add_contact($tab[$i][
'id'], $tab[$i][
'code'], $tab[$i][
'source']);
2008 if ($clone_task->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2009 $langs->load(
"errors");
2010 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
2013 if ($clone_task->error !=
'') {
2014 $this->error .= $clone_task->error;
2028 unset($clone_task->context[
'createfromclone']);
2031 $this->
db->commit();
2032 return $clone_task_id;
2034 $this->
db->rollback();
2035 dol_syslog(get_class($this).
"::createFromClone nbError: ".$error.
" error : ".$this->error, LOG_ERR);
2049 return $this->LibStatut($this->fk_statut, $mode);
2066 $this->statuts[0] =
'Draft';
2067 $this->statuts[1] =
'ToDo';
2068 $this->statuts[2] =
'Running';
2069 $this->statuts[3] =
'Finish';
2070 $this->statuts[4] =
'Transfered';
2071 $this->statuts_short[0] =
'Draft';
2072 $this->statuts_short[1] =
'ToDo';
2073 $this->statuts_short[2] =
'Running';
2074 $this->statuts_short[3] =
'Completed';
2075 $this->statuts_short[4] =
'Transfered';
2078 return $langs->trans($this->statuts[$status]);
2079 } elseif ($mode == 1) {
2080 return $langs->trans($this->statuts_short[$status]);
2081 } elseif ($mode == 2) {
2083 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts_short[$status]);
2084 } elseif ($status == 1) {
2085 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1').
' '.$langs->trans($this->statuts_short[$status]);
2086 } elseif ($status == 2) {
2087 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3').
' '.$langs->trans($this->statuts_short[$status]);
2088 } elseif ($status == 3) {
2089 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
2090 } elseif ($status == 4) {
2091 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
2092 } elseif ($status == 5) {
2093 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5').
' '.$langs->trans($this->statuts_short[$status]);
2095 } elseif ($mode == 3) {
2097 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0');
2098 } elseif ($status == 1) {
2099 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1');
2100 } elseif ($status == 2) {
2101 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3');
2102 } elseif ($status == 3) {
2103 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
2104 } elseif ($status == 4) {
2105 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
2106 } elseif ($status == 5) {
2107 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5');
2109 } elseif ($mode == 4) {
2111 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts[$status]);
2112 } elseif ($status == 1) {
2113 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1').
' '.$langs->trans($this->statuts[$status]);
2114 } elseif ($status == 2) {
2115 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3').
' '.$langs->trans($this->statuts[$status]);
2116 } elseif ($status == 3) {
2117 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
2118 } elseif ($status == 4) {
2119 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
2120 } elseif ($status == 5) {
2121 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5').
' '.$langs->trans($this->statuts[$status]);
2123 } elseif ($mode == 5) {
2133 } elseif ($mode == 6) {
2156 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2160 $outputlangs->load(
"projects");
2163 $modele =
'nodefault';
2165 if (!empty($this->model_pdf)) {
2166 $modele = $this->model_pdf;
2167 } elseif (!empty($this->modelpdf)) {
2168 $modele = $this->modelpdf;
2169 } elseif (!empty($conf->global->PROJECT_TASK_ADDON_PDF)) {
2170 $modele = $conf->global->PROJECT_TASK_ADDON_PDF;
2174 $modelpath =
"core/modules/project/task/doc/";
2176 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2190 global $conf, $langs;
2196 $projectstatic =
new Project($this->
db);
2197 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
2200 $sql =
"SELECT p.rowid as projectid, p.fk_statut as projectstatus,";
2201 $sql .=
" t.rowid as taskid, t.progress as progress, t.fk_statut as status,";
2202 $sql .=
" t.dateo as date_start, t.datee as datee";
2203 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2206 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2207 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2208 $sql .=
" AND p.fk_statut = 1";
2209 $sql .=
" AND t.fk_projet = p.rowid";
2210 $sql .=
" AND (t.progress IS NULL OR t.progress < 100)";
2211 if (empty($user->rights->projet->all->lire)) {
2212 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2222 $task_static =
new Task($this->
db);
2225 $response->warning_delay = $conf->project->task->warning_delay / 60 / 60 / 24;
2226 $response->label = $langs->trans(
"OpenedTasks");
2227 if ($user->hasRight(
"projet",
"all",
"lire")) {
2228 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mainmenu=project';
2230 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mode=mine&mainmenu=project';
2235 while ($obj = $this->
db->fetch_object(
$resql)) {
2236 $response->nbtodo++;
2238 $task_static->projectstatus = $obj->projectstatus;
2239 $task_static->progress = $obj->progress;
2240 $task_static->fk_statut = $obj->status;
2241 $task_static->date_end = $this->
db->jdate($obj->datee);
2243 if ($task_static->hasDelay()) {
2244 $response->nbtodolate++;
2250 $this->error = $this->
db->error();
2267 $mine = 0; $socid = $user->socid;
2269 $projectstatic =
new Project($this->
db);
2270 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $mine, 1, $socid);
2273 $sql =
"SELECT count(p.rowid) as nb";
2274 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2275 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
2276 if (empty($user->rights->societe->client->voir) && !$socid) {
2277 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2279 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2280 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2281 $sql .=
" AND t.fk_projet = p.rowid";
2282 if ($mine || empty($user->rights->projet->all->lire)) {
2283 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2288 $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).
")";
2290 if (empty($user->rights->societe->client->voir) && !$socid) {
2291 $sql .=
" AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).
") OR (s.rowid IS NULL))";
2297 while ($obj = $this->
db->fetch_object(
$resql)) {
2298 $this->nb[
"tasks"] = $obj->nb;
2304 $this->error = $this->
db->error();
2318 if (!($this->progress >= 0 && $this->progress < 100)) {
2324 $datetouse = ($this->date_end > 0) ? $this->date_end : ((isset($this->datee) && $this->datee > 0) ? $this->datee : 0);
2326 return ($datetouse > 0 && ($datetouse < ($now - $conf->project->task->warning_delay)));
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...
isObjectUsed($id=0, $entity=0)
Function to check if an object is used by others.
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage 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.
getSumOfAmount($fuser='', $dates='', $datee='')
Calculate quantity and value of time consumed using the thm (hourly amount value of work for user ent...
__construct($db)
Constructor.
fetchTimeSpentOnTask($morewherefilter='')
Fetch records of time spent of this task.
hasTimeSpent()
Return nb of time spent.
getNomUrl($withpicto=0, $option='', $mode='task', $addlabel=0, $sep=' - ', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
getListContactId($source='internal')
Return list of id of contacts of task.
delTimeSpent($user, $notrigger=0)
Delete time spent.
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, $loadRoleMode=1)
Return list of tasks for all projects or for one particular project Sort order is on project,...
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.
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.
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.
initAsSpecimen()
Initialise an instance with random values.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
addTimeSpent($user, $notrigger=0)
Add time spent.
hasDelay()
Is the task delayed?
LibStatut($status, $mode=0)
Return status label for an object.
hasChildren()
Return nb of children.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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)
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
dol_move_dir($srcdir, $destdir, $overwriteifexists=1, $indexdatabase=1, $renamedircontent=1)
Move a directory into another name.
dol_dir_list($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 informations (by default a local PHP server timestamp) Re...
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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)
div float
Buy price without taxes.
$conf db
API class for accounts.