Project

General

Profile

Feature #1371 » BudgetCalculationController.js

Tri Rizqiaty, 07/21/2022 02:49 PM

 
1
Ext.define('MinovaES.controller.Budget.BudgetCalculationController', {
2
	extend : 'Ext.app.ViewController',
3
	alias : 'controller.BudgetCalculationController-controller',
4
	init : function () {
5
		this.control({
6
			'ViewBudgetCalculation [name=LoadData]' : {
7
				click : this.displayData
8
			},
9
			'ViewBudgetCalculation [name=ObjectType]' : {
10
				//change : this.CreateResult
11
			},
12
			'ViewBudgetCalculation [name=Execute]' : {
13
				click : this.Execute
14
			},
15
			'ViewBudgetCalculation [name=btnExport]' : {
16
				click : this.exportExcel
17
			},
18
			'ViewBudgetCalculation [name=btnSave]' : {
19
				click : this.SaveAdjusment
20
			}
21
		});
22
	},
23
	displayData : function () {
24
		var vObjType = Ext.ComponentQuery.query('[name=ObjectType]')[0].getValue();
25
		var tblName = "PDSBU0001";
26
		var paramList = "";
27
		var storeName = "";
28
		var _Scenario = Ext.ComponentQuery.query('[name=Scenario]')[0].getValue();
29
		var e_grid = Ext.ComponentQuery.query('[name=PHRBU0001]')[0];
30
		var cc_grid = Ext.ComponentQuery.query('[name=PHRBU0002]')[0];
31
		var p_grid = Ext.ComponentQuery.query('[name=PHRBU0003]')[0];
32

    
33
		if (_Scenario != "" && _Scenario != undefined) {
34
			paramList += _Scenario;
35
		}
36
		paramList += ",";
37
		if (vObjType != "" && vObjType != undefined) {
38
			paramList += vObjType;
39
		}
40

    
41
		paramList += ",";
42
		if (vObjType == 'CC') {
43
			storeName = 'storePHRBU0002';
44
			e_grid.setHidden(true);
45
			cc_grid.setHidden(false);
46
			p_grid.setHidden(true);
47
			var CostCenter = Ext.ComponentQuery.query('[name=CostCenter]')[0].getValue();
48
			if (CostCenter != "" && CostCenter != undefined) {
49
				paramList += CostCenter +','+CostCenter; //paramList += CostCenter //// edit by Tri nwh 20220712
50
			}
51
			//paramList += ",";
52
		} else if (vObjType == 'P') {
53
			storeName = 'storePHRBU0003';
54
			e_grid.setHidden(true);
55
			cc_grid.setHidden(true);
56
			p_grid.setHidden(false);
57
			var OrganizationID = Ext.ComponentQuery.query('[name=Position]')[0].getValue();
58
			if (OrganizationID != "" && OrganizationID != undefined) {
59

    
60
				paramList += OrganizationID;
61
			}
62
			paramList += ",";
63
		} else if (vObjType == 'E') {
64
			storeName = 'storePHRBU0001';
65
			e_grid.setHidden(false);
66
			cc_grid.setHidden(true);
67
			p_grid.setHidden(true);
68
			var EmployeeIDFrom = Ext.ComponentQuery.query('[name=EmployeeIDFrom]')[0].getValue();
69
			var EmployeeIDTo = Ext.ComponentQuery.query('[name=EmployeeIDTo]')[0].getValue();
70
			if ((EmployeeIDFrom != "" && EmployeeIDFrom != undefined) && (EmployeeIDTo != "" && EmployeeIDTo != undefined)) {
71
				paramList += EmployeeIDFrom + ',' + EmployeeIDTo;
72
			} else if (EmployeeIDFrom != "" && EmployeeIDFrom != undefined) {
73
				paramList += EmployeeIDFrom + ',0';
74
			} else if (EmployeeIDTo != "" && EmployeeIDTo != undefined) {
75
				paramList += EmployeeIDTo + ',0'; ;
76
			} else {
77
				paramList += ",,";
78
			}
79
			//tblName = 'PHRBUTREMP';
80
		}
81
		var overView = Ext.StoreMgr.lookup(storeName);
82

    
83
		Ext.Ajax.request({
84
			async : false,
85
			//method : 'POST',=
86
			url : '/UserControl/GetStore',
87
			params : {
88
				tableName : tblName,
89
				param : paramList
90
			},
91

    
92
			success : function (response) {
93
				var results = Ext.decode(response.responseText);
94
				overView.removeAll();
95
				overView.loadData(results.data);
96
			}
97
		});
98
	},
99
	CreateResult : function () {
100
		var vObjType = Ext.ComponentQuery.query('[name=ObjectType]')[0].getValue();
101
		var ccResult = Ext.ComponentQuery.query('[name=PHRBUTRCOSTCENTER]')[0];
102
		var vResult = Ext.ComponentQuery.query('[name=PHRBUTRVACANT]')[0];
103
		var eResult = Ext.ComponentQuery.query('[name=PHRBUTREMP]')[0];
104

    
105
		if (vObjType == 'CC') {
106
			ccResult.setHidden(false);
107
			vResult.setHidden(true);
108
			eResult.setHidden(true);
109
		} else if (vObjType == 'V') {
110
			ccResult.setHidden(true);
111
			vResult.setHidden(false);
112
			eResult.setHidden(true);
113
		} else if (vObjType == 'E') {
114
			ccResult.setHidden(true);
115
			vResult.setHidden(true);
116
			eResult.setHidden(false);
117
		}
118
	},
119
	Execute : function () {
120
		var me = this;
121
		var MainBudgetCalculation = Ext.ComponentQuery.query('[name=BudgetFilter]')[0].getForm();
122
		var formValid = MainBudgetCalculation.isValid();
123
		Ext.ComponentQuery.query('[name=CostObjectID2]')[0].setValue("");
124
		Ext.ComponentQuery.query('[name=CostObjectID2]')[0].setValue("");
125
		if (formValid) {
126
			var vObjType = Ext.ComponentQuery.query('[name=ObjectType]')[0].getValue();
127
			var storeName = "";
128
			var e_grid = Ext.ComponentQuery.query('[name=PHRBU0001]')[0];
129
			var cc_grid = Ext.ComponentQuery.query('[name=PHRBU0002]')[0];
130
			var p_grid = Ext.ComponentQuery.query('[name=PHRBU0003]')[0];
131
			if (vObjType == 'CC') {
132
				storeName = 'storePHRBU0002';
133
				var CostCenter = Ext.ComponentQuery.query('[name=CostCenter]')[0].getValue();
134
				if (CostCenter != "" && CostCenter != undefined) {
135
					Ext.ComponentQuery.query('[name=CostObjectID1]')[0].setValue(CostCenter);
136
				}
137
				var BudgetType = Ext.ComponentQuery.query('[name=BudgetType]')[0].getValue();
138
				if (BudgetType != "" && BudgetType != undefined) {
139
					Ext.ComponentQuery.query('[name=CostObjectID2]')[0].setValue(BudgetType);
140
				}
141
			} else if (vObjType == 'P') {
142
				storeName = 'storePHRBU0003';
143
				var OrganizationID = Ext.ComponentQuery.query('[name=Position]')[0].getValue();
144
				if (OrganizationID != "" && OrganizationID != undefined) {
145
					Ext.ComponentQuery.query('[name=CostObjectID1]')[0].setValue(OrganizationID);
146
				}
147
			} else if (vObjType == 'E') {
148
				storeName = 'storePHRBU0001';
149
				var EmployeeIDFrom = Ext.ComponentQuery.query('[name=EmployeeIDFrom]')[0].getValue();
150
				var EmployeeIDTo = Ext.ComponentQuery.query('[name=EmployeeIDTo]')[0].getValue();
151
				if ((EmployeeIDFrom != "" && EmployeeIDFrom != undefined) && (EmployeeIDTo != "" && EmployeeIDTo != undefined)) {
152
					Ext.ComponentQuery.query('[name=CostObjectID1]')[0].setValue(EmployeeIDFrom);
153
					Ext.ComponentQuery.query('[name=CostObjectID2]')[0].setValue(EmployeeIDTo);
154
				} else if (EmployeeIDFrom != "" && EmployeeIDFrom != undefined) {
155
					Ext.ComponentQuery.query('[name=CostObjectID1]')[0].setValue(EmployeeIDFrom);
156
					Ext.ComponentQuery.query('[name=CostObjectID2]')[0].setValue(EmployeeIDFrom);
157
				} else if (EmployeeIDTo != "" && EmployeeIDTo != undefined) {
158
					Ext.ComponentQuery.query('[name=CostObjectID1]')[0].setValue(EmployeeIDTo);
159
					Ext.ComponentQuery.query('[name=CostObjectID2]')[0].setValue(EmployeeIDTo);
160
				}
161
			}
162

    
163
			var overView = Ext.StoreMgr.lookup(storeName);
164
			var formValues = MainBudgetCalculation.getValues();
165
			var params = {
166
				serviceName : 'Budget.asmx',
167
				methodName : 'calculatebudget',
168
				parameter : 'param=' + Ext.encode(formValues) + '&userid=' +  MinovaUtil.GetUserName()
169
			};
170
			MinovaAjaxPost('/InvokeService/Invoke/', params, function (xhr) {
171
				var result = Ext.decode(xhr.responseText);
172
				if (result.success) {
173
					MinovaMessage('Not Null', '000006', '', 'S');
174
					me.displayData();
175
				} else {
176
					MinovaMessage('', '000005', result.message.text, 'E');
177
				}
178

    
179
				me.displayData();
180
			});
181
		}
182
	},
183
	exportExcel : function () {
184
		var vObjType = Ext.ComponentQuery.query('[name=ObjectType]')[0].getValue();
185
		var storeName = "";
186
		if (vObjType == 'CC')
187
			storeName = 'storePHRBU0002';
188
		else if (vObjType == 'E')
189
			storeName = 'storePHRBU0001';
190
		else if (vObjType == 'P')
191
			storeName = 'storePHRBU0003';
192

    
193
		var grid = Ext.StoreMgr.lookup(storeName);
194
		this.href = 'data:application/vnd.ms-excel;base64,' + Ext.ux.exporter.Base64.encode(Ext.ux.exporter.Exporter.exportAny(grid, 'csv'));
195
		if (this.href) {
196
			window.location.href = this.href;
197
		}
198
	},
199
	SaveAdjusment : function () {
200
		var me = this;
201
		var MainBudgetCalculation = Ext.ComponentQuery.query('[name=BudgetFilter]')[0].getForm();
202
		var formValid = MainBudgetCalculation.isValid();
203
		if (formValid) {
204
			var vObjType = Ext.ComponentQuery.query('[name=ObjectType]')[0].getValue();
205
			var storeName = "";
206
			if (vObjType == 'CC') {
207
				storeName = 'storePHRBU0002';
208
				var CostCenter = Ext.ComponentQuery.query('[name=CostCenter]')[0].getValue();
209
				if (CostCenter != "" && CostCenter != undefined) {
210
					Ext.ComponentQuery.query('[name=CostObjectID1]')[0].setValue(CostCenter);
211
				}
212
				var BudgetType = Ext.ComponentQuery.query('[name=BudgetType]')[0].getValue();
213
				if (BudgetType != "" && BudgetType != undefined) {
214
					Ext.ComponentQuery.query('[name=CostObjectID2]')[0].setValue(BudgetType);
215
				}
216
			} else if (vObjType == 'P') {
217
				storeName = 'storePHRBU0003';
218
				var OrganizationID = Ext.ComponentQuery.query('[name=Position]')[0].getValue();
219
				if (OrganizationID != "" && OrganizationID != undefined) {
220
					Ext.ComponentQuery.query('[name=CostObjectID1]')[0].setValue(OrganizationID);
221
				}
222
			} else if (vObjType == 'E') {
223
				storeName = 'storePHRBU0001';
224
				var EmployeeIDFrom = Ext.ComponentQuery.query('[name=EmployeeIDFrom]')[0].getValue();
225
				var EmployeeIDTo = Ext.ComponentQuery.query('[name=EmployeeIDTo]')[0].getValue();
226
				if ((EmployeeIDFrom != "" && EmployeeIDFrom != undefined) && (EmployeeIDTo != "" && EmployeeIDTo != undefined)) {
227
					Ext.ComponentQuery.query('[name=CostObjectID1]')[0].setValue(EmployeeIDFrom);
228
					Ext.ComponentQuery.query('[name=CostObjectID2]')[0].setValue(EmployeeIDTo);
229
				} else if (EmployeeIDFrom != "" && EmployeeIDFrom != undefined) {
230
					Ext.ComponentQuery.query('[name=CostObjectID1]')[0].setValue(EmployeeIDFrom);
231
					Ext.ComponentQuery.query('[name=CostObjectID2]')[0].setValue(EmployeeIDFrom);
232
				} else if (EmployeeIDTo != "" && EmployeeIDTo != undefined) {
233
					Ext.ComponentQuery.query('[name=CostObjectID1]')[0].setValue(EmployeeIDTo);
234
					Ext.ComponentQuery.query('[name=CostObjectID2]')[0].setValue(EmployeeIDTo);
235
				}
236
			}
237

    
238
			var overView = Ext.StoreMgr.lookup(storeName);
239
			var data = Ext.encode(Ext.pluck(overView.data.items, 'data'));
240
			var formValues = MainBudgetCalculation.getValues();
241

    
242
			var params = {
243
				serviceName : 'Budget.asmx',
244
				methodName : 'SaveAdjusted',
245
				parameter : 'param=' + Ext.encode(formValues)
246
				 + '&data=' + data + '&userid=' +  MinovaUtil.GetUserName()
247
			};
248
			MinovaAjaxPost('/InvokeService/Invoke/', params, function (xhr) {
249
				var result = Ext.decode(xhr.responseText);
250
				if (result.success) {
251
					MinovaMessage('Not Null', '000006', '', 'S');
252
					me.displayData(a, b, c);
253
				} else {
254
					MinovaMessage('', '000005', result.message.text, 'E');
255
				}
256
			});
257

    
258
			me.displayData();
259
		}
260
	}
261
})
(4-4/9)