Skip to content
Snippets Groups Projects
Commit f7f2d770 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

fix object tree and salesproject

parent d8ca8647
No related branches found
No related tags found
No related merge requests found
......@@ -129,6 +129,9 @@
<valueProcess>%aditoprj%/entity/ObjectTree_entity/entityfields/objectrelationtypeid/valueProcess.js</valueProcess>
<displayValueProcess>%aditoprj%/entity/ObjectTree_entity/entityfields/objectrelationtypeid/displayValueProcess.js</displayValueProcess>
<onValueChange>%aditoprj%/entity/ObjectTree_entity/entityfields/objectrelationtypeid/onValueChange.js</onValueChange>
<onValueChangeTypes>
<element>MASK</element>
</onValueChangeTypes>
</entityField>
<entityConsumer>
<name>Objects</name>
......
......@@ -101,6 +101,8 @@
<onValueChange>%aditoprj%/entity/Salesproject_entity/entityfields/state/onValueChange.js</onValueChange>
<onValueChangeTypes>
<element>MASK</element>
<element>PROCESS</element>
<element>PROCESS_SETVALUE</element>
</onValueChangeTypes>
</entityField>
<entityField>
......
import("system.vars");
import("system.logging");
import("Sql_lib");
import("system.vars");
import("system.db");
import("KeywordRegistry_basic");
import("Keyword_lib");
import("system.translate");
import("system.question");
import("system.neon");
if (vars.get("$sys.recordstate") != neon.OPERATINGSTATE_NEW)
{
var state = vars.get("local.value");
// Postponed
if (state == $KeywordRegistry.salesprojectState$postponed())
{
var stateName = KeywordUtils.getViewValue($KeywordRegistry.salesprojectState(), state);
var clearForecast = question.askYesNo(translate.withArguments("Clear forecast and set state to '%0'?", [stateName]), translate.withArguments("Would you really like to clear the forecast and set the state to '%0'?", [stateName]) + "\n" + translate.text("This cannot be undone!"), false);
if (!clearForecast)
{
// reset to value from db
neon.setFieldValue("$field.STATE", db.cell(SqlCondition.begin()
.andPrepareVars("SALESPROJECT.SALESPROJECTID", "$field.SALESPROJECTID")
.buildSql("select STATE from SALESPROJECT", "1=2")));
}
}
}
logging.log(JSON.stringify(db.cell(SqlCondition.begin()
.andPrepareVars("SALESPROJECT.SALESPROJECTID", "$field.SALESPROJECTID")
.buildSql("select STATE from SALESPROJECT", "1=2")), null, "\t"))
vars.set("$context.statusBefore", db.cell(SqlCondition.begin()
.andPrepareVars("SALESPROJECT.SALESPROJECTID", "$field.SALESPROJECTID")
.buildSql("select STATE from SALESPROJECT", "1=2")));
\ No newline at end of file
import("system.logging");
import("Context_lib");
import("system.neon");
import("system.translate");
import("system.vars");
......@@ -31,7 +33,10 @@ vars.get("$local.changed").forEach(function(fieldName) {
if (state == $KeywordRegistry.salesprojectState$lost())
{
// set all offers of the salesproject to lost
db.updateData("OFFER", ["STATUS"], null, [$KeywordRegistry.offerStatus$lost()], SqlCondition.equals("OFFER.OBJECT_ROWID", vars.getString("$local.uid"), "1=2"));
db.updateData("OFFER", ["STATUS"], null, [$KeywordRegistry.offerStatus$lost()], SqlCondition.begin()
.andPrepare("OFFER.OBJECT_ROWID", vars.getString("$local.uid"))
.andPrepare("OFFER.OBJECT_TYPE", ContextUtils.getCurrentContextId())
.build("1=2"));
_updateReasons();
clearReason = false;
}
......@@ -39,16 +44,31 @@ vars.get("$local.changed").forEach(function(fieldName) {
else if (state == $KeywordRegistry.salesprojectState$order())
{
// set all competitions of the salesproject to lost
db.updateData("COMPETITION", ["STATUS"], null, [$KeywordRegistry.competitionState$lost()], SqlCondition.equals("COMPETITION.OBJECT_ROWID", vars.getString("$local.uid"), "1=2"));
db.updateData("COMPETITION", ["STATUS"], null, [$KeywordRegistry.competitionState$lost()], SqlCondition.begin()
.andPrepare("COMPETITION.OBJECT_ROWID", vars.getString("$local.uid"))
.andPrepare("COMPETITION.OBJECT_TYPE", ContextUtils.getCurrentContextId())
.build("1=2"));
_updateReasons();
clearReason = false;
}
// Postponed
else if (state == $KeywordRegistry.salesprojectState$postponed())
{
// do not notify as the user just got a question, if he really would like to clear the forecast
needToUpdateForecast = false;
db.deleteData("FORECAST", SqlCondition.equals("FORECAST.OBJECT_ROWID", vars.getString("$local.uid"), "1=2"));
// ask if forecast should be cleared. Else reset to old value.
var stateName = KeywordUtils.getViewValue($KeywordRegistry.salesprojectState(), state);
var clearForecast = question.askYesNo(translate.withArguments("Clear forecast and set state to '%0'?", [stateName]), translate.withArguments("Would you really like to clear the forecast and set the state to '%0'?", [stateName]) + "\n" + translate.text("This cannot be undone!"), false);
if (!clearForecast)
{
// reset to value from db
db.updateData("SALESPROJECT", ["STATE"], null, [vars.get("$context.statusBefore")], SqlCondition.begin()
.andPrepare("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid"))
.build("1=2"));
} else {
// do not notify as the user just got a question, if he really would like to clear the forecast
needToUpdateForecast = false;
db.deleteData("FORECAST", SqlCondition.equals("FORECAST.OBJECT_ROWID", vars.getString("$local.uid"), "1=2"));
}
}
// if state changed, but not to one of the above states
else
......@@ -58,7 +78,7 @@ vars.get("$local.changed").forEach(function(fieldName) {
break;
}
// It clearReason is undefined, it the state did not change. So do nothing
// If clearReason is undefined, it the state did not change. So do nothing
if (clearReason != undefined)
{
_clearReasons(clearReason);
......@@ -70,13 +90,15 @@ vars.get("$local.changed").forEach(function(fieldName) {
if (needToUpdateForecast === null)
needToUpdateForecast = true;
Salesproject.insertMilestone(vars.getString("$local.uid"), typeValue, vars.getString(fieldVar));
Salesproject.insertMilestone(vars.getString("$local.uid"), typeValue, rowdata[fieldName]);
}
});
if (needToUpdateForecast)
Salesproject.notifyToUpdateForecast();
neon.refreshAll();
function _updateReasons()
{
var reasons = rowdata["SALESPROJECT.REASONS"];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment