Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.04 KB | None | 0 0
  1. public void updateKpis(TreeNode treeTable, Map<String, ScenarioRow> tableElements){
  2.  
  3. for (Map.Entry<String, ScenarioRow> entry : tableElements.entrySet()) {
  4.  
  5. if (entry.getKey().startsWith(CategoryEnum.UNITS.getCodice()) && entry.getKey().indexOf("_") > 0) {
  6.  
  7. String codeSuffix = "";
  8. if (entry.getKey().indexOf("_") > -1 &&
  9. (entry.getKey().endsWith(CategoryEnum.EMEA_ROADMAP.getCodice()) || entry.getKey().endsWith(CategoryEnum.EMEA_CORRECTION.getCodice()))) {
  10. codeSuffix = entry.getKey().substring(entry.getKey().indexOf("_") + 1);
  11. }
  12.  
  13. Double unitsScenarioPw = tableElements.get(CategoryEnum.UNITS.getCodice() + "_" + codeSuffix) != null
  14. && tableElements.get(CategoryEnum.UNITS.getCodice() + "_" + codeSuffix).getPreviousWeekForecast() != null
  15. && tableElements.get(CategoryEnum.UNITS.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() != null ?
  16. tableElements.get(CategoryEnum.UNITS.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() : 0;
  17.  
  18. Double unitsScenarioPwAdj = tableElements.get(CategoryEnum.UNITS.getCodice() + "_" + codeSuffix) != null
  19. && tableElements.get(CategoryEnum.UNITS.getCodice() + "_" + codeSuffix).getPreviousWeekForecastTotalAdjustments() != null
  20. && tableElements.get(CategoryEnum.UNITS.getCodice() + "_" + codeSuffix).getPreviousWeekForecastTotalAdjustments().getAmount() != null ?
  21. tableElements.get(CategoryEnum.UNITS.getCodice() + "_" + codeSuffix).getPreviousWeekForecastTotalAdjustments().getAmount() : 0;
  22.  
  23. Integer count = 0;
  24.  
  25. if (codeSuffix.contains(CategoryEnum.EMEA_ROADMAP.getCodice()) || codeSuffix.contains(CategoryEnum.EMEA_CORRECTION.getCodice())) {
  26. for (TreeNode child : treeTable.getChildren()) {
  27. if (((ScenarioRow) child.getData()).getKpi().equals(CategoryEnum.CAS.getCodice())) {
  28. updateCasPreviousWeekForecastValue(child, CategoryEnum.CAS.getCodice(), codeSuffix, count, unitsScenarioPw);
  29. updateCasPreviousWeekForecastTotalAdjValue(child, CategoryEnum.CAS.getCodice(), codeSuffix, count, unitsScenarioPwAdj);
  30. }
  31. }
  32. }
  33. }
  34. }
  35.  
  36. for (Map.Entry<String, ScenarioRow> entry : tableElements.entrySet()) {
  37.  
  38. if (entry.getKey().startsWith(CategoryEnum.NBMC_P.getCodice()) && entry.getKey().indexOf("_") > 0) {
  39.  
  40. String codeSuffix = "";
  41. if (entry.getKey().indexOf("_") > -1) {
  42. codeSuffix = entry.getKey().substring(entry.getKey().indexOf("_") + 1);
  43. }
  44.  
  45. Double netRevenueScenarioMx = tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix) != null
  46. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getMx() != null
  47. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getMx().getAmount() != null ?
  48. tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getMx().getAmount() : 0;
  49.  
  50. Double nbmcScenarioMx = tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix) != null
  51. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getMx() != null
  52. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getMx().getAmount() != null ?
  53. tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getMx().getAmount() : 0;
  54.  
  55. Double netRevenueScenarioCw = tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix) != null
  56. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getCurrentWeekForecast() != null
  57. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() != null ?
  58. tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() : 0;
  59.  
  60. Double nbmcScenarioCw = tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix) != null
  61. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getCurrentWeekForecast() != null
  62. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() != null ?
  63. tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() : 0;
  64.  
  65. Double netRevenueScenarioCampaign = tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix) != null
  66. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getCampaignPlan() != null
  67. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getCampaignPlan().getAmount() != null ?
  68. tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getCampaignPlan().getAmount() : 0;
  69.  
  70. Double nbmcScenarioCampaign = tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix) != null
  71. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getCampaignPlan() != null
  72. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getCampaignPlan().getAmount() != null ?
  73. tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getCampaignPlan().getAmount() : 0;
  74.  
  75. Double netRevenueScenarioBudget = tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix) != null
  76. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getBudget() != null
  77. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getBudget().getAmount() != null ?
  78. tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getBudget().getAmount() : 0;
  79.  
  80. Double nbmcScenarioBudget = tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix) != null
  81. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getBudget() != null
  82. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getBudget().getAmount() != null ?
  83. tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getBudget().getAmount() : 0;
  84.  
  85. Double netRevenueScenarioPw = tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix) != null
  86. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getPreviousWeekForecast() != null
  87. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() != null ?
  88. tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() : 0;
  89.  
  90. Double nbmcScenarioPw = tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix) != null
  91. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getPreviousWeekForecast() != null
  92. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() != null ?
  93. tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() : 0;
  94.  
  95.  
  96. Double nbmcPercScenarioMx = netRevenueScenarioMx != 0 ? (nbmcScenarioMx / netRevenueScenarioMx) * 100 : 0;
  97. Double nbmcPercScenarioCw = netRevenueScenarioCw != 0 ? (nbmcScenarioCw / netRevenueScenarioCw) * 100 : 0;
  98. Double nbmcPercScenarioCampaign = netRevenueScenarioCampaign != 0 ? (nbmcScenarioCampaign / netRevenueScenarioCampaign) * 100 : 0;
  99. Double nbmcPercScenarioBudget = netRevenueScenarioBudget != 0 ? (nbmcScenarioBudget / netRevenueScenarioBudget) * 100 : 0;
  100. Double nbmcPercScenarioPw = netRevenueScenarioPw != 0 ? (nbmcScenarioPw / netRevenueScenarioPw) * 100 : 0;
  101.  
  102. Integer count = 0;
  103. for (TreeNode child : treeTable.getChildren()) {
  104. updateMxValue(child, CategoryEnum.NBMC_P.getCodice(), codeSuffix, count, nbmcPercScenarioMx);
  105. updateBudgetValue(child, CategoryEnum.NBMC_P.getCodice(), codeSuffix, count, nbmcPercScenarioBudget);
  106. updateCampaignValue(child, CategoryEnum.NBMC_P.getCodice(), codeSuffix, count, nbmcPercScenarioCampaign);
  107. updateCurrentWeekForecastValue(child, CategoryEnum.NBMC_P.getCodice(), codeSuffix, count, nbmcPercScenarioCw);
  108. updatePreviousWeekForecastValue(child, CategoryEnum.NBMC_P.getCodice(), codeSuffix, count, nbmcPercScenarioPw);
  109. }
  110. }
  111. }
  112.  
  113. for (Map.Entry<String, ScenarioRow> entry : tableElements.entrySet()) {
  114.  
  115. if (entry.getKey().equals(CategoryEnum.NBMC_P.getCodice())) {
  116.  
  117. Double netRevenueScenarioMx = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  118. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getMx() != null
  119. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getMx().getAmount() != null ?
  120. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getMx().getAmount() : 0;
  121.  
  122. Double nbmcScenarioMx = tableElements.get(CategoryEnum.NBMC_K.getCodice()) != null
  123. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getMx() != null
  124. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getMx().getAmount() != null ?
  125. tableElements.get(CategoryEnum.NBMC_K.getCodice()).getMx().getAmount() : 0;
  126.  
  127. Double netRevenueScenarioCw = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  128. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCurrentWeekForecast() != null
  129. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCurrentWeekForecast().getAmount() != null ?
  130. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCurrentWeekForecast().getAmount() : 0;
  131.  
  132. Double nbmcScenarioCw = tableElements.get(CategoryEnum.NBMC_K.getCodice()) != null
  133. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCurrentWeekForecast() != null
  134. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCurrentWeekForecast().getAmount() != null ?
  135. tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCurrentWeekForecast().getAmount() : 0;
  136.  
  137. Double netRevenueScenarioCampaign = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  138. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCampaignPlan() != null
  139. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCampaignPlan().getAmount() != null ?
  140. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCampaignPlan().getAmount() : 0;
  141.  
  142. Double nbmcScenarioCampaign = tableElements.get(CategoryEnum.NBMC_K.getCodice()) != null
  143. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCampaignPlan() != null
  144. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCampaignPlan().getAmount() != null ?
  145. tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCampaignPlan().getAmount() : 0;
  146.  
  147. Double netRevenueScenarioBudget = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  148. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getBudget() != null
  149. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getBudget().getAmount() != null ?
  150. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getBudget().getAmount() : 0;
  151.  
  152. Double nbmcScenarioBudget = tableElements.get(CategoryEnum.NBMC_K.getCodice()) != null
  153. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getBudget() != null
  154. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getBudget().getAmount() != null ?
  155. tableElements.get(CategoryEnum.NBMC_K.getCodice()).getBudget().getAmount() : 0;
  156.  
  157. Double netRevenueScenarioPw = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  158. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getPreviousWeekForecast() != null
  159. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getPreviousWeekForecast().getAmount() != null ?
  160. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getPreviousWeekForecast().getAmount() : 0;
  161.  
  162. Double nbmcScenarioPw = tableElements.get(CategoryEnum.NBMC_K.getCodice()) != null
  163. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getPreviousWeekForecast() != null
  164. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getPreviousWeekForecast().getAmount() != null ?
  165. tableElements.get(CategoryEnum.NBMC_K.getCodice()).getPreviousWeekForecast().getAmount() : 0;
  166.  
  167. Double nbmcPercScenarioMx = netRevenueScenarioMx != 0 ? (nbmcScenarioMx / netRevenueScenarioMx) * 100 : 0;
  168. Double nbmcPercScenarioCw = netRevenueScenarioCw != 0 ? (nbmcScenarioCw / netRevenueScenarioCw) * 100 : 0;
  169. Double nbmcPercScenarioCampaign = netRevenueScenarioCampaign != 0 ? (nbmcScenarioCampaign / netRevenueScenarioCampaign) * 100 : 0;
  170. Double nbmcPercScenarioBudget = netRevenueScenarioBudget != 0 ? (nbmcScenarioBudget / netRevenueScenarioBudget) * 100 : 0;
  171. Double nbmcPercScenarioPw = netRevenueScenarioPw != 0 ? (nbmcScenarioPw / netRevenueScenarioPw) * 100 : 0;
  172.  
  173. for (TreeNode child : treeTable.getChildren()) {
  174.  
  175. if (((ScenarioRow) child.getData()).getCategoryCode().equals(CategoryEnum.NBMC_P.getCodice())) {
  176.  
  177. ScenarioRow scenarioUpdate = (ScenarioRow) child.getData();
  178. Double oldValueCw = scenarioUpdate.getCurrentWeekForecast() != null
  179. && scenarioUpdate.getCurrentWeekForecast().getAmount() != null ?
  180. scenarioUpdate.getCurrentWeekForecast().getAmount() : 0;
  181. scenarioUpdate.getCurrentWeekForecast().setAmount(nbmcPercScenarioCw);
  182.  
  183. Double oldValueMx = scenarioUpdate.getMx() != null
  184. && scenarioUpdate.getMx().getAmount() != null ?
  185. scenarioUpdate.getMx().getAmount() : 0;
  186. scenarioUpdate.getMx().setAmount(nbmcPercScenarioMx);
  187.  
  188. Double oldValueBudget = scenarioUpdate.getBudget() != null
  189. && scenarioUpdate.getBudget().getAmount() != null ?
  190. scenarioUpdate.getBudget().getAmount() : 0;
  191. scenarioUpdate.getBudget().setAmount(nbmcPercScenarioBudget);
  192.  
  193. Double oldValueCampaign = scenarioUpdate.getCampaignPlan() != null
  194. && scenarioUpdate.getCampaignPlan().getAmount() != null ?
  195. scenarioUpdate.getCampaignPlan().getAmount() : 0;
  196. scenarioUpdate.getCampaignPlan().setAmount(nbmcPercScenarioCampaign);
  197.  
  198. Double oldValuePw = scenarioUpdate.getPreviousWeekForecast() != null
  199. && scenarioUpdate.getPreviousWeekForecast().getAmount() != null ?
  200. scenarioUpdate.getPreviousWeekForecast().getAmount() : 0;
  201. scenarioUpdate.getPreviousWeekForecast().setAmount(nbmcPercScenarioPw);
  202. }
  203. }
  204. }
  205. }
  206.  
  207. for (Map.Entry<String, ScenarioRow> entry : tableElements.entrySet()) {
  208.  
  209. if (entry.getKey().equals(CategoryEnum.BMC_MARGIN_P.getCodice())) {
  210.  
  211. ScenarioRow scenarioBmc = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice());
  212.  
  213. ScenarioRow scenarionetRevenue = tableElements.get(CategoryEnum.NET_REVENUE.getCodice());
  214.  
  215. ScenarioRow scenarioUpdate = new ScenarioRow();
  216. scenarioUpdate.setCategoryCode(CategoryEnum.BMC_MARGIN_P.getCodice());
  217.  
  218. if (scenarioBmc != null && scenarionetRevenue != null) {
  219.  
  220. scenarioUpdate = Utils.updateScenarioRow(scenarioUpdate, scenarioBmc, scenarionetRevenue);
  221.  
  222. for (TreeNode child : treeTable.getChildren()) {
  223.  
  224. if (((ScenarioRow) child.getData()).getCategoryCode().equals(CategoryEnum.BMC_MARGIN_P.getCodice())) {
  225. ScenarioRow selectedScenario = (ScenarioRow) child.getData();
  226. ScenarioRow oldScenario = selectedScenario;
  227. child = Utils.updateNodeValues(child, scenarioUpdate, oldScenario);
  228. }
  229. }
  230. }
  231.  
  232. }
  233. }
  234.  
  235. for (Map.Entry<String, ScenarioRow> entry : tableElements.entrySet()) {
  236.  
  237. if (entry.getKey().equals(CategoryEnum.AUR.getCodice())) {
  238.  
  239. ScenarioRow scenarioCas = tableElements.get(CategoryEnum.UNITS.getCodice());
  240.  
  241. ScenarioRow scenarioNetRevenue = tableElements.get(CategoryEnum.NET_REVENUE.getCodice());
  242.  
  243. ScenarioRow scenarioUpdate = new ScenarioRow();
  244.  
  245. if (scenarioCas != null && scenarioNetRevenue != null) {
  246.  
  247. scenarioUpdate = Utils.updateScenarioRow(scenarioUpdate, scenarioNetRevenue, scenarioCas);
  248.  
  249. for (TreeNode child : treeTable.getChildren()) {
  250.  
  251. if (((ScenarioRow) child.getData()).getCategoryCode().equals(CategoryEnum.AUR.getCodice())) {
  252. ScenarioRow selectedScenario = (ScenarioRow) child.getData();
  253. ScenarioRow oldScenario = selectedScenario;
  254. child = Utils.updateNodeValues(child, scenarioUpdate, oldScenario);
  255. }
  256. }
  257. }
  258.  
  259. }
  260. }
  261.  
  262. for (Map.Entry<String, ScenarioRow> entry : tableElements.entrySet()) {
  263.  
  264. if (entry.getKey().equals(CategoryEnum.AUC.getCodice())) {
  265.  
  266. ScenarioRow scenarioBmc = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice());
  267.  
  268. ScenarioRow scenarioNetRevenue = tableElements.get(CategoryEnum.NET_REVENUE.getCodice());
  269.  
  270. ScenarioRow scenarioDifference = new ScenarioRow();
  271.  
  272. scenarioDifference = Utils.differenceScenarioRow(scenarioDifference, scenarioNetRevenue, scenarioBmc);
  273.  
  274. ScenarioRow scenarioCas = tableElements.get(CategoryEnum.UNITS.getCodice());
  275.  
  276. ScenarioRow scenarioUpdate = new ScenarioRow();
  277.  
  278. if (scenarioCas != null && scenarioBmc != null) {
  279.  
  280. scenarioUpdate = Utils.updateScenarioRow(scenarioUpdate, scenarioDifference, scenarioCas);
  281.  
  282. for (TreeNode child : treeTable.getChildren()) {
  283.  
  284. if (((ScenarioRow) child.getData()).getCategoryCode().equals(CategoryEnum.AUC.getCodice())) {
  285. ScenarioRow selectedScenario = (ScenarioRow) child.getData();
  286. ScenarioRow oldScenario = selectedScenario;
  287. child = Utils.updateNodeValues(child, scenarioUpdate, oldScenario);
  288. }
  289. }
  290. }
  291. }
  292. }
  293.  
  294. for (Map.Entry<String, ScenarioRow> entry : tableElements.entrySet()) {
  295.  
  296. if (entry.getKey().startsWith(CategoryEnum.BMC_MARGIN_P.getCodice()) && entry.getKey().indexOf("_") > 0) {
  297.  
  298. String codeSuffix = "";
  299. if (entry.getKey().indexOf("_") > -1) {
  300. codeSuffix = entry.getKey().substring(entry.getKey().indexOf("_") + 1);
  301. }
  302.  
  303. ScenarioRow scenarioBmc = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix);
  304.  
  305. ScenarioRow scenarionetRevenue = tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix);
  306.  
  307. ScenarioRow scenarioUpdate = new ScenarioRow();
  308. scenarioUpdate.setCategoryCode(CategoryEnum.BMC_MARGIN_P.getCodice() + "_" + codeSuffix);
  309.  
  310. if (scenarioBmc != null && scenarionetRevenue != null) {
  311.  
  312. scenarioUpdate = Utils.updateScenarioRow(scenarioUpdate, scenarioBmc, scenarionetRevenue);
  313.  
  314. Integer count = 0;
  315. for (TreeNode child : treeTable.getChildren()) {
  316. updateScenarioRow(child, CategoryEnum.BMC_MARGIN_P.getCodice(), codeSuffix, count, scenarioUpdate);
  317. }
  318. }
  319. }
  320.  
  321. if (entry.getKey().startsWith(CategoryEnum.AUR.getCodice()) && entry.getKey().indexOf("_") > 0) {
  322.  
  323. String codeSuffix = "";
  324. if (entry.getKey().indexOf("_") > -1) {
  325. codeSuffix = entry.getKey().substring(entry.getKey().indexOf("_") + 1);
  326. }
  327.  
  328. ScenarioRow scenarioCas = tableElements.get(CategoryEnum.UNITS.getCodice() + "_" + codeSuffix);
  329.  
  330. ScenarioRow scenarioNetRevenue = tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix);
  331.  
  332. ScenarioRow scenarioUpdate = new ScenarioRow();
  333.  
  334. if (scenarioCas != null && scenarioNetRevenue != null) {
  335.  
  336. scenarioUpdate = Utils.updateScenarioRow(scenarioUpdate, scenarioNetRevenue, scenarioCas);
  337.  
  338. Integer count = 0;
  339. for (TreeNode child : treeTable.getChildren()) {
  340. updateScenarioRow(child, CategoryEnum.AUR.getCodice(), codeSuffix, count, scenarioUpdate);
  341. }
  342. }
  343. }
  344.  
  345. if (entry.getKey().startsWith(CategoryEnum.AUC.getCodice()) && entry.getKey().indexOf("_") > 0) {
  346.  
  347. String codeSuffix = "";
  348. if (entry.getKey().indexOf("_") > -1) {
  349. codeSuffix = entry.getKey().substring(entry.getKey().indexOf("_") + 1);
  350. }
  351.  
  352. ScenarioRow scenarioBmc = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix);
  353.  
  354. ScenarioRow scenarioCas = tableElements.get(CategoryEnum.UNITS.getCodice() + "_" + codeSuffix);
  355.  
  356. ScenarioRow scenarioUpdate = new ScenarioRow(new CurrentWeek());
  357.  
  358. if (scenarioCas != null && scenarioBmc != null) {
  359.  
  360. scenarioUpdate = Utils.updateScenarioRow(scenarioUpdate, scenarioBmc, scenarioCas);
  361.  
  362. Integer count = 0;
  363. for (TreeNode child : treeTable.getChildren()) {
  364. updateScenarioRow(child, CategoryEnum.AUC.getCodice(), codeSuffix, count, scenarioUpdate);
  365. }
  366. }
  367. }
  368.  
  369.  
  370. }
  371.  
  372. for (Map.Entry<String, ScenarioRow> entry : tableElements.entrySet()) {
  373.  
  374. if (entry.getKey().startsWith(CategoryEnum.PTI_K.getCodice()) && entry.getKey().indexOf("_") > 0) {
  375.  
  376. String codeSuffix = "";
  377. if (entry.getKey().indexOf("_") > -1) {
  378. codeSuffix = entry.getKey().substring(entry.getKey().indexOf("_") + 1);
  379. }
  380.  
  381. Double bmcMarginScenario = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix) != null
  382. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix).getCurrentWeekForecast() != null ?
  383. tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() : 0;
  384.  
  385. Double nbmcScenario = tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix) != null
  386. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getCurrentWeekForecast() != null ?
  387. tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() : 0;
  388.  
  389. Double controllExpScenario = tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix) != null
  390. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix).getCurrentWeekForecast() != null ?
  391. tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() : 0;
  392.  
  393. Double allocExpScenario = tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix) != null
  394. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix).getCurrentWeekForecast() != null ?
  395. tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() : 0;
  396.  
  397.  
  398. Double bmcMarginScenarioBudget = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix) != null
  399. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix).getBudget() != null ?
  400. tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix).getBudget().getAmount() : 0;
  401.  
  402. Double nbmcScenarioBudget = tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix) != null
  403. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getBudget() != null ?
  404. tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getBudget().getAmount() : 0;
  405.  
  406. Double controllExpScenarioBudget = tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix) != null
  407. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix).getBudget() != null ?
  408. tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix).getBudget().getAmount() : 0;
  409.  
  410. Double allocExpScenarioBudget = tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix) != null
  411. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix).getBudget() != null ?
  412. tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix).getBudget().getAmount() : 0;
  413.  
  414.  
  415. Double bmcMarginScenarioMx = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix) != null
  416. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix).getMx() != null ?
  417. tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix).getMx().getAmount() : 0;
  418.  
  419. Double nbmcScenarioMx = tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix) != null
  420. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getMx() != null ?
  421. tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getMx().getAmount() : 0;
  422.  
  423. Double controllExpScenarioMx = tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix) != null
  424. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix).getMx() != null ?
  425. tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix).getMx().getAmount() : 0;
  426.  
  427. Double allocExpScenarioMx = tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix) != null
  428. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix).getMx() != null ?
  429. tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix).getMx().getAmount() : 0;
  430.  
  431.  
  432. Double bmcMarginScenarioCampaign = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix) != null
  433. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix).getCampaignPlan() != null ?
  434. tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix).getCampaignPlan().getAmount() : 0;
  435.  
  436. Double nbmcScenarioCampaign = tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix) != null
  437. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getCampaignPlan() != null ?
  438. tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getCampaignPlan().getAmount() : 0;
  439.  
  440. Double controllExpScenarioCampaign = tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix) != null
  441. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix).getCampaignPlan() != null ?
  442. tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix).getCampaignPlan().getAmount() : 0;
  443.  
  444. Double allocExpScenarioCampaign = tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix) != null
  445. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix).getCampaignPlan() != null ?
  446. tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix).getCampaignPlan().getAmount() : 0;
  447.  
  448. Double bmcMarginScenarioPw = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix) != null
  449. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix).getPreviousWeekForecast() != null ?
  450. tableElements.get(CategoryEnum.BMC_MARGIN.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() : 0;
  451.  
  452. Double nbmcScenarioPw = tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix) != null
  453. && tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getPreviousWeekForecast() != null ?
  454. tableElements.get(CategoryEnum.NBMC_K.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() : 0;
  455.  
  456. Double controllExpScenarioPw = tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix) != null
  457. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix).getPreviousWeekForecast() != null ?
  458. tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() : 0;
  459.  
  460. Double allocExpScenarioPw = tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix) != null
  461. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix).getPreviousWeekForecast() != null ?
  462. tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() : 0;
  463.  
  464. Double ptiScenario = bmcMarginScenario - nbmcScenario - controllExpScenario - allocExpScenario;
  465.  
  466. Double ptiScenarioBudget = bmcMarginScenarioBudget - nbmcScenarioBudget - controllExpScenarioBudget - allocExpScenarioBudget;
  467.  
  468. Double ptiScenarioMx = bmcMarginScenarioMx - nbmcScenarioMx - controllExpScenarioMx - allocExpScenarioMx;
  469.  
  470. Double ptiScenarioCampaign = bmcMarginScenarioCampaign - nbmcScenarioCampaign - controllExpScenarioCampaign - allocExpScenarioCampaign;
  471.  
  472. Double ptiScenarioPw = bmcMarginScenarioPw - nbmcScenarioPw - controllExpScenarioPw - allocExpScenarioPw;
  473.  
  474. Integer count = 0;
  475. for (TreeNode child : treeTable.getChildren()) {
  476. updateCurrentWeekForecastValue(child, CategoryEnum.PTI_K.getCodice(), codeSuffix, count, ptiScenario);
  477.  
  478. updateBudgetValue(child, CategoryEnum.PTI_K.getCodice(), codeSuffix, count, ptiScenarioBudget);
  479. updateMxValue(child, CategoryEnum.PTI_K.getCodice(), codeSuffix, count, ptiScenarioMx);
  480. updateCampaignValue(child, CategoryEnum.PTI_K.getCodice(), codeSuffix, count, ptiScenarioCampaign);
  481. updatePreviousWeekForecastValue(child, CategoryEnum.PTI_K.getCodice(), codeSuffix, count, ptiScenarioPw);
  482. }
  483.  
  484. }
  485. }
  486.  
  487. for (Map.Entry<String, ScenarioRow> entry : tableElements.entrySet()) {
  488.  
  489. if (entry.getKey().equals(CategoryEnum.PTI_K.getCodice())) {
  490.  
  491.  
  492. Double bmcMarginScenario = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()) != null
  493. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getCurrentWeekForecast() != null
  494. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getCurrentWeekForecast().getAmount() != null ?
  495. tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getCurrentWeekForecast().getAmount() : 0;
  496.  
  497. Double nbmcScenario = tableElements.get(CategoryEnum.NBMC_K.getCodice()) != null
  498. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCurrentWeekForecast() != null
  499. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCurrentWeekForecast().getAmount() != null ?
  500. tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCurrentWeekForecast().getAmount() : 0;
  501.  
  502. Double controllExpScenario = tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()) != null
  503. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getCurrentWeekForecast() != null
  504. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getCurrentWeekForecast().getAmount() != null ?
  505. tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getCurrentWeekForecast().getAmount() : 0;
  506.  
  507. Double allocExpScenario = tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()) != null
  508. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getCurrentWeekForecast() != null
  509. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getCurrentWeekForecast().getAmount() != null ?
  510. tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getCurrentWeekForecast().getAmount() : 0;
  511.  
  512.  
  513. Double bmcMarginScenarioBudget = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()) != null
  514. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getBudget() != null
  515. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getBudget().getAmount() != null ?
  516. tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getBudget().getAmount() : 0;
  517.  
  518. Double nbmcScenarioBudget = tableElements.get(CategoryEnum.NBMC_K.getCodice()) != null
  519. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getBudget() != null
  520. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getBudget().getAmount() != null ?
  521. tableElements.get(CategoryEnum.NBMC_K.getCodice()).getBudget().getAmount() : 0;
  522.  
  523. Double controllExpScenarioBudget = tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()) != null
  524. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getBudget() != null
  525. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getBudget().getAmount() != null ?
  526. tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getBudget().getAmount() : 0;
  527.  
  528. Double allocExpScenarioBudget = tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()) != null
  529. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getBudget() != null
  530. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getBudget().getAmount() != null ?
  531. tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getBudget().getAmount() : 0;
  532.  
  533.  
  534. Double bmcMarginScenarioMx = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()) != null
  535. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getMx() != null
  536. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getMx().getAmount() != null ?
  537. tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getMx().getAmount() : 0;
  538.  
  539. Double nbmcScenarioMx = tableElements.get(CategoryEnum.NBMC_K.getCodice()) != null
  540. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getMx() != null
  541. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getMx().getAmount() != null ?
  542. tableElements.get(CategoryEnum.NBMC_K.getCodice()).getMx().getAmount() : 0;
  543.  
  544. Double controllExpScenarioMx = tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()) != null
  545. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getMx() != null
  546. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getMx().getAmount() != null ?
  547. tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getMx().getAmount() : 0;
  548.  
  549. Double allocExpScenarioMx = tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()) != null
  550. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getMx() != null
  551. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getMx().getAmount() != null ?
  552. tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getMx().getAmount() : 0;
  553.  
  554.  
  555. Double bmcMarginScenarioCampaign = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()) != null
  556. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getCampaignPlan() != null
  557. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getCampaignPlan().getAmount() != null ?
  558. tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getCampaignPlan().getAmount() : 0;
  559.  
  560. Double nbmcScenarioCampaign = tableElements.get(CategoryEnum.NBMC_K.getCodice()) != null
  561. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCampaignPlan() != null
  562. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCampaignPlan().getAmount() != null ?
  563. tableElements.get(CategoryEnum.NBMC_K.getCodice()).getCampaignPlan().getAmount() : 0;
  564.  
  565. Double controllExpScenarioCampaign = tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()) != null
  566. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getCampaignPlan() != null
  567. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getCampaignPlan().getAmount() != null ?
  568. tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getCampaignPlan().getAmount() : 0;
  569.  
  570. Double allocExpScenarioCampaign = tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()) != null
  571. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getCampaignPlan() != null
  572. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getCampaignPlan().getAmount() != null ?
  573. tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getCampaignPlan().getAmount() : 0;
  574.  
  575. Double bmcMarginScenarioPw = tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()) != null
  576. && tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getPreviousWeekForecast() != null ?
  577. tableElements.get(CategoryEnum.BMC_MARGIN.getCodice()).getPreviousWeekForecast().getAmount() : 0;
  578.  
  579. Double nbmcScenarioPw = tableElements.get(CategoryEnum.NBMC_K.getCodice()) != null
  580. && tableElements.get(CategoryEnum.NBMC_K.getCodice()).getPreviousWeekForecast() != null ?
  581. tableElements.get(CategoryEnum.NBMC_K.getCodice()).getPreviousWeekForecast().getAmount() : 0;
  582.  
  583. Double controllExpScenarioPw = tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()) != null
  584. && tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getPreviousWeekForecast() != null ?
  585. tableElements.get(CategoryEnum.CONTROLLABLE_EXPENSES.getCodice()).getPreviousWeekForecast().getAmount() : 0;
  586.  
  587. Double allocExpScenarioPw = tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()) != null
  588. && tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getPreviousWeekForecast() != null ?
  589. tableElements.get(CategoryEnum.ALLOCATED_EXPENSES.getCodice()).getPreviousWeekForecast().getAmount() : 0;
  590.  
  591. Double ptiScenario = bmcMarginScenario - nbmcScenario - controllExpScenario - allocExpScenario;
  592.  
  593. Double ptiScenarioBudget = bmcMarginScenarioBudget - nbmcScenarioBudget - controllExpScenarioBudget - allocExpScenarioBudget;
  594.  
  595. Double ptiScenarioMx = bmcMarginScenarioMx - nbmcScenarioMx - controllExpScenarioMx - allocExpScenarioMx;
  596.  
  597. Double ptiScenarioCampaign = bmcMarginScenarioCampaign - nbmcScenarioCampaign - controllExpScenarioCampaign - allocExpScenarioCampaign;
  598.  
  599. Double ptiScenarioPw = bmcMarginScenarioPw - nbmcScenarioPw - controllExpScenarioPw - allocExpScenarioPw;
  600.  
  601. for (TreeNode child : treeTable.getChildren()) {
  602.  
  603. if (((ScenarioRow) child.getData()).getCategoryCode().equals(CategoryEnum.PTI_K.getCodice())) {
  604.  
  605. ScenarioRow scenarioUpdate = (ScenarioRow) child.getData();
  606. Double oldValueCw = scenarioUpdate.getCurrentWeekForecast() != null
  607. && scenarioUpdate.getCurrentWeekForecast().getAmount() != null ?
  608. scenarioUpdate.getCurrentWeekForecast().getAmount() : 0;
  609. scenarioUpdate.getCurrentWeekForecast().setAmount(ptiScenario);
  610.  
  611. Double oldValueMx = scenarioUpdate.getMx() != null
  612. && scenarioUpdate.getMx().getAmount() != null ?
  613. scenarioUpdate.getMx().getAmount() : 0;
  614. scenarioUpdate.getMx().setAmount(ptiScenarioMx);
  615.  
  616. Double oldValueBudget = scenarioUpdate.getBudget() != null
  617. && scenarioUpdate.getBudget().getAmount() != null ?
  618. scenarioUpdate.getBudget().getAmount() : 0;
  619. scenarioUpdate.getBudget().setAmount(ptiScenarioBudget);
  620.  
  621. Double oldValueCampaign = scenarioUpdate.getCampaignPlan() != null
  622. && scenarioUpdate.getCampaignPlan().getAmount() != null ?
  623. scenarioUpdate.getCampaignPlan().getAmount() : 0;
  624. scenarioUpdate.getCampaignPlan().setAmount(ptiScenarioCampaign);
  625.  
  626. Double oldValuePw = scenarioUpdate.getPreviousWeekForecast() != null
  627. && scenarioUpdate.getPreviousWeekForecast().getAmount() != null ?
  628. scenarioUpdate.getPreviousWeekForecast().getAmount() : 0;
  629. scenarioUpdate.getPreviousWeekForecast().setAmount(ptiScenarioPw);
  630. }
  631. }
  632. }
  633. }
  634.  
  635. for (Map.Entry<String, ScenarioRow> entry : tableElements.entrySet()) {
  636.  
  637. if (entry.getKey().startsWith(CategoryEnum.PTI_P.getCodice()) && entry.getKey().indexOf("_") > 1) {
  638.  
  639. String codeSuffix = "";
  640. if (entry.getKey().indexOf("_") > -1) {
  641. codeSuffix = entry.getKey().substring(entry.getKey().indexOf("_") + 1);
  642. }
  643.  
  644. Double ptiScenario = tableElements.get(CategoryEnum.PTI_K.getCodice() + "_" + codeSuffix) != null
  645. && tableElements.get(CategoryEnum.PTI_K.getCodice() + "_" + codeSuffix).getCurrentWeekForecast() != null
  646. && tableElements.get(CategoryEnum.PTI_K.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() != null ?
  647. tableElements.get(CategoryEnum.PTI_K.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() : 0;
  648.  
  649. Double netRevenueScenario = tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix) != null
  650. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getCurrentWeekForecast() != null
  651. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() != null ?
  652. tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getCurrentWeekForecast().getAmount() : 0;
  653.  
  654. Double ptiScenarioMx = tableElements.get(CategoryEnum.PTI_K.getCodice()) != null
  655. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getMx() != null
  656. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getMx().getAmount() != null ?
  657. tableElements.get(CategoryEnum.PTI_K.getCodice()).getMx().getAmount() : 0;
  658.  
  659. Double netRevenueScenarioMx = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  660. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getMx() != null
  661. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getMx().getAmount() != null ?
  662. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getMx().getAmount() : 0;
  663.  
  664. Double ptiScenarioBudget = tableElements.get(CategoryEnum.PTI_K.getCodice()) != null
  665. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getBudget() != null
  666. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getBudget().getAmount() != null ?
  667. tableElements.get(CategoryEnum.PTI_K.getCodice()).getBudget().getAmount() : 0;
  668.  
  669. Double netRevenueScenarioBudget = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  670. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getBudget() != null
  671. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getBudget().getAmount() != null ?
  672. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getBudget().getAmount() : 0;
  673.  
  674. Double ptiScenarioCampaign = tableElements.get(CategoryEnum.PTI_K.getCodice()) != null
  675. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getCampaignPlan() != null
  676. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getCampaignPlan().getAmount() != null ?
  677. tableElements.get(CategoryEnum.PTI_K.getCodice()).getCampaignPlan().getAmount() : 0;
  678.  
  679. Double netRevenueScenarioCampaign = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  680. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCampaignPlan() != null
  681. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCampaignPlan().getAmount() != null ?
  682. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCampaignPlan().getAmount() : 0;
  683.  
  684. Double ptiScenarioPw = tableElements.get(CategoryEnum.PTI_K.getCodice() + "_" + codeSuffix) != null
  685. && tableElements.get(CategoryEnum.PTI_K.getCodice() + "_" + codeSuffix).getPreviousWeekForecast() != null
  686. && tableElements.get(CategoryEnum.PTI_K.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() != null ?
  687. tableElements.get(CategoryEnum.PTI_K.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() : 0;
  688.  
  689. Double netRevenueScenarioPw = tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix) != null
  690. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getPreviousWeekForecast() != null
  691. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() != null ?
  692. tableElements.get(CategoryEnum.NET_REVENUE.getCodice() + "_" + codeSuffix).getPreviousWeekForecast().getAmount() : 0;
  693.  
  694. Double ptiPercScenario = netRevenueScenario != 0 ? (ptiScenario / netRevenueScenario) * 100 : 0;
  695.  
  696. Double ptiPercScenarioMx = netRevenueScenarioMx != 0 ? (ptiScenarioMx / netRevenueScenarioMx) * 100 : 0;
  697. Double ptiPercScenarioBudget = netRevenueScenarioBudget != 0 ? (ptiScenarioBudget / netRevenueScenarioBudget) * 100 : 0;
  698. Double ptiPercScenarioCampaign = netRevenueScenarioCampaign != 0 ? (ptiScenarioCampaign / netRevenueScenarioCampaign) * 100 : 0;
  699.  
  700. Double ptiPercScenarioPw = netRevenueScenarioPw != 0 ? (ptiScenarioPw / netRevenueScenarioPw) * 100 : 0;
  701.  
  702. Integer count = 0;
  703. for (TreeNode child : treeTable.getChildren()) {
  704. updateCurrentWeekForecastValue(child, CategoryEnum.PTI_P.getCodice(), codeSuffix, count, ptiPercScenario);
  705.  
  706. updateBudgetValue(child, CategoryEnum.PTI_P.getCodice(), codeSuffix, count, ptiPercScenarioBudget);
  707. updateMxValue(child, CategoryEnum.PTI_P.getCodice(), codeSuffix, count, ptiPercScenarioMx);
  708. updateCampaignValue(child, CategoryEnum.PTI_P.getCodice(), codeSuffix, count, ptiPercScenarioCampaign);
  709.  
  710. updatePreviousWeekForecastValue(child, CategoryEnum.PTI_P.getCodice(), codeSuffix, count, ptiPercScenarioPw);
  711. }
  712. }
  713. }
  714.  
  715. for (Map.Entry<String, ScenarioRow> entry : tableElements.entrySet()) {
  716.  
  717. if (entry.getKey().equals(CategoryEnum.PTI_P.getCodice())) {
  718.  
  719.  
  720. Double ptiScenario = tableElements.get(CategoryEnum.PTI_K.getCodice()) != null
  721. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getCurrentWeekForecast() != null
  722. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getCurrentWeekForecast().getAmount() != null ?
  723. tableElements.get(CategoryEnum.PTI_K.getCodice()).getCurrentWeekForecast().getAmount() : 0;
  724.  
  725. Double netRevenueScenario = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  726. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCurrentWeekForecast() != null
  727. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCurrentWeekForecast().getAmount() != null ?
  728. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCurrentWeekForecast().getAmount() : 0;
  729.  
  730. Double ptiScenarioMx = tableElements.get(CategoryEnum.PTI_K.getCodice()) != null
  731. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getMx() != null
  732. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getMx().getAmount() != null ?
  733. tableElements.get(CategoryEnum.PTI_K.getCodice()).getMx().getAmount() : 0;
  734.  
  735. Double netRevenueScenarioMx = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  736. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getMx() != null
  737. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getMx().getAmount() != null ?
  738. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getMx().getAmount() : 0;
  739.  
  740. Double ptiScenarioBudget = tableElements.get(CategoryEnum.PTI_K.getCodice()) != null
  741. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getBudget() != null
  742. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getBudget().getAmount() != null ?
  743. tableElements.get(CategoryEnum.PTI_K.getCodice()).getBudget().getAmount() : 0;
  744.  
  745. Double netRevenueScenarioBudget = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  746. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getBudget() != null
  747. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getBudget().getAmount() != null ?
  748. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getBudget().getAmount() : 0;
  749.  
  750. Double ptiScenarioCampaign = tableElements.get(CategoryEnum.PTI_K.getCodice()) != null
  751. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getCampaignPlan() != null
  752. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getCampaignPlan().getAmount() != null ?
  753. tableElements.get(CategoryEnum.PTI_K.getCodice()).getCampaignPlan().getAmount() : 0;
  754.  
  755. Double netRevenueScenarioCampaign = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  756. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCampaignPlan() != null
  757. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCampaignPlan().getAmount() != null ?
  758. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getCampaignPlan().getAmount() : 0;
  759.  
  760. Double ptiScenarioPw = tableElements.get(CategoryEnum.PTI_K.getCodice()) != null
  761. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getPreviousWeekForecast() != null
  762. && tableElements.get(CategoryEnum.PTI_K.getCodice()).getPreviousWeekForecast().getAmount() != null ?
  763. tableElements.get(CategoryEnum.PTI_K.getCodice()).getPreviousWeekForecast().getAmount() : 0;
  764.  
  765. Double netRevenueScenarioPw = tableElements.get(CategoryEnum.NET_REVENUE.getCodice()) != null
  766. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getPreviousWeekForecast() != null
  767. && tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getPreviousWeekForecast().getAmount() != null ?
  768. tableElements.get(CategoryEnum.NET_REVENUE.getCodice()).getPreviousWeekForecast().getAmount() : 0;
  769.  
  770. Double ptiPercScenario = netRevenueScenario != 0 ? (ptiScenario / netRevenueScenario) * 100 : 0;
  771.  
  772. Double ptiPercScenarioMx = netRevenueScenarioMx != 0 ? (ptiScenarioMx / netRevenueScenarioMx) * 100 : 0;
  773. Double ptiPercScenarioBudget = netRevenueScenarioBudget != 0 ? (ptiScenarioBudget / netRevenueScenarioBudget) * 100 : 0;
  774. Double ptiPercScenarioCampaign = netRevenueScenarioCampaign != 0 ? (ptiScenarioCampaign / netRevenueScenarioCampaign) * 100 : 0;
  775.  
  776. Double ptiPercScenarioPw = netRevenueScenarioPw != 0 ? (ptiScenarioPw / netRevenueScenarioPw) * 100 : 0;
  777.  
  778. for (TreeNode child : treeTable.getChildren()) {
  779.  
  780. if (((ScenarioRow) child.getData()).getCategoryCode().equals(CategoryEnum.PTI_P.getCodice())) {
  781.  
  782. ScenarioRow scenarioUpdate = (ScenarioRow) child.getData();
  783. Double oldValueCw = scenarioUpdate.getCurrentWeekForecast() != null
  784. && scenarioUpdate.getCurrentWeekForecast().getAmount() != null ?
  785. scenarioUpdate.getCurrentWeekForecast().getAmount() : 0;
  786. scenarioUpdate.getCurrentWeekForecast().setAmount(ptiPercScenario);
  787.  
  788. Double oldValueMx = scenarioUpdate.getMx() != null
  789. && scenarioUpdate.getMx().getAmount() != null ?
  790. scenarioUpdate.getMx().getAmount() : 0;
  791. scenarioUpdate.getMx().setAmount(ptiPercScenarioMx);
  792.  
  793. Double oldValueBudget = scenarioUpdate.getBudget() != null
  794. && scenarioUpdate.getBudget().getAmount() != null ?
  795. scenarioUpdate.getBudget().getAmount() : 0;
  796. scenarioUpdate.getBudget().setAmount(ptiPercScenarioBudget);
  797.  
  798. Double oldValueCampaign = scenarioUpdate.getCampaignPlan() != null
  799. && scenarioUpdate.getCampaignPlan().getAmount() != null ?
  800. scenarioUpdate.getCampaignPlan().getAmount() : 0;
  801. scenarioUpdate.getCampaignPlan().setAmount(ptiPercScenarioCampaign);
  802.  
  803. Double oldValuePw = scenarioUpdate.getPreviousWeekForecast() != null
  804. && scenarioUpdate.getPreviousWeekForecast().getAmount() != null ?
  805. scenarioUpdate.getPreviousWeekForecast().getAmount() : 0;
  806. scenarioUpdate.getPreviousWeekForecast().setAmount(ptiPercScenarioPw);
  807. }
  808.  
  809. }
  810. }
  811. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement