From 9a9b31c9c0291a5cb659eb88b85046e33ca22787 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 1 Feb 2017 13:25:16 +0100 Subject: [PATCH] Fix cancel button + logic to close project when setting opp to WON/LOST. --- htdocs/contact/card.php | 33 ++------ htdocs/core/class/html.formprojet.class.php | 5 +- htdocs/langs/en_US/projects.lang | 1 + htdocs/product/card.php | 2 +- htdocs/projet/card.php | 90 +++++++++++++++------ htdocs/projet/class/project.class.php | 4 +- htdocs/societe/soc.php | 11 ++- 7 files changed, 89 insertions(+), 57 deletions(-) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 37bd3078c7d..7d95da69aef 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -714,6 +714,11 @@ else print '     '; print ''; } + else + { + print '     '; + print ''; + } print ''; print ""; @@ -997,7 +1002,7 @@ else print '
'; print ''; - print '     '; + print '     '; print ''; print '
'; @@ -1229,33 +1234,7 @@ else } print ""; - //print "
"; - /* - if (! empty($conf->agenda->enabled)) - { - $objthirdparty=$objsoc; - $objcon=$object; - - $out=''; - $permok=$user->rights->agenda->myactions->create; - if ((! empty($objthirdparty->id) || ! empty($objcon->id)) && $permok) - { - $out.=''; - $out.=$langs->trans("AddAnAction").' '; - $out.=img_picto($langs->trans("AddAnAction"),'filenew'); - $out.=""; - } - - print load_fiche_titre($langs->trans("TasksHistoryForThisContact"),$out,''); - - //print show_actions_todo($conf,$langs,$db,$objsoc,$object); - - print show_actions_done($conf,$langs,$db,$objsoc,$object,0,'',''); - } - */ } } diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index 6e5284aaab3..ffce8300a0c 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -566,9 +566,10 @@ class FormProjets * @param int $useshortlabel Use short label * @param int $showallnone Add choice "All" and "None" * @param int $showpercent Show default probability for status + * @param string $morecss Add more css * @return int|string The HTML select list of element or '' if nothing or -1 if KO */ - function selectOpportunityStatus($htmlname, $preselected='-1', $showempty=1, $useshortlabel=0, $showallnone=0, $showpercent=0) + function selectOpportunityStatus($htmlname, $preselected='-1', $showempty=1, $useshortlabel=0, $showallnone=0, $showpercent=0, $morecss='') { global $conf, $langs; @@ -584,7 +585,7 @@ class FormProjets $i = 0; if ($num > 0) { - $sellist = ''; if ($showempty) $sellist.= ''; if ($showallnone) $sellist.= ''; if ($showallnone) $sellist.= ''; diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 1defe9d9163..8e40307cac6 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -96,6 +96,7 @@ ValidateProject=Validate projet ConfirmValidateProject=Are you sure you want to validate this project? CloseAProject=Close project ConfirmCloseAProject=Are you sure you want to close this project? +AlsoCloseAProject=Also close project (keep it open if you still need to follow production tasks on it) ReOpenAProject=Open project ConfirmReOpenAProject=Are you sure you want to re-open this project? ProjectContact=Project contacts diff --git a/htdocs/product/card.php b/htdocs/product/card.php index ade5916792d..e8d86bbdbf2 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1149,7 +1149,7 @@ else print '
'; print ''; - print '     '; + print '     '; print ''; print '
'; diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index 71f2dcd02c9..6221e4c2b87 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -286,11 +286,23 @@ if (empty($reshook)) if ($result < 0) { $error++; - setEventMessages($langs->trans("ErrorShiftTaskDate").':'.$object->error, $langs->trans("ErrorShiftTaskDate").':'.$object->errors, 'errors'); + setEventMessages($langs->trans("ErrorShiftTaskDate").':'.$object->error, $object->errors, 'errors'); } } } + // Check if we must change status + if (GETPOST('closeproject')) + { + $resclose = $object->setClose($user); + if ($resclose < 0) + { + $error++; + setEventMessages($langs->trans("FailedToCloseProject").':'.$object->error, $object->errors, 'errors'); + } + } + + if ($error) { $db->rollback(); @@ -303,6 +315,7 @@ if (empty($reshook)) if (GETPOST('socid','int') > 0) $object->fetch_thirdparty(GETPOST('socid','int')); else unset($object->thirdparty); } + } // Build doc @@ -594,6 +607,11 @@ if ($action == 'create' && $user->rights->projet->creer) print '     '; print ''; } + else + { + print '     '; + print ''; + } print ''; print ''; @@ -730,7 +748,11 @@ elseif ($object->id > 0) // Opportunity status print ''.$langs->trans("OpportunityStatus").''; print ''; - print $formproject->selectOpportunityStatus('opp_status', $object->opp_status, 1); + print $formproject->selectOpportunityStatus('opp_status', $object->opp_status, 1, 0, 0, 0, 'inline-block valignmiddle'); + print ''; print ''; print ''; @@ -843,12 +865,12 @@ elseif ($object->id > 0) // Opportunity percent print ''.$langs->trans("OpportunityProbability").''; - if (strcmp($object->opp_percent,'')) print price($object->opp_percent,'',$langs,1,0).' %'; + if (strcmp($object->opp_percent,'')) print price($object->opp_percent,0,$langs,1,0).' %'; print ''; // Opportunity Amount print ''.$langs->trans("OpportunityAmount").''; - if (strcmp($object->opp_amount,'')) print price($object->opp_amount,'',$langs,1,0,0,$conf->currency); + if (strcmp($object->opp_amount,'')) print price($object->opp_amount,0,$langs,1,0,0,$conf->currency); print ''; } @@ -865,7 +887,7 @@ elseif ($object->id > 0) // Budget print ''.$langs->trans("Budget").''; - if (strcmp($object->budget_amount, '')) print price($object->budget_amount,'',$langs,1,0,0,$conf->currency); + if (strcmp($object->budget_amount, '')) print price($object->budget_amount,0,$langs,1,0,0,$conf->currency); print ''; // Other attributes @@ -915,27 +937,49 @@ elseif ($object->id > 0) print ''; // Change probability from status - if (! empty($conf->use_javascript_ajax)) + if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { + $defaultcheckedwhenoppclose=1; + if (empty($conf->global->PROJECT_HIDE_TASKS)) $defaultcheckedwhenoppclose=0; + + print ''; print ''; } diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 460e698e432..b242f7d6b06 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -773,7 +773,7 @@ class Project extends CommonObject * Close a project * * @param User $user User that close project - * @return int <0 if KO, >0 if OK + * @return int <0 if KO, 0 if already closed, >0 if OK */ function setClose($user) { @@ -828,6 +828,8 @@ class Project extends CommonObject return -1; } } + + return 0; } /** diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 374a87c72ef..3da099390ac 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -1308,11 +1308,16 @@ else print '
'; print ''; - if ($backtopage) + if (! empty($backtopage)) { - print '   '; + print '     '; print ''; } + else + { + print '     '; + print ''; + } print '
'."\n"; print ''."\n"; @@ -1898,7 +1903,7 @@ else print '
'; print ''; - print '     '; + print '     '; print ''; print '
';