{
  "eventsAndFunctions": [
    {
      "algorithm": {
        "parameters": [],
        "statements": [
          {
            "command": "ReadModel",
            "modelVariableName": "domainId",
            "variableName": "domainId"
          },
          {
            "command": "Load",
            "expression": "Select(GetFrequencies(),[code,name])",
            "widgetName": "cboControlFrequency"
          },
          {
            "command": "Load",
            "expression": "Select(GetFrequencies(),[code,name])",
            "widgetName": "cboPartialFrequency"
          },
          {
            "command": "Load",
            "expression": "Select(GetTimeFrequencies(),[code,name])",
            "widgetName": "cboFrequency"
          },
          {
            "command": "Load",
            "expression": "Select(ExtStrategicPlanMng.EntityMeasuresList(^domainId, \"opportunity\", {}),[id, name])",
            "widgetName": "cboMeasure"
          },
          {
            "command": "Load",
            "expression": "Select(ExtCommonBusiness.ListCurrencies({}), [id, name])",
            "widgetName": "cboCurrencies"
          }
        ],
        "typeReturn": "any",
        "variables": [
          {
            "name": "domainId",
            "type": "string"
          }
        ]
      },
      "name": "main_init"
    },
    {
      "algorithm": {
        "parameters": [],
        "statements": [
          {
            "command": "ReadModel",
            "modelVariableName": "plan",
            "variableName": "plan"
          },
          {
            "children": [
              {
                "command": "Execute",
                "expression": "createPlan()"
              }
            ],
            "command": "If",
            "expression": "IsNull(^plan.id)"
          },
          {
            "children": [
              {
                "command": "Execute",
                "expression": "updatePlan()"
              }
            ],
            "command": "Else"
          },
          {
            "command": "Execute",
            "expression": "setMainGoal()"
          }
        ],
        "typeReturn": "any",
        "variables": [
          {
            "name": "plan",
            "type": "ExtStrategicPlanMng.Plan"
          }
        ]
      },
      "name": "main_submit"
    },
    {
      "algorithm": {
        "parameters": [],
        "statements": [
          {
            "command": "Execute",
            "expression": "setFormEnabled()"
          }
        ],
        "variables": []
      },
      "name": "frmPlan_init"
    },
    {
      "algorithm": {
        "parameters": [
          {
            "name": "plan",
            "type": "ExtStrategicPlanMng.Plan"
          }
        ],
        "statements": [
          {
            "command": "ReadModel",
            "modelVariableName": "salesTeam",
            "variableName": "salesTeam"
          },
          {
            "command": "Set",
            "expression": "true",
            "variableName": "isValid"
          },
          {
            "command": "Set",
            "expression": "[]",
            "variableName": "validations"
          },
          {
            "command": "GetValue",
            "variableName": "to",
            "widgetName": "dtTo"
          },
          {
            "command": "GetValue",
            "variableName": "from",
            "widgetName": "dtFrom"
          },
          {
            "command": "GetValue",
            "variableName": "plan.name",
            "widgetName": "txtName"
          },
          {
            "command": "GetValue",
            "variableName": "plan.controlFrequency",
            "widgetName": "cboControlFrequency"
          },
          {
            "command": "GetValue",
            "variableName": "plan.partialFrequency",
            "widgetName": "cboPartialFrequency"
          },
          {
            "command": "Set",
            "expression": "false",
            "variableName": "isValid"
          },
          {
            "children": [
              {
                "command": "Set",
                "expression": "{header: ^plan.name, list: []}",
                "variableName": "validation"
              },
              {
                "command": "Push",
                "expressionItem": "{severity:\"error\",message: \"[[ErrorPlanInvalidDates]]\"}",
                "variableNameList": "validation.list"
              },
              {
                "command": "Push",
                "expressionItem": "^validation",
                "variableNameList": "validations"
              }
            ],
            "command": "If",
            "expression": "^from >= ^to"
          },
          {
            "command": "Set",
            "expression": "{header: ^plan.name, list: []}",
            "variableName": "validation"
          },
          {
            "command": "Switch",
            "expression": "^plan.controlFrequency"
          },
          {
            "children": [
              {
                "children": [
                  {
                    "command": "Push",
                    "expressionItem": "{severity:\"error\",message: \"[[ErrorPartialFrequency]]\"}",
                    "variableNameList": "validation.list"
                  }
                ],
                "command": "If",
                "expression": "Contains(^plan.partialFrequency, \"annual\")"
              }
            ],
            "command": "Case",
            "expression": "\"semester\""
          },
          {
            "children": [
              {
                "children": [
                  {
                    "command": "Push",
                    "expressionItem": "{severity:\"error\",message: \"[[ErrorPartialFrequency]]\"}",
                    "variableNameList": "validation.list"
                  }
                ],
                "command": "If",
                "expression": "Contains(^plan.partialFrequency, \"annual\") || Contains(^plan.partialFrequency, \"semester\")"
              }
            ],
            "command": "Case",
            "expression": "\"quarter\""
          },
          {
            "children": [
              {
                "children": [
                  {
                    "command": "Push",
                    "expressionItem": "{severity:\"error\",message: \"[[ErrorPartialFrequency]]\"}",
                    "variableNameList": "validation.list"
                  }
                ],
                "command": "If",
                "expression": "Contains(^plan.partialFrequency, \"annual\") || Contains(^plan.partialFrequency, \"semester\") || Contains(^plan.partialFrequency, \"quarter\")"
              }
            ],
            "command": "Case",
            "expression": "\"bimester\""
          },
          {
            "children": [
              {
                "children": [
                  {
                    "command": "Push",
                    "expressionItem": "{severity:\"error\",message: \"[[ErrorPartialFrequency]]\"}",
                    "variableNameList": "validation.list"
                  }
                ],
                "command": "If",
                "expression": "Contains(^plan.partialFrequency, \"annual\") || Contains(^plan.partialFrequency, \"semester\") || Contains(^plan.partialFrequency, \"quarter\") || Contains(^plan.partialFrequency, \"bimester\")"
              }
            ],
            "command": "Case",
            "expression": "\"monthly\""
          },
          {
            "children": [
              {
                "children": [
                  {
                    "command": "Push",
                    "expressionItem": "{severity:\"error\",message: \"[[ErrorPartialFrequency]]\"}",
                    "variableNameList": "validation.list"
                  }
                ],
                "command": "If",
                "expression": "!Contains(^plan.partialFrequency, \"weekly\")"
              }
            ],
            "command": "Case",
            "expression": "\"weekly\""
          },
          {
            "children": [
              {
                "command": "Push",
                "expressionItem": "{severity:\"error\",title:\"[[ErrorSelectingTitle]]\", message: \"[[ErrorSelectingMessage]]\"}",
                "variableNameList": "validation.list"
              }
            ],
            "command": "If",
            "expression": "IsNull(^salesTeam)"
          },
          {
            "children": [
              {
                "command": "Push",
                "expressionItem": "^validation",
                "variableNameList": "validations"
              }
            ],
            "command": "If",
            "expression": "Count(^validation.list) > 0"
          },
          {
            "children": [
              {
                "command": "Throw",
                "errorName": "Error",
                "expressionData": "GetValidationsTemplate(^validations)",
                "expressionInnerError": "\"[[ErrorCustom]]\""
              }
            ],
            "command": "If",
            "expression": "Count(^validations) > 0"
          }
        ],
        "typeReturn": "any",
        "variables": [
          {
            "name": "from",
            "type": "date"
          },
          {
            "name": "to",
            "type": "date"
          },
          {
            "name": "validation",
            "type": "any"
          },
          {
            "name": "validations",
            "type": "any"
          },
          {
            "name": "isValid",
            "type": "boolean"
          },
          {
            "name": "domain",
            "type": "string"
          },
          {
            "name": "salesTeam",
            "type": "ExtPresales.SalesTeam"
          }
        ]
      },
      "name": "validations"
    },
    {
      "algorithm": {
        "parameters": [],
        "statements": [
          {
            "command": "ReadModel",
            "modelVariableName": "domainId",
            "variableName": "domainId"
          },
          {
            "command": "ReadModel",
            "modelVariableName": "plan",
            "variableName": "plan"
          },
          {
            "command": "Execute",
            "expression": "validations(^plan)"
          },
          {
            "command": "Set",
            "expression": "^domainId",
            "variableName": "plan.domain"
          },
          {
            "command": "Set",
            "expression": "ExtStrategicPlanMng.PlanCreation(^plan)",
            "variableName": "plan"
          },
          {
            "command": "WriteModel",
            "expression": "^plan",
            "modelVariableName": "plan"
          }
        ],
        "typeReturn": "any",
        "variables": [
          {
            "name": "domainId",
            "type": "string"
          },
          {
            "name": "plan",
            "type": "any"
          }
        ]
      },
      "name": "createPlan"
    },
    {
      "algorithm": {
        "parameters": [],
        "statements": [
          {
            "command": "ReadModel",
            "modelVariableName": "mainGoal",
            "variableName": "mainGoal"
          },
          {
            "command": "GetValue",
            "variableName": "mainGoal.description",
            "widgetName": "txtDescription"
          },
          {
            "command": "GetValue",
            "variableName": "mainGoal.goalValue",
            "widgetName": "txtGoalValue"
          },
          {
            "command": "GetValue",
            "variableName": "measure",
            "widgetName": "cboMeasure"
          },
          {
            "command": "Set",
            "expression": "{id: ^measure}",
            "variableName": "mainGoal.measure"
          },
          {
            "command": "WriteModel",
            "expression": "^mainGoal",
            "modelVariableName": "mainGoal"
          }
        ],
        "typeReturn": "any",
        "variables": [
          {
            "name": "mainGoal",
            "type": "ExtStrategicPlanMng.MainGoal"
          },
          {
            "name": "measure",
            "type": "string"
          }
        ]
      },
      "name": "setMainGoal"
    },
    {
      "algorithm": {
        "parameters": [],
        "statements": [
          {
            "command": "ReadModel",
            "modelVariableName": "plan",
            "variableName": "plan"
          },
          {
            "command": "Execute",
            "expression": "validations(^plan)"
          },
          {
            "command": "Set",
            "expression": "ExtStrategicPlanMng.PlanUpdate(^plan.id, ^plan)",
            "variableName": "plan"
          },
          {
            "command": "WriteModel",
            "expression": "^plan",
            "modelVariableName": "plan"
          }
        ],
        "typeReturn": "any",
        "variables": [
          {
            "name": "plan",
            "type": "any"
          }
        ]
      },
      "name": "updatePlan"
    },
    {
      "algorithm": {
        "parameters": [],
        "statements": [
          {
            "command": "ReadModel",
            "modelVariableName": "plan",
            "variableName": "plan"
          },
          {
            "children": [
              {
                "command": "Disable",
                "widgetName": "cboControlFrequency"
              },
              {
                "command": "Disable",
                "widgetName": "cboPartialFrequency"
              },
              {
                "command": "Disable",
                "widgetName": "cboMeasure"
              },
              {
                "command": "Disable",
                "widgetName": "txtGoalValue"
              },
              {
                "command": "Disable",
                "widgetName": "cboCurrencies"
              }
            ],
            "command": "If",
            "expression": "IsNotNull(^plan.id)"
          }
        ],
        "typeReturn": "any",
        "variables": [
          {
            "name": "plan",
            "type": "ExtStrategicPlanMng.Plan"
          }
        ]
      },
      "name": "setFormEnabled"
    }
  ],
  "model": [
    {
      "name": "plan",
      "required": false,
      "type": "ExtStrategicPlanMng.SimplePlan"
    },
    {
      "name": "domainId",
      "required": false,
      "type": "string"
    },
    {
      "name": "salesTeam",
      "required": false,
      "type": "ExtPresales.SalesTeam"
    },
    {
      "name": "mainGoal",
      "required": false,
      "type": "ExtStrategicPlanMng.MainGoal"
    },
    {
      "name": "currency",
      "required": false,
      "type": "ExtCommonBusiness.Currency"
    }
  ],
  "root": {
    "children": [
      {
        "children": [
          {
            "binding": "plan.name",
            "label": "[[Name]]",
            "last": true,
            "mandatory": true,
            "name": "txtName",
            "size": 2,
            "widget": "TextBox"
          },
          {
            "binding": "plan.description",
            "label": "[[Description]]",
            "last": true,
            "name": "txtDescription",
            "size": 2,
            "widget": "TextBox"
          },
          {
            "binding": "plan.fromDate",
            "label": "[[From]]",
            "last": true,
            "mandatory": true,
            "name": "dtFrom",
            "size": 2,
            "widget": "DateBox"
          },
          {
            "binding": "plan.toDate",
            "label": "[[To]]",
            "last": true,
            "mandatory": true,
            "name": "dtTo",
            "size": 2,
            "widget": "DateBox"
          },
          {
            "binding": "plan.controlFrequency",
            "dataFormat": "KeyValueList",
            "label": "[[ControlFrequency]]",
            "mandatory": true,
            "name": "cboControlFrequency",
            "widget": "ComboBox"
          },
          {
            "binding": "plan.partialFrequency",
            "dataFormat": "KeyValueList",
            "label": "[[PartialFrequency]]",
            "last": true,
            "name": "cboPartialFrequency",
            "widget": "ComboBox"
          },
          {
            "binding": "mainGoal.measure.id",
            "dataFormat": "KeyValueList",
            "label": "[[Measure]]",
            "last": true,
            "mandatory": true,
            "name": "cboMeasure",
            "size": 2,
            "widget": "ComboBox"
          },
          {
            "binding": "currency.id",
            "dataFormat": "KeyValueList",
            "label": "[[Currencies]]",
            "name": "cboCurrencies",
            "widget": "ComboBox"
          },
          {
            "allowDecimals": true,
            "binding": "mainGoal.goalValue",
            "decimalPlaces": 2,
            "label": "[[MainGoalValue]]",
            "last": true,
            "mandatory": true,
            "name": "txtGoalValue",
            "widget": "NumericBox"
          },
          {
            "binding": "plan.snapshotFrequency",
            "label": "[[SnapshotFrequency]]",
            "name": "txtSnapshotFrequency",
            "widget": "NumericBox"
          },
          {
            "dataFormat": "KeyValueList",
            "label": "[[Frequency]]",
            "last": true,
            "name": "cboFrequency",
            "widget": "ComboBox"
          }
        ],
        "layout": "form",
        "name": "frmPlan"
      }
    ],
    "layout": "responsive"
  },
  "routing": {
    "path": "/sf-plan/editor"
  },
  "unused": []
}