Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.43 KB | None | 0 0
  1. sap.ui.define([
  2. "sap/ui/core/mvc/Controller",
  3. "sap/m/MessageBox",
  4. "../utilities",
  5. "sap/ui/core/routing/History",
  6. "../Formatter"
  7. ], function(BaseController, MessageBox, Utilities, History, Formatter) {
  8. "use strict";
  9. return BaseController.extend("com.techedge.entitydemo.controller.Loading.LoadSuppliesMaterialsList", {
  10. /* Starting the formatter for dynamic translations*/
  11. formatter: Formatter,
  12.  
  13. onInit: function() {
  14. this.list = this.byId('AddedMcList');
  15. this.mBindingOptions = {};
  16. this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
  17. this.oRouter.getTarget("LoadSuppliesMaterialsList").attachDisplay(jQuery.proxy(this.handleRouteMatched, this));
  18. /* this.oRouter.getRoute("EntityList").attachPatternMatched(this.onGroupSelected, this);*/
  19. this.oRouter.getTarget("LoadSuppliesMaterialsListNewRow").attachDisplay(jQuery.proxy(this.handleRouteMatchedNewRow, this));
  20. this._arrayMastercode = [];
  21.  
  22. },
  23.  
  24. handleRouteMatched: function(oEvent) {
  25. this.byId('objectHeaderSummary').setTitle(window.currentSupplier.DS_ENTITY_DESCRIPTION);
  26. var oBundle = this.getView().getModel("i18n").getResourceBundle();
  27. var newText = oBundle.getText("erpCode");
  28. this.byId('objectAttributeErp').setText(newText + ': ' + window.currentSupplier.CD_ERP_SHIPMENT.replace(/^0+/, ''))
  29. this.list.removeAllItems();
  30. var subtitle = this.byId('objectAttributeSummary').getText().split(':')[0];
  31. this.byId('objectAttributeSummary').setText(subtitle + ': 0');
  32. },
  33.  
  34. handleRouteMatchedNewRow: function(oEvent) {
  35. var titleNewRow = window.currentMastercode.CD + ' - ' + window.currentMastercode.TX;
  36. var numberNewRow = window.currentMastercode.QTY;
  37. var umNewRow = window.currentMastercode.CD_UM;
  38. var object = new sap.m.ObjectListItem({
  39. title: titleNewRow,
  40. number: numberNewRow,
  41. numberUnit: umNewRow
  42. });
  43. this.list.addItem(object);
  44.  
  45.  
  46. var subtitle = this.byId('objectAttributeSummary').getText().split(':')[0];
  47. var previousQty = parseInt(this.byId('objectAttributeSummary').getText().split(':')[1]);
  48.  
  49. var items = this.list.getItems();
  50. var qty = 0;
  51. for (var i = 0; i < items.length; i++) {
  52. qty += parseInt(items[i].getNumber());
  53. }
  54. var subtitle = this.byId('objectAttributeSummary').getText().split(':')[0];
  55. this.byId('objectAttributeSummary').setText(subtitle + ': ' + qty);
  56.  
  57.  
  58. //var newQty = previousQty + parseInt(numberNewRow);
  59. //this.byId('objectAttributeSummary').setText(subtitle + ': ' + newQty);
  60. this._arrayMastercode.push(window.currentMastercode);
  61. debugger;
  62. window.currentMastercode = {};
  63. },
  64.  
  65.  
  66. //------------------------------------
  67. //---------- Button functions ----------
  68. //----------------------------------------
  69. onAddMC: function() {
  70. if (this.list.getSelectedItems().length === 0) {
  71. this.doNavigate("LoadSuppliesAddMaterial", "", "", "");
  72. } else if (this.list.getSelectedItems().length === 1) {
  73. var that = this;
  74. var query = encodeURI(sap.hybrid.OData.offlineStore.appOfflineStore.storeAll.serviceUri +
  75. "/MasterCodesView?$filter=CD eq '" + this.list.getSelectedItems()[0].getTitle().split(' -')[0] + "'");
  76. var success = function(data) {
  77. if (data.results.length > 0) {
  78. window.currentMastercode = data.results[0];
  79. var context = {};
  80. context.sPath = '/' + data.results[0].__metadata.uri.split('/')[data.results[0].__metadata.uri.split('/').length - 1];
  81. that.doNavigate("LoadSuppliesMaterialQty", context, "", "", true);
  82. }
  83. };
  84. Utilities._makeOfflineQuery(query, success, function() {});
  85. this.list.getSelectedItems()[0].destroy();
  86. }
  87. },
  88. onRemoveMC: function(event) {
  89. console.log('Remove MC');
  90.  
  91. if (this.list.getItems().length > 0) {
  92. var selected = this.list.getSelectedItems();
  93. for (var i = 0; i < selected.length; i++) {
  94. selected[i].destroy();
  95. }
  96. } else {
  97. //list is empty
  98. }
  99.  
  100. var items = this.list.getItems();
  101. var qty = 0;
  102. for (var i = 0; i < items.length; i++) {
  103. qty += parseInt(items[i].getNumber());
  104. }
  105. var subtitle = this.byId('objectAttributeSummary').getText().split(':')[0];
  106. this.byId('objectAttributeSummary').setText(subtitle + ': ' + qty);
  107. },
  108. onClearMC: function() {
  109.  
  110. console.log('Clear');
  111. if (this.list.getItems().length > 0) {
  112. this.list.selectAll();
  113.  
  114. } else {
  115. //list is empty
  116. }
  117. },
  118.  
  119.  
  120. //----------------------------------------
  121. //--------------------------------------
  122. //------------------------------------
  123.  
  124. _onPageNavButtonPress: function() {
  125. this.doNavigate("LoadingList", "", "", "");
  126. },
  127.  
  128.  
  129.  
  130. getQueryParameters: function(oLocation) {
  131. var oQuery = {};
  132. var aParams = oLocation.search.substring(1).split("&");
  133. for (var i = 0; i < aParams.length; i++) {
  134. var aPair = aParams[i].split("=");
  135. oQuery[aPair[0]] = decodeURIComponent(aPair[1]);
  136. }
  137. return oQuery;
  138. },
  139.  
  140. doNavigate: function(sRouteName, oBindingContext, fnPromiseResolve, sViaRelation, viaAdd) {
  141. if (viaAdd === true) {
  142. var sPath = oBindingContext.sPath;
  143. var oModel = null;
  144. } else {
  145. var sPath = oBindingContext ? oBindingContext.getPath() : null;
  146. var oModel = oBindingContext ? oBindingContext.getModel() : null;
  147. }
  148.  
  149. var sEntityNameSet;
  150. if (sPath !== null && sPath !== "") {
  151. if (sPath.substring(0, 1) === "/") {
  152. sPath = sPath.substring(1);
  153. }
  154. sEntityNameSet = sPath.split("(")[0];
  155. }
  156. var sNavigationPropertyName;
  157. var sMasterContext = this.sMasterContext ? this.sMasterContext : sPath;
  158. if (sEntityNameSet !== null) {
  159. sNavigationPropertyName = sViaRelation || this.getOwnerComponent().getNavigationPropertyForNavigationWithContext(sEntityNameSet,
  160. sRouteName);
  161. }
  162. if (sNavigationPropertyName !== null && sNavigationPropertyName !== undefined) {
  163. if (sNavigationPropertyName === "") {
  164. this.oRouter.navTo(sRouteName, {
  165. context: sPath,
  166. masterContext: sMasterContext
  167. }, false);
  168. } else {
  169. oModel.createBindingContext(sNavigationPropertyName, oBindingContext, null, function(bindingContext) {
  170. if (bindingContext) {
  171. sPath = bindingContext.getPath();
  172. if (sPath.substring(0, 1) === "/") {
  173. sPath = sPath.substring(1);
  174. }
  175. } else {
  176. sPath = "undefined";
  177. }
  178. // If the navigation is a 1-n, sPath would be "undefined" as this is not supported in Build
  179. if (sPath === "undefined") {
  180. this.oRouter.navTo(sRouteName);
  181. } else {
  182. this.oRouter.navTo(sRouteName, {
  183. context: sPath,
  184. masterContext: sMasterContext
  185. }, false);
  186. }
  187. }.bind(this));
  188. }
  189. } else {
  190. this.oRouter.navTo(sRouteName, {
  191. context: sPath
  192. });
  193. }
  194. if (typeof fnPromiseResolve === "function") {
  195. fnPromiseResolve();
  196. }
  197. },
  198. onContinuePress: function(oEvent) {
  199. //CREATE + FLUSH
  200. debugger;
  201. var that = this;
  202. var success = function(results){
  203.  
  204. if (that._arrayMastercode && that._arrayMastercode.length !== 0) {
  205. var urlMovementsConfig = encodeURI(sap.hybrid.OData.offlineStore.appOfflineStore.storeAll.serviceUri + "MovementsConfig");
  206. var oHeaders = {};
  207. oHeaders['Content-Type'] = "application/json";
  208. oHeaders['accept'] = "application/json";
  209.  
  210. // Iterate over all objects and update offlineStore
  211.  
  212. for (var i = 0; i < that._arrayMastercode.length; i++) {
  213. var currObj = that._arrayMastercode[i];
  214.  
  215. var newUpdateObjMovementsConfig = [];
  216. newUpdateObjMovementsConfig = {
  217. "CD_MOVEMENT_TYPE": "SUP",
  218. "CD_ITEM_TYPE": "PRO",
  219. "ID_ITEM": currObj.ID,
  220. "ID_CENTER": 2080,
  221. "CD_LOC_TYPE": "T001",
  222. "IS_FINAL_QTY": "1",
  223. "DT_MOVEMENT": "/Date(1496016000000)/"
  224. };
  225. var requestMovementsConfig = {
  226. headers: oHeaders,
  227. requestUri: urlMovementsConfig,
  228. method: "POST",
  229. data: newUpdateObjMovementsConfig
  230. };
  231.  
  232.  
  233. var match = results.results.find(function(el){
  234. return el.ID_ITEM === currObj.ID;
  235. });
  236. if(typeof (match) !== 'undefined'){
  237. requestMovementsConfig.requestUri = match.__metadata.uri;
  238. requestMovementsConfig.method = 'PUT';
  239.  
  240. }
  241.  
  242.  
  243. //Database write
  244. OData.request(requestMovementsConfig, function(res) {
  245. console.log("success", res)
  246. // window.somethingToSync = true;
  247.  
  248. jQuery.sap.require("jquery.sap.storage");
  249. var locStorage = jQuery.sap.storage(jQuery.sap.storage.Type.local);
  250. locStorage.remove('somethingToSync');
  251. locStorage.put("somethingToSync", 1);
  252. that._arrayMastercode = [];
  253. that.doNavigate("Launchpad", "", "", "");
  254.  
  255.  
  256.  
  257. }, function(res) {
  258. console.log("failure", res)
  259. });
  260.  
  261.  
  262.  
  263. // STO14
  264. var urlStockWarehouseView = encodeURI(sap.hybrid.OData.offlineStore.appOfflineStore.storeAll.serviceUri + "StockWarehouseView");
  265.  
  266. // Iterate over all objects and update offlineStore
  267.  
  268. for (var i = 0; i < that._arrayMastercode.length; i++) {
  269. var currObj = that._arrayMastercode[i];
  270.  
  271. var newUpdateObjStockWarehouseView = [];
  272. newUpdateObjStockWarehouseView = {
  273. "CD_LOC_TYPE": "SUP",
  274. "ID_LOCATION": 3093,
  275. "ID_ITEM": currObj.ID,
  276. "ID_CENTER": 2080,
  277. "FL_QTY": "22222222222222",
  278. "CD_ITEM_TYPE": "PRO",
  279. "CD_ITEM_BATCH": "000-1012-0920-I"
  280. };
  281.  
  282.  
  283. var requestStockWarehouseView = {
  284. headers: oHeaders,
  285. requestUri: urlStockWarehouseView,
  286. method: "POST",
  287. data: newUpdateObjStockWarehouseView
  288. };
  289.  
  290.  
  291. /* var match = results.results.find(function(el){
  292. return el.ID_ITEM === currObj.ID;
  293. });
  294. if(typeof (match) !== 'undefined'){
  295. requestMovementsConfig.requestUri = match.__metadata.uri;
  296. requestMovementsConfig.method = 'PUT';
  297.  
  298. } */
  299.  
  300.  
  301. //Database write
  302. OData.request(requestStockWarehouseView, function(res) {
  303. console.log("success", res)
  304. // window.somethingToSync = true;
  305.  
  306. jQuery.sap.require("jquery.sap.storage");
  307. var locStorage = jQuery.sap.storage(jQuery.sap.storage.Type.local);
  308. locStorage.remove('somethingToSync');
  309. locStorage.put("somethingToSync", 1);
  310. that._arrayMastercode = [];
  311. that.doNavigate("Launchpad", "", "", "");
  312.  
  313.  
  314.  
  315. }, function(res) {
  316. console.log("failure", res)
  317. });
  318.  
  319. }
  320.  
  321.  
  322.  
  323. }
  324.  
  325.  
  326.  
  327. };
  328. var fail = function(){};
  329. var query = encodeURI(sap.hybrid.OData.offlineStore.appOfflineStore.storeAll.serviceUri + "MovementsConfig");
  330.  
  331. Utilities._makeOfflineQuery(query, success, fail);
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338. // this._arrayMastercode = [];
  339.  
  340. // window.hasLocalChange = true;
  341. //this.doNavigate("Launchpad", "", "", "");
  342. }
  343.  
  344.  
  345.  
  346. });
  347. }, /* bExport= */
  348. true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement