diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index 6e3f37d824c..bb6584ad4ba 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -921,4 +921,53 @@ class FormProjets extends Form return $out; } + + /** + * Output html select to select opportunity status + * + * @param string $page Page + * @param string $selected Id preselected + * @param int $percent_value percentage of the opportunity + * @param string $htmlname_status name of HTML element for status select + * @param string $htmlname_percent name of HTML element for percent input + * @param string $filter optional filters criteras + * @param int $nooutput No print output. Return it only. + * @return void|string + */ + public function formOpportunityStatus($page, $selected = '', $percent_value = 0, $htmlname_status = 'none', $htmlname_percent = 'none', $filter = '', $nooutput = 0) + { + // phpcs:enable + global $conf, $langs; + + $out = ''; + if ($htmlname_status != "none" && $htmlname_percent != 'none') { + $out .= '
'; + $out .= ''; + $out .= ''; + $out .= $this-> selectOpportunityStatus($htmlname_status, $selected, 1, 0, 0, 0, 'minwidth150 inline-block valignmiddle', 1, 1); + $out .= ' / '; + $out .= ' %'; + $out .= ''; + $out .= ''; + $out .= '
'; + } else { + if ($selected > 0) { + $code = dol_getIdFromCode($this->db, $selected, 'c_lead_status', 'rowid', 'code'); + $out .= $langs->trans("OppStatus".$code); + + // Opportunity percent + $out.= ' / '; + $out.= price($percent_value, 0, $langs, 1, 0).' %'; + $out.= ''; + } else { + $out .= " "; + } + } + + if ($nooutput) { + return $out; + } else { + print $out; + } + } } diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index 74ab3a085de..fac60bca8f5 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -404,6 +404,42 @@ if (empty($reshook)) { } } + if ($action == 'set_opp_status' && $user->rights->projet->creer) { + $error = 0; + if (GETPOSTISSET('opp_status')) { + $object->opp_status = $opp_status; + } + if (GETPOSTISSET('opp_percent')) { + $object->opp_percent = $opp_percent; + } + + if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { + if ($object->opp_amount && ($object->opp_status <= 0)) { + $error++; + setEventMessages($langs->trans("ErrorOppStatusRequiredIfAmount"), null, 'errors'); + } + } + + if (!$error) { + $result = $object->update($user); + if ($result < 0) { + $error++; + if ($result == -4) { + setEventMessages($langs->trans("ErrorRefAlreadyExists"), null, 'errors'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } + + if ($error) { + $db->rollback(); + $action = 'edit'; + } else { + $db->commit(); + } + } + // Build doc if ($action == 'builddoc' && $permissiontoadd) { // Save last template used to generate document @@ -1347,18 +1383,16 @@ if ($action == 'create' && $user->hasRight('projet', 'creer')) { if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') && !empty($object->usage_opportunity)) { // Opportunity status - print ''.$langs->trans("OpportunityStatus").''; - $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code'); - if ($code) { - print $langs->trans("OppStatus".$code); + print ''.$langs->trans("OpportunityStatus"); + if ($action != 'edit_opp_status' && $user->hasRight('projet', 'creer')) { + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).''; } - - // Opportunity percent - print ' / '; - if (strcmp($object->opp_percent, '')) { - print price($object->opp_percent, 0, $langs, 1, 0).' %'; - } - print ''; + print ''; + $html_name_status = ($action == 'edit_opp_status') ? 'opp_status' : 'none'; + $html_name_percent = ($action == 'edit_opp_status') ? 'opp_percent' : 'none'; + $percent_value = (GETPOSTISSET('opp_percent') ? GETPOST('opp_percent') : (strcmp($object->opp_percent, '') ? vatrate($object->opp_percent) : '')); + $formproject->formOpportunityStatus($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->opp_status, $percent_value, $html_name_status, $html_name_percent); + print ''; // Opportunity Amount print ''.$langs->trans("OpportunityAmount").'';