diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 55970f0b35c..75bc4a29f5a 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -120,6 +120,7 @@ TypeContact_project_task_internal_TASKCONTRIBUTOR=Contributor TypeContact_project_task_external_TASKCONTRIBUTOR=Contributor SelectElement=Select element AddElement=Link to element +UnlinkElement=Unlink element # Documents models DocumentModelBaleine=A complete project's report model (logo...) PlannedWorkload = Planned workload @@ -128,3 +129,4 @@ ProjectReferers=Refering objects SearchAProject=Search a project ProjectMustBeValidatedFirst=Project must be validated first ProjectDraft=Draft projects +FirstAddRessourceToAllocateTime=Associate a ressource to allocate time \ No newline at end of file diff --git a/htdocs/langs/fr_FR/projects.lang b/htdocs/langs/fr_FR/projects.lang index e76a2777161..52fd913ee29 100644 --- a/htdocs/langs/fr_FR/projects.lang +++ b/htdocs/langs/fr_FR/projects.lang @@ -119,7 +119,8 @@ TypeContact_project_task_external_TASKEXECUTIVE=Responsable TypeContact_project_task_internal_TASKCONTRIBUTOR=Contributeur TypeContact_project_task_external_TASKCONTRIBUTOR=Contributeur SelectElement=Séléctionnez l'élément -AddElement=Link to element +AddElement=Associer l'élément +UnlinkElement=Délier l'element # Documents models DocumentModelBaleine=Modèle de rapport de projet complet (logo...) PlannedWorkload = Charge de travail prévue @@ -128,3 +129,4 @@ ProjectReferers=Objets associés SearchAProject=Rechercher un projet ProjectMustBeValidatedFirst=Le projet doit être validé d'abord ProjectDraft=Projets brouillons +FirstAddRessourceToAllocateTime=Associer une ressource pour allouer du temps consomée \ No newline at end of file diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 8cbaea46c39..40ef5248a7b 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -322,6 +322,7 @@ class Project extends CommonObject $this->note_private = $obj->note_private; $this->note_public = $obj->note_public; $this->socid = $obj->fk_soc; + $this->societe=(object)array();// To avoid warning on next line $this->societe->id = $obj->fk_soc; // TODO For backward compatibility $this->user_author_id = $obj->fk_user_creat; $this->public = $obj->public; @@ -1276,23 +1277,23 @@ class Project extends CommonObject /** * Associate element to a project * - * @param string $TableName Table of the element to update - * @param int $ElementSelectId Key-rowid of the line of the element to update + * @param string $tableName Table of the element to update + * @param int $elementSelectId Key-rowid of the line of the element to update * @return int 1 if OK or < 0 if KO */ - function update_element($TableName, $ElementSelectId) + function update_element($tableName, $elementSelectId) { - $sql="UPDATE ".MAIN_DB_PREFIX.$TableName; + $sql="UPDATE ".MAIN_DB_PREFIX.$tableName; if ($TableName=="actioncomm") { $sql.= " SET fk_project=".$this->id; - $sql.= " WHERE id=".$ElementSelectId; + $sql.= " WHERE id=".$elementSelectId; } else { $sql.= " SET fk_projet=".$this->id; - $sql.= " WHERE rowid=".$ElementSelectId; + $sql.= " WHERE rowid=".$elementSelectId; } dol_syslog(get_class($this)."::update_element", LOG_DEBUG); @@ -1305,5 +1306,38 @@ class Project extends CommonObject } } + + /** + * Associate element to a project + * + * @param string $tableName Table of the element to update + * @param int $elementSelectId Key-rowid of the line of the element to update + * @return int 1 if OK or < 0 if KO + */ + function remove_element($tableName, $elementSelectId) + { + $sql="UPDATE ".MAIN_DB_PREFIX.$tableName; + + if ($TableName=="actioncomm") + { + $sql.= " SET fk_project=NULL"; + $sql.= " WHERE id=".$elementSelectId; + } + else + { + $sql.= " SET fk_projet=NULL"; + $sql.= " WHERE rowid=".$elementSelectId; + } + + dol_syslog(get_class($this)."::remove_element", LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { + $this->error=$this->db->lasterror(); + return -1; + }else { + return 1; + } + + } } diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index b5a1d089c96..da4de04b8bc 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -215,6 +215,15 @@ if ($action=="addelement") if ($result<0) { setEventMessage($mailchimp->error,'errors'); } +}elseif ($action == "unlink") { + + $tablename = GETPOST("tablename"); + $elementselectid = GETPOST("elementselect"); + + $result = $project->remove_element($tablename, $elementselectid); + if ($result < 0) { + setEventMessage($project->error, 'errors'); + } } foreach ($listofreferent as $key => $value) @@ -247,7 +256,7 @@ foreach ($listofreferent as $key => $value) print ''; print ''; - print ''; + print ''; print ''; print ''; if (empty($value['disableamount'])) print ''; @@ -276,7 +285,9 @@ foreach ($listofreferent as $key => $value) $var=!$var; print ""; - + print '\n"; // Ref print ''; + print ''; if (empty($value['disableamount'])) print ''; if (empty($value['disableamount'])) print ''; print ''; diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 994779fcac9..e037a7ea9ec 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -300,7 +300,8 @@ if ($action == 'create' && $user->rights->projet->creer && (empty($object->third print ''; print ''; // Date start diff --git a/htdocs/projet/tasks/contact.php b/htdocs/projet/tasks/contact.php index 3cc8b51ca1a..da002ef72d2 100644 --- a/htdocs/projet/tasks/contact.php +++ b/htdocs/projet/tasks/contact.php @@ -155,7 +155,7 @@ if ($id > 0 || ! empty($ref)) if ($object->fetch($id) > 0) { $result=$projectstatic->fetch($object->fk_project); - if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); + if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); $object->project = dol_clone($projectstatic); @@ -179,7 +179,7 @@ if ($id > 0 || ! empty($ref)) // Define a complementary filter for search of next/prev ref. if (! $user->rights->projet->all->lire) { - $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,0); + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,0); $projectstatic->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; } print $form->showrefnav($projectstatic,'project_ref','',1,'ref','ref','',$param.'&withproject=1'); @@ -188,7 +188,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; @@ -239,7 +239,7 @@ if ($id > 0 || ! empty($ref)) print '"; print ''; } diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 7337c152f4e..0ec0ab2cbe2 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -202,7 +202,7 @@ if ($id > 0 || ! empty($ref)) $res=$object->fetch_optionals($object->id,$extralabels); $result=$projectstatic->fetch($object->fk_project); - if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); + if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); $object->project = dol_clone($projectstatic); @@ -235,7 +235,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 56048ad1cf2..5c790df32f0 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -195,7 +195,7 @@ if ($id > 0 || ! empty($ref)) if ($object->fetch($id) >= 0) { $result=$projectstatic->fetch($object->fk_project); - if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); + if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); $object->project = dol_clone($projectstatic); @@ -230,7 +230,7 @@ if ($id > 0 || ! empty($ref)) // Thirdparty print ''; print ''; @@ -302,7 +302,7 @@ if ($id > 0 || ! empty($ref)) // Third party print ''; } @@ -345,13 +345,14 @@ if ($id > 0 || ! empty($ref)) // Contributor print ''; // Note @@ -440,7 +441,15 @@ if ($id > 0 || ! empty($ref)) print '
'.$langs->trans("Ref").''.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("ThirdParty").''.$langs->trans("AmountHT").'
'; + print '' . img_picto($langs->trans('Unlink'), 'editdelete') . ''; + print "'; print $element->getNomUrl(1); @@ -326,7 +337,7 @@ foreach ($listofreferent as $key => $value) } } - print '
'.$langs->trans("Number").': '.$i.'
'.$langs->trans("Number").': '.$i.''.$langs->trans("TotalHT").' : '.price($total_ht).''.$langs->trans("TotalTTC").' : '.price($total_ttc).' 
'.$langs->trans("AffectedTo").''; - print $form->select_dolusers($user->id,'userid',1); + $contactsofproject=$object->getListContactId('internal'); + $form->select_users($user->id,'userid',0,'',0,'',$contactsofproject); print '
'.$langs->trans("Label").''.$projectstatic->title.'
'.$langs->trans("ThirdParty").''; - if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1); + if (! empty($projectstatic->thridparty->id)) print $projectstatic->thridparty->getNomUrl(1); else print ' '; print '
'.$langs->trans('Ref').''; if (! GETPOST('withproject') || empty($projectstatic->id)) { - $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1); + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1); $object->next_prev_filter=" fk_projet in (".$projectsListId.")"; } else $object->next_prev_filter=" fk_projet = ".$projectstatic->id; @@ -259,7 +259,7 @@ if ($id > 0 || ! empty($ref)) // Customer print "
".$langs->trans("ThirdParty")."'; - if ($projectstatic->societe->id > 0) print $projectstatic->societe->getNomUrl(1); + if ($projectstatic->thridparty->id > 0) print $projectstatic->thridparty->getNomUrl(1); else print ' '; print '
'.$langs->trans("Label").''.$projectstatic->title.'
'.$langs->trans("ThirdParty").''; - if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1); + if (! empty($projectstatic->thirdparty->id)) print $projectstatic->thirdparty->getNomUrl(1); else print ' '; print '
'.$langs->trans("ThirdParty").''; - if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1); + if (! empty($projectstatic->thirdparty->id)) print $projectstatic->thirdparty->getNomUrl(1); else print ' '; print '
'.$langs->trans("ThirdParty").''; - if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1); + if ($projectstatic->thirdparty->id) print $projectstatic->thirdparty->getNomUrl(1); else print ' '; print '
'; - $restrictaddtimetocontactoftask=0; - if (empty($conf->global->PROJECT_TIME_ON_ALL_TASKS_MY_PROJECTS)) - { - $restrictaddtimetocontactoftask=$object->getListContactId('internal'); - } print img_object('','user'); - print $form->select_dolusers($_POST["userid"]?$_POST["userid"]:$user->id,'userid',0,'',0,'',$restrictaddtimetocontactoftask); // Note: If user is not allowed it will be disabled into combo list and userid not posted + $contactsoftask=$object->getListContactId('internal'); + if (count($contactsoftask)>0) { + $userid=$contactsoftask[0]; + $form->select_users($userid,'userid',0,'',0,'',$contactsoftask); + }else { + print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime'); + } print ''; if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid) { - print $form->select_dolusers($task_time->fk_user,'userid_line'); + $contactsoftask=$object->getListContactId('internal'); + if (!in_array($task_time->fk_user,$contactsoftask)) { + $contactsoftask[]=$task_time->fk_user; + } + if (count($contactsoftask)>0) { + $form->select_users($task_time->fk_user,'userid_line',0,'',0,'',$contactsoftask); + }else { + print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime'); + } } else {