Skip to content

Commit

Permalink
Merge pull request #722 from Easya-Solutions/2022.5.3_rc_new_quick_ed…
Browse files Browse the repository at this point in the history
…it_opportunity_status

quick edit opportunity status
  • Loading branch information
lvessiller-opendsi authored Feb 9, 2024
2 parents 4c902ce + 12528b4 commit 465480f
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 11 deletions.
49 changes: 49 additions & 0 deletions htdocs/core/class/html.formprojet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,4 +722,53 @@ public function selectOpportunityStatus($htmlname, $preselected = '-1', $showemp
return -1;
}
}

/**
* 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 .= '<form method="post" action="' . $page . '">';
$out .= '<input type="hidden" name="action" value="set_opp_status">';
$out .= '<input type="hidden" name="token" value="' . newToken() . '">';
$out .= $this-> selectOpportunityStatus($htmlname_status, $selected, 1, 0, 0, 0, 'minwidth150 inline-block valignmiddle', 1, 1);
$out .= ' / <span title="'.$langs->trans("OpportunityProbability").'"> ';
$out .= '<input class="width50 right" type="text" id="'.$htmlname_percent.'" name="'.$htmlname_percent.'" title="'.dol_escape_htmltag($langs->trans("OpportunityProbability")).'" value="'.$percent_value.'"> %';
$out .= '</span>';
$out .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans("Modify") . '">';
$out .= '</form>';
} else {
if ($selected > 0) {
$code = dol_getIdFromCode($this->db, $selected, 'c_lead_status', 'rowid', 'code');
$out .= $langs->trans("OppStatus".$code);

// Opportunity percent
$out.= ' / <span title="'.$langs->trans("OpportunityProbability").'"> ';
$out.= price($percent_value, 0, $langs, 1, 0).' %';
$out.= '</span>';
} else {
$out .= "&nbsp;";
}
}

if ($nooutput) {
return $out;
} else {
print $out;
}
}
}
55 changes: 44 additions & 11 deletions htdocs/projet/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,42 @@
}
}

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' && $user->rights->projet->creer) {
// Save last template used to generate document
Expand Down Expand Up @@ -1066,18 +1102,15 @@ function change_percent()

if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) && !empty($object->usage_opportunity)) {
// Opportunity status
print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
$code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
if ($code) {
print $langs->trans("OppStatus".$code);
}
print '</td></tr>';

// Opportunity percent
print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
if (strcmp($object->opp_percent, '')) {
print price($object->opp_percent, 0, $langs, 1, 0).' %';
print '<tr><td>'.$langs->trans("OpportunityStatus");
if ($action != 'edit_opp_status' && $user->hasRight('projet', 'creer')) {
print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit_opp_status&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a>';
}
print '</td><td>';
$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 '</td></tr>';

// Opportunity Amount
Expand Down

0 comments on commit 465480f

Please sign in to comment.