Project

General

Profile

Bug #2098 » MaintainMasterData.txt

Saswanto Tampan, 04/10/2023 02:53 PM

 
1
if(mdcode == ""){
2
	var md = cmbMasterData.getValue();}
3
else{
4
	var md = mdcode;}
5
var _idTab = program + '_tab_' + md;
6
if (pnlMDbody.findById(_idTab) != null) 
7
{
8
	pnlMDbody.findById(_idTab).show();
9
	return;
10
}
11

    
12
else
13
{
14

    
15
	var empid = hidEmpId.getValue();
16
	var percode = perCode.getValue(); 
17
	var accesscode = accessCode.getValue();
18
	var mdcat = mdCat.getValue();
19
	var gen = percode+mdcat+accesscode+md+empid;
20
    //alert(gen);
21
	var spload = "0";
22
	var spval = "0";
23
	
24
	datacmbMasterData.each(function(rec){	
25
		var id = rec.get('code');
26
		if (md == id)
27
		{
28
		   	spload = rec.get('load');
29
			spval = rec.get('val');	
30
		}
31
	});
32
		
33
	var stringArray = new Array();
34
		stringArray[gen] = new Ext.data.JsonStore({
35
	        fields: ["field_name", "column_name", "class", "gridview", "read_only", "required", "max_size", "min_value", "max_value", "default_value", "controller_store", "width", "anchor", "column_no", "popup_func", "select_func", "change_func", "grid_renderer_func", "select_func_target", "change_func_target", "submit_value"]
36
	    });
37
	var stringPrimaryKey = new Array();
38
		stringPrimaryKey[gen] = new Ext.data.JsonStore({
39
	        fields: ["field_name", "column_name"]
40
	    });
41

    
42
	$.ajax({
43
	       
44
	    url : "Devt/getStructureMD",
45
	    data : {md_code:md, per_code:percode},
46
	    async:false,
47
	    success : function(result){
48
	    
49
		stringArray[gen].loadData(result.data.column);
50
		stringPrimaryKey[gen].loadData(result.data.PK);
51
		
52
	    if(result.success==false)
53
	    {
54
	       alert("Error On Save");
55
	    }
56
	    }
57

    
58
	});
59

    
60
	var jsGetGrid = new Array();
61
		jsGetGrid[gen] = new Ext.data.JsonStore({
62
	        metaData: true,
63
	        root: 'rows',
64
			url: 'Devt/getDataMDLimit',
65
			baseParams : {
66
					start : 0,
67
					limit : 25,
68
					cmd : 'save',
69
					emp_id : '00000001',
70
					md_cat : '0001',
71
					per_code : 'emp',
72
					from_period : '',
73
                    to_period : ''
74
				}
75
	    });
76
	jsGetGrid[gen].on('render', function(){new Ext.data.JsonReader();});
77
	jsGetGrid[gen].on('beforeload', function(){
78
	
79
		var o4 = Ext.getCmp("start_period_" + gen)
80
		var o5 = Ext.getCmp("end_period_" + gen)
81
		var val4 = ''
82
		var val5 = ''
83
		if (o4 != undefined) val4 = o4.getValue();
84
		if (o5 != undefined) val5 = o5.getValue();
85
		if (val4 != '') val4 = val4.format('d/m/Y');
86
		if (val5 != '') val5 = val5.format('d/m/Y');
87

    
88
		jsGetGrid[gen].setBaseParam('cmd', 'save')
89
		jsGetGrid[gen].setBaseParam('emp_id', empid)
90
		jsGetGrid[gen].setBaseParam('md_cat', md)
91
		jsGetGrid[gen].setBaseParam('per_code', percode)
92
		jsGetGrid[gen].setBaseParam('from_period', val4)
93
		jsGetGrid[gen].setBaseParam('to_period', val5)
94
	
95
	});
96

    
97
	var btnhide = false;
98
	if (accesscode == "main"){
99
		btnhide = false;
100
		}
101
		
102
	if (accesscode == "disp"){
103
		btnhide = true;
104
		}
105
	
106
	var btnRefresh = new Array();
107
		btnRefresh[gen] = new Ext.Button({
108
			text : 'Refresh',
109
			hidden : btnhide,
110
			iconCls: 'icon-database_refresh'
111
		});
112
	btnRefresh[gen].on('click', function(){pnlMDGrid[gen].el.mask("Loading Data...", "x-mask-loading"); refreshgrid(); pnlMDGrid[gen].el.unmask();});
113
		
114
	var btnAdd = new Array();
115
		btnAdd[gen] = new Ext.Button({
116
			text : 'Add',
117
			hidden : btnhide,
118
			iconCls: 'icon-add'
119
		});
120
	btnAdd[gen].on('click', function(){addclick(); pnlForm[gen].getForm().reset(); _pnlTemp.layout.setActiveItem(1); action[gen].setValue("insert"); actionCode.setValue("insert"); copyCode[gen].setValue("no"); initload();});
121

    
122
	var btnCopy = new Array();
123
		btnCopy[gen] = new Ext.Button({
124
			text : 'Copy',
125
			hidden : btnhide,
126
			iconCls: 'icon-page_copy'
127
		});
128
	btnCopy[gen].on('click', function(){_pnlTemp.layout.setActiveItem(1); pnlForm[gen].getForm().reset(); action[gen].setValue("insert"); actionCode.setValue("insert"); copyCode[gen].setValue("yes"); var selected =pnlMDGrid[gen].getSelectionModel().getSelected(); pnlForm[gen].getForm().loadRecord(selected); md_type[gen].setValue(md_temp); initload();});
129

    
130
	var btnDel = new Array();
131
		btnDel[gen] = new Ext.Button({
132
			text : 'Delete',
133
			hidden : btnhide,
134
			iconCls: 'icon-delete'
135
		});
136
	btnDel[gen].on('click', function(){delclick();});
137

    
138
	var btnSave = new Array();
139
		btnSave[gen] = new Ext.Button({
140
			text : 'Save',
141
			hidden : btnhide,
142
			iconCls: 'icon-table_save'
143
		});
144
	btnSave[gen].on('click', function(){saveclick();});
145

    
146
	var btnCancel = new Array();
147
		btnCancel[gen] = new Ext.Button({
148
			text : 'Cancel',
149
			iconCls: 'icon-arrow_undo'
150
		});
151
	btnCancel[gen].on('click', function(){refreshgrid(); _pnlTemp.layout.setActiveItem(0); action[gen].setValue("update");});
152

    
153
	var btnComplete = new Array();
154
		btnComplete[gen] = new Ext.Button({
155
			text : 'Activity Completed',
156
			iconCls: 'icon-tick'
157
		});
158
	btnComplete[gen].on('click', function(){completeclick();});
159

    
160
	var btnFollowUp = new Array();
161
		btnFollowUp[gen] = new Ext.Button({
162
			text : 'Follow-Up Activity',
163
			iconCls: 'icon-page_forward'
164
		});
165
	btnFollowUp[gen].on('click', function(){followupclick();});
166

    
167
	var pnlFormleft = new Array();
168
		pnlFormleft[gen] = new Ext.Panel({
169
			bodyStyle:'padding:5px 5px 0',
170
			border:false,
171
			isForm:true,
172
			layout:'form',
173
			height:380,
174
			width:350
175
	    });
176
		
177
	var pnlFormright = new Array();
178
		pnlFormright[gen] = new Ext.Panel({
179
			bodyStyle:'padding:5px 5px 0',
180
			border:false,
181
			isForm:true,
182
			layout:'form',
183
			height:380,
184
			width:350
185
	    });
186

    
187
		var pnlFormTop = new Array();
188
			pnlFormTop[gen] = new Ext.Panel({
189
				bodyStyle:'padding:5px 5px 0',
190
				labelWidth:120,
191
				border:false,
192
				isForm:true,
193
				layout:'hbox',
194
				height:380,
195
				items:[pnlFormleft[gen], pnlFormright[gen]]
196
			});
197
			
198
			
199
		var pnlFormBottom = new Array();
200
			pnlFormBottom[gen] = new Ext.Panel({
201
				layout: 'fit',
202
				border:false,
203
				height: 500,
204
				collapsible: true,
205
				autoScroll:true,
206
				id: "pnlFormBottom"+gen
207
			});
208
			
209
		var pnlForm = new Array(); //-- Modif by Muchlis
210
			pnlForm[gen] = new Ext.form.FormPanel({
211
				border: false,
212
				autoScroll:true,
213
				fileUpload: true,
214
				frame:false,
215
				labelWidth:120,
216
				layout:'anchor',
217
				items:[pnlFormTop[gen]]
218
			});
219
			pnlForm[gen].on('beforeaction',function(){
220
														if(!pnlForm[gen].getForm().isValid()){
221
																//alert("One or more fields are empty, please fill data to continue."); return
222
																Ext.Msg.show({
223
																	title: 'Error',
224
																	msg: 'One or more fields are empty, please fill data to continue.',
225
																	buttons: Ext.Msg.OK,
226
																	animEl: 'elId',
227
																	icon: Ext.MessageBox.ERROR
228
																});
229
														} 
230
			}); // add by irwan 20110502
231

    
232
		var pnlParentForm = new Array();
233
			pnlParentForm[gen] =  new Ext.Panel({
234
				frame:false,
235
				autoScroll:true,
236
				layout: 'anchor',
237
				height:1000,
238
				region: 'north',	
239
				bbar:[btnSave[gen], btnDel[gen], btnCancel[gen]],
240
				items: [pnlForm[gen],pnlFormBottom[gen]]
241
			});
242
			
243
		var paging = new Array();
244
			paging[gen] = {
245
								xtype : 'paging',
246
								store : jsGetGrid[gen],
247
								displayInfo : true,
248
								pageSize : 25,
249
								prependButtons : true
250
							};
251
		
252
		if(md == '0027' && accesscode == 'main')
253
		{
254
			var pnlMDGrid = new Array();	
255
				pnlMDGrid[gen] = new Ext.grid.GridPanel({
256
					store:jsGetGrid[gen],
257
					columns:'[]',
258
					height:160,
259
					loadMask:'true',
260
					region:'center',
261
					split:'true',
262
					tbar:[btnAdd[gen],btnCopy[gen],{xtype: 'tbfill'},{xtype: 'tbseparator'},btnRefresh[gen]],
263
					bbar:[btnComplete[gen],btnFollowUp[gen],paging[gen]]
264
				});
265
			pnlMDGrid[gen].on('rowdblclick', function(thisGrid, rowIndex){
266
						action[gen].setValue("update");
267
						actionCode.setValue("update"); 
268
						copyCode[gen].setValue("no");
269
						_pnlTemp.layout.setActiveItem(1); 
270
						var selected =pnlMDGrid[gen].getSelectionModel().getSelected(); 
271
						pnlForm[gen].getForm().loadRecord(selected); 
272
						var record = thisGrid.getStore().getAt(rowIndex); 
273
						assignPK(record); 
274
						md_type[gen].setValue(md_temp); 
275
						initload();
276
				});
277
		}
278
		else
279
		{
280
			var pnlMDGrid = new Array();	
281
				pnlMDGrid[gen] = new Ext.grid.GridPanel({
282
					store:jsGetGrid[gen],
283
					columns:'[]',
284
					height:165,
285
					loadMask:'true',
286
					region:'center',
287
					split:'true',
288
					tbar:[btnAdd[gen],btnCopy[gen],{xtype: 'tbfill'},{xtype: 'tbseparator'},btnRefresh[gen]],
289
					bbar:[paging[gen]]
290
				});
291
			pnlMDGrid[gen].on('rowdblclick', function(thisGrid, rowIndex){
292
						action[gen].setValue("update");
293
						actionCode.setValue("update"); 
294
						copyCode[gen].setValue("no");
295
						_pnlTemp.layout.setActiveItem(1); 
296
						var selected =pnlMDGrid[gen].getSelectionModel().getSelected(); 
297
						pnlForm[gen].getForm().loadRecord(selected); 
298
						var record = thisGrid.getStore().getAt(rowIndex); 
299
						assignPK(record); 
300
						md_type[gen].setValue(md_temp); 
301
						initload(); 
302
						specialload();
303
				});
304
		}
305
		
306
		var formPanelGrid = Array();
307
			formPanelGrid[gen] = 
308
		{
309
			xtype: 'panel',
310
			height: 200,
311
			region: 'north',
312
			layout: {
313
				type: 'border'
314
			},
315
			items: [
316
				{
317
					xtype: 'panel',
318
					height: 35,
319
					layout: {
320
						type: 'column'
321
					},
322
					region: 'north',
323
					items: [
324
						{
325
							xtype: 'panel',
326
							height: 35,
327
							width: 220,
328
							layout: {
329
								type: 'form'
330
							},
331
							bodyStyle: 'padding:5px 5px 0',
332
							border: false,
333
							flex: 1,
334
							items: [
335
								{
336
									xtype: 'datefield',
337
									format: 'd/m/Y',
338
									fieldLabel: 'Start Period',
339
									id: 'start_period_' + gen
340
								}
341
							]
342
						},
343
						{
344
							xtype: 'panel',
345
							height: 35,
346
							width: 220,
347
							layout: {
348
								type: 'form'
349
							},
350
							bodyStyle: 'padding:5px 5px 0',
351
							border: false,
352
							flex: 1,
353
							items: [
354
								{
355
									xtype: 'datefield',
356
									format: 'd/m/Y',
357
									fieldLabel: 'End Period',
358
									id: 'end_period_' + gen
359
								}
360
							]
361
						},
362
						{
363
							xtype: 'panel',
364
							height: 35,
365
							bodyStyle: 'padding:5px 5px 0',
366
							border: false,
367
							flex: 1,
368
							items: [
369
								{
370
									xtype: 'button',
371
									text: 'Search',
372
									listeners: {
373
						                click: function () {
374
						                    jsGetGrid[gen].load();
375
						                }
376
						            }
377
								}
378
							]
379
						}
380
					]
381
				},
382
				pnlMDGrid[gen]
383
			]
384
		}
385
		
386
		if (spload == '0'){
387
			pnlFormBottom[gen].hide();
388
		}
389
		 
390
		else if (spload == '1'){
391
			if (md == '0021'){
392
				eval("fn_spec_" + md + "('load',gen,accesscode,fldReimburseID.getValue());");
393
			}
394
			else {
395
				eval("fn_spec_" + md + "('load',gen,accesscode,'','','','');");
396
			}
397
		}
398
		
399
	//fnGenerateForm(md,empid);
400

    
401
	var clearColumnModel = new Ext.grid.ColumnModel([]);
402

    
403
	pnlMDGrid[gen].reconfigure(pnlMDGrid[gen].getStore(), clearColumnModel);
404

    
405
	var cm = pnlMDGrid[gen].getColumnModel();
406
	var curColConfig = cm.config;
407
	var Fields = [];
408
	var i = 0;
409
	var tabIndex = 100;
410

    
411
	var md_id = "id" +percode+mdcat+accesscode+md+empid;
412
	var md_temp = percode+"md"+md;
413
	var md_type = new Array();	
414
		md_type[gen] = new Ext.form.Hidden({
415
		name : "md_type",
416
		id : md_id,
417
		value : md_temp
418
		});
419
		
420
	var act_id = "act" +percode+mdcat+accesscode+md+empid;
421
	var action = new Array();	
422
	var queryCode = new Array();
423
	var copyCode = new Array();
424
		action[gen] = new Ext.form.Hidden({
425
		name : "action",
426
		id : act_id,
427
		value : "update"
428
		});
429
	queryCode[gen] = new Ext.form.Hidden({
430
				id : "query_wt" + percode + mdcat + accesscode + md + empid,
431
				value : "000"
432
			});
433
	copyCode[gen] = new Ext.form.Hidden({
434
				id : "copy" + percode + mdcat + accesscode + md + empid,
435
				value : ""
436
			});
437
	pnlFormleft[gen].add(queryCode[gen]);
438
	pnlFormleft[gen].add(copyCode[gen]);
439
		
440
	stringArray[gen].each(function(rec){
441

    
442
	  var name = rec.get('field_name');
443
	  var header = rec.get('column_name');
444
	  var id = name +percode+mdcat+accesscode+md+empid;
445
	  var iddate = percode+mdcat+accesscode+md+empid + name;
446
	  var columnno = rec.get('column_no');
447
	  var gridview = rec.get('gridview');
448
	  var hidden = false;
449
	  var required = rec.get('required');
450
	  var blank_status = true;
451
	  var css_class = 'minova-blank'
452
	  var _class = rec.get('class');
453
	  var max_size = rec.get('max_size');
454
	  var min_value = rec.get('min_value');
455
	  var max_value = rec.get('max_value');
456
	  var default_value = rec.get('default_value');
457
	  var controller = rec.get('controller_store');
458
	  var popup_func = rec.get('popup_func');
459
	  var select_func = rec.get('select_func');
460
	  var change_func = rec.get('change_func');
461
	  var grid_renderer_func = rec.get('grid_renderer_func');
462
	  var select_func_target = rec.get('select_func_target');
463
	  var change_func_target = rec.get('change_func_target');
464
	  var submit_value = rec.get('submit_value');
465
	  var _readonly = rec.get('read_only');
466
	  var display = false;
467
	  
468
	  if (default_value.indexOf("p:") != -1)
469
	  {
470
	  	default_value = fnGetParam(default_value, "emp_id:"+empid);
471
	  }
472
	  if (required.indexOf("p:") != -1)
473
	  {
474
	  	required = fnGetParam(required, "emp_id:"+empid);
475
	  }
476
	  if (_readonly.indexOf("p:") != -1)
477
	  {
478
	  	_readonly = fnGetParam(_readonly, "emp_id:"+empid);
479
	  }
480
	  
481
	  if (Ext.util.Format.trim(min_value) == "")
482
		{
483
		min_value = 0;
484
		}	  
485
	  if (Ext.util.Format.trim(max_value) == "")
486
		{
487
		max_value = 999;
488
		}	  
489
		
490
	  var prefix_id = percode+mdcat+accesscode+md+empid;
491
	  
492
	  var submitValue = false;
493
	  if (submit_value == "1")
494
	  {
495
		submitValue = true;
496
	  }
497
  
498
	  if(_readonly == "1")
499
	  {
500
		display = true;
501
		css_class = 'minova-readonly'
502
	  }
503
	  
504
	  if(accesscode == "disp")
505
	  {
506
		display = true;
507
		css_class = 'minova-readonly'
508
	  }
509
	  
510
	  if(required == "1")
511
	  {     
512
		blank_status = false;
513
		css_class = 'minova-mandatory'
514
	  }
515
	  if (gridview=="0")
516
		hidden = true;
517
	   
518
	    
519
	  if( _class == "hidden")
520
	  {
521
		if(name == "emp_id")
522
		{
523
			Fields[i] = new Ext.form.Hidden({
524
			name: name,
525
			id:id,
526
			value:empid
527
			});
528
		}
529
		else
530
		{
531
			var target_id = change_func_target + prefix_id;
532
			
533
		    Fields[i] = new Ext.form.Hidden({
534
			name: name,
535
			id:id,
536
			value:default_value,
537
			submitValue:submitValue,
538
			listeners:{
539
				change: function(fld, nval, oval){
540
					if (change_func != "" && change_func_target != "")
541
					{
542
						eval(change_func+"('"+id+"','"+target_id+"','"+nval+"');");
543
					}
544
				}
545
			}
546
			});
547
		}
548
	  }
549
	  else if(_class == "datefield")
550
	  {
551
			Fields[i] = new Ext.form.DateField({
552
			fieldLabel: header,
553
			allowBlank: blank_status,
554
			cls: css_class,
555
			msgTarget: 'side',
556
			readOnly: display,
557
                        width: '150',
558
			id:iddate,
559
			format:'d/m/Y',
560
			tabIndex : tabIndex
561
			,listeners:{
562
				change: function(fld, nval, oval, toFld){ 
563
						fnDateChg(fld, nval, oval, id );
564
						if (change_func != "")
565
							{
566
								eval(change_func+"('"+prefix_id+"');");
567
							}			
568
					},
569
				select: function(fld, dt, toFld){ 
570
						fnDateSelect(fld, dt, id ); 
571
						if (select_func != "")
572
							{
573
								eval(select_func+"('"+prefix_id+"');");
574
							}	
575
					},
576
				specialkey: function(field, e) {
577
			            if (e.getKey() == e.ENTER) {
578
			                focusNextField(name, prefix_id);
579
			            }
580
			        }
581
			}
582
			});
583
			
584
			if (columnno == "1")
585
			{
586
				pnlFormleft[gen].add(Fields[i]);
587
			}
588
			else if (columnno == "2")
589
			{
590
				pnlFormright[gen].add(Fields[i]);
591
			}
592
			i++;
593
			
594
			Fields[i] = new Ext.form.Hidden({
595
			name: name,
596
			id:id,
597
			value:default_value,
598
			listeners:{
599
				change: function(fld, nval, oval, toFld){ fnDateHidChg(fld, nval, oval, iddate ); }
600
			}
601
			});
602
			pnlFormleft[gen].add(Fields[i]);
603
	  }
604
	  else if(_class == "timefield" )
605
	  {
606
		   Fields[i] = new Ext.form.TimeField({ 
607
		   //minValue: min_value,
608
		   //maxValue: max_value,
609
	       fieldLabel: header,
610
		   allowBlank: blank_status,
611
		   cls: css_class,
612
		   msgTarget: 'side',
613
		   readOnly: display,
614
	       name: name,
615
	       format: 'Hi',
616
	       id:id,
617
		   tabIndex : tabIndex,
618
		   listeners:{
619
						change: function(fld, nval, oval){
620
							if (change_func != "")
621
							{
622
								eval(change_func+"('"+prefix_id+"');");
623
							}
624
						},
625
						specialkey: function(field, e) {
626
				            if (e.getKey() == e.ENTER) {
627
				                focusNextField(name, prefix_id);
628
				            }
629
				        }
630
					}
631
		   });
632
	  }
633
	  else if(_class == "combobox" )
634
	  {
635
			var target_id = select_func_target + prefix_id;
636
			
637
			var str = new Ext.data.JsonStore({
638
		        fields: [
639
		            'code',
640
		            'desc'
641
		        ],
642
		        url: controller
643
		    });
644
		    str.load();
645
			
646
			Fields[i] = new Ext.form.ComboBox({
647
			forceSelection: true,
648
			fieldLabel: header,
649
			allowBlank: blank_status,
650
			cls: css_class,
651
			msgTarget: 'side',
652
			readOnly: display,
653
			hiddenName: name,
654
			id:id,
655
			tabIndex : tabIndex,
656
		    typeAhead: true,
657
		    triggerAction: 'all',
658
		    lazyRender:true,
659
		    mode: 'local',
660
		    store: str,
661
		    value:default_value,
662
		   	valueField: 'code',
663
		    displayField: 'desc',
664
			listeners:{
665
				select: function(cmb, rec){ 
666
					if (select_func != "" && target_id != "")
667
					{
668
						eval(select_func+"('"+id+"','"+target_id+"','"+rec.get('code')+"');");
669
					}
670
				},
671
				specialkey: function(field, e) {
672
					if (e.getKey() == e.ENTER) {
673
						focusNextField(name, prefix_id);
674
					}
675
				}
676
			}
677
		});
678
				
679
	  }
680
	  else if (_class == "lookupfld")
681
	  {
682
	  	//var target_id = change_func_target + prefix_id;
683
	  	var extendedQuery = change_func_target == '' 
684
								? undefined : change_func_target;
685
		
686
		if (md == "0004" || md == "0005")
687
			queryCode[gen].setValue(controller);
688
									
689
	    var fieldLook = new Ext.form.TextField({
690
		   minLength : min_value,
691
		   maxLength : max_value,
692
	       fieldLabel: header,
693
		   allowBlank: blank_status,
694
		   cls: css_class,
695
		   value:default_value,
696
		   msgTarget: 'side',
697
		   readOnly: display,
698
	       name: name,
699
	       width: '150',
700
	       id:id,
701
		   tabIndex : tabIndex,
702
		   listeners:{
703
				change: function(fld, nval, oval){
704
					if (change_func != "")
705
					{
706
						eval(change_func+"('"+fld.id+"','"+fld.getValue()+"','"+extendedQuery+"');");
707
					}
708
				},
709
				specialkey: function(field, e) {
710
		            if (e.getKey() == e.ENTER) {
711
		                if (change_func != "")
712
						{
713
							eval(change_func+"('"+field.id+"','"+field.getValue()+"','"+extendedQuery+"');");
714
						}
715
		            }
716
		        }
717
			}
718
		})
719
		
720
		Fields[i] = LookUpFieldGen(name, 150, 120, header, 500, 500, controller, 
721
									false, true, extendedQuery, false, id, prefix_id+'end_date');
722
	  }
723
	  else if(_class == "popup")
724
	  {
725
		    var target_id = change_func_target + prefix_id;
726
			
727
			var txtDesc = new Array();
728
				txtDesc[gen] = new Ext.form.TextField({
729
					fieldLabel : header,
730
					readOnly : true,
731
					width : 158,
732
					cls: 'minova-readonly',
733
				    msgTarget: 'side',
734
				    name: name,
735
			        id:id,
736
				    listeners:{
737
						change: function(fld, nval, oval){
738
							if (change_func != "" && change_func_target != "")
739
							{
740
								eval(change_func+"('"+id+"','"+target_id+"','"+nval+"');");
741
							}
742
						},
743
						specialkey: function(field, e) {
744
				            if (e.getKey() == e.ENTER) {
745
				                focusNextField(name, prefix_id);
746
				            }
747
				        }
748
					}
749
			});		
750
			var pnlTxt = new Array();
751
				pnlTxt[gen] = new Ext.Panel({
752
					border: false,
753
					isForm: true,
754
					layout: 'form',
755
					items: [txtDesc[gen]]
756
			});
757
			var btnLookUp = new Array();
758
				btnLookUp[gen] = new Ext.Button({
759
					iconCls: 'icon-magnifier',
760
					hidden: display,
761
					listeners:{
762
						click: function(){
763
							if (popup_func != "")
764
							{
765
								//alert(popup_func+"('"+id+"','"+prefix_id+"');");
766
								eval(popup_func+"('"+id+"','"+prefix_id+"');");
767
							}
768
						}
769
					}
770
			});
771
			//btnLookUp[gen].on('click', function(){alert("LookUp");});
772
			Fields[i] = new Ext.Panel({
773
				border: false,
774
				layout: 'column',
775
				region: 'north',
776
				items: [pnlTxt[gen],btnLookUp[gen]]
777
			});
778
	  }
779
	  else if(_class == "radio")
780
	  {
781
	       var radioItems = new Array();
782
		   var radioData = new Ext.data.JsonStore({
783
		        fields: [
784
		            'code',
785
		            'desc'
786
		        ],
787
		        url: controller
788
		    })
789
			radioData.load();
790
			var j = 0;
791
			radioData.each(function(rec){
792
			
793
				var code = rec.get('code');
794
				var desc = rec.get('desc');
795
				radioItems[j] = new Ext.form.Radio({
796
				id:name+code+gen,
797
				boxLabel : desc,
798
				inputValue : code,
799
				name : name
800
				});
801
				j++;
802
			});
803
		   
804
		   Fields[i] = new Ext.form.RadioGroup({
805
		   columns : 1,
806
		   items : radioItems
807
		   });
808
	  }
809
	  else if (_class == "textarea")
810
	  {
811
		   var target_id = change_func_target + prefix_id;
812
		   
813
		   Fields[i] = new Ext.form.TextArea({
814
	       fieldLabel: header,
815
		   allowBlank: blank_status,
816
		   cls: css_class,
817
		   msgTarget: 'side',
818
		   readOnly: display,
819
	       name: name,
820
	       width: '200',
821
		   height: '100',
822
	       id:id,
823
		   value:default_value,
824
		   tabIndex : tabIndex,
825
		   listeners:{
826
				change: function(fld, nval, oval){
827
					if (change_func != "" && change_func_target != "")
828
					{
829
						eval(change_func+"('"+id+"','"+target_id+"','"+nval+"');");
830
					}
831
				},
832
				specialkey: function(field, e) {
833
					if (e.getKey() == e.ENTER) {
834
						focusNextField(name, prefix_id);
835
					}
836
				}
837
			}
838
	        
839
	    });
840
	  }
841
	  else if (_class == "number")
842
	  {
843
		   var target_id = change_func_target + prefix_id;
844
		   
845
		   Fields[i] = new Ext.form.NumberField({
846
		   minLength : min_value,
847
		   maxLength : max_value,
848
	       fieldLabel: header,
849
		   allowBlank: blank_status,
850
		   cls: css_class,
851
		   msgTarget: 'side',
852
		   readOnly: display,
853
	       name: name,
854
	       width: '150',
855
	       id:id,
856
		   value:default_value,
857
		   tabIndex : tabIndex,
858
		   listeners:{
859
				change: function(fld, nval, oval){
860
					if (change_func != "" && change_func_target != "")
861
					{
862
						eval(change_func+"('"+id+"','"+target_id+"','"+nval+"');");
863
					}
864
				},
865
				specialkey: function(field, e) {
866
					if (e.getKey() == e.ENTER) {
867
						focusNextField(name, prefix_id);
868
					}
869
				}
870
			}
871
	        
872
	    });
873
	  }
874
	  else if (_class == "fileupload")
875
	  {
876
	  	 Fields[i] = 
877
	  	 {
878
	  	 	xtype: 'fileuploadfield',
879
            emptyText: 'Select a file',
880
            fieldLabel: header,
881
            name: name,
882
            id: id,
883
            width: '200',
884
            buttonText: 'Browse'
885
	  	 }
886
	  }
887
	  else
888
	  {
889
		   var target_id = change_func_target + prefix_id;
890
		   
891
		   Fields[i] = new Ext.form.TextField({
892
		   minLength : min_value,
893
		   maxLength : max_value,
894
	       fieldLabel: header,
895
		   allowBlank: blank_status,
896
		   cls: css_class,
897
		   value:default_value,
898
		   msgTarget: 'side',
899
		   readOnly: display,
900
	       name: name,
901
	       width: '150',
902
	       id:id,
903
		   tabIndex : tabIndex,
904
		   listeners:{
905
				change: function(fld, nval, oval){
906
					if (change_func != "" && change_func_target != "")
907
					{
908
						eval(change_func+"('"+id+"','"+target_id+"','"+nval+"');");
909
					}
910
				},
911
				specialkey: function(field, e) {
912
					if (e.getKey() == e.ENTER) {
913
						focusNextField(name, prefix_id);
914
					}
915
				}
916
			}
917
	        
918
	    });
919

    
920
	  }  
921
	  
922
	  if (_class == "datefield")
923
	  {
924
		curColConfig.push({
925
		header: header,
926
		width: 100,
927
		dataIndex:  name,
928
		hidden: hidden,
929
		renderer: function(val){
930
			return fnGrid_Date8(val);
931
		}
932
		});
933
	  }
934
	  else if (_class == "combobox")
935
	  {
936
		curColConfig.push({
937
		header: header,
938
		width: 100,
939
		dataIndex:  name,
940
		hidden: hidden,
941
		renderer: function(val){
942
			var cmbStore = Ext.getCmp(id).getStore();
943
			if (cmbStore.getCount() == 0)
944
			{
945
				cmbStore.load();
946
			}
947
			
948
			var index = cmbStore.find('code',val);
949

    
950
			if (index != -1)
951
			{
952
				var rec = cmbStore.getAt(index);
953

    
954
				return rec.get("desc");
955
			}
956
			else
957
			{
958
				return val;
959
			}
960
		}
961
		});
962
	  }
963
	  else if (_class == "lookupfld")
964
	  {
965
	  	curColConfig.push({
966
			header: header,
967
			width: 100,
968
			dataIndex:  name,
969
			hidden: hidden,
970
			renderer : function(val, metaData, record, rowIndex, colIndex, store) {
971
				var keyDate = (new Date()).format('d/m/Y');
972
				if ((record.get("end_date")!="") && (record.get("end_date").length==8))
973
				{
974
					keyDate = fnGrid_Date8(record.get("end_date"));
975
				}
976
				var res = GetDescription(val, controller, keyDate,
977
						extendedQuery);
978
				if (res == "") res = val;
979
    			return res;
980
			}
981
		});
982
	  }
983
	  else if (name == "last_change")
984
	  {
985
		curColConfig.push({
986
		header: header,
987
		width: 100,
988
		dataIndex:  name,
989
		hidden: hidden,
990
		renderer: function(val){
991
			return fnGrid_Date14(val);
992
		}
993
		});
994
	  }
995
	  else if (grid_renderer_func != "")
996
	  {
997
		curColConfig.push({
998
		header: header,
999
		width: 100,
1000
		dataIndex:  name,
1001
		hidden: hidden,
1002
		renderer: function(val){
1003
			var ret = eval(grid_renderer_func+"('"+id+"','"+val+"');");
1004
			return ret;
1005
		}
1006
		});
1007
	  }
1008
	  else
1009
	  {
1010
		curColConfig.push({
1011
		header: header,
1012
		width: 100,
1013
		dataIndex:  name,
1014
		hidden: hidden
1015
		});
1016
	  }
1017
	  
1018
	    if(name == "seq" || name == "user_change" || name == "last_change")
1019
			{
1020
				Ext.getCmp(id).setReadOnly(true);
1021
			}   
1022
			
1023
		tabIndex++;
1024
		if (columnno == "1" && _class != "datefield" )
1025
			{
1026
			pnlFormleft[gen].add(Fields[i]);
1027
			}
1028
		else if (columnno == "2" && _class != "datefield" )
1029
			{
1030
			pnlFormright[gen].add(Fields[i]);
1031
			}
1032
		i++;
1033
	});
1034
	pnlFormleft[gen].add(md_type[gen]);
1035

    
1036
	var i=0;
1037
	stringPrimaryKey[gen].each(function(rec){
1038
	   var data = rec.get('field_name');
1039
	   var key = "key_"+data;
1040
	   
1041
	   Fields[i] = new Ext.form.Hidden({
1042
	     
1043
	     name: key,
1044
	     width: '150',
1045
	     id: key+gen
1046
	        
1047
	    });
1048

    
1049
		
1050
		pnlFormleft[gen].add(Fields[i]);
1051
		i++;
1052

    
1053
	});
1054

    
1055
	cm.setConfig(curColConfig, true);
1056

    
1057

    
1058
	pnlMDGrid[gen].reconfigure(pnlMDGrid[gen].getStore(), new Ext.grid.ColumnModel(curColConfig));
1059

    
1060
	pnlFormright[gen].doLayout();
1061
	pnlFormleft[gen].doLayout();
1062
	pnlForm[gen].doLayout();
1063

    
1064
	/*
1065
	$.ajax({
1066
	       
1067
	    url : "Devt/getDataMD",
1068
	    data : {md_cat:md, per_code:percode , emp_id:empid},
1069
	    async:false,
1070
	    success : function(result){
1071
		
1072

    
1073
		jsGetGrid[gen].loadData(result);
1074
	    
1075
	  
1076

    
1077
	    if(result.success==false)
1078
	    {
1079
	       alert("Error On Save");
1080
	    }
1081

    
1082
	    }
1083

    
1084
	})
1085
	*/
1086
		
1087
	//finish GenerateForm
1088
	var _title = "";
1089
	if(mdcode == ""){	
1090
		_title = cmbMasterData.getRawValue();}
1091
	else
1092
	{
1093
		datacmbMasterData.each(function(rec){	
1094
			var idmd = rec.get('code');
1095
			if (mdcode == idmd)
1096
			{
1097
			   	_title = rec.get('desc');
1098
			}
1099
		});
1100
	}
1101
		
1102
	var _idTemp = program + '_temp_' + md;
1103
	var _idBottom = program + '_bottom_' + md;
1104
    //pnlMDGrid formPanelGrid
1105
	var _pnlTemp = new Ext.Panel({
1106
		closable:true,
1107
		activeItem:0,
1108
		layout:'card',
1109
		title:_title,
1110
		id: _idTab,
1111
		items:[formPanelGrid[gen],pnlParentForm[gen]],
1112
		listeners:{ 
1113
			afterrender: function(){
1114
				jsGetGrid[gen].load();
1115
			}
1116
		}
1117
	});
1118

    
1119
	pnlMDbody.add(_pnlTemp);
1120
	pnlMDbody.doLayout();
1121
	
1122
	//jsGetGrid[gen].load();
1123
		
1124
	function focusNextField(name, prefix_id)
1125
	{
1126
		
1127
	}
1128

    
1129
	function addclick()
1130
	{
1131
		pnlForm[gen].getForm().reset();
1132
		
1133
		if (md == '0032')
1134
		{
1135
			dataMD0033_Grid.removeAll(false);
1136
			dataMD0034_Grid.removeAll(false);
1137
			dataMD0035_Grid.removeAll(false);
1138
		}
1139
	}
1140

    
1141
	function refreshgrid()
1142
	{
1143
		/*
1144
		$.ajax({
1145
	       
1146
		url : "Devt/getDataMD",
1147
	    data : {md_cat:md, per_code:percode , emp_id:empid},
1148
	    async:false,
1149
	    success : function(result){
1150
		
1151
		jsGetGrid[gen].loadData(result);
1152
	    
1153
		    if(result.success==false)
1154
		    {
1155
		       //alert("Error On Get Grid");
1156
			   fnShowMsg(result.message,null);
1157
		    }
1158
			
1159
		}
1160

    
1161
		});
1162
		*/
1163
		
1164
		jsGetGrid[gen].load();
1165
	}
1166

    
1167
	function delclick()
1168
	{
1169
		Ext.Msg.show({
1170
			title: 'Delete Record Confirmation',
1171
			msg: 'The Record specified will be deleted from the Master Data. \nAre you sure to process the deletion?',
1172
			buttons: Ext.Msg.YESNO,
1173
			fn: function(btn) {
1174
				if (btn == 'yes') {
1175
					delclickProcess();
1176
				}                                
1177
			},
1178
			animEl: 'elId',
1179
			icon: Ext.MessageBox.QUESTION
1180
		});
1181
	}
1182
	
1183
	function delclickProcess()
1184
	{
1185
		pnlForm[gen].el.mask("Deleting...", "x-mask-loading");
1186
		pnlForm[gen].getForm().submit({
1187
			url : "HR_PA/DeletePersonMasterData",
1188
			success : function(form, action){
1189
				pnlForm[gen].el.unmask();
1190
			    var result = action.result;
1191
			    pnlForm[gen].getForm().reset();
1192
			    refreshgrid();
1193
				_pnlTemp.layout.setActiveItem(0);
1194
			},
1195
			failure : function(form, action){
1196
				pnlForm[gen].el.unmask();
1197
				var result = action.result;
1198
		        
1199
				if (result.success == false){
1200
					fnShowMsg(result.message,null);
1201
				}
1202
			}
1203
		});
1204
	}
1205

    
1206
	function assignPK(record)
1207
	{
1208
		stringPrimaryKey[gen].each(function(rec){
1209
			var data = rec.get('field_name');
1210
			var key = "key_"+data+gen;
1211
			var item = record.get(data); 
1212
		  
1213
			Ext.getCmp(key).setValue(item);
1214

    
1215
	});
1216
	}
1217

    
1218
	function saveclick()
1219
	{
1220
		if (spval == '1'){
1221
			var _beforeSave = eval("fn_spec_" + md + "('beforeSave');");
1222
			if (_beforeSave) {
1223
				saveclickbtn("0");		
1224
			}
1225
		}
1226
		else{
1227
			saveclickbtn("0");	
1228
		}
1229
	}
1230

    
1231
	function saveclickbtn(force)
1232
	{
1233
		var employeeid = "emp_id" +percode+mdcat+accesscode+md+empid;
1234
			pnlForm[gen].el.mask("Processing Data...","x-mask-loading");
1235
			md_type[gen].setValue(md_temp);
1236
			var url = "/HR_PA/EditMasterData/";
1237
			
1238
			if (action[gen].getValue() == "insert"){
1239
			    url = "/HR_PA/AddMasterData/";
1240
				Ext.getCmp(employeeid).setValue(empid);
1241
			}
1242
			
1243
			pnlForm[gen].getForm().submit({
1244
				clientValidation: true,
1245
				params: {force:force},
1246
				url : url,
1247
				success : function(form, action){
1248
					pnlForm[gen].el.unmask();
1249
					refreshgrid();
1250
					_pnlTemp.layout.setActiveItem(0);
1251
					if (spval == '1'){
1252
						eval("fn_spec_" + md + "('afterSave');");
1253
					}
1254
					
1255
					if(Ext.getCmp("movement_type"+gen).getValue()=="80"){
1256
						var startDate = Ext.getCmp("start_date"+gen).getValue();
1257
						var year = startDate.substring(0, 4);
1258
						var month = startDate.substring(4, 6);
1259
						var day = startDate.substring(6, 8);
1260
						var valid_from = day  + '/' + month + '/' + year;
1261
						Ext.Ajax.request({
1262
									url : '/UserAdministration/SaveChanges',
1263
									params : {
1264
										flagCommand : 'EDIT',
1265
										header_left : '{"header_user_id":"'+empid+'","header_status_active":"on","header_ldap_id":""}',
1266
										header_right : '{"txtDisplayField_header_emp_id":"'+empid+'","txtHiddenField_header_emp_id":"'+empid+'","dateHiddenField_header_emp_id":"","header_status_lock":"on"}',
1267
										personalDataLeft : '{"title":"","first_name":"'+ headerFullName.getValue()+'","middle_name":"","last_name":"'+ headerFullName.getValue()+'","format_name":"'+ headerFullName.getValue()+'","language":""}',
1268
										personalDataRight : '{}',
1269
										userLogon : '{"password":"","re_password":"","valid_from":"'+valid_from+'","valid_through":"31/12/9999"}',
1270
										dataDeleted : '[]',
1271
										dataNonDeleted : '[]',
1272
										approval:false
1273
									},
1274
									method : 'POST',
1275
									success : function(result, request) {
1276
									}
1277

    
1278
								});							
1279
					}
1280
				  
1281
				},
1282
				failure : function(form, action){
1283
					//alert("error on : "+ action.failureType);
1284
					pnlForm[gen].el.unmask(); 
1285
					//refreshgrid();
1286
					//_pnlTemp.layout.setActiveItem(0);
1287
					var result = action.result;
1288
					if (result.success == false){
1289
						if (result.message.action == "1")
1290
						{
1291
							Ext.Msg.show({
1292
						        title: 'Confirmation',
1293
						        msg: result.message.text,
1294
						        buttons: Ext.Msg.YESNO,
1295
						        fn: function(btn) {
1296
						            if (btn == 'yes') {
1297
						                saveclickbtn("1");
1298
						            }                                
1299
						        },
1300
						        animEl: 'elId',
1301
						        icon: Ext.MessageBox.QUESTION
1302
						    });
1303
						}
1304
						else
1305
							fnShowMsg(result.message,null);            
1306
					}   		  
1307
				}
1308
				});
1309
	}
1310
	
1311
	function completeclick()
1312
	{
1313
		//GET GRID
1314
		action[gen].setValue("update"); 
1315
		_pnlTemp.layout.setActiveItem(1); 
1316
		var selected =pnlMDGrid[gen].getSelectionModel().getSelected(); 
1317
		selected.set("applicant_status","02");
1318
		assignPK(selected); 
1319
		pnlForm[gen].getForm().loadRecord(selected); 
1320
		md_type[gen].setValue(md_temp);	
1321

    
1322

    
1323
		//SAVE
1324
		var employeeid = "emp_id" +percode+mdcat+accesscode+md+empid;
1325
			pnlForm[gen].el.mask("Loading Data...","x-mask-loading");
1326
			md_type[gen].setValue(md_temp);
1327
			var url = "/HR_PA/EditMasterData/";
1328
			
1329
			pnlForm[gen].getForm().submit({
1330
				clientValidation: true,
1331
				url : url,
1332
				success : function(form, action){
1333
					pnlForm[gen].el.unmask();
1334
					refreshgrid();
1335
					_pnlTemp.layout.setActiveItem(0);
1336
					if (spval == '1'){
1337
						eval("fn_spec_" + md + "('afterSave');");
1338
					}
1339
				  
1340
				},
1341
				failure : function(form, action){
1342
					alert("error on : "+ action.failureType);
1343
					pnlForm[gen].el.unmask(); 
1344
				    }
1345
				});
1346
		
1347
	}
1348

    
1349
	function followupclick()
1350
	{
1351
		//Add by Kindy Confirmation Follow-Up 10/05/2011
1352
		Ext.Msg.show({
1353
			title: 'Follow-Up Confirmation',
1354
			msg: 'The Activity specified will be followed-up even the last activity has NOT been Passed. \nAre you sure want to Follow-up Activity?',
1355
			buttons: Ext.Msg.YESNO,
1356
			fn: function(btn) {
1357
				if (btn == 'yes') {
1358
					fnfollowup();
1359
				}                                
1360
			},
1361
			animEl: 'elId',
1362
			icon: Ext.MessageBox.QUESTION
1363
		});
1364
	}
1365
	function fnfollowup()
1366
	{
1367
		//GET GRID
1368
		action[gen].setValue("insert"); 
1369
		_pnlTemp.layout.setActiveItem(1); 
1370
		var selected =pnlMDGrid[gen].getSelectionModel().getSelected(); 
1371
		//selected.set("applicant_status","01");
1372
		var _enddate = selected.get("end_date");
1373
		var act_type = selected.get("activity_type");
1374
		//alert (parseInt(act_type)+1);
1375
		//assignPK(selected); 
1376
		//pnlForm[gen].getForm().loadRecord(selected); 
1377
		pnlForm[gen].getForm().reset();
1378
		Ext.getCmp("start_date"+gen).setValue(_enddate);
1379
		Ext.getCmp("end_date"+gen).setValue(_enddate);
1380
		Ext.getCmp("activity_type"+gen).setValue(parseInt(act_type)+1);
1381
		Ext.getCmp("applicant_status"+gen).setValue("01");
1382
		md_type[gen].setValue(md_temp);	
1383
	}
1384

    
1385
	function initload()
1386
	{
1387
		if ((md == '0004') || (md == '0005')) {
1388
			try
1389
			{
1390
				var wtCmp = Ext.getCmp('wage_type'+gen);
1391
				var btnLookupWT = Ext.getCmp('buttonLookup_wage_type'+gen);
1392
				if (action[gen].getValue() == 'update'){
1393
					wtCmp.setReadOnly(true);
1394
					fnSetWTFlag(wtCmp.getValue(), gen);
1395
					fnSetOverwriteWT(wtCmp.getValue(), gen);
1396
					if (btnLookupWT != undefined)
1397
					{
1398
						btnLookupWT.setVisible(false);
1399
					}
1400
				}
1401
				else{
1402
					if (accesscode == 'main')
1403
					{
1404
						wtCmp.setReadOnly(false);
1405
						if (btnLookupWT != undefined)
1406
						{
1407
							btnLookupWT.setVisible(true);
1408
						}
1409
					}
1410
				}
1411
			}
1412
			catch(e){}
1413
		}
1414
		if (md == '0032'){
1415
			try
1416
			{
1417
				var loanTypeCmp = Ext.getCmp('loan_type'+gen);
1418
				if (action[gen].getValue() == 'update'){
1419
					loanTypeCmp.setReadOnly(true);
1420
				}
1421
				else{
1422
					if (accesscode == 'main')
1423
						loanTypeCmp.setReadOnly(false);
1424
				}
1425
			}
1426
			catch(e){}
1427
		}
1428
	}
1429
	
1430
		
1431
	function specialload()
1432
	{
1433
		if (md == '0021') {
1434
			try
1435
			{	
1436
				var idre = Ext.getCmp('reimbursement_id'+gen).getValue(); 
1437
				fldReimburseID.setValue(idre);
1438
				fn_spec_0021('reload',gen,accesscode,idre);
1439
			}
1440
			catch(e){}
1441
		}
1442
		else if (md == '0032') {
1443
			try
1444
			{	
1445
				var stdate = Ext.getCmp('start_date'+gen).getValue();
1446
				var edate =  Ext.getCmp('end_date'+gen).getValue();
1447
				var lntype = Ext.getCmp('loan_type'+gen).getValue();
1448
				var seq	= Ext.getCmp('seq'+gen).getValue();
1449
				fn_spec_0032('reload',gen,accesscode,stdate,edate,lntype,seq);
1450
				
1451
				// remove by adi, not load balance in edit mode.
1452
				/*
1453
				// add by irwan
1454
				var empid2 = hidEmpId.getValue();
1455
				$.ajax({
1456
						url : "/HR_PA/GetLoanBalance",
1457
						data : {md_type:"empmd0035", emp_id:empid2, start_date:stdate, end_date:edate, loan_type:lntype, seq:seq},
1458
						async:false,
1459
						success : function(result){
1460
							if (result.success)
1461
							{
1462
								dataMD0035_Grid.loadData(result.data);
1463
							}
1464
						}
1465
				});
1466
				*/
1467
			}
1468
			catch(e){}
1469
		}
1470
		else{}
1471
	}
1472
	 
1473
	fnInitForm();
1474

    
1475
}
(2-2/3)