NEW Develop new quick edit opportunity status (#27892)
* Add ability to quickly edit project status & percentage * TEMP * PHPstan checks
This commit is contained in:
parent
52182852fa
commit
f40b891cfe
2 changed files with 94 additions and 11 deletions
|
|
@ -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 .= '<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 .= " ";
|
||||
}
|
||||
}
|
||||
|
||||
if ($nooutput) {
|
||||
return $out;
|
||||
} else {
|
||||
print $out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 '<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 '<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>';
|
||||
}
|
||||
|
||||
// Opportunity percent
|
||||
print ' <span title="'.$langs->trans("OpportunityProbability").'"> / ';
|
||||
if (strcmp($object->opp_percent, '')) {
|
||||
print price($object->opp_percent, 0, $langs, 1, 0).' %';
|
||||
}
|
||||
print '</span></td></tr>';
|
||||
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
|
||||
print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
|
||||
|
|
|
|||
Loading…
Reference in a new issue