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 .= (!empty($this->entity) ? (int) $this->entity : (
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.entity,";
279 $sql .=
" t.fk_projet as fk_project,";
280 $sql .=
" t.fk_task_parent,";
282 $sql .=
" t.description,";
283 $sql .=
" t.duration_effective,";
284 $sql .=
" t.planned_workload,";
288 $sql .=
" t.fk_user_creat,";
289 $sql .=
" t.fk_user_valid,";
290 $sql .=
" t.fk_statut,";
291 $sql .=
" t.progress,";
292 $sql .=
" t.budget_amount,";
293 $sql .=
" t.priority,";
294 $sql .=
" t.note_private,";
295 $sql .=
" t.note_public,";
297 if (!empty($loadparentdata)) {
298 $sql .=
", t2.ref as task_parent_ref";
299 $sql .=
", t2.rang as task_parent_position";
301 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as t";
302 if (!empty($loadparentdata)) {
303 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t2 ON t.fk_task_parent = t2.rowid";
307 $sql .=
"entity IN (".getEntity(
'project').
")";
308 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
310 $sql .=
"t.rowid = ".((int) $id);
313 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
316 $num_rows = $this->
db->num_rows(
$resql);
319 $obj = $this->
db->fetch_object(
$resql);
321 $this->
id = $obj->rowid;
322 $this->
ref = $obj->ref;
323 $this->entity = $obj->entity;
324 $this->fk_project = $obj->fk_project;
325 $this->fk_task_parent = $obj->fk_task_parent;
326 $this->label = $obj->label;
328 $this->duration_effective = $obj->duration_effective;
329 $this->planned_workload = $obj->planned_workload;
330 $this->date_c = $this->
db->jdate($obj->datec);
331 $this->date_start = $this->
db->jdate($obj->dateo);
332 $this->date_end = $this->
db->jdate($obj->datee);
333 $this->fk_user_creat = $obj->fk_user_creat;
334 $this->fk_user_valid = $obj->fk_user_valid;
335 $this->fk_statut = $obj->fk_statut;
336 $this->progress = $obj->progress;
337 $this->budget_amount = $obj->budget_amount;
338 $this->priority = $obj->priority;
339 $this->note_private = $obj->note_private;
340 $this->note_public = $obj->note_public;
341 $this->rang = $obj->rang;
343 if (!empty($loadparentdata)) {
344 $this->task_parent_ref = $obj->task_parent_ref;
345 $this->task_parent_position = $obj->task_parent_position;
360 $this->error =
"Error ".$this->db->lasterror();
373 public function update($user =
null, $notrigger = 0)
375 global $conf, $langs;
379 if (isset($this->fk_project)) {
380 $this->fk_project = trim($this->fk_project);
382 if (isset($this->
ref)) {
383 $this->
ref = trim($this->
ref);
385 if (isset($this->fk_task_parent)) {
386 $this->fk_task_parent = (int) $this->fk_task_parent;
388 if (isset($this->label)) {
389 $this->label = trim($this->label);
394 if (isset($this->duration_effective)) {
395 $this->duration_effective = trim($this->duration_effective);
397 if (isset($this->planned_workload)) {
398 $this->planned_workload = trim($this->planned_workload);
400 if (isset($this->budget_amount)) {
401 $this->budget_amount = trim($this->budget_amount);
404 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
405 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
413 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
414 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
415 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"'".$this->db->escape($this->
id).
"'").
",";
416 $sql .=
" fk_task_parent=".(isset($this->fk_task_parent) ? $this->fk_task_parent :
"null").
",";
417 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
418 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
419 $sql .=
" duration_effective=".(isset($this->duration_effective) ? $this->duration_effective :
"null").
",";
420 $sql .=
" planned_workload=".((isset($this->planned_workload) && $this->planned_workload !=
'') ? $this->planned_workload :
"null").
",";
421 $sql .=
" dateo=".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
'null').
",";
422 $sql .=
" datee=".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
'null').
",";
423 $sql .=
" progress=".(($this->progress !=
'' && $this->progress >= 0) ? $this->progress :
'null').
",";
424 $sql .=
" budget_amount=".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? $this->budget_amount :
'null').
",";
425 $sql .=
" rang=".((!empty($this->rang)) ? $this->rang :
"0");
426 $sql .=
" WHERE rowid=".((int) $this->
id);
430 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
433 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
444 if (!$error && !empty($conf->global->PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE)) {
447 if ($project->fetch($this->fk_project) > 0) {
449 $project->getLinesArray(
null);
450 $projectCompleted = array_reduce(
452 function ($allTasksCompleted, $task) {
453 return $allTasksCompleted && $task->progress >= 100;
457 if ($projectCompleted) {
458 if ($project->setClose($user) <= 0) {
467 $this->errors[] = $project->error;
482 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
484 if ($conf->project->dir_output) {
486 $project->fetch($this->fk_project);
490 if (file_exists($olddir)) {
491 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
494 $langs->load(
"errors");
495 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
504 foreach ($this->errors as $errmsg) {
505 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
506 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
508 $this->
db->rollback();
524 public function delete($user, $notrigger = 0)
527 global $conf, $langs;
528 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
535 dol_syslog(get_class($this).
"::delete Can't delete record as it has some sub tasks", LOG_WARNING);
536 $this->error =
'ErrorRecordHasSubTasks';
537 $this->
db->rollback();
542 if (!empty($objectisused)) {
543 dol_syslog(get_class($this).
"::delete Can't delete record as it has some child", LOG_WARNING);
544 $this->error =
'ErrorRecordHasChildren';
545 $this->
db->rollback();
553 $this->error =
'ErrorFailToDeleteLinkedContact';
555 $this->
db->rollback();
561 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_time";
562 $sql .=
" WHERE fk_task = ".((int) $this->
id);
566 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
571 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_extrafields";
572 $sql .=
" WHERE fk_object = ".((int) $this->
id);
576 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
581 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task";
582 $sql .=
" WHERE rowid=".((int) $this->
id);
586 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
603 foreach ($this->errors as $errmsg) {
604 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
605 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
607 $this->
db->rollback();
611 if ($conf->project->dir_output) {
613 $projectstatic->fetch($this->fk_project);
616 dol_syslog(get_class($this).
"::delete dir=".$dir, LOG_DEBUG);
617 if (file_exists($dir)) {
618 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
621 $this->error =
'ErrorFailToDeleteDir';
622 $this->
db->rollback();
644 $sql =
"SELECT COUNT(*) as nb";
645 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task";
646 $sql .=
" WHERE fk_task_parent = ".((int) $this->
id);
648 dol_syslog(get_class($this).
"::hasChildren", LOG_DEBUG);
651 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
653 $obj = $this->
db->fetch_object(
$resql);
677 $sql =
"SELECT COUNT(*) as nb";
678 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time";
679 $sql .=
" WHERE fk_task = ".((int) $this->
id);
681 dol_syslog(get_class($this).
"::hasTimeSpent", LOG_DEBUG);
684 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
686 $obj = $this->
db->fetch_object(
$resql);
713 public function getNomUrl($withpicto = 0, $option =
'', $mode =
'task', $addlabel = 0, $sep =
' - ', $notooltip = 0, $save_lastsearch_value = -1)
715 global $conf, $langs, $user;
717 if (!empty($conf->dol_no_mouse_hover)) {
722 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Task").
'</u>';
723 if (!empty($this->
ref)) {
724 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
726 if (!empty($this->label)) {
727 $label .=
'<br><b>'.$langs->trans(
'LabelTask').
':</b> '.$this->label;
729 if ($this->date_start || $this->date_end) {
730 $label .=
"<br>".get_date_range($this->date_start, $this->date_end,
'', $langs, 0);
733 $url = DOL_URL_ROOT.
'/projet/tasks/'.$mode.
'.php?id='.$this->
id.($option ==
'withproject' ?
'&withproject=1' :
'');
735 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
736 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
737 $add_save_lastsearch_values = 1;
739 if ($add_save_lastsearch_values) {
740 $url .=
'&save_lastsearch_values=1';
744 if (empty($notooltip)) {
745 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
746 $label = $langs->trans(
"ShowTask");
747 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
749 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
750 $linkclose .=
' class="classfortooltip nowraponall"';
752 $linkclose .=
' class="nowraponall"';
755 $linkstart =
'<a href="'.$url.
'"';
756 $linkstart .= $linkclose.
'>';
759 $picto =
'projecttask';
761 $result .= $linkstart;
763 $result .=
img_object(($notooltip ?
'' : $label), $picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
765 if ($withpicto != 2) {
766 $result .= $this->ref;
769 if ($withpicto != 2) {
770 $result .= (($addlabel && $this->label) ? $sep.dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) :
'');
787 $this->fk_project =
'';
789 $this->fk_task_parent =
null;
790 $this->label =
'Specimen task TK01';
791 $this->duration_effective =
'';
792 $this->fk_user_creat =
null;
793 $this->progress =
'25';
794 $this->fk_statut =
null;
795 $this->note =
'This is a specimen task not';
821 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, $sortfield =
'', $sortorder =
'')
823 global $conf, $hookmanager;
831 if ($filteronprojuser > 0 || $filterontaskuser > 0) {
834 $sql .=
" p.rowid as projectid, p.ref, p.title as plabel, p.public, p.fk_statut as projectstatus, p.usage_bill_time,";
835 $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,";
836 $sql .=
" t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang,";
837 $sql .=
" t.description, ";
838 $sql .=
" t.budget_amount, ";
839 $sql .=
" s.rowid as thirdparty_id, s.nom as thirdparty_name, s.email as thirdparty_email,";
840 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount as project_budget_amount";
841 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
842 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
843 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key.
" as options_".$key :
'');
846 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
847 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
848 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key.
" as options_".$key :
'');
851 if ($includebilltime) {
852 $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";
855 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
856 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
857 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_extrafields as efp ON (p.rowid = efp.fk_object)";
860 if ($filteronprojuser > 0) {
861 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
862 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
864 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
865 if ($includebilltime) {
866 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
868 if ($filterontaskuser > 0) {
869 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
870 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
872 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
873 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
874 $sql .=
" AND t.fk_projet = p.rowid";
875 } elseif ($mode == 1) {
876 if ($filteronprojuser > 0) {
877 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
878 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
880 if ($filterontaskuser > 0) {
881 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
882 if ($includebilltime) {
883 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
885 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
886 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
888 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t on t.fk_projet = p.rowid";
889 if ($includebilltime) {
890 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
893 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
894 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
896 return 'BadValueForParameterMode';
899 if ($filteronprojuser > 0) {
900 $sql .=
" AND p.rowid = ec.element_id";
901 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
902 $sql .=
" AND ctc.element = 'project'";
903 $sql .=
" AND ec.fk_socpeople = ".((int) $filteronprojuser);
904 $sql .=
" AND ec.statut = 4";
905 $sql .=
" AND ctc.source = 'internal'";
907 if ($filterontaskuser > 0) {
908 $sql .=
" AND t.fk_projet = p.rowid";
909 $sql .=
" AND p.rowid = ec2.element_id";
910 $sql .=
" AND ctc2.rowid = ec2.fk_c_type_contact";
911 $sql .=
" AND ctc2.element = 'project_task'";
912 $sql .=
" AND ec2.fk_socpeople = ".((int) $filterontaskuser);
913 $sql .=
" AND ec2.statut = 4";
914 $sql .=
" AND ctc2.source = 'internal'";
917 $sql .=
" AND p.fk_soc = ".((int) $socid);
920 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectid).
")";
925 if ($filteronprojstatus && $filteronprojstatus !=
'-1') {
926 $sql .=
" AND p.fk_statut IN (".$this->db->sanitize($filteronprojstatus).
")";
928 if ($morewherefilter) {
929 $sql .= $morewherefilter;
932 $extrafieldsobjectkey =
'projet_task';
933 $extrafieldsobjectprefix =
'efpt.';
935 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
937 $parameters = array();
938 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
939 $sql .= $hookmanager->resPrint;
940 if ($includebilltime) {
941 $sql .=
" GROUP BY p.rowid, p.ref, p.title, p.public, p.fk_statut, p.usage_bill_time,";
942 $sql .=
" t.datec, t.dateo, t.datee, t.tms,";
943 $sql .=
" t.rowid, t.ref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut,";
944 $sql .=
" t.dateo, t.datee, t.planned_workload, t.rang,";
945 $sql .=
" t.description, ";
946 $sql .=
" t.budget_amount, ";
947 $sql .=
" s.rowid, s.nom, s.email,";
948 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount";
949 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
950 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
951 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key :
'');
954 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
955 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
956 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key :
'');
961 if ($sortfield && $sortorder) {
962 $sql .= $this->
db->order($sortfield, $sortorder);
964 $sql .=
" ORDER BY p.ref, t.rang, t.dateo";
968 dol_syslog(get_class($this).
"::getTasksArray", LOG_DEBUG);
977 $obj = $this->
db->fetch_object(
$resql);
980 if ((!$obj->public) && (is_object($userp))) {
985 if (is_object($usert)) {
993 $tasks[$i] =
new Task($this->
db);
994 $tasks[$i]->id = $obj->taskid;
995 $tasks[$i]->ref = $obj->taskref;
996 $tasks[$i]->fk_project = $obj->projectid;
997 $tasks[$i]->projectref = $obj->ref;
998 $tasks[$i]->projectlabel = $obj->plabel;
999 $tasks[$i]->projectstatus = $obj->projectstatus;
1001 $tasks[$i]->fk_opp_status = $obj->fk_opp_status;
1002 $tasks[$i]->opp_amount = $obj->opp_amount;
1003 $tasks[$i]->opp_percent = $obj->opp_percent;
1004 $tasks[$i]->budget_amount = $obj->budget_amount;
1005 $tasks[$i]->project_budget_amount = $obj->project_budget_amount;
1006 $tasks[$i]->usage_bill_time = $obj->usage_bill_time;
1008 $tasks[$i]->label = $obj->label;
1009 $tasks[$i]->description = $obj->description;
1010 $tasks[$i]->fk_parent = $obj->fk_task_parent;
1011 $tasks[$i]->fk_task_parent = $obj->fk_task_parent;
1012 $tasks[$i]->duration = $obj->duration_effective;
1013 $tasks[$i]->planned_workload = $obj->planned_workload;
1015 if ($includebilltime) {
1016 $tasks[$i]->tobill = $obj->tobill;
1017 $tasks[$i]->billed = $obj->billed;
1020 $tasks[$i]->progress = $obj->progress;
1021 $tasks[$i]->fk_statut = $obj->status;
1022 $tasks[$i]->public = $obj->public;
1023 $tasks[$i]->date_start = $this->
db->jdate($obj->date_start);
1024 $tasks[$i]->date_end = $this->
db->jdate($obj->date_end);
1025 $tasks[$i]->rang = $obj->rang;
1027 $tasks[$i]->socid = $obj->thirdparty_id;
1028 $tasks[$i]->thirdparty_id = $obj->thirdparty_id;
1029 $tasks[$i]->thirdparty_name = $obj->thirdparty_name;
1030 $tasks[$i]->thirdparty_email = $obj->thirdparty_email;
1032 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1033 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1034 if ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate') {
1035 $tasks[$i]->{
'options_'.$key} = $obj->{
'options_'.$key};
1040 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
1041 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
1042 if ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate') {
1043 $tasks[$i]->{
'options_'.$key} = $obj->{
'options_'.$key};
1049 $tasks[$i]->fetch_optionals();
1075 $arrayroles = array();
1077 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks userp=".is_object($userp).
" usert=".is_object($usert).
" projectid=".$projectid.
" taskid=".$taskid);
1080 if (empty($userp) && empty($usert)) {
1081 $this->error =
"CallWithWrongParameters";
1084 if (!empty($userp) && !empty($usert)) {
1085 $this->error =
"CallWithWrongParameters";
1090 $sql =
"SELECT pt.rowid as pid, ec.element_id, ctc.code, ctc.source";
1092 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as pt";
1094 if ($usert && $filteronprojstatus > -1) {
1095 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"projet_task as pt";
1097 if ($usert && $filteronprojstatus <= -1) {
1098 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as pt";
1100 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1101 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1102 $sql .=
" WHERE pt.rowid = ec.element_id";
1103 if ($userp && $filteronprojstatus > -1) {
1104 $sql .=
" AND pt.fk_statut = ".((int) $filteronprojstatus);
1106 if ($usert && $filteronprojstatus > -1) {
1107 $sql .=
" AND pt.fk_projet = p.rowid AND p.fk_statut = ".((int) $filteronprojstatus);
1110 $sql .=
" AND ctc.element = 'project'";
1113 $sql .=
" AND ctc.element = 'project_task'";
1115 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
1117 $sql .=
" AND ec.fk_socpeople = ".((int) $userp->id);
1120 $sql .=
" AND ec.fk_socpeople = ".((int) $usert->id);
1122 $sql .=
" AND ec.statut = 4";
1123 $sql .=
" AND ctc.source = 'internal'";
1126 $sql .=
" AND pt.rowid IN (".$this->db->sanitize($projectid).
")";
1129 $sql .=
" AND pt.fk_projet IN (".$this->db->sanitize($projectid).
")";
1134 $sql .=
" ERROR SHOULD NOT HAPPENS";
1137 $sql .=
" AND pt.rowid = ".((int) $taskid);
1142 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks execute request", LOG_DEBUG);
1145 $num = $this->
db->num_rows(
$resql);
1148 $obj = $this->
db->fetch_object(
$resql);
1149 if (empty($arrayroles[$obj->pid])) {
1150 $arrayroles[$obj->pid] = $obj->code;
1152 $arrayroles[$obj->pid] .=
','.$obj->code;
1173 $contactAlreadySelected = array();
1174 $tab = $this->liste_contact(-1, $source);
1179 if ($source ==
'thirdparty') {
1180 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
1182 $contactAlreadySelected[$i] = $tab[$i][
'id'];
1186 return $contactAlreadySelected;
1199 global $conf, $langs;
1201 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1207 if (!is_object($user)) {
1208 dol_print_error(
'',
"Method addTimeSpent was called with wrong parameter user");
1213 if (isset($this->timespent_note)) {
1214 $this->timespent_note = trim($this->timespent_note);
1216 if (empty($this->timespent_datehour) || ($this->timespent_date != $this->timespent_datehour)) {
1217 $this->timespent_datehour = $this->timespent_date;
1220 if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1221 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1224 if ($this->timespent_date < $restrictBefore) {
1225 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1226 $this->errors[] = $this->error;
1234 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet_task_time (";
1236 $sql .=
", task_date";
1237 $sql .=
", task_datehour";
1238 $sql .=
", task_date_withhour";
1239 $sql .=
", task_duration";
1240 $sql .=
", fk_user";
1241 $sql .=
", fk_product";
1244 $sql .=
") VALUES (";
1245 $sql .= ((int) $this->
id);
1246 $sql .=
", '".$this->db->idate($this->timespent_date).
"'";
1247 $sql .=
", '".$this->db->idate($this->timespent_datehour).
"'";
1248 $sql .=
", ".(empty($this->timespent_withhour) ? 0 : 1);
1249 $sql .=
", ".((int) $this->timespent_duration);
1250 $sql .=
", ".((int) $this->timespent_fk_user);
1251 $sql .=
", ".((int) $this->timespent_fk_product);
1252 $sql .=
", ".(isset($this->timespent_note) ?
"'".$this->db->escape($this->timespent_note).
"'" :
"null");
1253 $sql .=
", '".$this->db->idate($now).
"'";
1258 $tasktime_id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"projet_task_time");
1259 $ret = $tasktime_id;
1260 $this->timespent_id = $ret;
1264 $result = $this->call_trigger(
'TASK_TIMESPENT_CREATE', $user);
1271 $this->error = $this->
db->lasterror();
1277 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1278 $sql .=
" SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt where ptt.fk_task = ".((int) $this->
id).
")";
1279 if (isset($this->progress)) {
1280 $sql .=
", progress = ".((float) $this->progress);
1282 $sql .=
" WHERE rowid = ".((int) $this->
id);
1284 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1285 if (!$this->
db->query($sql)) {
1286 $this->error = $this->
db->lasterror();
1291 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time";
1292 $sql .=
" SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX.
"user WHERE rowid = ".((int) $this->timespent_fk_user).
")";
1293 $sql .=
" WHERE rowid = ".((int) $tasktime_id);
1295 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1296 if (!$this->
db->query($sql)) {
1297 $this->error = $this->
db->lasterror();
1303 $this->
db->commit();
1305 $this->
db->rollback();
1320 $arrayres = array();
1323 $sql .=
" s.rowid as socid,";
1324 $sql .=
" s.nom as thirdparty_name,";
1325 $sql .=
" s.email as thirdparty_email,";
1326 $sql .=
" ptt.rowid,";
1327 $sql .=
" ptt.fk_task,";
1328 $sql .=
" ptt.task_date,";
1329 $sql .=
" ptt.task_datehour,";
1330 $sql .=
" ptt.task_date_withhour,";
1331 $sql .=
" ptt.task_duration,";
1332 $sql .=
" ptt.fk_user,";
1333 $sql .=
" ptt.note,";
1334 $sql .=
" ptt.thm,";
1335 $sql .=
" pt.rowid as task_id,";
1336 $sql .=
" pt.ref as task_ref,";
1337 $sql .=
" pt.label as task_label,";
1338 $sql .=
" p.rowid as project_id,";
1339 $sql .=
" p.ref as project_ref,";
1340 $sql .=
" p.title as project_label,";
1341 $sql .=
" p.public as public";
1342 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1343 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1344 $sql .=
" WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1345 $sql .=
" AND pt.rowid = ".((int) $this->
id);
1346 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1347 if ($morewherefilter) {
1348 $sql .= $morewherefilter;
1351 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1354 $num = $this->
db->num_rows(
$resql);
1358 $obj = $this->
db->fetch_object(
$resql);
1360 $newobj =
new stdClass();
1362 $newobj->socid = $obj->socid;
1363 $newobj->thirdparty_name = $obj->thirdparty_name;
1364 $newobj->thirdparty_email = $obj->thirdparty_email;
1366 $newobj->fk_project = $obj->project_id;
1367 $newobj->project_ref = $obj->project_ref;
1368 $newobj->project_label = $obj->project_label;
1369 $newobj->public = $obj->project_public;
1371 $newobj->fk_task = $obj->task_id;
1372 $newobj->task_ref = $obj->task_ref;
1373 $newobj->task_label = $obj->task_label;
1375 $newobj->timespent_line_id = $obj->rowid;
1376 $newobj->timespent_line_date = $this->
db->jdate($obj->task_date);
1377 $newobj->timespent_line_datehour = $this->
db->jdate($obj->task_datehour);
1378 $newobj->timespent_line_withhour = $obj->task_date_withhour;
1379 $newobj->timespent_line_duration = $obj->task_duration;
1380 $newobj->timespent_line_fk_user = $obj->fk_user;
1381 $newobj->timespent_line_thm = $obj->thm;
1382 $newobj->timespent_line_note = $obj->note;
1384 $arrayres[] = $newobj;
1391 $this->lines = $arrayres;
1395 $this->error =
"Error ".$this->db->lasterror();
1412 if (is_object($userobj)) {
1413 $userid = $userobj->id;
1419 if (empty($id) && empty($userid)) {
1420 dol_syslog(
"getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR);
1427 $sql .=
" MIN(t.task_datehour) as min_date,";
1428 $sql .=
" MAX(t.task_datehour) as max_date,";
1429 $sql .=
" SUM(t.task_duration) as total_duration,";
1430 $sql .=
" SUM(t.task_duration / 3600 * ".$this->db->ifsql(
"t.thm IS NULL", 0,
"t.thm").
") as total_amount,";
1431 $sql .=
" COUNT(t.rowid) as nblines,";
1432 $sql .=
" SUM(".$this->db->ifsql(
"t.thm IS NULL", 1, 0).
") as nblinesnull";
1433 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1434 $sql .=
" WHERE 1 = 1";
1435 if ($morewherefilter) {
1436 $sql .= $morewherefilter;
1439 $sql .=
" AND t.fk_task = ".((int) $id);
1442 $sql .=
" AND t.fk_user = ".((int) $userid);
1445 dol_syslog(get_class($this).
"::getSummaryOfTimeSpent", LOG_DEBUG);
1448 $obj = $this->
db->fetch_object(
$resql);
1450 $result[
'min_date'] = $obj->min_date;
1451 $result[
'max_date'] = $obj->max_date;
1452 $result[
'total_duration'] = $obj->total_duration;
1454 $this->timespent_min_date = $this->
db->jdate($obj->min_date);
1455 $this->timespent_max_date = $this->
db->jdate($obj->max_date);
1456 $this->timespent_total_duration = $obj->total_duration;
1457 $this->timespent_total_amount = $obj->total_amount;
1458 $this->timespent_nblinesnull = ($obj->nblinesnull ? $obj->nblinesnull : 0);
1459 $this->timespent_nblines = ($obj->nblines ? $obj->nblines : 0);
1487 $sql .=
" SUM(t.task_duration) as nbseconds,";
1488 $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";
1489 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1490 $sql .=
" WHERE t.fk_task = ".((int) $id);
1491 if (is_object($fuser) && $fuser->id > 0) {
1492 $sql .=
" AND fk_user = ".((int) $fuser->id);
1495 $datefieldname =
"task_datehour";
1496 $sql .=
" AND (".$datefieldname.
" >= '".$this->
db->idate($dates).
"' OR ".$datefieldname.
" IS NULL)";
1499 $datefieldname =
"task_datehour";
1500 $sql .=
" AND (".$datefieldname.
" <= '".$this->
db->idate($datee).
"' OR ".$datefieldname.
" IS NULL)";
1504 dol_syslog(get_class($this).
"::getSumOfAmount", LOG_DEBUG);
1507 $obj = $this->
db->fetch_object(
$resql);
1509 $result[
'amount'] = $obj->amount;
1510 $result[
'nbseconds'] = $obj->nbseconds;
1511 $result[
'nblinesnull'] = $obj->nblinesnull;
1532 $sql .=
" t.rowid,";
1533 $sql .=
" t.fk_task,";
1534 $sql .=
" t.task_date,";
1535 $sql .=
" t.task_datehour,";
1536 $sql .=
" t.task_date_withhour,";
1537 $sql .=
" t.task_duration,";
1538 $sql .=
" t.fk_user,";
1539 $sql .=
" t.fk_product,";
1542 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1543 $sql .=
" WHERE t.rowid = ".((int) $id);
1545 dol_syslog(get_class($this).
"::fetchTimeSpent", LOG_DEBUG);
1549 $obj = $this->
db->fetch_object(
$resql);
1551 $this->timespent_id = $obj->rowid;
1552 $this->
id = $obj->fk_task;
1553 $this->timespent_date = $this->
db->jdate($obj->task_date);
1554 $this->timespent_datehour = $this->
db->jdate($obj->task_datehour);
1555 $this->timespent_withhour = $obj->task_date_withhour;
1556 $this->timespent_duration = $obj->task_duration;
1557 $this->timespent_fk_user = $obj->fk_user;
1558 $this->timespent_fk_product = $obj->fk_product;
1559 $this->timespent_thm = $obj->thm;
1560 $this->timespent_note = $obj->note;
1567 $this->error =
"Error ".$this->db->lasterror();
1583 $arrayres = array();
1586 $sql .=
" s.rowid as socid,";
1587 $sql .=
" s.nom as thirdparty_name,";
1588 $sql .=
" s.email as thirdparty_email,";
1589 $sql .=
" ptt.rowid,";
1590 $sql .=
" ptt.fk_task,";
1591 $sql .=
" ptt.task_date,";
1592 $sql .=
" ptt.task_datehour,";
1593 $sql .=
" ptt.task_date_withhour,";
1594 $sql .=
" ptt.task_duration,";
1595 $sql .=
" ptt.fk_user,";
1596 $sql .=
" ptt.note,";
1597 $sql .=
" ptt.thm,";
1598 $sql .=
" pt.rowid as task_id,";
1599 $sql .=
" pt.ref as task_ref,";
1600 $sql .=
" pt.label as task_label,";
1601 $sql .=
" p.rowid as project_id,";
1602 $sql .=
" p.ref as project_ref,";
1603 $sql .=
" p.title as project_label,";
1604 $sql .=
" p.public as public";
1605 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1606 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1607 $sql .=
" WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1608 $sql .=
" AND ptt.fk_user = ".((int) $userobj->id);
1609 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1610 if ($morewherefilter) {
1611 $sql .= $morewherefilter;
1614 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1617 $num = $this->
db->num_rows(
$resql);
1621 $obj = $this->
db->fetch_object(
$resql);
1623 $newobj =
new stdClass();
1625 $newobj->socid = $obj->socid;
1626 $newobj->thirdparty_name = $obj->thirdparty_name;
1627 $newobj->thirdparty_email = $obj->thirdparty_email;
1629 $newobj->fk_project = $obj->project_id;
1630 $newobj->project_ref = $obj->project_ref;
1631 $newobj->project_label = $obj->project_label;
1632 $newobj->public = $obj->project_public;
1634 $newobj->fk_task = $obj->task_id;
1635 $newobj->task_ref = $obj->task_ref;
1636 $newobj->task_label = $obj->task_label;
1638 $newobj->timespent_id = $obj->rowid;
1639 $newobj->timespent_date = $this->
db->jdate($obj->task_date);
1640 $newobj->timespent_datehour = $this->
db->jdate($obj->task_datehour);
1641 $newobj->timespent_withhour = $obj->task_date_withhour;
1642 $newobj->timespent_duration = $obj->task_duration;
1643 $newobj->timespent_fk_user = $obj->fk_user;
1644 $newobj->timespent_thm = $obj->thm;
1645 $newobj->timespent_note = $obj->note;
1647 $arrayres[] = $newobj;
1655 $this->error =
"Error ".$this->db->lasterror();
1671 global $conf, $langs;
1676 if ($this->timespent_date ==
'') {
1677 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date"));
1680 if (!($this->timespent_fk_user > 0)) {
1681 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"User"));
1686 if (empty($this->timespent_datehour)) {
1687 $this->timespent_datehour = $this->timespent_date;
1689 if (isset($this->timespent_note)) {
1690 $this->timespent_note = trim($this->timespent_note);
1693 if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1694 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1697 if ($this->timespent_date < $restrictBefore) {
1698 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1699 $this->errors[] = $this->error;
1706 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time SET";
1707 $sql .=
" task_date = '".$this->db->idate($this->timespent_date).
"',";
1708 $sql .=
" task_datehour = '".$this->db->idate($this->timespent_datehour).
"',";
1709 $sql .=
" task_date_withhour = ".(empty($this->timespent_withhour) ? 0 : 1).
",";
1710 $sql .=
" task_duration = ".((int) $this->timespent_duration).
",";
1711 $sql .=
" fk_user = ".((int) $this->timespent_fk_user).
",";
1712 $sql .=
" fk_product = ".((int) $this->timespent_fk_product).
",";
1713 $sql .=
" note = ".(isset($this->timespent_note) ?
"'".$this->db->escape($this->timespent_note).
"'" :
"null");
1714 $sql .=
" WHERE rowid = ".((int) $this->timespent_id);
1716 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
1717 if ($this->
db->query($sql)) {
1720 $result = $this->call_trigger(
'TASK_TIMESPENT_MODIFY', $user);
1722 $this->
db->rollback();
1732 $this->error = $this->
db->lasterror();
1733 $this->
db->rollback();
1737 if ($ret == 1 && (($this->timespent_old_duration != $this->timespent_duration) || !empty($conf->global->TIMESPENT_ALWAYS_UPDATE_THM))) {
1738 if ($this->timespent_old_duration != $this->timespent_duration) {
1740 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"projet_task";
1741 $sql .=
" SET duration_effective = (SELECT SUM(task_duration) FROM " . MAIN_DB_PREFIX .
"projet_task_time as ptt where ptt.fk_task = " . ((int) $this->
id) .
")";
1742 if (isset($this->progress)) {
1743 $sql .=
", progress = " . ((
float) $this->progress);
1745 $sql .=
" WHERE rowid = " . ((int) $this->
id);
1747 dol_syslog(get_class($this) .
"::updateTimeSpent", LOG_DEBUG);
1748 if (!$this->
db->query($sql)) {
1749 $this->error = $this->
db->lasterror();
1750 $this->
db->rollback();
1756 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time";
1757 $sql .=
" SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX.
"user WHERE rowid = ".((int) $this->timespent_fk_user).
")";
1758 $sql .=
" WHERE rowid = ".((int) $this->timespent_id);
1759 if (empty($conf->global->TIMESPENT_ALWAYS_UPDATE_THM)) {
1760 $sql .=
" AND (thm IS NULL OR thm = 0)";
1763 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1764 if (!$this->
db->query($sql)) {
1765 $this->error = $this->
db->lasterror();
1771 $this->
db->commit();
1785 global $conf, $langs;
1789 if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1790 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1793 if ($this->timespent_date < $restrictBefore) {
1794 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1795 $this->errors[] = $this->error;
1804 $result = $this->call_trigger(
'TASK_TIMESPENT_DELETE', $user);
1812 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_time";
1813 $sql .=
" WHERE rowid = ".((int) $this->timespent_id);
1815 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
1818 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1823 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1824 $sql .=
" SET duration_effective = duration_effective - ".$this->db->escape($this->timespent_duration ? $this->timespent_duration : 0);
1825 $sql .=
" WHERE rowid = ".((int) $this->
id);
1827 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
1828 if ($this->
db->query($sql)) {
1831 $this->error = $this->
db->lasterror();
1838 foreach ($this->errors as $errmsg) {
1839 dol_syslog(get_class($this).
"::delTimeSpent ".$errmsg, LOG_ERR);
1840 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1842 $this->
db->rollback();
1845 $this->
db->commit();
1864 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)
1866 global $langs, $conf;
1875 $clone_task =
new Task($this->
db);
1876 $origin_task =
new Task($this->
db);
1878 $clone_task->context[
'createfromclone'] =
'createfromclone';
1883 $clone_task->fetch($fromid);
1884 $clone_task->fetch_optionals();
1887 $origin_task->fetch($fromid);
1890 $obj = empty($conf->global->PROJECT_TASK_ADDON) ?
'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
1891 if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT.
"/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.
".php")) {
1892 require_once DOL_DOCUMENT_ROOT.
"/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.
'.php';
1893 $modTask =
new $obj;
1894 $defaultref = $modTask->getNextValue(0, $clone_task);
1897 $ori_project_id = $clone_task->fk_project;
1899 $clone_task->id = 0;
1900 $clone_task->ref = $defaultref;
1901 $clone_task->fk_project = $project_id;
1902 $clone_task->fk_task_parent = $parent_task_id;
1903 $clone_task->date_c = $datec;
1904 $clone_task->planned_workload = $origin_task->planned_workload;
1905 $clone_task->rang = $origin_task->rang;
1908 if ($clone_change_dt) {
1909 $projectstatic =
new Project($this->
db);
1910 $projectstatic->fetch($ori_project_id);
1913 $orign_project_dt_start = $projectstatic->date_start;
1916 if (!empty($clone_task->date_start)) {
1917 $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
1921 if (!empty($clone_task->date_end)) {
1922 $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
1927 $clone_task->progress = 0;
1931 $result = $clone_task->create($user);
1935 $this->error = $clone_task->error;
1941 $clone_task_id = $clone_task->id;
1942 $clone_task_ref = $clone_task->ref;
1946 $clone_task->note_private =
'';
1947 $clone_task->note_public =
'';
1950 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_public, ENT_QUOTES | ENT_HTML5),
'_public');
1952 $this->error .= $clone_task->error;
1954 $this->
db->rollback();
1956 $this->
db->commit();
1960 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_private, ENT_QUOTES | ENT_HTML5),
'_private');
1962 $this->error .= $clone_task->error;
1964 $this->
db->rollback();
1966 $this->
db->commit();
1972 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1975 $projectstatic =
new Project($this->
db);
1976 $projectstatic->fetch($ori_project_id);
1977 $ori_project_ref = $projectstatic->ref;
1979 if ($ori_project_id != $project_id) {
1980 $projectstatic->fetch($project_id);
1981 $clone_project_ref = $projectstatic->ref;
1983 $clone_project_ref = $ori_project_ref;
1989 $filearray =
dol_dir_list($ori_task_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'', SORT_ASC, 1);
1990 foreach ($filearray as $key => $file) {
1991 if (!file_exists($clone_task_dir)) {
1993 $this->error .= $langs->trans(
'ErrorInternalErrorDetected').
':dol_mkdir';
1998 $rescopy =
dol_copy($ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name'], 0, 1);
1999 if (is_numeric($rescopy) && $rescopy < 0) {
2000 $this->error .= $langs->trans(
"ErrorFailToCopyFile", $ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name']);
2007 if ($clone_affectation) {
2008 $origin_task =
new Task($this->
db);
2009 $origin_task->fetch($fromid);
2011 foreach (array(
'internal',
'external') as $source) {
2012 $tab = $origin_task->liste_contact(-1, $source);
2016 $clone_task->add_contact($tab[$i][
'id'], $tab[$i][
'code'], $tab[$i][
'source']);
2017 if ($clone_task->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2018 $langs->load(
"errors");
2019 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
2022 if ($clone_task->error !=
'') {
2023 $this->error .= $clone_task->error;
2037 unset($clone_task->context[
'createfromclone']);
2040 $this->
db->commit();
2041 return $clone_task_id;
2043 $this->
db->rollback();
2044 dol_syslog(get_class($this).
"::createFromClone nbError: ".$error.
" error : ".$this->error, LOG_ERR);
2058 return $this->LibStatut($this->fk_statut, $mode);
2075 $this->statuts[0] =
'Draft';
2076 $this->statuts[1] =
'ToDo';
2077 $this->statuts[2] =
'Running';
2078 $this->statuts[3] =
'Finish';
2079 $this->statuts[4] =
'Transfered';
2080 $this->statuts_short[0] =
'Draft';
2081 $this->statuts_short[1] =
'ToDo';
2082 $this->statuts_short[2] =
'Running';
2083 $this->statuts_short[3] =
'Completed';
2084 $this->statuts_short[4] =
'Transfered';
2087 return $langs->trans($this->statuts[$status]);
2088 } elseif ($mode == 1) {
2089 return $langs->trans($this->statuts_short[$status]);
2090 } elseif ($mode == 2) {
2092 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts_short[$status]);
2093 } elseif ($status == 1) {
2094 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1').
' '.$langs->trans($this->statuts_short[$status]);
2095 } elseif ($status == 2) {
2096 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3').
' '.$langs->trans($this->statuts_short[$status]);
2097 } elseif ($status == 3) {
2098 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
2099 } elseif ($status == 4) {
2100 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
2101 } elseif ($status == 5) {
2102 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5').
' '.$langs->trans($this->statuts_short[$status]);
2104 } elseif ($mode == 3) {
2106 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0');
2107 } elseif ($status == 1) {
2108 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1');
2109 } elseif ($status == 2) {
2110 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3');
2111 } elseif ($status == 3) {
2112 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
2113 } elseif ($status == 4) {
2114 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
2115 } elseif ($status == 5) {
2116 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5');
2118 } elseif ($mode == 4) {
2120 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts[$status]);
2121 } elseif ($status == 1) {
2122 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1').
' '.$langs->trans($this->statuts[$status]);
2123 } elseif ($status == 2) {
2124 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3').
' '.$langs->trans($this->statuts[$status]);
2125 } elseif ($status == 3) {
2126 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
2127 } elseif ($status == 4) {
2128 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
2129 } elseif ($status == 5) {
2130 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5').
' '.$langs->trans($this->statuts[$status]);
2132 } elseif ($mode == 5) {
2142 } elseif ($mode == 6) {
2165 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2169 $outputlangs->load(
"projects");
2172 $modele =
'nodefault';
2174 if (!empty($this->model_pdf)) {
2175 $modele = $this->model_pdf;
2176 } elseif (!empty($this->modelpdf)) {
2177 $modele = $this->modelpdf;
2178 } elseif (!empty($conf->global->PROJECT_TASK_ADDON_PDF)) {
2179 $modele = $conf->global->PROJECT_TASK_ADDON_PDF;
2183 $modelpath =
"core/modules/project/task/doc/";
2185 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2199 global $conf, $langs;
2205 $projectstatic =
new Project($this->
db);
2206 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
2209 $sql =
"SELECT p.rowid as projectid, p.fk_statut as projectstatus,";
2210 $sql .=
" t.rowid as taskid, t.progress as progress, t.fk_statut as status,";
2211 $sql .=
" t.dateo as date_start, t.datee as datee";
2212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2215 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2216 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2217 $sql .=
" AND p.fk_statut = 1";
2218 $sql .=
" AND t.fk_projet = p.rowid";
2219 $sql .=
" AND (t.progress IS NULL OR t.progress < 100)";
2220 if (empty($user->rights->projet->all->lire)) {
2221 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2231 $task_static =
new Task($this->
db);
2234 $response->warning_delay = $conf->project->task->warning_delay / 60 / 60 / 24;
2235 $response->label = $langs->trans(
"OpenedTasks");
2236 if ($user->hasRight(
"projet",
"all",
"lire")) {
2237 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mainmenu=project';
2239 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mode=mine&mainmenu=project';
2244 while ($obj = $this->
db->fetch_object(
$resql)) {
2245 $response->nbtodo++;
2247 $task_static->projectstatus = $obj->projectstatus;
2248 $task_static->progress = $obj->progress;
2249 $task_static->fk_statut = $obj->status;
2250 $task_static->date_end = $this->
db->jdate($obj->datee);
2252 if ($task_static->hasDelay()) {
2253 $response->nbtodolate++;
2259 $this->error = $this->
db->error();
2276 $mine = 0; $socid = $user->socid;
2278 $projectstatic =
new Project($this->
db);
2279 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $mine, 1, $socid);
2282 $sql =
"SELECT count(p.rowid) as nb";
2283 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2284 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
2285 if (empty($user->rights->societe->client->voir) && !$socid) {
2286 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2288 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2289 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2290 $sql .=
" AND t.fk_projet = p.rowid";
2291 if ($mine || empty($user->rights->projet->all->lire)) {
2292 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2297 $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).
")";
2299 if (empty($user->rights->societe->client->voir) && !$socid) {
2300 $sql .=
" AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).
") OR (s.rowid IS NULL))";
2306 while ($obj = $this->
db->fetch_object(
$resql)) {
2307 $this->nb[
"tasks"] = $obj->nb;
2313 $this->error = $this->
db->error();
2327 if (!($this->progress >= 0 && $this->progress < 100)) {
2333 $datetouse = ($this->date_end > 0) ? $this->date_end : ((isset($this->datee) && $this->datee > 0) ? $this->datee : 0);
2335 return ($datetouse > 0 && ($datetouse < ($now - $conf->project->task->warning_delay)));