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);
177 $this->note_public = trim($this->note_public);
178 $this->note_private = trim($this->note_private);
180 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
181 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
189 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet_task (";
191 $sql .=
", fk_projet";
193 $sql .=
", fk_task_parent";
195 $sql .=
", description";
196 $sql .=
", note_public";
197 $sql .=
", note_private";
199 $sql .=
", fk_user_creat";
202 $sql .=
", planned_workload";
203 $sql .=
", progress";
204 $sql .=
", budget_amount";
205 $sql .=
", priority";
206 $sql .=
") VALUES (";
207 $sql .= (!empty($this->entity) ? (int) $this->entity : (
int) $conf->entity);
208 $sql .=
", ".((int) $this->fk_project);
209 $sql .=
", ".(!empty($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
'null');
210 $sql .=
", ".((int) $this->fk_task_parent);
211 $sql .=
", '".$this->db->escape($this->label).
"'";
212 $sql .=
", '".$this->db->escape($this->
description).
"'";
213 $sql .=
", '".$this->db->escape($this->note_public).
"'";
214 $sql .=
", '".$this->db->escape($this->note_private).
"'";
215 $sql .=
", '".$this->db->idate($now).
"'";
216 $sql .=
", ".((int) $user->id);
217 $sql .=
", ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
'null');
218 $sql .=
", ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
'null');
219 $sql .=
", ".(($this->planned_workload !=
'' && $this->planned_workload >= 0) ? ((
int) $this->planned_workload) :
'null');
220 $sql .=
", ".(($this->progress !=
'' && $this->progress >= 0) ? ((
int) $this->progress) :
'null');
221 $sql .=
", ".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? ((
int) $this->budget_amount) :
'null');
222 $sql .=
", ".(($this->priority !=
'' && $this->priority >= 0) ? (
int) $this->priority :
'null');
227 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
230 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
234 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"projet_task");
258 foreach ($this->errors as $errmsg) {
259 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
260 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
262 $this->
db->rollback();
279 public function fetch($id, $ref =
'', $loadparentdata = 0)
281 global $langs, $conf;
286 $sql .=
" t.entity,";
287 $sql .=
" t.fk_projet as fk_project,";
288 $sql .=
" t.fk_task_parent,";
290 $sql .=
" t.description,";
291 $sql .=
" t.duration_effective,";
292 $sql .=
" t.planned_workload,";
296 $sql .=
" t.fk_user_creat,";
297 $sql .=
" t.fk_user_valid,";
298 $sql .=
" t.fk_statut,";
299 $sql .=
" t.progress,";
300 $sql .=
" t.budget_amount,";
301 $sql .=
" t.priority,";
302 $sql .=
" t.note_private,";
303 $sql .=
" t.note_public,";
305 if (!empty($loadparentdata)) {
306 $sql .=
", t2.ref as task_parent_ref";
307 $sql .=
", t2.rang as task_parent_position";
309 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as t";
310 if (!empty($loadparentdata)) {
311 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t2 ON t.fk_task_parent = t2.rowid";
315 $sql .=
"entity IN (".getEntity(
'project').
")";
316 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
318 $sql .=
"t.rowid = ".((int) $id);
321 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
324 $num_rows = $this->
db->num_rows(
$resql);
327 $obj = $this->
db->fetch_object(
$resql);
329 $this->
id = $obj->rowid;
330 $this->
ref = $obj->ref;
331 $this->entity = $obj->entity;
332 $this->fk_project = $obj->fk_project;
333 $this->fk_task_parent = $obj->fk_task_parent;
334 $this->label = $obj->label;
336 $this->duration_effective = $obj->duration_effective;
337 $this->planned_workload = $obj->planned_workload;
338 $this->date_c = $this->
db->jdate($obj->datec);
339 $this->date_start = $this->
db->jdate($obj->dateo);
340 $this->date_end = $this->
db->jdate($obj->datee);
341 $this->fk_user_creat = $obj->fk_user_creat;
342 $this->fk_user_valid = $obj->fk_user_valid;
343 $this->fk_statut = $obj->fk_statut;
344 $this->progress = $obj->progress;
345 $this->budget_amount = $obj->budget_amount;
346 $this->priority = $obj->priority;
347 $this->note_private = $obj->note_private;
348 $this->note_public = $obj->note_public;
349 $this->rang = $obj->rang;
351 if (!empty($loadparentdata)) {
352 $this->task_parent_ref = $obj->task_parent_ref;
353 $this->task_parent_position = $obj->task_parent_position;
368 $this->error =
"Error ".$this->db->lasterror();
381 public function update($user =
null, $notrigger = 0)
383 global $conf, $langs;
387 if (isset($this->fk_project)) {
388 $this->fk_project = trim($this->fk_project);
390 if (isset($this->
ref)) {
391 $this->
ref = trim($this->
ref);
393 if (isset($this->fk_task_parent)) {
394 $this->fk_task_parent = (int) $this->fk_task_parent;
396 if (isset($this->label)) {
397 $this->label = trim($this->label);
402 if (isset($this->note_public)) {
403 $this->note_public = trim($this->note_public);
405 if (isset($this->note_private)) {
406 $this->note_private = trim($this->note_private);
408 if (isset($this->duration_effective)) {
409 $this->duration_effective = trim($this->duration_effective);
411 if (isset($this->planned_workload)) {
412 $this->planned_workload = trim($this->planned_workload);
414 if (isset($this->budget_amount)) {
415 $this->budget_amount = trim($this->budget_amount);
418 if (!empty($this->date_start) && !empty($this->date_end) && $this->date_start > $this->date_end) {
419 $this->errors[] = $langs->trans(
'StartDateCannotBeAfterEndDate');
427 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
428 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
429 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"'".$this->db->escape($this->
id).
"'").
",";
430 $sql .=
" fk_task_parent=".(isset($this->fk_task_parent) ? $this->fk_task_parent :
"null").
",";
431 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
432 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
433 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
434 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
435 $sql .=
" duration_effective=".(isset($this->duration_effective) ? $this->duration_effective :
"null").
",";
436 $sql .=
" planned_workload=".((isset($this->planned_workload) && $this->planned_workload !=
'') ? $this->planned_workload :
"null").
",";
437 $sql .=
" dateo=".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
'null').
",";
438 $sql .=
" datee=".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
'null').
",";
439 $sql .=
" progress=".(($this->progress !=
'' && $this->progress >= 0) ? $this->progress :
'null').
",";
440 $sql .=
" budget_amount=".(($this->budget_amount !=
'' && $this->budget_amount >= 0) ? $this->budget_amount :
'null').
",";
441 $sql .=
" rang=".((!empty($this->rang)) ? ((
int) $this->rang) :
"0").
",";
442 $sql .=
" priority=".((!empty($this->priority)) ? ((
int) $this->priority) :
"0");
443 $sql .=
" WHERE rowid=".((int) $this->
id);
447 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
450 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
461 if (!$error && !empty($conf->global->PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE)) {
464 if ($project->fetch($this->fk_project) > 0) {
466 $project->getLinesArray(
null);
467 $projectCompleted = array_reduce(
469 function ($allTasksCompleted, $task) {
470 return $allTasksCompleted && $task->progress >= 100;
474 if ($projectCompleted) {
475 if ($project->setClose($user) <= 0) {
484 $this->errors[] = $project->error;
499 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
501 if ($conf->project->dir_output) {
503 $project->fetch($this->fk_project);
507 if (file_exists($olddir)) {
508 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
511 $langs->load(
"errors");
512 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
521 foreach ($this->errors as $errmsg) {
522 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
523 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
525 $this->
db->rollback();
541 public function delete($user, $notrigger = 0)
544 global $conf, $langs;
545 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
552 dol_syslog(get_class($this).
"::delete Can't delete record as it has some sub tasks", LOG_WARNING);
553 $this->error =
'ErrorRecordHasSubTasks';
554 $this->
db->rollback();
559 if (!empty($objectisused)) {
560 dol_syslog(get_class($this).
"::delete Can't delete record as it has some child", LOG_WARNING);
561 $this->error =
'ErrorRecordHasChildren';
562 $this->
db->rollback();
570 $this->error =
'ErrorFailToDeleteLinkedContact';
572 $this->
db->rollback();
578 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_time";
579 $sql .=
" WHERE fk_task = ".((int) $this->
id);
583 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
588 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_extrafields";
589 $sql .=
" WHERE fk_object = ".((int) $this->
id);
593 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
598 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task";
599 $sql .=
" WHERE rowid=".((int) $this->
id);
603 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
620 foreach ($this->errors as $errmsg) {
621 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
622 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
624 $this->
db->rollback();
628 if ($conf->project->dir_output) {
630 $projectstatic->fetch($this->fk_project);
633 dol_syslog(get_class($this).
"::delete dir=".$dir, LOG_DEBUG);
634 if (file_exists($dir)) {
635 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
638 $this->error =
'ErrorFailToDeleteDir';
639 $this->
db->rollback();
661 $sql =
"SELECT COUNT(*) as nb";
662 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task";
663 $sql .=
" WHERE fk_task_parent = ".((int) $this->
id);
665 dol_syslog(get_class($this).
"::hasChildren", LOG_DEBUG);
668 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
670 $obj = $this->
db->fetch_object(
$resql);
694 $sql =
"SELECT COUNT(*) as nb";
695 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time";
696 $sql .=
" WHERE fk_task = ".((int) $this->
id);
698 dol_syslog(get_class($this).
"::hasTimeSpent", LOG_DEBUG);
701 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
703 $obj = $this->
db->fetch_object(
$resql);
730 public function getNomUrl($withpicto = 0, $option =
'', $mode =
'task', $addlabel = 0, $sep =
' - ', $notooltip = 0, $save_lastsearch_value = -1)
732 global $conf, $langs, $user;
734 if (!empty($conf->dol_no_mouse_hover)) {
739 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Task").
'</u>';
740 if (!empty($this->
ref)) {
741 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
743 if (!empty($this->label)) {
744 $label .=
'<br><b>'.$langs->trans(
'LabelTask').
':</b> '.$this->label;
746 if ($this->date_start || $this->date_end) {
747 $label .=
"<br>".get_date_range($this->date_start, $this->date_end,
'', $langs, 0);
750 $url = DOL_URL_ROOT.
'/projet/tasks/'.$mode.
'.php?id='.$this->
id.($option ==
'withproject' ?
'&withproject=1' :
'');
752 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
753 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
754 $add_save_lastsearch_values = 1;
756 if ($add_save_lastsearch_values) {
757 $url .=
'&save_lastsearch_values=1';
761 if (empty($notooltip)) {
762 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
763 $label = $langs->trans(
"ShowTask");
764 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
766 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
767 $linkclose .=
' class="classfortooltip nowraponall"';
769 $linkclose .=
' class="nowraponall"';
772 $linkstart =
'<a href="'.$url.
'"';
773 $linkstart .= $linkclose.
'>';
776 $picto =
'projecttask';
778 $result .= $linkstart;
780 $result .=
img_object(($notooltip ?
'' : $label), $picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
782 if ($withpicto != 2) {
783 $result .= $this->ref;
786 if ($withpicto != 2) {
787 $result .= (($addlabel && $this->label) ? $sep.dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) :
'');
804 $this->fk_project =
'';
806 $this->fk_task_parent =
null;
807 $this->label =
'Specimen task TK01';
808 $this->duration_effective =
'';
809 $this->fk_user_creat =
null;
810 $this->progress =
'25';
812 $this->fk_statut =
null;
813 $this->note =
'This is a specimen task not';
839 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 =
'')
841 global $conf, $hookmanager;
849 if ($filteronprojuser > 0 || $filterontaskuser > 0) {
852 $sql .=
" p.rowid as projectid, p.ref, p.title as plabel, p.public, p.fk_statut as projectstatus, p.usage_bill_time,";
853 $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,";
854 $sql .=
" t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang, t.priority,";
855 $sql .=
" t.budget_amount,";
856 $sql .=
" t.note_public, t.note_private,";
857 $sql .=
" s.rowid as thirdparty_id, s.nom as thirdparty_name, s.email as thirdparty_email,";
858 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount as project_budget_amount";
859 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
860 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
861 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key.
" as options_".$key :
'');
864 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
865 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
866 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key.
" as options_".$key :
'');
869 if ($includebilltime) {
870 $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";
873 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
874 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
875 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_extrafields as efp ON (p.rowid = efp.fk_object)";
878 if ($filteronprojuser > 0) {
879 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
880 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
882 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
883 if ($includebilltime) {
884 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
886 if ($filterontaskuser > 0) {
887 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
888 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
890 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
891 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
892 $sql .=
" AND t.fk_projet = p.rowid";
893 } elseif ($mode == 1) {
894 if ($filteronprojuser > 0) {
895 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
896 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
898 if ($filterontaskuser > 0) {
899 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
900 if ($includebilltime) {
901 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
903 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
904 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
906 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t on t.fk_projet = p.rowid";
907 if ($includebilltime) {
908 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
911 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
912 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
914 return 'BadValueForParameterMode';
917 if ($filteronprojuser > 0) {
918 $sql .=
" AND p.rowid = ec.element_id";
919 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
920 $sql .=
" AND ctc.element = 'project'";
921 $sql .=
" AND ec.fk_socpeople = ".((int) $filteronprojuser);
922 $sql .=
" AND ec.statut = 4";
923 $sql .=
" AND ctc.source = 'internal'";
925 if ($filterontaskuser > 0) {
926 $sql .=
" AND t.fk_projet = p.rowid";
927 $sql .=
" AND p.rowid = ec2.element_id";
928 $sql .=
" AND ctc2.rowid = ec2.fk_c_type_contact";
929 $sql .=
" AND ctc2.element = 'project_task'";
930 $sql .=
" AND ec2.fk_socpeople = ".((int) $filterontaskuser);
931 $sql .=
" AND ec2.statut = 4";
932 $sql .=
" AND ctc2.source = 'internal'";
935 $sql .=
" AND p.fk_soc = ".((int) $socid);
938 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectid).
")";
943 if ($filteronprojstatus && $filteronprojstatus !=
'-1') {
944 $sql .=
" AND p.fk_statut IN (".$this->db->sanitize($filteronprojstatus).
")";
946 if ($morewherefilter) {
947 $sql .= $morewherefilter;
950 $extrafieldsobjectkey =
'projet_task';
951 $extrafieldsobjectprefix =
'efpt.';
953 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
955 $parameters = array();
956 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
957 $sql .= $hookmanager->resPrint;
958 if ($includebilltime) {
959 $sql .=
" GROUP BY p.rowid, p.ref, p.title, p.public, p.fk_statut, p.usage_bill_time,";
960 $sql .=
" t.datec, t.dateo, t.datee, t.tms,";
961 $sql .=
" t.rowid, t.ref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut,";
962 $sql .=
" t.dateo, t.datee, t.planned_workload, t.rang, t.priority,";
963 $sql .=
" t.budget_amount,";
964 $sql .=
" t.note_public, t.note_private,";
965 $sql .=
" s.rowid, s.nom, s.email,";
966 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount";
967 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
968 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
969 $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key :
'');
972 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
973 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
974 $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key :
'');
979 if ($sortfield && $sortorder) {
980 $sql .= $this->
db->order($sortfield, $sortorder);
982 $sql .=
" ORDER BY p.ref, t.rang, t.dateo";
986 dol_syslog(get_class($this).
"::getTasksArray", LOG_DEBUG);
995 $obj = $this->
db->fetch_object(
$resql);
998 if ((!$obj->public) && (is_object($userp))) {
1003 if (is_object($usert)) {
1011 $tasks[$i] =
new Task($this->
db);
1012 $tasks[$i]->id = $obj->taskid;
1013 $tasks[$i]->ref = $obj->taskref;
1014 $tasks[$i]->fk_project = $obj->projectid;
1015 $tasks[$i]->projectref = $obj->ref;
1016 $tasks[$i]->projectlabel = $obj->plabel;
1017 $tasks[$i]->projectstatus = $obj->projectstatus;
1019 $tasks[$i]->fk_opp_status = $obj->fk_opp_status;
1020 $tasks[$i]->opp_amount = $obj->opp_amount;
1021 $tasks[$i]->opp_percent = $obj->opp_percent;
1022 $tasks[$i]->budget_amount = $obj->budget_amount;
1023 $tasks[$i]->project_budget_amount = $obj->project_budget_amount;
1024 $tasks[$i]->usage_bill_time = $obj->usage_bill_time;
1026 $tasks[$i]->label = $obj->label;
1027 $tasks[$i]->description = $obj->description;
1028 $tasks[$i]->fk_parent = $obj->fk_task_parent;
1029 $tasks[$i]->note_public = $obj->note_public;
1030 $tasks[$i]->note_private = $obj->note_private;
1031 $tasks[$i]->fk_task_parent = $obj->fk_task_parent;
1032 $tasks[$i]->duration = $obj->duration_effective;
1033 $tasks[$i]->planned_workload = $obj->planned_workload;
1035 if ($includebilltime) {
1036 $tasks[$i]->tobill = $obj->tobill;
1037 $tasks[$i]->billed = $obj->billed;
1040 $tasks[$i]->progress = $obj->progress;
1041 $tasks[$i]->fk_statut = $obj->status;
1042 $tasks[$i]->public = $obj->public;
1043 $tasks[$i]->date_start = $this->
db->jdate($obj->date_start);
1044 $tasks[$i]->date_end = $this->
db->jdate($obj->date_end);
1045 $tasks[$i]->rang = $obj->rang;
1046 $tasks[$i]->priority = $obj->priority;
1048 $tasks[$i]->socid = $obj->thirdparty_id;
1049 $tasks[$i]->thirdparty_id = $obj->thirdparty_id;
1050 $tasks[$i]->thirdparty_name = $obj->thirdparty_name;
1051 $tasks[$i]->thirdparty_email = $obj->thirdparty_email;
1053 if (!empty($extrafields->attributes[
'projet'][
'label'])) {
1054 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) {
1055 if ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate') {
1056 $tasks[$i]->{
'options_'.$key} = $obj->{
'options_'.$key};
1061 if (!empty($extrafields->attributes[
'projet_task'][
'label'])) {
1062 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) {
1063 if ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate') {
1064 $tasks[$i]->{
'options_'.$key} = $obj->{
'options_'.$key};
1070 $tasks[$i]->fetch_optionals();
1096 $arrayroles = array();
1098 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks userp=".is_object($userp).
" usert=".is_object($usert).
" projectid=".$projectid.
" taskid=".$taskid);
1101 if (empty($userp) && empty($usert)) {
1102 $this->error =
"CallWithWrongParameters";
1105 if (!empty($userp) && !empty($usert)) {
1106 $this->error =
"CallWithWrongParameters";
1111 $sql =
"SELECT pt.rowid as pid, ec.element_id, ctc.code, ctc.source";
1113 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as pt";
1115 if ($usert && $filteronprojstatus > -1) {
1116 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"projet_task as pt";
1118 if ($usert && $filteronprojstatus <= -1) {
1119 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as pt";
1121 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1122 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1123 $sql .=
" WHERE pt.rowid = ec.element_id";
1124 if ($userp && $filteronprojstatus > -1) {
1125 $sql .=
" AND pt.fk_statut = ".((int) $filteronprojstatus);
1127 if ($usert && $filteronprojstatus > -1) {
1128 $sql .=
" AND pt.fk_projet = p.rowid AND p.fk_statut = ".((int) $filteronprojstatus);
1131 $sql .=
" AND ctc.element = 'project'";
1134 $sql .=
" AND ctc.element = 'project_task'";
1136 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
1138 $sql .=
" AND ec.fk_socpeople = ".((int) $userp->id);
1141 $sql .=
" AND ec.fk_socpeople = ".((int) $usert->id);
1143 $sql .=
" AND ec.statut = 4";
1144 $sql .=
" AND ctc.source = 'internal'";
1147 $sql .=
" AND pt.rowid IN (".$this->db->sanitize($projectid).
")";
1150 $sql .=
" AND pt.fk_projet IN (".$this->db->sanitize($projectid).
")";
1155 $sql .=
" ERROR SHOULD NOT HAPPENS";
1158 $sql .=
" AND pt.rowid = ".((int) $taskid);
1163 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks execute request", LOG_DEBUG);
1166 $num = $this->
db->num_rows(
$resql);
1169 $obj = $this->
db->fetch_object(
$resql);
1170 if (empty($arrayroles[$obj->pid])) {
1171 $arrayroles[$obj->pid] = $obj->code;
1173 $arrayroles[$obj->pid] .=
','.$obj->code;
1194 $contactAlreadySelected = array();
1195 $tab = $this->liste_contact(-1, $source);
1200 if ($source ==
'thirdparty') {
1201 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
1203 $contactAlreadySelected[$i] = $tab[$i][
'id'];
1207 return $contactAlreadySelected;
1220 global $conf, $langs;
1222 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1228 if (!is_object($user)) {
1229 dol_print_error(
'',
"Method addTimeSpent was called with wrong parameter user");
1234 if (isset($this->timespent_note)) {
1235 $this->timespent_note = trim($this->timespent_note);
1237 if (empty($this->timespent_datehour) || ($this->timespent_date != $this->timespent_datehour)) {
1238 $this->timespent_datehour = $this->timespent_date;
1241 if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1242 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1245 if ($this->timespent_date < $restrictBefore) {
1246 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1247 $this->errors[] = $this->error;
1255 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet_task_time (";
1257 $sql .=
", task_date";
1258 $sql .=
", task_datehour";
1259 $sql .=
", task_date_withhour";
1260 $sql .=
", task_duration";
1261 $sql .=
", fk_user";
1262 $sql .=
", fk_product";
1265 $sql .=
") VALUES (";
1266 $sql .= ((int) $this->
id);
1267 $sql .=
", '".$this->db->idate($this->timespent_date).
"'";
1268 $sql .=
", '".$this->db->idate($this->timespent_datehour).
"'";
1269 $sql .=
", ".(empty($this->timespent_withhour) ? 0 : 1);
1270 $sql .=
", ".((int) $this->timespent_duration);
1271 $sql .=
", ".((int) $this->timespent_fk_user);
1272 $sql .=
", ".((int) $this->timespent_fk_product);
1273 $sql .=
", ".(isset($this->timespent_note) ?
"'".$this->db->escape($this->timespent_note).
"'" :
"null");
1274 $sql .=
", '".$this->db->idate($now).
"'";
1279 $tasktime_id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"projet_task_time");
1280 $ret = $tasktime_id;
1281 $this->timespent_id = $ret;
1285 $result = $this->call_trigger(
'TASK_TIMESPENT_CREATE', $user);
1292 $this->error = $this->
db->lasterror();
1298 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1299 $sql .=
" SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt where ptt.fk_task = ".((int) $this->
id).
")";
1300 if (isset($this->progress)) {
1301 $sql .=
", progress = ".((float) $this->progress);
1303 $sql .=
" WHERE rowid = ".((int) $this->
id);
1305 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1306 if (!$this->
db->query($sql)) {
1307 $this->error = $this->
db->lasterror();
1312 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time";
1313 $sql .=
" SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX.
"user WHERE rowid = ".((int) $this->timespent_fk_user).
")";
1314 $sql .=
" WHERE rowid = ".((int) $tasktime_id);
1316 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1317 if (!$this->
db->query($sql)) {
1318 $this->error = $this->
db->lasterror();
1324 $this->
db->commit();
1326 $this->
db->rollback();
1341 $arrayres = array();
1344 $sql .=
" s.rowid as socid,";
1345 $sql .=
" s.nom as thirdparty_name,";
1346 $sql .=
" s.email as thirdparty_email,";
1347 $sql .=
" ptt.rowid,";
1348 $sql .=
" ptt.fk_task,";
1349 $sql .=
" ptt.task_date,";
1350 $sql .=
" ptt.task_datehour,";
1351 $sql .=
" ptt.task_date_withhour,";
1352 $sql .=
" ptt.task_duration,";
1353 $sql .=
" ptt.fk_user,";
1354 $sql .=
" ptt.note,";
1355 $sql .=
" ptt.thm,";
1356 $sql .=
" pt.rowid as task_id,";
1357 $sql .=
" pt.ref as task_ref,";
1358 $sql .=
" pt.label as task_label,";
1359 $sql .=
" p.rowid as project_id,";
1360 $sql .=
" p.ref as project_ref,";
1361 $sql .=
" p.title as project_label,";
1362 $sql .=
" p.public as public";
1363 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1364 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1365 $sql .=
" WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1366 $sql .=
" AND pt.rowid = ".((int) $this->
id);
1367 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1368 if ($morewherefilter) {
1369 $sql .= $morewherefilter;
1372 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1375 $num = $this->
db->num_rows(
$resql);
1379 $obj = $this->
db->fetch_object(
$resql);
1381 $newobj =
new stdClass();
1383 $newobj->socid = $obj->socid;
1384 $newobj->thirdparty_name = $obj->thirdparty_name;
1385 $newobj->thirdparty_email = $obj->thirdparty_email;
1387 $newobj->fk_project = $obj->project_id;
1388 $newobj->project_ref = $obj->project_ref;
1389 $newobj->project_label = $obj->project_label;
1390 $newobj->public = $obj->project_public;
1392 $newobj->fk_task = $obj->task_id;
1393 $newobj->task_ref = $obj->task_ref;
1394 $newobj->task_label = $obj->task_label;
1396 $newobj->timespent_line_id = $obj->rowid;
1397 $newobj->timespent_line_date = $this->
db->jdate($obj->task_date);
1398 $newobj->timespent_line_datehour = $this->
db->jdate($obj->task_datehour);
1399 $newobj->timespent_line_withhour = $obj->task_date_withhour;
1400 $newobj->timespent_line_duration = $obj->task_duration;
1401 $newobj->timespent_line_fk_user = $obj->fk_user;
1402 $newobj->timespent_line_thm = $obj->thm;
1403 $newobj->timespent_line_note = $obj->note;
1405 $arrayres[] = $newobj;
1412 $this->lines = $arrayres;
1416 $this->error =
"Error ".$this->db->lasterror();
1433 if (is_object($userobj)) {
1434 $userid = $userobj->id;
1440 if (empty($id) && empty($userid)) {
1441 dol_syslog(
"getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR);
1448 $sql .=
" MIN(t.task_datehour) as min_date,";
1449 $sql .=
" MAX(t.task_datehour) as max_date,";
1450 $sql .=
" SUM(t.task_duration) as total_duration,";
1451 $sql .=
" SUM(t.task_duration / 3600 * ".$this->db->ifsql(
"t.thm IS NULL", 0,
"t.thm").
") as total_amount,";
1452 $sql .=
" COUNT(t.rowid) as nblines,";
1453 $sql .=
" SUM(".$this->db->ifsql(
"t.thm IS NULL", 1, 0).
") as nblinesnull";
1454 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1455 $sql .=
" WHERE 1 = 1";
1456 if ($morewherefilter) {
1457 $sql .= $morewherefilter;
1460 $sql .=
" AND t.fk_task = ".((int) $id);
1463 $sql .=
" AND t.fk_user = ".((int) $userid);
1466 dol_syslog(get_class($this).
"::getSummaryOfTimeSpent", LOG_DEBUG);
1469 $obj = $this->
db->fetch_object(
$resql);
1471 $result[
'min_date'] = $obj->min_date;
1472 $result[
'max_date'] = $obj->max_date;
1473 $result[
'total_duration'] = $obj->total_duration;
1475 $this->timespent_min_date = $this->
db->jdate($obj->min_date);
1476 $this->timespent_max_date = $this->
db->jdate($obj->max_date);
1477 $this->timespent_total_duration = $obj->total_duration;
1478 $this->timespent_total_amount = $obj->total_amount;
1479 $this->timespent_nblinesnull = ($obj->nblinesnull ? $obj->nblinesnull : 0);
1480 $this->timespent_nblines = ($obj->nblines ? $obj->nblines : 0);
1508 $sql .=
" SUM(t.task_duration) as nbseconds,";
1509 $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";
1510 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1511 $sql .=
" WHERE t.fk_task = ".((int) $id);
1512 if (is_object($fuser) && $fuser->id > 0) {
1513 $sql .=
" AND fk_user = ".((int) $fuser->id);
1516 $datefieldname =
"task_datehour";
1517 $sql .=
" AND (".$datefieldname.
" >= '".$this->
db->idate($dates).
"' OR ".$datefieldname.
" IS NULL)";
1520 $datefieldname =
"task_datehour";
1521 $sql .=
" AND (".$datefieldname.
" <= '".$this->
db->idate($datee).
"' OR ".$datefieldname.
" IS NULL)";
1525 dol_syslog(get_class($this).
"::getSumOfAmount", LOG_DEBUG);
1528 $obj = $this->
db->fetch_object(
$resql);
1530 $result[
'amount'] = $obj->amount;
1531 $result[
'nbseconds'] = $obj->nbseconds;
1532 $result[
'nblinesnull'] = $obj->nblinesnull;
1553 $sql .=
" t.rowid,";
1554 $sql .=
" t.fk_task,";
1555 $sql .=
" t.task_date,";
1556 $sql .=
" t.task_datehour,";
1557 $sql .=
" t.task_date_withhour,";
1558 $sql .=
" t.task_duration,";
1559 $sql .=
" t.fk_user,";
1560 $sql .=
" t.fk_product,";
1563 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1564 $sql .=
" WHERE t.rowid = ".((int) $id);
1566 dol_syslog(get_class($this).
"::fetchTimeSpent", LOG_DEBUG);
1570 $obj = $this->
db->fetch_object(
$resql);
1572 $this->timespent_id = $obj->rowid;
1573 $this->
id = $obj->fk_task;
1574 $this->timespent_date = $this->
db->jdate($obj->task_date);
1575 $this->timespent_datehour = $this->
db->jdate($obj->task_datehour);
1576 $this->timespent_withhour = $obj->task_date_withhour;
1577 $this->timespent_duration = $obj->task_duration;
1578 $this->timespent_fk_user = $obj->fk_user;
1579 $this->timespent_fk_product = $obj->fk_product;
1580 $this->timespent_thm = $obj->thm;
1581 $this->timespent_note = $obj->note;
1588 $this->error =
"Error ".$this->db->lasterror();
1604 $arrayres = array();
1607 $sql .=
" s.rowid as socid,";
1608 $sql .=
" s.nom as thirdparty_name,";
1609 $sql .=
" s.email as thirdparty_email,";
1610 $sql .=
" ptt.rowid,";
1611 $sql .=
" ptt.fk_task,";
1612 $sql .=
" ptt.task_date,";
1613 $sql .=
" ptt.task_datehour,";
1614 $sql .=
" ptt.task_date_withhour,";
1615 $sql .=
" ptt.task_duration,";
1616 $sql .=
" ptt.fk_user,";
1617 $sql .=
" ptt.note,";
1618 $sql .=
" ptt.thm,";
1619 $sql .=
" pt.rowid as task_id,";
1620 $sql .=
" pt.ref as task_ref,";
1621 $sql .=
" pt.label as task_label,";
1622 $sql .=
" p.rowid as project_id,";
1623 $sql .=
" p.ref as project_ref,";
1624 $sql .=
" p.title as project_label,";
1625 $sql .=
" p.public as public";
1626 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1627 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1628 $sql .=
" WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1629 $sql .=
" AND ptt.fk_user = ".((int) $userobj->id);
1630 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1631 if ($morewherefilter) {
1632 $sql .= $morewherefilter;
1635 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1638 $num = $this->
db->num_rows(
$resql);
1642 $obj = $this->
db->fetch_object(
$resql);
1644 $newobj =
new stdClass();
1646 $newobj->socid = $obj->socid;
1647 $newobj->thirdparty_name = $obj->thirdparty_name;
1648 $newobj->thirdparty_email = $obj->thirdparty_email;
1650 $newobj->fk_project = $obj->project_id;
1651 $newobj->project_ref = $obj->project_ref;
1652 $newobj->project_label = $obj->project_label;
1653 $newobj->public = $obj->project_public;
1655 $newobj->fk_task = $obj->task_id;
1656 $newobj->task_ref = $obj->task_ref;
1657 $newobj->task_label = $obj->task_label;
1659 $newobj->timespent_id = $obj->rowid;
1660 $newobj->timespent_date = $this->
db->jdate($obj->task_date);
1661 $newobj->timespent_datehour = $this->
db->jdate($obj->task_datehour);
1662 $newobj->timespent_withhour = $obj->task_date_withhour;
1663 $newobj->timespent_duration = $obj->task_duration;
1664 $newobj->timespent_fk_user = $obj->fk_user;
1665 $newobj->timespent_thm = $obj->thm;
1666 $newobj->timespent_note = $obj->note;
1668 $arrayres[] = $newobj;
1676 $this->error =
"Error ".$this->db->lasterror();
1692 global $conf, $langs;
1697 if ($this->timespent_date ==
'') {
1698 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date"));
1701 if (!($this->timespent_fk_user > 0)) {
1702 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"User"));
1707 if (empty($this->timespent_datehour)) {
1708 $this->timespent_datehour = $this->timespent_date;
1710 if (isset($this->timespent_note)) {
1711 $this->timespent_note = trim($this->timespent_note);
1714 if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1715 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1718 if ($this->timespent_date < $restrictBefore) {
1719 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1720 $this->errors[] = $this->error;
1727 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time SET";
1728 $sql .=
" task_date = '".$this->db->idate($this->timespent_date).
"',";
1729 $sql .=
" task_datehour = '".$this->db->idate($this->timespent_datehour).
"',";
1730 $sql .=
" task_date_withhour = ".(empty($this->timespent_withhour) ? 0 : 1).
",";
1731 $sql .=
" task_duration = ".((int) $this->timespent_duration).
",";
1732 $sql .=
" fk_user = ".((int) $this->timespent_fk_user).
",";
1733 $sql .=
" fk_product = ".((int) $this->timespent_fk_product).
",";
1734 $sql .=
" note = ".(isset($this->timespent_note) ?
"'".$this->db->escape($this->timespent_note).
"'" :
"null");
1735 $sql .=
" WHERE rowid = ".((int) $this->timespent_id);
1737 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
1738 if ($this->
db->query($sql)) {
1741 $result = $this->call_trigger(
'TASK_TIMESPENT_MODIFY', $user);
1743 $this->
db->rollback();
1753 $this->error = $this->
db->lasterror();
1754 $this->
db->rollback();
1758 if ($ret == 1 && (($this->timespent_old_duration != $this->timespent_duration) || !empty($conf->global->TIMESPENT_ALWAYS_UPDATE_THM))) {
1759 if ($this->timespent_old_duration != $this->timespent_duration) {
1761 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"projet_task";
1762 $sql .=
" SET duration_effective = (SELECT SUM(task_duration) FROM " . MAIN_DB_PREFIX .
"projet_task_time as ptt where ptt.fk_task = " . ((int) $this->
id) .
")";
1763 if (isset($this->progress)) {
1764 $sql .=
", progress = " . ((
float) $this->progress);
1766 $sql .=
" WHERE rowid = " . ((int) $this->
id);
1768 dol_syslog(get_class($this) .
"::updateTimeSpent", LOG_DEBUG);
1769 if (!$this->
db->query($sql)) {
1770 $this->error = $this->
db->lasterror();
1771 $this->
db->rollback();
1777 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time";
1778 $sql .=
" SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX.
"user WHERE rowid = ".((int) $this->timespent_fk_user).
")";
1779 $sql .=
" WHERE rowid = ".((int) $this->timespent_id);
1780 if (empty($conf->global->TIMESPENT_ALWAYS_UPDATE_THM)) {
1781 $sql .=
" AND (thm IS NULL OR thm = 0)";
1784 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1785 if (!$this->
db->query($sql)) {
1786 $this->error = $this->
db->lasterror();
1792 $this->
db->commit();
1806 global $conf, $langs;
1810 if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1811 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1814 if ($this->timespent_date < $restrictBefore) {
1815 $this->error = $langs->trans(
'TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
1816 $this->errors[] = $this->error;
1825 $result = $this->call_trigger(
'TASK_TIMESPENT_DELETE', $user);
1833 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_time";
1834 $sql .=
" WHERE rowid = ".((int) $this->timespent_id);
1836 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
1839 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1844 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1845 $sql .=
" SET duration_effective = duration_effective - ".$this->db->escape($this->timespent_duration ? $this->timespent_duration : 0);
1846 $sql .=
" WHERE rowid = ".((int) $this->
id);
1848 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
1849 if ($this->
db->query($sql)) {
1852 $this->error = $this->
db->lasterror();
1859 foreach ($this->errors as $errmsg) {
1860 dol_syslog(get_class($this).
"::delTimeSpent ".$errmsg, LOG_ERR);
1861 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1863 $this->
db->rollback();
1866 $this->
db->commit();
1885 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)
1887 global $langs, $conf;
1896 $clone_task =
new Task($this->
db);
1897 $origin_task =
new Task($this->
db);
1899 $clone_task->context[
'createfromclone'] =
'createfromclone';
1904 $clone_task->fetch($fromid);
1905 $clone_task->fetch_optionals();
1908 $origin_task->fetch($fromid);
1911 $obj = empty($conf->global->PROJECT_TASK_ADDON) ?
'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
1912 if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT.
"/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.
".php")) {
1913 require_once DOL_DOCUMENT_ROOT.
"/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.
'.php';
1914 $modTask =
new $obj;
1915 $defaultref = $modTask->getNextValue(0, $clone_task);
1918 $ori_project_id = $clone_task->fk_project;
1920 $clone_task->id = 0;
1921 $clone_task->ref = $defaultref;
1922 $clone_task->fk_project = $project_id;
1923 $clone_task->fk_task_parent = $parent_task_id;
1924 $clone_task->date_c = $datec;
1925 $clone_task->planned_workload = $origin_task->planned_workload;
1926 $clone_task->rang = $origin_task->rang;
1927 $clone_task->priority = $origin_task->priority;
1930 if ($clone_change_dt) {
1931 $projectstatic =
new Project($this->
db);
1932 $projectstatic->fetch($ori_project_id);
1935 $orign_project_dt_start = $projectstatic->date_start;
1938 if (!empty($clone_task->date_start)) {
1939 $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
1943 if (!empty($clone_task->date_end)) {
1944 $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
1949 $clone_task->progress = 0;
1953 $result = $clone_task->create($user);
1957 $this->error = $clone_task->error;
1963 $clone_task_id = $clone_task->id;
1964 $clone_task_ref = $clone_task->ref;
1968 $clone_task->note_private =
'';
1969 $clone_task->note_public =
'';
1972 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_public, ENT_QUOTES | ENT_HTML5),
'_public');
1974 $this->error .= $clone_task->error;
1976 $this->
db->rollback();
1978 $this->
db->commit();
1982 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_private, ENT_QUOTES | ENT_HTML5),
'_private');
1984 $this->error .= $clone_task->error;
1986 $this->
db->rollback();
1988 $this->
db->commit();
1994 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1997 $projectstatic =
new Project($this->
db);
1998 $projectstatic->fetch($ori_project_id);
1999 $ori_project_ref = $projectstatic->ref;
2001 if ($ori_project_id != $project_id) {
2002 $projectstatic->fetch($project_id);
2003 $clone_project_ref = $projectstatic->ref;
2005 $clone_project_ref = $ori_project_ref;
2011 $filearray =
dol_dir_list($ori_task_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'', SORT_ASC, 1);
2012 foreach ($filearray as $key => $file) {
2013 if (!file_exists($clone_task_dir)) {
2015 $this->error .= $langs->trans(
'ErrorInternalErrorDetected').
':dol_mkdir';
2020 $rescopy =
dol_copy($ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name'], 0, 1);
2021 if (is_numeric($rescopy) && $rescopy < 0) {
2022 $this->error .= $langs->trans(
"ErrorFailToCopyFile", $ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name']);
2029 if ($clone_affectation) {
2030 $origin_task =
new Task($this->
db);
2031 $origin_task->fetch($fromid);
2033 foreach (array(
'internal',
'external') as $source) {
2034 $tab = $origin_task->liste_contact(-1, $source);
2038 $clone_task->add_contact($tab[$i][
'id'], $tab[$i][
'code'], $tab[$i][
'source']);
2039 if ($clone_task->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2040 $langs->load(
"errors");
2041 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
2044 if ($clone_task->error !=
'') {
2045 $this->error .= $clone_task->error;
2059 unset($clone_task->context[
'createfromclone']);
2062 $this->
db->commit();
2063 return $clone_task_id;
2065 $this->
db->rollback();
2066 dol_syslog(get_class($this).
"::createFromClone nbError: ".$error.
" error : ".$this->error, LOG_ERR);
2080 return $this->LibStatut($this->fk_statut, $mode);
2097 $this->statuts[0] =
'Draft';
2098 $this->statuts[1] =
'ToDo';
2099 $this->statuts[2] =
'Running';
2100 $this->statuts[3] =
'Finish';
2101 $this->statuts[4] =
'Transfered';
2102 $this->statuts_short[0] =
'Draft';
2103 $this->statuts_short[1] =
'ToDo';
2104 $this->statuts_short[2] =
'Running';
2105 $this->statuts_short[3] =
'Completed';
2106 $this->statuts_short[4] =
'Transfered';
2109 return $langs->trans($this->statuts[$status]);
2110 } elseif ($mode == 1) {
2111 return $langs->trans($this->statuts_short[$status]);
2112 } elseif ($mode == 2) {
2114 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts_short[$status]);
2115 } elseif ($status == 1) {
2116 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1').
' '.$langs->trans($this->statuts_short[$status]);
2117 } elseif ($status == 2) {
2118 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3').
' '.$langs->trans($this->statuts_short[$status]);
2119 } elseif ($status == 3) {
2120 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
2121 } elseif ($status == 4) {
2122 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
2123 } elseif ($status == 5) {
2124 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5').
' '.$langs->trans($this->statuts_short[$status]);
2126 } elseif ($mode == 3) {
2128 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0');
2129 } elseif ($status == 1) {
2130 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1');
2131 } elseif ($status == 2) {
2132 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3');
2133 } elseif ($status == 3) {
2134 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
2135 } elseif ($status == 4) {
2136 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
2137 } elseif ($status == 5) {
2138 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5');
2140 } elseif ($mode == 4) {
2142 return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts[$status]);
2143 } elseif ($status == 1) {
2144 return img_picto($langs->trans($this->statuts_short[$status]),
'statut1').
' '.$langs->trans($this->statuts[$status]);
2145 } elseif ($status == 2) {
2146 return img_picto($langs->trans($this->statuts_short[$status]),
'statut3').
' '.$langs->trans($this->statuts[$status]);
2147 } elseif ($status == 3) {
2148 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
2149 } elseif ($status == 4) {
2150 return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
2151 } elseif ($status == 5) {
2152 return img_picto($langs->trans($this->statuts_short[$status]),
'statut5').
' '.$langs->trans($this->statuts[$status]);
2154 } elseif ($mode == 5) {
2164 } elseif ($mode == 6) {
2187 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2191 $outputlangs->load(
"projects");
2194 $modele =
'nodefault';
2196 if (!empty($this->model_pdf)) {
2197 $modele = $this->model_pdf;
2198 } elseif (!empty($this->modelpdf)) {
2199 $modele = $this->modelpdf;
2200 } elseif (!empty($conf->global->PROJECT_TASK_ADDON_PDF)) {
2201 $modele = $conf->global->PROJECT_TASK_ADDON_PDF;
2205 $modelpath =
"core/modules/project/task/doc/";
2207 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2221 global $conf, $langs;
2227 $projectstatic =
new Project($this->
db);
2228 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
2231 $sql =
"SELECT p.rowid as projectid, p.fk_statut as projectstatus,";
2232 $sql .=
" t.rowid as taskid, t.progress as progress, t.fk_statut as status,";
2233 $sql .=
" t.dateo as date_start, t.datee as datee";
2234 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2237 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2238 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2239 $sql .=
" AND p.fk_statut = 1";
2240 $sql .=
" AND t.fk_projet = p.rowid";
2241 $sql .=
" AND (t.progress IS NULL OR t.progress < 100)";
2242 if (empty($user->rights->projet->all->lire)) {
2243 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2253 $task_static =
new Task($this->
db);
2256 $response->warning_delay = $conf->project->task->warning_delay / 60 / 60 / 24;
2257 $response->label = $langs->trans(
"OpenedTasks");
2258 if ($user->hasRight(
"projet",
"all",
"lire")) {
2259 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mainmenu=project';
2261 $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mode=mine&mainmenu=project';
2266 while ($obj = $this->
db->fetch_object(
$resql)) {
2267 $response->nbtodo++;
2269 $task_static->projectstatus = $obj->projectstatus;
2270 $task_static->progress = $obj->progress;
2271 $task_static->fk_statut = $obj->status;
2272 $task_static->date_end = $this->
db->jdate($obj->datee);
2274 if ($task_static->hasDelay()) {
2275 $response->nbtodolate++;
2281 $this->error = $this->
db->error();
2298 $mine = 0; $socid = $user->socid;
2300 $projectstatic =
new Project($this->
db);
2301 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $mine, 1, $socid);
2304 $sql =
"SELECT count(p.rowid) as nb";
2305 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2306 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
2307 if (empty($user->rights->societe->client->voir) && !$socid) {
2308 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2310 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2311 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2312 $sql .=
" AND t.fk_projet = p.rowid";
2313 if ($mine || empty($user->rights->projet->all->lire)) {
2314 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2319 $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).
")";
2321 if (empty($user->rights->societe->client->voir) && !$socid) {
2322 $sql .=
" AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).
") OR (s.rowid IS NULL))";
2328 while ($obj = $this->
db->fetch_object(
$resql)) {
2329 $this->nb[
"tasks"] = $obj->nb;
2335 $this->error = $this->
db->error();
2349 if (!($this->progress >= 0 && $this->progress < 100)) {
2355 $datetouse = ($this->date_end > 0) ? $this->date_end : ((isset($this->datee) && $this->datee > 0) ? $this->datee : 0);
2357 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 in llx_element_contact.
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, $sortfield='', $sortorder='')
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.