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

fix salesproject

parent 7f9a8cec
No related branches found
No related tags found
No related merge requests found
import("system.logging");
import("system.result");
import("system.vars");
// IDs: SalesprojectState Order and Lost
var res = vars.get("$field.STATE") && (vars.get("$field.STATE") == 'd8a60f60-a4e6-46ee-88ec-bac53e1afedd' || vars.get("$field.STATE") == '130bb53a-a97e-455e-8f34-8d445e985474');
result.string(res);
logging.log(res)
\ No newline at end of file
result.string(res);
\ No newline at end of file
......@@ -4,6 +4,7 @@ import("system.vars");
import("Salesproject_lib");
import("Sql_lib");
import("system.db");
import("KeywordRegistry_basic");
var needToUpdateForecast = false;
......@@ -11,6 +12,8 @@ var needToUpdateForecast = false;
vars.get("$local.changed").forEach(function(fieldName) {
var typeValue;
var fieldVar;
var clearReason;
switch (fieldName) {
case "SALESPROJECT.PHASE":
......@@ -27,19 +30,33 @@ vars.get("$local.changed").forEach(function(fieldName) {
// Lost
if ( vars.get("$field.STATE") == 'd8a60f60-a4e6-46ee-88ec-bac53e1afedd')
{
_updateDataToLost("OFFER", $KeywordRegistry.offerStatus());
// 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"));
_updateReasons();
clearReason = false;
}
// Order
else if(vars.get("$field.STATE") == '130bb53a-a97e-455e-8f34-8d445e985474')
else if (vars.get("$field.STATE") == '130bb53a-a97e-455e-8f34-8d445e985474')
{
_updateDataToLost("SALESPROJECT_COMPETITION", $KeywordRegistry.salesprojectCompetitionState());
// 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;
}
// if state changed, but not to one of the above states
else if (clearReason == undefined)
{
clearReason = true;
}
else
_updateReasons("del");
break;
}
// It clearReason is undefined, it the state did not change. So do nothing
if (clearReason != undefined)
{
_clearReasons(clearReason);
}
if (typeValue) {
needToUpdateForecast = true;
......@@ -53,26 +70,15 @@ if (needToUpdateForecast)
neon.refresh()
function _updateReasons(pDelete)
function _updateReasons()
{
var reasons = "";
if(!pDelete)
vars.getString("field.REASONS");
if(reasons != null)
var reasons = vars.getString("field.REASONS");
if(reasons)
db.updateData("SALESPROJECT", ["REASONS"], null, [reasons], SqlCondition.equals("SALESPROJECT.SALESPROJECTID", vars.getString("$field.SALESPROJECTID"), "1=2"));
}
/**
* when project is state offer sets competitors to lost, when project is state lost sets offer to lost
* @param pTable {String}
* @param pContainer {String}
*/
function _updateDataToLost(pTable, pContainer )
function _clearReasons(pReallyClear)
{
var statusLost = db.table(SqlCondition.begin()
.andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pContainer)
.andPrepare("AB_KEYWORD_ENTRY.TITLE", "Lost")
.buildSql("select KEYID from AB_KEYWORD_ENTRY", "1=2"));
db.updateData(pTable, ["STATUS"], null, statusLost, SqlCondition.equals(pTable + ".SALESPROJECT_ID", vars.getString("$field.SALESPROJECTID"), "1=2"));
}
if (pReallyClear)
db.updateData("SALESPROJECT", ["REASONS"], null, [""], SqlCondition.equals("SALESPROJECT.SALESPROJECTID", vars.getString("$field.SALESPROJECTID"), "1=2"));
}
\ No newline at end of file
......@@ -60,3 +60,4 @@ $KeywordRegistry.salesprojectCompetitionState = function(){return "SalesprojectC
$KeywordRegistry.objectRelationType = function(){return "ObjectRelationType"};
$KeywordRegistry.deliveryTerm = function(){return "DeliveryTerm"};
$KeywordRegistry.paymentTerm = function(){return "PaymentTerm"};
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