From cc1df26cf9095544feda0057d8ce794376aef2cc Mon Sep 17 00:00:00 2001 From: Johannes Hoermann <j.hoermann@adito.de> Date: Fri, 12 Apr 2019 10:16:05 +0200 Subject: [PATCH] =?UTF-8?q?[Projekt:=20Entwicklung=20-=20Neon][TicketNr.:?= =?UTF-8?q?=201035103][Hinweismeldung=20bei=20=C3=84nderung=20der=20Phase]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Salesproject_entity.aod | 4 +++ .../entityfields/state/onValueChange.js | 25 +++++++++++++++++++ .../recordcontainers/db/onDBUpdate.js | 24 +++++++++++++----- .../_____LANGUAGE_EXTRA.aod | 15 +++++++++++ .../_____LANGUAGE_de/_____LANGUAGE_de.aod | 18 +++++++++++++ .../_____LANGUAGE_en/_____LANGUAGE_en.aod | 15 +++++++++++ process/Salesproject_lib/process.js | 2 +- 7 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 entity/Salesproject_entity/entityfields/state/onValueChange.js diff --git a/entity/Salesproject_entity/Salesproject_entity.aod b/entity/Salesproject_entity/Salesproject_entity.aod index 02d64dfe90..a7c8206d47 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 0000000000..7f831d53c9 --- /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 977509bc98..95c901de86 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 be43907d4c..c3ee7d877f 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 36eb9eceec..c50f65492b 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 f4ee928878..fe65e56bc8 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 a7713459de..b9a24ffdad 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 */ -- GitLab