28 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
40 public $element =
'project_task';
45 public $table_element =
'projet_task';
50 public $fk_element =
'fk_task';
55 public $picto =
'projecttask';
60 protected $childtables = array(
'projet_task_time');
65 public $fk_task_parent = 0;
77 public $duration_effective;
78 public $planned_workload;
94 public $fk_user_creat;
99 public $fk_user_valid;
103 public $timespent_min_date;
104 public $timespent_max_date;
105 public $timespent_total_duration;
106 public $timespent_total_amount;
107 public $timespent_nblinesnull;
108 public $timespent_nblines;
112 public $timespent_id;
113 public $timespent_duration;
114 public $timespent_old_duration;
115 public $timespent_date;
116 public $timespent_datehour;
117 public $timespent_withhour;
118 public $timespent_fk_user;
119 public $timespent_note;
121 public $comments = array();
144 public function create($user, $notrigger = 0)
146 global $conf, $langs;
154 $this->label = trim($this->label);
161 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet_task (";
163 $sql .=
", fk_projet";
165 $sql .=
", fk_task_parent";
167 $sql .=
", description";
169 $sql .=
", fk_user_creat";
172 $sql .=
", planned_workload";
173 $sql .=
", progress";
174 $sql .=
") VALUES (";
175 $sql .= $conf->entity;
176 $sql .=
", ".$this->fk_project;
177 $sql .=
", ".(!empty($this->ref) ?
"'".$this->db->escape($this->ref).
"'" :
'null');
178 $sql .=
", ".$this->fk_task_parent;
179 $sql .=
", '".$this->db->escape($this->label).
"'";
180 $sql .=
", '".$this->db->escape($this->
description).
"'";
181 $sql .=
", '".$this->db->idate($now).
"'";
182 $sql .=
", ".$user->id;
183 $sql .=
", ".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
'null');
184 $sql .=
", ".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
'null');
185 $sql .=
", ".(($this->planned_workload !=
'' && $this->planned_workload >= 0) ? $this->planned_workload :
'null');
186 $sql .=
", ".(($this->progress !=
'' && $this->progress >= 0) ? $this->progress :
'null');
191 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
193 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
197 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"projet_task");
203 if ($result < 0) { $error++; }
224 foreach ($this->errors as $errmsg)
226 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
227 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
229 $this->
db->rollback();
246 public function fetch($id, $ref =
'', $loadparentdata = 0)
248 global $langs, $conf;
253 $sql .=
" t.fk_projet as fk_project,";
254 $sql .=
" t.fk_task_parent,";
256 $sql .=
" t.description,";
257 $sql .=
" t.duration_effective,";
258 $sql .=
" t.planned_workload,";
262 $sql .=
" t.fk_user_creat,";
263 $sql .=
" t.fk_user_valid,";
264 $sql .=
" t.fk_statut,";
265 $sql .=
" t.progress,";
266 $sql .=
" t.priority,";
267 $sql .=
" t.note_private,";
268 $sql .=
" t.note_public,";
270 if (!empty($loadparentdata))
272 $sql .=
", t2.ref as task_parent_ref";
273 $sql .=
", t2.rang as task_parent_position";
275 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as t";
276 if (!empty($loadparentdata)) $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t2 ON t.fk_task_parent = t2.rowid";
279 $sql .=
"t.ref = '".$this->db->escape($ref).
"'";
281 $sql .=
"t.rowid = ".$id;
284 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
288 $num_rows = $this->
db->num_rows(
$resql);
292 $obj = $this->
db->fetch_object(
$resql);
294 $this->
id = $obj->rowid;
295 $this->ref = $obj->ref;
296 $this->fk_project = $obj->fk_project;
297 $this->fk_task_parent = $obj->fk_task_parent;
298 $this->label = $obj->label;
300 $this->duration_effective = $obj->duration_effective;
301 $this->planned_workload = $obj->planned_workload;
302 $this->date_c = $this->
db->jdate($obj->datec);
303 $this->date_start = $this->
db->jdate($obj->dateo);
304 $this->date_end = $this->
db->jdate($obj->datee);
305 $this->fk_user_creat = $obj->fk_user_creat;
306 $this->fk_user_valid = $obj->fk_user_valid;
307 $this->fk_statut = $obj->fk_statut;
308 $this->progress = $obj->progress;
309 $this->priority = $obj->priority;
310 $this->note_private = $obj->note_private;
311 $this->note_public = $obj->note_public;
312 $this->rang = $obj->rang;
314 if (!empty($loadparentdata))
316 $this->task_parent_ref = $obj->task_parent_ref;
317 $this->task_parent_position = $obj->task_parent_position;
333 $this->error =
"Error ".$this->db->lasterror();
346 public function update($user = null, $notrigger = 0)
348 global $conf, $langs;
352 if (isset($this->fk_project)) $this->fk_project = trim($this->fk_project);
353 if (isset($this->ref)) $this->ref = trim($this->ref);
354 if (isset($this->fk_task_parent)) $this->fk_task_parent = (int) $this->fk_task_parent;
355 if (isset($this->label)) $this->label = trim($this->label);
357 if (isset($this->duration_effective)) $this->duration_effective = trim($this->duration_effective);
358 if (isset($this->planned_workload)) $this->planned_workload = trim($this->planned_workload);
364 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
365 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
366 $sql .=
" ref=".(isset($this->ref) ?
"'".$this->db->escape($this->ref).
"'" :
"'".$this->db->escape($this->
id).
"'").
",";
367 $sql .=
" fk_task_parent=".(isset($this->fk_task_parent) ? $this->fk_task_parent :
"null").
",";
368 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
369 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
370 $sql .=
" duration_effective=".(isset($this->duration_effective) ? $this->duration_effective :
"null").
",";
371 $sql .=
" planned_workload=".((isset($this->planned_workload) && $this->planned_workload !=
'') ? $this->planned_workload :
"null").
",";
372 $sql .=
" dateo=".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
'null').
",";
373 $sql .=
" datee=".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
'null').
",";
374 $sql .=
" progress=".(($this->progress !=
'' && $this->progress >= 0) ? $this->progress :
'null').
",";
375 $sql .=
" rang=".((!empty($this->rang)) ? $this->rang :
"0");
376 $sql .=
" WHERE rowid=".$this->id;
380 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
382 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
402 if ($result < 0) { $error++; }
407 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref))
410 if ($conf->projet->dir_output)
413 $project->fetch($this->fk_project);
417 if (file_exists($olddir))
419 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
423 $langs->load(
"errors");
424 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
434 foreach ($this->errors as $errmsg)
436 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
437 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
439 $this->
db->rollback();
455 public function delete($user, $notrigger = 0)
458 global $conf, $langs;
459 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
467 dol_syslog(get_class($this).
"::delete Can't delete record as it has some sub tasks", LOG_WARNING);
468 $this->error =
'ErrorRecordHasSubTasks';
469 $this->
db->rollback();
474 if (!empty($objectisused))
476 dol_syslog(get_class($this).
"::delete Can't delete record as it has some child", LOG_WARNING);
477 $this->error =
'ErrorRecordHasChildren';
478 $this->
db->rollback();
488 $this->error =
'ErrorFailToDeleteLinkedContact';
490 $this->
db->rollback();
497 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_time";
498 $sql .=
" WHERE fk_task=".$this->id;
501 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
506 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_extrafields";
507 $sql .=
" WHERE fk_object=".$this->id;
510 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
515 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task";
516 $sql .=
" WHERE rowid=".$this->id;
519 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
528 if ($result < 0) { $error++; }
536 foreach ($this->errors as $errmsg)
538 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
539 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
541 $this->
db->rollback();
545 if ($conf->projet->dir_output)
548 $projectstatic->fetch($this->fk_project);
551 dol_syslog(get_class($this).
"::delete dir=".$dir, LOG_DEBUG);
552 if (file_exists($dir))
554 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
558 $this->error =
'ErrorFailToDeleteDir';
559 $this->
db->rollback();
581 $sql =
"SELECT COUNT(*) as nb";
582 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task";
583 $sql .=
" WHERE fk_task_parent=".$this->id;
585 dol_syslog(get_class($this).
"::hasChildren", LOG_DEBUG);
587 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
else {
588 $obj = $this->
db->fetch_object(
$resql);
589 if ($obj) $ret = $obj->nb;
611 $sql =
"SELECT COUNT(*) as nb";
612 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time";
613 $sql .=
" WHERE fk_task=".$this->id;
615 dol_syslog(get_class($this).
"::hasTimeSpent", LOG_DEBUG);
617 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
else {
618 $obj = $this->
db->fetch_object(
$resql);
619 if ($obj) $ret = $obj->nb;
644 public function getNomUrl($withpicto = 0, $option =
'', $mode =
'task', $addlabel = 0, $sep =
' - ', $notooltip = 0, $save_lastsearch_value = -1)
646 global $conf, $langs, $user;
648 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
651 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Task").
'</u>';
652 if (!empty($this->ref))
653 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
654 if (!empty($this->label))
655 $label .=
'<br><b>'.$langs->trans(
'LabelTask').
':</b> '.$this->label;
656 if ($this->date_start || $this->date_end)
658 $label .=
"<br>".get_date_range($this->date_start, $this->date_end,
'', $langs, 0);
661 $url = DOL_URL_ROOT.
'/projet/tasks/'.$mode.
'.php?id='.$this->
id.($option ==
'withproject' ?
'&withproject=1' :
'');
663 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
664 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
665 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
668 if (empty($notooltip))
670 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
672 $label = $langs->trans(
"ShowTask");
673 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
675 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
676 $linkclose .=
' class="classfortooltip nowraponall"';
678 $linkclose .=
' class="nowraponall"';
681 $linkstart =
'<a href="'.$url.
'"';
682 $linkstart .= $linkclose.
'>';
685 $picto =
'projecttask';
687 $result .= $linkstart;
688 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), $picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
689 if ($withpicto != 2) $result .= $this->ref;
691 if ($withpicto != 2) $result .= (($addlabel && $this->label) ? $sep.dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) :
'');
707 $this->fk_project =
'';
709 $this->fk_task_parent = null;
710 $this->label =
'Specimen task TK01';
711 $this->duration_effective =
'';
712 $this->fk_user_creat = null;
713 $this->progress =
'25';
714 $this->fk_statut = null;
715 $this->
note =
'This is a specimen task not';
737 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())
739 global $conf, $hookmanager;
747 if ($filteronprojuser > 0 || $filterontaskuser > 0) $sql .=
" DISTINCT";
748 $sql .=
" p.rowid as projectid, p.ref, p.title as plabel, p.public, p.fk_statut as projectstatus, p.usage_bill_time,";
749 $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,";
750 $sql .=
" t.dateo as date_start, t.datee as date_end, t.planned_workload, t.rang,";
751 $sql .=
" t.description, ";
752 $sql .=
" s.rowid as thirdparty_id, s.nom as thirdparty_name, s.email as thirdparty_email,";
753 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount";
754 if (!empty($extrafields->attributes[
'projet'][
'label']))
756 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key.
' as options_'.$key :
'');
758 if (!empty($extrafields->attributes[
'projet_task'][
'label']))
760 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key.
' as options_'.$key :
'');
762 if ($includebilltime)
764 $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";
767 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
768 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
769 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_extrafields as efp ON (p.rowid = efp.fk_object)";
773 if ($filteronprojuser > 0)
775 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
776 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
778 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
779 if ($includebilltime)
781 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
783 if ($filterontaskuser > 0)
785 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
786 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
788 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
789 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
790 $sql .=
" AND t.fk_projet = p.rowid";
791 } elseif ($mode == 1)
793 if ($filteronprojuser > 0)
795 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
796 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
798 if ($filterontaskuser > 0)
800 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
801 if ($includebilltime)
803 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
805 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec2";
806 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc2";
808 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task as t on t.fk_projet = p.rowid";
809 if ($includebilltime)
811 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_time as tt ON tt.fk_task = t.rowid";
814 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
815 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
816 }
else return 'BadValueForParameterMode';
818 if ($filteronprojuser > 0)
820 $sql .=
" AND p.rowid = ec.element_id";
821 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
822 $sql .=
" AND ctc.element = 'project'";
823 $sql .=
" AND ec.fk_socpeople = ".$filteronprojuser;
824 $sql .=
" AND ec.statut = 4";
825 $sql .=
" AND ctc.source = 'internal'";
827 if ($filterontaskuser > 0)
829 $sql .=
" AND t.fk_projet = p.rowid";
830 $sql .=
" AND p.rowid = ec2.element_id";
831 $sql .=
" AND ctc2.rowid = ec2.fk_c_type_contact";
832 $sql .=
" AND ctc2.element = 'project_task'";
833 $sql .=
" AND ec2.fk_socpeople = ".$filterontaskuser;
834 $sql .=
" AND ec2.statut = 4";
835 $sql .=
" AND ctc2.source = 'internal'";
837 if ($socid) $sql .=
" AND p.fk_soc = ".$socid;
838 if ($projectid) $sql .=
" AND p.rowid in (".$projectid.
")";
839 if ($filteronproj) $sql .=
natural_search(array(
"p.ref",
"p.title"), $filteronproj);
840 if ($filteronprojstatus && $filteronprojstatus !=
'-1') $sql .=
" AND p.fk_statut IN (".$filteronprojstatus.
")";
841 if ($morewherefilter) $sql .= $morewherefilter;
843 $extrafieldsobjectkey =
'projet_task';
844 $extrafieldsobjectprefix =
'efpt.';
845 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
847 $parameters = array();
848 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
849 $sql .= $hookmanager->resPrint;
850 if ($includebilltime)
852 $sql .=
" GROUP BY p.rowid, p.ref, p.title, p.public, p.fk_statut, p.usage_bill_time,";
853 $sql .=
" t.datec, t.dateo, t.datee, t.tms,";
854 $sql .=
" t.rowid, t.ref, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress, t.fk_statut,";
855 $sql .=
" t.dateo, t.datee, t.planned_workload, t.rang,";
856 $sql .=
" t.description, ";
857 $sql .=
" s.rowid, s.nom, s.email,";
858 $sql .=
" p.fk_opp_status, p.opp_amount, p.opp_percent, p.budget_amount";
859 if (!empty($extrafields->attributes[
'projet'][
'label']))
861 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val) $sql .= ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate' ?
",efp.".$key :
'');
863 if (!empty($extrafields->attributes[
'projet_task'][
'label']))
865 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val) $sql .= ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate' ?
",efpt.".$key :
'');
870 $sql .=
" ORDER BY p.ref, t.rang, t.dateo";
873 dol_syslog(get_class($this).
"::getTasksArray", LOG_DEBUG);
884 $obj = $this->
db->fetch_object(
$resql);
886 if ((!$obj->public) && (is_object($userp)))
893 if (is_object($usert))
903 $tasks[$i] =
new Task($this->
db);
904 $tasks[$i]->id = $obj->taskid;
905 $tasks[$i]->ref = $obj->taskref;
906 $tasks[$i]->fk_project = $obj->projectid;
907 $tasks[$i]->projectref = $obj->ref;
908 $tasks[$i]->projectlabel = $obj->plabel;
909 $tasks[$i]->projectstatus = $obj->projectstatus;
911 $tasks[$i]->fk_opp_status = $obj->fk_opp_status;
912 $tasks[$i]->opp_amount = $obj->opp_amount;
913 $tasks[$i]->opp_percent = $obj->opp_percent;
914 $tasks[$i]->budget_amount = $obj->budget_amount;
915 $tasks[$i]->usage_bill_time = $obj->usage_bill_time;
917 $tasks[$i]->label = $obj->label;
918 $tasks[$i]->description = $obj->description;
919 $tasks[$i]->fk_parent = $obj->fk_task_parent;
920 $tasks[$i]->fk_task_parent = $obj->fk_task_parent;
921 $tasks[$i]->duration = $obj->duration_effective;
922 $tasks[$i]->planned_workload = $obj->planned_workload;
924 if ($includebilltime) {
925 $tasks[$i]->tobill = $obj->tobill;
926 $tasks[$i]->billed = $obj->billed;
929 $tasks[$i]->progress = $obj->progress;
930 $tasks[$i]->fk_statut = $obj->status;
931 $tasks[$i]->public = $obj->public;
932 $tasks[$i]->date_start = $this->
db->jdate($obj->date_start);
933 $tasks[$i]->date_end = $this->
db->jdate($obj->date_end);
934 $tasks[$i]->rang = $obj->rang;
936 $tasks[$i]->socid = $obj->thirdparty_id;
937 $tasks[$i]->thirdparty_id = $obj->thirdparty_id;
938 $tasks[$i]->thirdparty_name = $obj->thirdparty_name;
939 $tasks[$i]->thirdparty_email = $obj->thirdparty_email;
941 if (!empty($extrafields->attributes[
'projet'][
'label']))
943 foreach ($extrafields->attributes[
'projet'][
'label'] as $key => $val)
945 if ($extrafields->attributes[
'projet'][
'type'][$key] !=
'separate')
946 $tasks[$i]->{
'options_'.$key} = $obj->{
'options_'.$key};
950 if (!empty($extrafields->attributes[
'projet_task'][
'label']))
952 foreach ($extrafields->attributes[
'projet_task'][
'label'] as $key => $val)
954 if ($extrafields->attributes[
'projet_task'][
'type'][$key] !=
'separate')
955 $tasks[$i]->{
'options_'.$key} = $obj->{
'options_'.$key};
982 $arrayroles = array();
984 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks userp=".is_object($userp).
" usert=".is_object($usert).
" projectid=".$projectid.
" taskid=".$taskid);
987 if (empty($userp) && empty($usert))
989 $this->error =
"CallWithWrongParameters";
992 if (!empty($userp) && !empty($usert))
994 $this->error =
"CallWithWrongParameters";
999 $sql =
"SELECT pt.rowid as pid, ec.element_id, ctc.code, ctc.source";
1000 if ($userp) $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as pt";
1001 if ($usert && $filteronprojstatus > -1) $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p, ".MAIN_DB_PREFIX.
"projet_task as pt";
1002 if ($usert && $filteronprojstatus <= -1) $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as pt";
1003 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1004 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1005 $sql .=
" WHERE pt.rowid = ec.element_id";
1006 if ($userp && $filteronprojstatus > -1) $sql .=
" AND pt.fk_statut = ".$filteronprojstatus;
1007 if ($usert && $filteronprojstatus > -1) $sql .=
" AND pt.fk_projet = p.rowid AND p.fk_statut = ".$filteronprojstatus;
1008 if ($userp) $sql .=
" AND ctc.element = 'project'";
1009 if ($usert) $sql .=
" AND ctc.element = 'project_task'";
1010 $sql .=
" AND ctc.rowid = ec.fk_c_type_contact";
1011 if ($userp) $sql .=
" AND ec.fk_socpeople = ".$userp->id;
1012 if ($usert) $sql .=
" AND ec.fk_socpeople = ".$usert->id;
1013 $sql .=
" AND ec.statut = 4";
1014 $sql .=
" AND ctc.source = 'internal'";
1017 if ($userp) $sql .=
" AND pt.rowid in (".$projectid.
")";
1018 if ($usert) $sql .=
" AND pt.fk_projet in (".$projectid.
")";
1022 if ($userp) $sql .=
" ERROR SHOULD NOT HAPPENS";
1023 if ($usert) $sql .=
" AND pt.rowid = ".$taskid;
1027 dol_syslog(get_class($this).
"::getUserRolesForProjectsOrTasks execute request", LOG_DEBUG);
1031 $num = $this->
db->num_rows(
$resql);
1035 $obj = $this->
db->fetch_object(
$resql);
1036 if (empty($arrayroles[$obj->pid])) $arrayroles[$obj->pid] = $obj->code;
1037 else $arrayroles[$obj->pid] .=
','.$obj->code;
1057 $contactAlreadySelected = array();
1058 $tab = $this->liste_contact(-1, $source);
1064 if ($source ==
'thirdparty') $contactAlreadySelected[$i] = $tab[$i][
'socid'];
1065 else $contactAlreadySelected[$i] = $tab[$i][
'id'];
1068 return $contactAlreadySelected;
1081 global $conf, $langs;
1083 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1088 if (!is_object($user))
1090 dol_print_error(
'',
"Method addTimeSpent was called with wrong parameter user");
1095 if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note);
1096 if (empty($this->timespent_datehour)) $this->timespent_datehour = $this->timespent_date;
1100 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet_task_time (";
1102 $sql .=
", task_date";
1103 $sql .=
", task_datehour";
1104 $sql .=
", task_date_withhour";
1105 $sql .=
", task_duration";
1106 $sql .=
", fk_user";
1108 $sql .=
") VALUES (";
1110 $sql .=
", '".$this->db->idate($this->timespent_date).
"'";
1111 $sql .=
", '".$this->db->idate($this->timespent_datehour).
"'";
1112 $sql .=
", ".(empty($this->timespent_withhour) ? 0 : 1);
1113 $sql .=
", ".$this->timespent_duration;
1114 $sql .=
", ".$this->timespent_fk_user;
1115 $sql .=
", ".(isset($this->timespent_note) ?
"'".$this->db->escape($this->timespent_note).
"'" :
"null");
1121 $tasktime_id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"projet_task_time");
1122 $ret = $tasktime_id;
1123 $this->timespent_id = $ret;
1128 $result = $this->call_trigger(
'TASK_TIMESPENT_CREATE', $user);
1129 if ($result < 0) { $ret = -1; }
1133 $this->error = $this->
db->lasterror();
1140 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1141 $sql .=
" SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt where ptt.fk_task = ".$this->
id.
")";
1142 if (isset($this->progress)) $sql .=
", progress = ".$this->progress;
1143 $sql .=
" WHERE rowid = ".$this->id;
1145 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1146 if (!$this->
db->query($sql))
1148 $this->error = $this->
db->lasterror();
1152 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time";
1153 $sql .=
" SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX.
"user WHERE rowid = ".$this->timespent_fk_user.
")";
1154 $sql .=
" WHERE rowid = ".$tasktime_id;
1156 dol_syslog(get_class($this).
"::addTimeSpent", LOG_DEBUG);
1157 if (!$this->
db->query($sql))
1159 $this->error = $this->
db->lasterror();
1166 $this->
db->commit();
1168 $this->
db->rollback();
1184 if (is_object($userobj)) $userid = $userobj->id;
1185 else $userid = $userobj;
1188 if (empty($id) && empty($userid))
1190 dol_syslog(
"getSummaryOfTimeSpent called on a not loaded task without user param defined", LOG_ERR);
1197 $sql .=
" MIN(t.task_datehour) as min_date,";
1198 $sql .=
" MAX(t.task_datehour) as max_date,";
1199 $sql .=
" SUM(t.task_duration) as total_duration,";
1200 $sql .=
" SUM(t.task_duration / 3600 * ".$this->db->ifsql(
"t.thm IS NULL", 0,
"t.thm").
") as total_amount,";
1201 $sql .=
" COUNT(t.rowid) as nblines,";
1202 $sql .=
" SUM(".$this->db->ifsql(
"t.thm IS NULL", 1, 0).
") as nblinesnull";
1203 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1204 $sql .=
" WHERE 1 = 1";
1205 if ($morewherefilter) $sql .= $morewherefilter;
1206 if ($id > 0) $sql .=
" AND t.fk_task = ".$id;
1207 if ($userid > 0) $sql .=
" AND t.fk_user = ".$userid;
1209 dol_syslog(get_class($this).
"::getSummaryOfTimeSpent", LOG_DEBUG);
1213 $obj = $this->
db->fetch_object(
$resql);
1215 $result[
'min_date'] = $obj->min_date;
1216 $result[
'max_date'] = $obj->max_date;
1217 $result[
'total_duration'] = $obj->total_duration;
1219 $this->timespent_min_date = $this->
db->jdate($obj->min_date);
1220 $this->timespent_max_date = $this->
db->jdate($obj->max_date);
1221 $this->timespent_total_duration = $obj->total_duration;
1222 $this->timespent_total_amount = $obj->total_amount;
1223 $this->timespent_nblinesnull = ($obj->nblinesnull ? $obj->nblinesnull : 0);
1224 $this->timespent_nblines = ($obj->nblines ? $obj->nblines : 0);
1245 if (empty($id)) $id = $this->id;
1250 $sql .=
" SUM(t.task_duration) as nbseconds,";
1251 $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";
1252 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1253 $sql .=
" WHERE t.fk_task = ".$id;
1254 if (is_object($fuser) && $fuser->id > 0)
1256 $sql .=
" AND fk_user = ".$fuser->id;
1260 $datefieldname =
"task_datehour";
1261 $sql .=
" AND (".$datefieldname.
" >= '".$this->
db->idate($dates).
"' OR ".$datefieldname.
" IS NULL)";
1265 $datefieldname =
"task_datehour";
1266 $sql .=
" AND (".$datefieldname.
" <= '".$this->
db->idate($datee).
"' OR ".$datefieldname.
" IS NULL)";
1270 dol_syslog(get_class($this).
"::getSumOfAmount", LOG_DEBUG);
1274 $obj = $this->
db->fetch_object(
$resql);
1276 $result[
'amount'] = $obj->amount;
1277 $result[
'nbseconds'] = $obj->nbseconds;
1278 $result[
'nblinesnull'] = $obj->nblinesnull;
1299 $sql .=
" t.rowid,";
1300 $sql .=
" t.fk_task,";
1301 $sql .=
" t.task_date,";
1302 $sql .=
" t.task_datehour,";
1303 $sql .=
" t.task_date_withhour,";
1304 $sql .=
" t.task_duration,";
1305 $sql .=
" t.fk_user,";
1308 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as t";
1309 $sql .=
" WHERE t.rowid = ".$id;
1311 dol_syslog(get_class($this).
"::fetchTimeSpent", LOG_DEBUG);
1317 $obj = $this->
db->fetch_object(
$resql);
1319 $this->timespent_id = $obj->rowid;
1320 $this->
id = $obj->fk_task;
1321 $this->timespent_date = $this->
db->jdate($obj->task_date);
1322 $this->timespent_datehour = $this->
db->jdate($obj->task_datehour);
1323 $this->timespent_withhour = $obj->task_date_withhour;
1324 $this->timespent_duration = $obj->task_duration;
1325 $this->timespent_fk_user = $obj->fk_user;
1326 $this->timespent_thm = $obj->thm;
1327 $this->timespent_note = $obj->note;
1334 $this->error =
"Error ".$this->db->lasterror();
1350 $arrayres = array();
1353 $sql .=
" s.rowid as socid,";
1354 $sql .=
" s.nom as thirdparty_name,";
1355 $sql .=
" s.email as thirdparty_email,";
1356 $sql .=
" ptt.rowid,";
1357 $sql .=
" ptt.fk_task,";
1358 $sql .=
" ptt.task_date,";
1359 $sql .=
" ptt.task_datehour,";
1360 $sql .=
" ptt.task_date_withhour,";
1361 $sql .=
" ptt.task_duration,";
1362 $sql .=
" ptt.fk_user,";
1363 $sql .=
" ptt.note,";
1364 $sql .=
" pt.rowid as task_id,";
1365 $sql .=
" pt.ref as task_ref,";
1366 $sql .=
" pt.label as task_label,";
1367 $sql .=
" p.rowid as project_id,";
1368 $sql .=
" p.ref as project_ref,";
1369 $sql .=
" p.title as project_label,";
1370 $sql .=
" p.public as public";
1371 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt, ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet as p";
1372 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
1373 $sql .=
" WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
1374 $sql .=
" AND ptt.fk_user = ".$userobj->id;
1375 $sql .=
" AND pt.entity IN (".getEntity(
'project').
")";
1376 if ($morewherefilter) $sql .= $morewherefilter;
1378 dol_syslog(get_class($this).
"::fetchAllTimeSpent", LOG_DEBUG);
1382 $num = $this->
db->num_rows(
$resql);
1387 $obj = $this->
db->fetch_object(
$resql);
1389 $newobj =
new stdClass();
1391 $newobj->socid = $obj->socid;
1392 $newobj->thirdparty_name = $obj->thirdparty_name;
1393 $newobj->thirdparty_email = $obj->thirdparty_email;
1395 $newobj->fk_project = $obj->project_id;
1396 $newobj->project_ref = $obj->project_ref;
1397 $newobj->project_label = $obj->project_label;
1398 $newobj->public = $obj->project_public;
1400 $newobj->fk_task = $obj->task_id;
1401 $newobj->task_ref = $obj->task_ref;
1402 $newobj->task_label = $obj->task_label;
1404 $newobj->timespent_id = $obj->rowid;
1405 $newobj->timespent_date = $this->
db->jdate($obj->task_date);
1406 $newobj->timespent_datehour = $this->
db->jdate($obj->task_datehour);
1407 $newobj->timespent_withhour = $obj->task_date_withhour;
1408 $newobj->timespent_duration = $obj->task_duration;
1409 $newobj->timespent_fk_user = $obj->fk_user;
1410 $newobj->timespent_note = $obj->note;
1412 $arrayres[] = $newobj;
1420 $this->error =
"Error ".$this->db->lasterror();
1436 global $conf, $langs;
1441 if ($this->timespent_date ==
'')
1443 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date"));
1446 if (!($this->timespent_fk_user > 0))
1448 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"User"));
1453 if (empty($this->timespent_datehour)) $this->timespent_datehour = $this->timespent_date;
1454 if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note);
1458 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time SET";
1459 $sql .=
" task_date = '".$this->db->idate($this->timespent_date).
"',";
1460 $sql .=
" task_datehour = '".$this->db->idate($this->timespent_datehour).
"',";
1461 $sql .=
" task_date_withhour = ".(empty($this->timespent_withhour) ? 0 : 1).
",";
1462 $sql .=
" task_duration = ".$this->timespent_duration.
",";
1463 $sql .=
" fk_user = ".$this->timespent_fk_user.
",";
1464 $sql .=
" note = ".(isset($this->timespent_note) ?
"'".$this->db->escape($this->timespent_note).
"'" :
"null");
1465 $sql .=
" WHERE rowid = ".$this->timespent_id;
1467 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
1468 if ($this->
db->query($sql))
1473 $result = $this->call_trigger(
'TASK_TIMESPENT_MODIFY', $user);
1476 $this->
db->rollback();
1482 $this->error = $this->
db->lasterror();
1483 $this->
db->rollback();
1487 if ($ret == 1 && ($this->timespent_old_duration != $this->timespent_duration))
1489 $newDuration = $this->timespent_duration - $this->timespent_old_duration;
1491 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1492 $sql .=
" SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX.
"projet_task_time as ptt where ptt.fk_task = ".$this->
db->escape($this->
id).
")";
1493 $sql .=
" WHERE rowid = ".$this->id;
1495 dol_syslog(get_class($this).
"::updateTimeSpent", LOG_DEBUG);
1496 if (!$this->
db->query($sql))
1498 $this->error = $this->
db->lasterror();
1499 $this->
db->rollback();
1504 if ($ret >= 0) $this->
db->commit();
1517 global $conf, $langs;
1523 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_task_time";
1524 $sql .=
" WHERE rowid = ".$this->timespent_id;
1526 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
1528 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
1535 $result = $this->call_trigger(
'TASK_TIMESPENT_DELETE', $user);
1536 if ($result < 0) { $error++; }
1543 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task";
1544 $sql .=
" SET duration_effective = duration_effective - ".$this->db->escape($this->timespent_duration ? $this->timespent_duration : 0);
1545 $sql .=
" WHERE rowid = ".$this->id;
1547 dol_syslog(get_class($this).
"::delTimeSpent", LOG_DEBUG);
1548 if ($this->
db->query($sql))
1552 $this->error = $this->
db->lasterror();
1560 foreach ($this->errors as $errmsg)
1562 dol_syslog(get_class($this).
"::delTimeSpent ".$errmsg, LOG_ERR);
1563 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1565 $this->
db->rollback();
1568 $this->
db->commit();
1587 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)
1589 global $langs, $conf;
1598 $clone_task =
new Task($this->
db);
1599 $origin_task =
new Task($this->
db);
1601 $clone_task->context[
'createfromclone'] =
'createfromclone';
1606 $clone_task->fetch($fromid);
1607 $clone_task->fetch_optionals();
1610 $origin_task->fetch($fromid);
1613 $obj = empty($conf->global->PROJECT_TASK_ADDON) ?
'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
1614 if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT.
"/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.
".php"))
1616 require_once DOL_DOCUMENT_ROOT.
"/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.
'.php';
1617 $modTask =
new $obj;
1618 $defaultref = $modTask->getNextValue(0, $clone_task);
1621 $ori_project_id = $clone_task->fk_project;
1623 $clone_task->id = 0;
1624 $clone_task->ref = $defaultref;
1625 $clone_task->fk_project = $project_id;
1626 $clone_task->fk_task_parent = $parent_task_id;
1627 $clone_task->date_c = $datec;
1628 $clone_task->planned_workload = $origin_task->planned_workload;
1629 $clone_task->rang = $origin_task->rang;
1632 if ($clone_change_dt)
1634 $projectstatic =
new Project($this->
db);
1635 $projectstatic->fetch($ori_project_id);
1638 $orign_project_dt_start = $projectstatic->date_start;
1641 if (!empty($clone_task->date_start))
1643 $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
1647 if (!empty($clone_task->date_end))
1649 $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
1655 $clone_task->progress = 0;
1659 $result = $clone_task->create($user);
1664 $this->error = $clone_task->error;
1671 $clone_task_id = $clone_task->id;
1672 $clone_task_ref = $clone_task->ref;
1677 $clone_task->note_private =
'';
1678 $clone_task->note_public =
'';
1681 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_public, ENT_QUOTES | ENT_HTML5),
'_public');
1684 $this->error .= $clone_task->error;
1686 $this->
db->rollback();
1688 $this->
db->commit();
1692 $res = $clone_task->update_note(
dol_html_entity_decode($clone_task->note_private, ENT_QUOTES | ENT_HTML5),
'_private');
1695 $this->error .= $clone_task->error;
1697 $this->
db->rollback();
1699 $this->
db->commit();
1706 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1709 $projectstatic =
new Project($this->
db);
1710 $projectstatic->fetch($ori_project_id);
1711 $ori_project_ref = $projectstatic->ref;
1713 if ($ori_project_id != $project_id)
1715 $projectstatic->fetch($project_id);
1716 $clone_project_ref = $projectstatic->ref;
1718 $clone_project_ref = $ori_project_ref;
1724 $filearray =
dol_dir_list($ori_task_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'', SORT_ASC, 1);
1725 foreach ($filearray as $key => $file)
1727 if (!file_exists($clone_task_dir))
1731 $this->error .= $langs->trans(
'ErrorInternalErrorDetected').
':dol_mkdir';
1736 $rescopy =
dol_copy($ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name'], 0, 1);
1737 if (is_numeric($rescopy) && $rescopy < 0)
1739 $this->error .= $langs->trans(
"ErrorFailToCopyFile", $ori_task_dir.
'/'.$file[
'name'], $clone_task_dir.
'/'.$file[
'name']);
1746 if ($clone_affectation)
1748 $origin_task =
new Task($this->
db);
1749 $origin_task->fetch($fromid);
1751 foreach (array(
'internal',
'external') as $source)
1753 $tab = $origin_task->liste_contact(-1, $source);
1758 $clone_task->add_contact($tab[$i][
'id'], $tab[$i][
'code'], $tab[$i][
'source']);
1759 if ($clone_task->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS')
1761 $langs->load(
"errors");
1762 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
1765 if ($clone_task->error !=
'')
1767 $this->error .= $clone_task->error;
1782 unset($clone_task->context[
'createfromclone']);
1786 $this->
db->commit();
1787 return $clone_task_id;
1789 $this->
db->rollback();
1790 dol_syslog(get_class($this).
"::createFromClone nbError: ".$error.
" error : ".$this->error, LOG_ERR);
1804 return $this->LibStatut($this->fk_statut, $mode);
1821 $this->statuts[0] =
'Draft';
1822 $this->statuts[1] =
'ToDo';
1823 $this->statuts[2] =
'Running';
1824 $this->statuts[3] =
'Finish';
1825 $this->statuts[4] =
'Transfered';
1826 $this->statuts_short[0] =
'Draft';
1827 $this->statuts_short[1] =
'ToDo';
1828 $this->statuts_short[2] =
'Running';
1829 $this->statuts_short[3] =
'Completed';
1830 $this->statuts_short[4] =
'Transfered';
1834 return $langs->trans($this->statuts[$status]);
1835 } elseif ($mode == 1)
1837 return $langs->trans($this->statuts_short[$status]);
1838 } elseif ($mode == 2)
1840 if ($status == 0)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts_short[$status]);
1841 elseif ($status == 1)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut1').
' '.$langs->trans($this->statuts_short[$status]);
1842 elseif ($status == 2)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut3').
' '.$langs->trans($this->statuts_short[$status]);
1843 elseif ($status == 3)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
1844 elseif ($status == 4)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
1845 elseif ($status == 5)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut5').
' '.$langs->trans($this->statuts_short[$status]);
1846 } elseif ($mode == 3)
1848 if ($status == 0)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut0');
1849 elseif ($status == 1)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut1');
1850 elseif ($status == 2)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut3');
1851 elseif ($status == 3)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
1852 elseif ($status == 4)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
1853 elseif ($status == 5)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut5');
1854 } elseif ($mode == 4)
1856 if ($status == 0)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts[$status]);
1857 elseif ($status == 1)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut1').
' '.$langs->trans($this->statuts[$status]);
1858 elseif ($status == 2)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut3').
' '.$langs->trans($this->statuts[$status]);
1859 elseif ($status == 3)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
1860 elseif ($status == 4)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
1861 elseif ($status == 5)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut5').
' '.$langs->trans($this->statuts[$status]);
1862 } elseif ($mode == 5)
1873 } elseif ($mode == 6)
1897 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1901 $outputlangs->load(
"projects");
1904 $modele =
'nodefault';
1906 if (!empty($this->model_pdf)) {
1907 $modele = $this->model_pdf;
1908 } elseif (!empty($this->modelpdf)) {
1909 $modele = $this->modelpdf;
1910 } elseif (!empty($conf->global->PROJECT_TASK_ADDON_PDF)) {
1911 $modele = $conf->global->PROJECT_TASK_ADDON_PDF;
1915 $modelpath =
"core/modules/project/task/doc/";
1917 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1931 global $conf, $langs;
1936 $projectstatic =
new Project($this->
db);
1937 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
1940 $sql =
"SELECT p.rowid as projectid, p.fk_statut as projectstatus,";
1941 $sql .=
" t.rowid as taskid, t.progress as progress, t.fk_statut as status,";
1942 $sql .=
" t.dateo as date_start, t.datee as datee";
1943 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
1944 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
1946 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
1947 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
1948 $sql .=
" AND p.fk_statut = 1";
1949 $sql .=
" AND t.fk_projet = p.rowid";
1950 $sql .=
" AND (t.progress IS NULL OR t.progress < 100)";
1951 if (!$user->rights->projet->all->lire) $sql .=
" AND p.rowid IN (".$projectsListId.
")";
1954 if ($socid) $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.
")";
1962 $task_static =
new Task($this->
db);
1965 $response->warning_delay = $conf->projet->task->warning_delay / 60 / 60 / 24;
1966 $response->label = $langs->trans(
"OpenedTasks");
1967 if ($user->rights->projet->all->lire) $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mainmenu=project';
1968 else $response->url = DOL_URL_ROOT.
'/projet/tasks/list.php?mode=mine&mainmenu=project';
1972 while ($obj = $this->
db->fetch_object(
$resql))
1974 $response->nbtodo++;
1976 $task_static->projectstatus = $obj->projectstatus;
1977 $task_static->progress = $obj->progress;
1978 $task_static->fk_statut = $obj->status;
1979 $task_static->date_end = $this->
db->jdate($obj->datee);
1981 if ($task_static->hasDelay()) {
1982 $response->nbtodolate++;
1988 $this->error = $this->
db->error();
2005 $mine = 0; $socid = $user->socid;
2007 $projectstatic =
new Project($this->
db);
2008 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $mine, 1, $socid);
2011 $sql =
"SELECT count(p.rowid) as nb";
2012 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2013 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
2014 if (!$user->rights->societe->client->voir && !$socid) $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = s.rowid";
2015 $sql .=
", ".MAIN_DB_PREFIX.
"projet_task as t";
2016 $sql .=
" WHERE p.entity IN (".getEntity(
'project', 0).
')';
2017 $sql .=
" AND t.fk_projet = p.rowid";
2018 if ($mine || !$user->rights->projet->all->lire) $sql .=
" AND p.rowid IN (".$projectsListId.
")";
2021 if ($socid) $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.
")";
2022 if (!$user->rights->societe->client->voir && !$socid) $sql .=
" AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id.
") OR (s.rowid IS NULL))";
2028 while ($obj = $this->
db->fetch_object(
$resql))
2030 $this->nb[
"tasks"] = $obj->nb;
2036 $this->error = $this->
db->error();
2050 if (!($this->progress >= 0 && $this->progress < 100)) {
2056 $datetouse = ($this->date_end > 0) ? $this->date_end : ($this->datee > 0 ? $this->datee : 0);
2058 return ($datetouse > 0 && ($datetouse < ($now - $conf->projet->task->warning_delay)));
hasTimeSpent()
Return nb of time spent.
fetchTimeSpent($id)
Load one record of time spent.
getUserRolesForProjectsOrTasks($userp, $usert, $projectid= '', $taskid=0, $filteronprojstatus=-1)
Return list of roles for a user for each projects or each tasks (or a particular project or a particu...
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
getLibStatut($mode=0)
Return status label of object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
update($user=null, $notrigger=0)
Update database.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
isObjectUsed($id=0)
Function to check if an object is used by others.
updateTimeSpent($user, $notrigger=0)
Update time spent.
dol_html_entity_decode($a, $b, $c= 'UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_now($mode= 'auto')
Return date for now.
delete_linked_contact($source= '', $code= '')
Delete all links between an object $this and all its contacts.
Class to manage Dolibarr users.
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())
Return list of tasks for all projects or for one particular project Sort order is on project...
getNomUrl($withpicto=0, $option= '', $mode= 'task', $addlabel=0, $sep= '- ', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
create($user, $notrigger=0)
Create into database.
addTimeSpent($user, $notrigger=0)
Add time spent.
$conf db
API class for accounts.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
initAsSpecimen()
Initialise an instance with random values.
Class to manage projects.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
fetchAllTimeSpent(User $userobj, $morewherefilter= '')
Load all records of time spent.
hasDelay()
Is the task delayed?
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
hasChildren()
Return nb of children.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getSumOfAmount($fuser= '', $dates= '', $datee= '')
Calculate quantity and value of time consumed using the thm (hourly amount value of work for user ent...
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
__construct($db)
Constructor.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create an intervention document on disk using template defined into PROJECT_TASK_ADDON_PDF.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
getListContactId($source= 'internal')
Return list of id of contacts of task.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
print $_SERVER["PHP_SELF"]
Edit parameters.
getSummaryOfTimeSpent($userobj=null, $morewherefilter= '')
Calculate total of time spent for task.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
LibStatut($status, $mode=0)
Return status label for an object.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
delTimeSpent($user, $notrigger=0)
Delete time spent.
fetch($id, $ref= '', $loadparentdata=0)
Load object in memory from database.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
if(!empty($search_group)) natural_search(array("g.nom"g note
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
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.