diff --git a/entity/Salesproject_entity/Salesproject_entity.aod b/entity/Salesproject_entity/Salesproject_entity.aod index 02d64dfe90a94fa27d2e593d619406de0078ce1e..a7c8206d47e7428825c0f1c5f304530f20e5f385 100644 --- a/entity/Salesproject_entity/Salesproject_entity.aod +++ b/entity/Salesproject_entity/Salesproject_entity.aod @@ -89,6 +89,10 @@ <mandatory v="true" /> <valueProcess>%aditoprj%/entity/Salesproject_entity/entityfields/state/valueProcess.js</valueProcess> <displayValueProcess>%aditoprj%/entity/Salesproject_entity/entityfields/state/displayValueProcess.js</displayValueProcess> + <onValueChange>%aditoprj%/entity/Salesproject_entity/entityfields/state/onValueChange.js</onValueChange> + <onValueChangeTypes> + <element>MASK</element> + </onValueChangeTypes> </entityField> <entityField> <name>VOLUME</name> diff --git a/entity/Salesproject_entity/entityfields/state/onValueChange.js b/entity/Salesproject_entity/entityfields/state/onValueChange.js new file mode 100644 index 0000000000000000000000000000000000000000..7f831d53c9cf325f07395adad24800974a715ab4 --- /dev/null +++ b/entity/Salesproject_entity/entityfields/state/onValueChange.js @@ -0,0 +1,25 @@ +import("system.vars"); +import("Sql_lib"); +import("system.db"); +import("KeywordRegistry_basic"); +import("Keyword_lib"); +import("system.translate"); +import("system.question"); +import("system.neon"); + +var state = vars.get("$field.STATE"); + +// Postponed +if (state == '23d38486-4cce-41ce-a8df-164ad44df706') +{ + 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'?" + "\n" + translate.text("This cannot be undone!"), [stateName]), 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"))); + } +} diff --git a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js index 977509bc98a157fb920faa4baf44d35708a34c67..95c901de86dfdf90d075c1311539cfe8971f4886 100644 --- a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js @@ -4,9 +4,11 @@ import("system.vars"); import("Salesproject_lib"); import("Sql_lib"); import("system.db"); +import("system.question"); import("KeywordRegistry_basic"); +import("Keyword_lib"); -var needToUpdateForecast = false; +var needToUpdateForecast = null; // create Milestones if changed vars.get("$local.changed").forEach(function(fieldName) { @@ -24,11 +26,11 @@ vars.get("$local.changed").forEach(function(fieldName) { // Milestone typeValue = "SalesprojectState"; fieldVar = "$field.STATE"; - + var state = vars.get(fieldVar); // set COMPETITION / OFFER to Lost // Lost - if ( vars.get("$field.STATE") == 'd8a60f60-a4e6-46ee-88ec-bac53e1afedd') + if (state == 'd8a60f60-a4e6-46ee-88ec-bac53e1afedd') { // set all offers of the salesproject to lost db.updateData("OFFER", ["STATUS"], null, ["a5682630-01ae-4769-8f03-47dc1db44da4"], SqlCondition.equals("OFFER.SALESPROJECT_ID", vars.getString("$field.SALESPROJECTID"), "1=2")); @@ -36,15 +38,22 @@ vars.get("$local.changed").forEach(function(fieldName) { clearReason = false; } // Order - else if (vars.get("$field.STATE") == '130bb53a-a97e-455e-8f34-8d445e985474') + else if (state == '130bb53a-a97e-455e-8f34-8d445e985474') { // set all competitions of the salesproject to lost db.updateData("SALESPROJECT_COMPETITION", ["STATUS"], null, ["ff73172c-8517-4b6e-98cb-43aebacd9af1"], SqlCondition.equals("SALESPROJECT_COMPETITION.SALESPROJECT_ID", vars.getString("$field.SALESPROJECTID"), "1=2")); _updateReasons(); clearReason = false; } + // Postponed + else if (state == '23d38486-4cce-41ce-a8df-164ad44df706') + { + // do not notify as the user just got a question, if he really would like to clear the forecast + needToUpdateForecast = false; + db.deleteData("SALESPROJECT_FORECAST", SqlCondition.equals("SALESPROJECT_FORECAST.SALESPROJECT_ID", vars.getString("$field.SALESPROJECTID"), "1=2")); + } // if state changed, but not to one of the above states - else if (clearReason == undefined) + else { clearReason = true; } @@ -59,7 +68,10 @@ vars.get("$local.changed").forEach(function(fieldName) { if (typeValue) { - needToUpdateForecast = true; + // only notify, if not explicitely set to false above + if (needToUpdateForecast === null) + needToUpdateForecast = true; + Salesproject.insertMilestone(vars.getString("$field.SALESPROJECTID"), typeValue, vars.getString(fieldVar)); } }); diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod index be43907d4ca3a5f7cf7eff4c4d9c393ab40c6e28..c3ee7d877f3d269da36b01d0933bf562b9707051 100644 --- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod +++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod @@ -2850,6 +2850,21 @@ <entry> <key>Days count</key> </entry> + <entry> + <key>Clear forecast and set state to \"%0\"?</key> + </entry> + <entry> + <key>Would you like to clear the forecast and set the state to \"%0\"?</key> + </entry> + <entry> + <key>Clear forecast and set state to '%0'?</key> + </entry> + <entry> + <key>Would you really like to clear the forecast and set the state to '%0'?</key> + </entry> + <entry> + <key>This cannot be undone!</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> <sqlModels> diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod index 36eb9eceec1e7565d60a0cdf03452b73e08be4fc..c50f65492bcce2295d8bed1c178044b9d7188142 100644 --- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod +++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod @@ -3658,6 +3658,24 @@ <key>Days count</key> <value>Anzahl Tage</value> </entry> + <entry> + <key>Clear forecast and set state to '%0'?</key> + <value>Forecast löschen und status auf '%0' setzen?</value> + </entry> + <entry> + <key>Would you really like to clear the forecast and set the state to '%0'?</key> + <value>Möchten Sie wirklich den Forecast löschen und den status auf '%0' setzen?</value> + </entry> + <entry> + <key>This cannot be undone!</key> + <value>Das kann nicht rückgängig gemacht werden!</value> + </entry> + <entry> + <key>Clear forecast and set state to \"%0\"?</key> + </entry> + <entry> + <key>Would you like to clear the forecast and set the state to \"%0\"?</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> </language> diff --git a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod index f4ee92887815894d178aec2faab80c22a85409d0..fe65e56bc8f9293732fef04a7060ac0a6d4e33d6 100644 --- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod +++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod @@ -2881,6 +2881,21 @@ <entry> <key>Days count</key> </entry> + <entry> + <key>Clear forecast and set state to \"%0\"?</key> + </entry> + <entry> + <key>Would you like to clear the forecast and set the state to \"%0\"?</key> + </entry> + <entry> + <key>Clear forecast and set state to '%0'?</key> + </entry> + <entry> + <key>Would you really like to clear the forecast and set the state to '%0'?</key> + </entry> + <entry> + <key>This cannot be undone!</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> </language> diff --git a/process/Salesproject_lib/process.js b/process/Salesproject_lib/process.js index a7713459de8218a409a158b5bcf79b12659835c4..b9a24ffdadef81f22509e0e54f90d6061c987436 100644 --- a/process/Salesproject_lib/process.js +++ b/process/Salesproject_lib/process.js @@ -44,7 +44,7 @@ Salesproject.validateProjectNumber = function(projectNumber) { * @param {String} salesprojectId of the salesproject * @param {Integer} type can be any value of the keyword SALESPROJECT.MILESTONE.TYPE * @param {Integer} value value of the phase or state - * @param {Boolean} notifyForecast if true, notify user to update the forecast + * @param {Boolean} [notifyForecast=false] if true, notify user to update the forecast * * @result {Boolean} true if inserted, else false */