Fix cancel button + logic to close project when setting opp to WON/LOST.
This commit is contained in:
parent
fbf9986506
commit
9a9b31c9c0
@ -714,6 +714,11 @@ else
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
print ' ';
|
||||
print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
|
||||
}
|
||||
print '</div>';
|
||||
|
||||
print "</form>";
|
||||
@ -997,7 +1002,7 @@ else
|
||||
|
||||
print '<div class="center">';
|
||||
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
|
||||
print ' ';
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||
print '</div>';
|
||||
|
||||
@ -1229,33 +1234,7 @@ else
|
||||
}
|
||||
|
||||
print "</div>";
|
||||
//print "<br>";
|
||||
|
||||
/*
|
||||
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.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
|
||||
if (get_class($objthirdparty) == 'Societe') $out.='&socid='.$objthirdparty->id;
|
||||
$out.=(! empty($objcon->id)?'&contactid='.$objcon->id:'').'&backtopage=1&percentage=-1">';
|
||||
$out.=$langs->trans("AddAnAction").' ';
|
||||
$out.=img_picto($langs->trans("AddAnAction"),'filenew');
|
||||
$out.="</a>";
|
||||
}
|
||||
|
||||
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,'','');
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 = '<select class="flat oppstatus" id="'.$htmlname.'" name="'.$htmlname.'">';
|
||||
$sellist = '<select class="flat oppstatus'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
|
||||
if ($showempty) $sellist.= '<option value="-1"></option>';
|
||||
if ($showallnone) $sellist.= '<option value="all"'.($preselected == 'all'?' selected="selected"':'').'>--'.$langs->trans("OnlyOpportunitiesShort").'--</option>';
|
||||
if ($showallnone) $sellist.= '<option value="openedopp"'.($preselected == 'openedopp'?' selected="selected"':'').'>--'.$langs->trans("OpenedOpportunitiesShort").'--</option>';
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1149,7 +1149,7 @@ else
|
||||
|
||||
print '<div class="center">';
|
||||
print '<input type="submit" class="button" value="' . $langs->trans("Create") . '">';
|
||||
print ' ';
|
||||
print ' ';
|
||||
print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
|
||||
print '</div>';
|
||||
|
||||
|
||||
@ -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 '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
print ' ';
|
||||
print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
|
||||
}
|
||||
print '</div>';
|
||||
|
||||
print '</form>';
|
||||
@ -730,7 +748,11 @@ elseif ($object->id > 0)
|
||||
// Opportunity status
|
||||
print '<tr><td>'.$langs->trans("OpportunityStatus").'</td>';
|
||||
print '<td>';
|
||||
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 '<div id="divtocloseproject" class="inline-block valign" style="display: none;"> ';
|
||||
print '<input type="checkbox" id="inputcloseproject" name="closeproject" /> ';
|
||||
print $langs->trans("AlsoCloseAProject");
|
||||
print '</div>';
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
@ -843,12 +865,12 @@ elseif ($object->id > 0)
|
||||
|
||||
// Opportunity percent
|
||||
print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
|
||||
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 '</td></tr>';
|
||||
|
||||
// Opportunity Amount
|
||||
print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
|
||||
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 '</td></tr>';
|
||||
}
|
||||
|
||||
@ -865,7 +887,7 @@ elseif ($object->id > 0)
|
||||
|
||||
// Budget
|
||||
print '<tr><td>'.$langs->trans("Budget").'</td><td>';
|
||||
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 '</td></tr>';
|
||||
|
||||
// Other attributes
|
||||
@ -915,27 +937,49 @@ elseif ($object->id > 0)
|
||||
print '</form>';
|
||||
|
||||
// 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 '<!-- Javascript to manage opportunity status change -->';
|
||||
print '<script type="text/javascript" language="javascript">
|
||||
jQuery(document).ready(function() {
|
||||
function change_percent()
|
||||
{
|
||||
var element = jQuery("#opp_status option:selected");
|
||||
var defaultpercent = element.attr("defaultpercent");
|
||||
var elemcode = element.attr("elemcode");
|
||||
/* Change percent of default percent of new status is higher */
|
||||
if (parseFloat(jQuery("#opp_percent").val()) != parseFloat(defaultpercent))
|
||||
{
|
||||
if (jQuery("#opp_percent").val() != \'\' && ! jQuery("#oldopppercent").text()) jQuery("#oldopppercent").text(\' - '.dol_escape_js($langs->transnoentities("PreviousValue")).': \'+jQuery("#opp_percent").val()+\' %\');
|
||||
jQuery("#opp_percent").val(defaultpercent);
|
||||
jQuery(document).ready(function() {
|
||||
function change_percent()
|
||||
{
|
||||
var element = jQuery("#opp_status option:selected");
|
||||
var defaultpercent = element.attr("defaultpercent");
|
||||
var defaultcloseproject = '.$defaultcheckedwhenoppclose.';
|
||||
var elemcode = element.attr("elemcode");
|
||||
var oldpercent = \''.dol_escape_js($object->opp_percent).'\';
|
||||
|
||||
}
|
||||
}
|
||||
/*init_myfunc();*/
|
||||
jQuery("#opp_status").change(function() {
|
||||
change_percent();
|
||||
});
|
||||
console.log("We select "+elemcode);
|
||||
if (elemcode == \'LOST\') defaultcloseproject = 1;
|
||||
jQuery("#divtocloseproject").show();
|
||||
if (defaultcloseproject) jQuery("#inputcloseproject").prop("checked", true);
|
||||
else jQuery("#inputcloseproject").prop("checked", false);
|
||||
|
||||
/* Make close project visible or not */
|
||||
if (elemcode == \'WON\' || elemcode == \'LOST\')
|
||||
{
|
||||
jQuery("#divtocloseproject").show();
|
||||
}
|
||||
else
|
||||
{
|
||||
jQuery("#divtocloseproject").hide();
|
||||
}
|
||||
|
||||
/* Change percent of default percent of new status is higher */
|
||||
if (parseFloat(jQuery("#opp_percent").val()) != parseFloat(defaultpercent))
|
||||
{
|
||||
if (jQuery("#opp_percent").val() != \'\' && oldpercent != \'\') jQuery("#oldopppercent").text(\' - '.dol_escape_js($langs->transnoentities("PreviousValue")).': \'+oldpercent+\' %\');
|
||||
jQuery("#opp_percent").val(defaultpercent);
|
||||
}
|
||||
}
|
||||
|
||||
jQuery("#opp_status").change(function() {
|
||||
change_percent();
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1308,11 +1308,16 @@ else
|
||||
|
||||
print '<div class="center">';
|
||||
print '<input type="submit" class="button" name="create" value="'.$langs->trans('AddThirdParty').'">';
|
||||
if ($backtopage)
|
||||
if (! empty($backtopage))
|
||||
{
|
||||
print ' ';
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
print ' ';
|
||||
print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
|
||||
}
|
||||
print '</div>'."\n";
|
||||
|
||||
print '</form>'."\n";
|
||||
@ -1898,7 +1903,7 @@ else
|
||||
|
||||
print '<div align="center">';
|
||||
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
|
||||
print ' ';
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||
print '</div>';
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user