Project

General

Profile

Bug #399 » fn_spec_0032.js

Tri Rizqiaty, 06/22/2021 04:16 PM

 
1
// alert(action);
2
// alert(gen);
3
// alert(accesscode);
4
// alert(stdate);
5
// alert(edate);
6
// alert(lntype);
7
// alert(seq);
8
function Trim(s) {
9
if(s==null){
10
s="";
11
}
12
 var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/); 
13
return (m == null) ? "" : m[1];
14
}
15

    
16
var gen2 = gen + "_details";
17
var empid2 = hidEmpId.getValue();
18
var fldMD0034tenor = new Ext.form.NumberField({
19
				fieldLabel : 'Tenor',
20
				name : 'tenor',
21
				enableKeyEvents : true, 
22
				listeners : {
23
					change : function() {
24
						hitungtenor();
25
					},
26
					keypress : function() {
27
						hitungtenor();
28
					}
29
				}
30
			});
31
			
32
var fldMD0034amount = new Ext.form.TextField({
33
				id : 'fldMD0034amount',
34
				fieldLabel : 'Amount',
35
				name : 'amount',
36
				allowBlank : false,
37
				cls : 'minova-mandatory',
38
				msgTarget : 'side',
39
				listeners : {
40
					change : function(fld, nval, oval) {
41
						eval("fnAmount('fldMD0034amount','fldMD0034amount','"
42
								+ nval + "');");
43
					}
44
				}
45
			});
46

    
47
if (action == "reload") {
48

    
49
	dataMD0033_Grid.removeAll(false);
50
	dataMD0034_Grid.removeAll(false);
51
	dataMD0035_Grid.removeAll(false);
52

    
53
	$.ajax({
54
				url : "HR_PA/GetLoanPayment",
55
				data : {
56
					md_type : "empmd0033",
57
					emp_id : empid2,
58
					start_date : stdate,
59
					end_date : edate,
60
					loan_type : lntype,
61
					seq : seq
62
				},
63
				async : false,
64
				success : function(result) {
65

    
66
					if (result.success) {
67
						dataMD0033_Grid.loadData(result.data);
68
					}
69

    
70
				}
71
			});
72

    
73
	$.ajax({
74
				url : "HR_PA/GetLoanRegPayment",
75
				data : {
76
					md_type : "empmd0034",
77
					emp_id : empid2,
78
					start_date : stdate,
79
					end_date : edate,
80
					loan_type : lntype,
81
					seq : seq
82
				},
83
				async : false,
84
				success : function(result) {
85

    
86
					if (result.success) {
87
						dataMD0034_Grid.loadData(result.data);
88
					}
89

    
90
				}
91
			});
92
}
93

    
94
if (action == "load") {
95

    
96
	// button simulation
97
	var btnSimulate = new Ext.Button({
98
				text : 'Simulate Loan',
99
				iconCls : 'icon-add'
100
			});
101
	btnSimulate.on('click', function() {
102
				simulateclick();
103
				refreshgrid2();
104
			});
105

    
106
	function simulateclick() {
107
		var lntype = Ext.getCmp('loan_type' + gen).getValue();
108
		var seq = Ext.getCmp('seq' + gen).getValue();
109
		
110
		// add by adi - loading in simulation
111
		Ext.getCmp("pnlMDGrid2").el.mask("Simulate Loan...", "x-mask-loading");
112
		
113
		$.ajax({
114

    
115
					//url : "HR_PA/RunLoanSimulator",
116
					url : "HR_LOAN_IMFI/RunLoanSimulator",
117
					data : {
118
						emp_id : empid2,
119
						loan_type : lntype,
120
						seq : seq
121
					},
122
					async : false,
123
					success : function(result) {
124
						if (result.success) {
125
						}
126

    
127
					}
128
				});
129

    
130
		$.ajax({
131

    
132
					url : "HR_PA/GetLoanBalance",
133
					data : {
134
						md_type : "empmd0035",
135
						emp_id : empid2,
136
						start_date : stdate,
137
						end_date : edate,
138
						loan_type : lntype,
139
						seq : seq
140
					},
141
					async : false,
142
					success : function(result) {
143

    
144
						if (result.success) {
145
							dataMD0035_Grid.loadData(result.data);
146
						}
147

    
148
					}
149
				});
150
				
151
		// add by adi
152
		Ext.getCmp("pnlMDGrid2").el.unmask();
153
		
154
	}
155
	
156
	//button Load Loan Balance -- add by adi.
157
	var btnLoadBalance = new Ext.Button({
158
				text : 'Load Balance',
159
				iconCls : 'icon-database_refresh'
160
			});
161
	btnLoadBalance.on('click', function() {
162
				loadbalanceclick();
163
			});
164

    
165
	function loadbalanceclick() {
166
		var lntype = Ext.getCmp('loan_type' + gen).getValue();
167
		var seq = Ext.getCmp('seq' + gen).getValue();
168
		
169
		// add by adi - loading in simulation
170
		Ext.getCmp("pnlMDGrid2").el.mask("Load Loan Balance...", "x-mask-loading");
171
		
172
		$.ajax({
173

    
174
					url : "HR_PA/GetLoanBalance",
175
					data : {
176
						md_type : "empmd0035",
177
						emp_id : empid2,
178
						start_date : stdate,
179
						end_date : edate,
180
						loan_type : lntype,
181
						seq : seq
182
					},
183
					async : false,
184
					success : function(result) {
185

    
186
						if (result.success) {
187
							dataMD0035_Grid.loadData(result.data);
188
						}
189

    
190
					}
191
				});
192
				
193
		// add by adi
194
		Ext.getCmp("pnlMDGrid2").el.unmask();
195
		
196
	}
197
	
198
	// function refresh grid
199
	function refreshgrid2() {
200
		var stdate = Ext.getCmp('start_date' + gen).getValue();
201
		var edate = Ext.getCmp('end_date' + gen).getValue();
202
		var lntype = Ext.getCmp('loan_type' + gen).getValue();
203
		var seq = Ext.getCmp('seq' + gen).getValue();
204

    
205
		$.ajax({
206
					url : "HR_PA/GetLoanPayment",
207
					data : {
208
						md_type : "empmd0033",
209
						emp_id : empid2,
210
						start_date : stdate,
211
						end_date : edate,
212
						loan_type : lntype,
213
						seq : seq
214
					},
215
					async : false,
216
					success : function(result) {
217

    
218
						if (result.success) {
219
							dataMD0033_Grid.loadData(result.data);
220
						}
221

    
222
					}
223
				});
224

    
225
		$.ajax({
226
					url : "HR_PA/GetLoanRegPayment",
227
					data : {
228
						md_type : "empmd0034",
229
						emp_id : empid2,
230
						start_date : stdate,
231
						end_date : edate,
232
						loan_type : lntype,
233
						seq : seq
234
					},
235
					async : false,
236
					success : function(result) {
237

    
238
						if (result.success) {
239
							dataMD0034_Grid.loadData(result.data);
240
						}
241

    
242
					}
243
				});
244
	}
245

    
246
	// loan payment button
247
	var btnhide = false;
248
	if (accesscode == "main") {
249
		btnhide = false;
250
	}
251

    
252
	if (accesscode == "disp") {
253
		btnhide = true;
254
	}
255

    
256
	var btnAdd1 = new Ext.Button({
257
				text : 'Add',
258
				hidden : btnhide,
259
				iconCls : 'icon-add'
260
			});
261
	btnAdd1.on('click', function() {
262
				refreshgrid2();
263
				fnaddclick1();
264
			});
265

    
266
	function fnaddclick1() {
267
		action1.setValue("insertnew");
268
		pnlPayData.getForm().reset();
269
		var lntype = Ext.getCmp('loan_type' + gen).getValue();
270
		var seq = Ext.getCmp('seq' + gen).getValue();
271
		fldMD0033loantype.setValue(lntype);
272
		fldMD0033loanseq.setValue(seq);
273
		fldMD0033mdtype.setValue('empmd0033');
274
		pnlPayData.getForm().submit({
275
			url : "/HR_PA/DefineKeysMasterData/",
276
			success : function(form, action) {
277
				var result = action.result;
278
				var fields = ["key_landscape", "key_emp_id", "key_start_date",
279
						"key_end_date", "key_loan_type", "key_seq",
280
						"key_payment_type"];
281
				var record = fnJsonToRecord(result.data, fields);
282
			}
283
		});
284
		pnlLoanPay.layout.setActiveItem(1);
285
	}
286

    
287
	var btnCopy1 = new Ext.Button({
288
				text : 'Copy',
289
				hidden : btnhide,
290
				iconCls : 'icon-page_copy'
291
			});
292
	btnCopy1.on('click', function() {
293
				action1.setValue("insert");
294
				clickgrid1();
295
			});
296

    
297
	var btnDel1 = new Ext.Button({
298
				text : 'Delete',
299
				hidden : btnhide,
300
				iconCls : 'icon-delete'
301
			});
302
	btnDel1.on('click', function() {
303
				fndeleteclick1();
304
			});
305

    
306
	function fndeleteclick1() {
307
		pnlPayData.getForm().submit({
308
					url : "/HR_PA/DeletePersonMasterData/",
309
					success : function(form, action) {
310
						refreshgrid2();
311
						pnlLoanPay.layout.setActiveItem(0);
312
						action1.setValue("update");
313
					},
314
					failure : function(form, action) {
315
						alert("Deleting Error");
316
					}
317
				});
318
	}
319

    
320
	var btnSave1 = new Ext.Button({
321
				text : 'Save',
322
				hidden : btnhide,
323
				iconCls : 'icon-table_save'
324
			});
325
	btnSave1.on('click', function() {
326
				fnsaveclick1();
327
			});
328

    
329
	function fnsaveclick1() {
330
		var url = "/HR_PA/EditMasterData/";
331
		if (action1.getValue() == "insert") {
332
			url = "/HR_PA/AddMasterData/";
333
		}
334
		if (action1.getValue() == "insertnew") {
335
			// var _empid = headerEmpID.getValue();
336
			fldMD0033empid.setValue(empid2);
337
			url = "/HR_PA/AddMasterData/";
338
		}
339
		pnlPayData.getForm().submit({
340
					url : url,
341
					clientValidation: true,
342
					success : function(form, action) {
343
						refreshgrid2();
344
						pnlLoanPay.layout.setActiveItem(0);
345
						action1.setValue("update");
346
					},
347
					failure : function(form, action) {
348
						alert("error on : "+ action.failureType);
349
					}
350
				});
351
	}
352

    
353
	var btnCancel1 = new Ext.Button({
354
				text : 'Cancel',
355
				iconCls : 'icon-arrow_undo'
356
			});
357
	btnCancel1.on('click', function() {
358
				pnlLoanPay.layout.setActiveItem(0);
359
				refreshgrid2();
360
				action1.setValue("update");
361
			});
362

    
363
	var action1 = new Ext.form.Hidden({
364
				name : "action",
365
				value : "update"
366
			});
367

    
368
	// loan regular payment button
369

    
370
	var btnAdd2 = new Ext.Button({
371
				text : 'Add',
372
				hidden : btnhide,
373
				iconCls : 'icon-add'
374
			});
375
	btnAdd2.on('click', function() {
376
				refreshgrid2();
377
				fnaddclick2();
378
				fnFilledate34();
379
			});
380

    
381
	function hitungtenor()
382
	{
383
		var tenor = parseFloat(fldMD0034tenor.getValue());
384
		var ln = Ext.getCmp('amount' + gen).getValue();		
385
		var lnreplace = ln.replace(",", "");
386
		lnreplace = lnreplace.replace(",", "");
387
		lnreplace = lnreplace.replace(",", "");
388
		lnreplace = lnreplace.replace(",", "");
389
		lnreplace = lnreplace.replace(",", "");
390
		lnreplace = lnreplace.replace(",", "");
391
		lnreplace = lnreplace.replace(",", "");
392
		//console.log(lnreplace);
393
		var lnval = parseFloat(lnreplace);
394
		var hasil = lnval / tenor;
395
		//alert(ln);
396
		//alert(tenor);
397
		//alert(lnval);
398
		fldMD0034amount.setValue(hasil);
399
	}
400
			
401
	function fnaddclick2() {
402
		action2.setValue("insertnew");
403
		pnlRegPayData.getForm().reset();
404
		var tenval = Trim(fldMD0034tenor.getValue());
405
		
406
		if (tenval == '')
407
		{
408
			fldMD0034tenor.setValue('60');
409
			var tenor = parseFloat(fldMD0034tenor.getValue());
410
			var ln = Ext.getCmp('amount' + gen).getValue();		
411
			var lnreplace = ln.replace(",", "");
412
			lnreplace = lnreplace.replace(",", "");
413
			lnreplace = lnreplace.replace(",", "");
414
			lnreplace = lnreplace.replace(",", "");
415
			lnreplace = lnreplace.replace(",", "");
416
			lnreplace = lnreplace.replace(",", "");
417
			lnreplace = lnreplace.replace(",", "");
418
			//console.log(lnreplace);
419
			var lnval = parseFloat(lnreplace);
420
			
421
			//alert(ln);
422
			//alert(tenor);
423
			//alert(lnval);
424
			var hasil = lnval / tenor;
425
			fldMD0034amount.setValue(hasil);
426
		}
427
		
428
		var lntype = Ext.getCmp('loan_type' + gen).getValue();
429
		var seq = Ext.getCmp('seq' + gen).getValue();
430
		fldMD0034loantype.setValue(lntype);
431
		fldMD0034loanseq.setValue(seq);
432
		fldMD0034mdtype.setValue('empmd0034');
433
		pnlPayData.getForm().submit({
434
			url : "/HR_PA/DefineKeysMasterData/",
435
			success : function(form, action) {
436
				var result = action.result;
437
				var fields = ["key_landscape", "key_emp_id", "key_start_date",
438
						"key_end_date", "key_loan_type", "key_seq",
439
						"key_payment_type"];
440
				var record = fnJsonToRecord(result.data, fields);
441
				
442
			}
443
		});
444
		pnlLoanRegPay.layout.setActiveItem(1);
445
	}
446

    
447
	var btnCopy2 = new Ext.Button({
448
				text : 'Copy',
449
				hidden : btnhide,
450
				iconCls : 'icon-page_copy'
451
			});
452
	btnCopy2.on('click', function() {
453
				action2.setValue("insert");
454
				clickgrid2();
455
			});
456

    
457
	var btnDel2 = new Ext.Button({
458
				text : 'Delete',
459
				hidden : btnhide,
460
				iconCls : 'icon-delete'
461
			});
462
	btnDel2.on('click', function() {
463
				fndeleteclick2();
464
			});
465

    
466
	function fndeleteclick2() {
467
		pnlRegPayData.getForm().submit({
468
					url : "/HR_PA/DeletePersonMasterData/",
469
					success : function(form, action) {
470
						refreshgrid2();
471
						pnlLoanRegPay.layout.setActiveItem(0);
472
						action2.setValue("update");
473
					},
474
					failure : function(form, action) {
475
						alert("Deleting Error");
476
					}
477
				});
478
	}
479

    
480
	var btnSave2 = new Ext.Button({
481
				text : 'Save',
482
				hidden : btnhide,
483
				iconCls : 'icon-table_save'
484
			});
485
	btnSave2.on('click', function() {
486
				fnsaveclick2();
487
			});
488

    
489
	function fnsaveclick2() {
490
		var url = "/HR_PA/UpdateMasterData/";
491
		if (action2.getValue() == "insert") {
492
			url = "/HR_PA/AddMasterData/";
493
		}
494
		if (action2.getValue() == "insertnew") {
495
			fldMD0034empid.setValue(empid2);
496
			url = "/HR_PA/AddMasterData/";
497
		}
498
		pnlRegPayData.getForm().submit({
499
					url : url,
500
					clientValidation: true,
501
					success : function(form, action) {
502
						refreshgrid2();
503
						pnlLoanRegPay.layout.setActiveItem(0);
504
						action2.setValue("update");
505
					},
506
					failure : function(form, action) {
507
						var hasil = Ext.decode(action.response.responseText)
508
						alert(hasil.message.text);
509
					}
510
				});
511
	}
512

    
513
	var btnCancel2 = new Ext.Button({
514
				text : 'Cancel',
515
				iconCls : 'icon-arrow_undo'
516
			});
517
	btnCancel2.on('click', function() {
518
				pnlLoanRegPay.layout.setActiveItem(0);
519
				refreshgrid2();
520
				action2.setValue("update");
521
			});
522

    
523
	var action2 = new Ext.form.Hidden({
524
				name : "action",
525
				value : "update"
526
			});
527

    
528
	// loan payment field
529

    
530
	var fldMD0033landscape_key = new Ext.form.Hidden({
531
				name : 'key_landscape'
532
			});
533
	var fldMD0033empid_key = new Ext.form.Hidden({
534
				name : 'key_emp_id'
535
			});
536
	var fldMD0033stdate_key = new Ext.form.Hidden({
537
				name : 'key_start_date'
538
			});
539
	var fldMD0033edate_key = new Ext.form.Hidden({
540
				name : 'key_end_date'
541
			});
542
	var fldMD0033loantype_key = new Ext.form.Hidden({
543
				name : 'key_loan_type'
544
			});
545
	var fldMD0033seq_key = new Ext.form.Hidden({
546
				name : 'key_seq'
547
			});
548
	var fldMD0033paymenttype_key = new Ext.form.Hidden({
549
				name : 'key_payment_type'
550
			});
551
	var fldMD0033loanseq_key = new Ext.form.Hidden({
552
				name : 'key_loan_seq'
553
			});
554

    
555
	var fldMD0033mdtype = new Ext.form.Hidden({
556
				fieldLabel : 'MD Type',
557
				name : 'md_type',
558
				value : 'empmd0033'
559
			});
560

    
561
	var fldMD0033empid = new Ext.form.Hidden({
562
				fieldLabel : 'Employee ID',
563
				name : 'emp_id'
564
			});
565

    
566
	var fldMD0033stdate = new Ext.form.DateField({
567
				fieldLabel : 'Payment Date',
568
				format : 'd/m/Y',
569
				allowBlank : false,
570
				cls : 'minova-mandatory',
571
				msgTarget : 'side'
572
			});
573
	fldMD0033stdate.on('change', function(fld, nval, oval, toFld) {
574
				fnDateChg2(fld, nval, oval, fldMD0033stdateHid);
575
				fnFilledate33();
576
			});
577
	fldMD0033stdate.on('select', function(fld, dt, toFld) {
578
				fnDateSelect2(fld, dt, fldMD0033stdateHid);
579
				fnFilledate33();
580
			});
581

    
582
	var fldMD0033stdateHid = new Ext.form.Hidden({
583
				id : 'fldMD0033stdate',
584
				name : 'start_date',
585
				value : ''
586
			});
587
	fldMD0033stdateHid.on('change', function(fld, nval, oval, toFld) {
588
				fnDateHidChg2(fld, nval, oval, fldMD0033stdate);
589
			});
590

    
591
	var fldMD0033edate = new Ext.form.DateField({
592
				fieldLabel : 'End Date',
593
				format : 'd/m/Y',
594
				allowBlank : false,
595
				cls : 'minova-mandatory',
596
				msgTarget : 'side',
597
				hidden : true,
598
				hideLabel : true
599
			});
600
	fldMD0033edate.on('change', function(fld, nval, oval, toFld) {
601
				fnDateChg2(fld, nval, oval, fldMD0033edateHid);
602
			});
603
	fldMD0033edate.on('select', function(fld, dt, toFld) {
604
				fnDateSelect2(fld, dt, fldMD0033edateHid);
605
			});
606

    
607
	var fldMD0033edateHid = new Ext.form.Hidden({
608
				id : 'fldMD0033edate',
609
				name : 'end_date',
610
				value : ''
611
			});
612
	fldMD0033edateHid.on('change', function(fld, nval, oval, toFld) {
613
				fnDateHidChg2(fld, nval, oval, fldMD0033edate);
614
			});
615

    
616
	var fldMD0033loantype = new Ext.form.ComboBox({
617
				allowBlank : false,
618
				cls : 'minova-readonly',
619
				msgTarget : 'side',
620
				fieldLabel : 'Loan Type',
621
				hiddenName : 'loan_type',
622
				typeAhead : false,
623
				editable : false,
624
				triggerAction : 'all',
625
				readOnly : true,
626
				mode : 'local',
627
				store : new Ext.data.JsonStore({
628
							fields : ['code', 'desc'],
629
							url : '/HR_Core/GetAllLoanType/'
630
						}),
631
				valueField : 'code',
632
				displayField : 'desc',
633
				listeners : {
634
					render : function() {
635
						fldMD0033loantype.getStore().load();
636
					}
637
				}
638
			});
639

    
640
	var fldMD0033seq = new Ext.form.TextField({
641
				cls : 'minova-readonly',
642
				fieldLabel : 'Sequence',
643
				name : 'seq',
644
				readOnly : true
645
			});
646

    
647
	var fldMD0033paymenttype = new Ext.form.ComboBox({
648
				allowBlank : false,
649
				cls : 'minova-mandatory',
650
				msgTarget : 'side',
651
				fieldLabel : 'Payment Type',
652
				hiddenName : 'payment_type',
653
				typeAhead : false,
654
				editable : false,
655
				triggerAction : 'all',
656
				mode : 'local',
657
				store : new Ext.data.JsonStore({
658
							fields : ['code', 'desc'],
659
							url : '/HR_Core/GetPaymentType/'
660
						}),
661
				valueField : 'code',
662
				displayField : 'desc',
663
				listeners : {
664
					render : function() {
665
						fldMD0033paymenttype.getStore().load();
666
					}
667
				}
668
			});
669

    
670
	var fldMD0033amount = new Ext.form.TextField({
671
				id : 'fldMD0033amount',
672
				fieldLabel : 'Amount',
673
				name : 'amount',
674
				allowBlank : false,
675
				cls : 'minova-mandatory',
676
				msgTarget : 'side',
677
				listeners : {
678
					change : function(fld, nval, oval) {
679
						eval("fnAmount('fldMD0033amount','fldMD0033amount','"
680
								+ nval + "');");
681
					}
682
				}
683
			});
684

    
685
	var fldMD0033interest = new Ext.form.TextField({
686
				fieldLabel : 'Interest',
687
				name : 'interest',
688
				allowBlank : false,
689
				cls : 'minova-mandatory',
690
				msgTarget : 'side'
691
			});
692

    
693
	var fldMD0033loanseq = new Ext.form.TextField({
694
				fieldLabel : 'Loan Sequence',
695
				name : 'loan_seq',
696
				allowBlank : false,
697
				cls : 'minova-readonly',
698
				msgTarget : 'side',
699
				readOnly : true
700
			});
701

    
702
	// loan regular payment field
703

    
704
	var fldMD0034landscape_key = new Ext.form.Hidden({
705
				name : 'key_landscape'
706
			});
707
	var fldMD0034empid_key = new Ext.form.Hidden({
708
				name : 'key_emp_id'
709
			});
710
	var fldMD0034stdate_key = new Ext.form.Hidden({
711
				name : 'key_start_date'
712
			});
713
	var fldMD0034edate_key = new Ext.form.Hidden({
714
				name : 'key_end_date'
715
			});
716
	var fldMD0034loantype_key = new Ext.form.Hidden({
717
				name : 'key_loan_type'
718
			});
719
	var fldMD0034seq_key = new Ext.form.Hidden({
720
				name : 'key_seq'
721
			});
722
	var fldMD0034paymenttype_key = new Ext.form.Hidden({
723
				name : 'key_payment_type'
724
			});
725
	var fldMD0034loanseq_key = new Ext.form.Hidden({
726
				name : 'key_loan_seq'
727
			});
728

    
729
	var fldMD0034mdtype = new Ext.form.Hidden({
730
				fieldLabel : 'MD Type',
731
				name : 'md_type',
732
				value : 'empmd0034'
733
			});
734

    
735
	var fldMD0034empid = new Ext.form.Hidden({
736
				fieldLabel : 'Employee ID',
737
				name : 'emp_id'
738
			});
739

    
740
	var fldMD0034stdate = new Ext.form.DateField({
741
				fieldLabel : 'Start Date',
742
				format : 'd/m/Y',
743
				allowBlank : false,
744
				cls : 'minova-mandatory',
745
				msgTarget : 'side'
746
			});
747
	fldMD0034stdate.on('change', function(fld, nval, oval, toFld) {
748
				fnDateChg2(fld, nval, oval, fldMD0034stdateHid);
749
			});
750
	fldMD0034stdate.on('select', function(fld, dt, toFld) {
751
				fnDateSelect2(fld, dt, fldMD0034stdateHid);
752
			});
753

    
754
	var fldMD0034stdateHid = new Ext.form.Hidden({
755
				name : 'start_date',
756
				value : ''
757
			});
758
	fldMD0034stdateHid.on('change', function(fld, nval, oval, toFld) {
759
				fnDateHidChg2(fld, nval, oval, fldMD0034stdate);
760
			});
761

    
762
	var fldMD0034edate = new Ext.form.DateField({
763
				fieldLabel : 'End Date',
764
				format : 'd/m/Y',
765
				allowBlank : false,
766
				cls : 'minova-mandatory',
767
				hidden : true,
768
				hideLabel : true,
769
				msgTarget : 'side'
770
			});
771
	fldMD0034edate.on('change', function(fld, nval, oval, toFld) {
772
				fnDateChg2(fld, nval, oval, fldMD0034edateHid);
773
			});
774
	fldMD0034edate.on('select', function(fld, dt, toFld) {
775
				fnDateSelect2(fld, dt, fldMD0034edateHid);
776
			});
777

    
778
	var fldMD0034edateHid = new Ext.form.Hidden({
779
				id : 'fldMD0034edate',
780
				name : 'end_date',
781
				value : ''
782
			});
783
	fldMD0034edateHid.on('change', function(fld, nval, oval, toFld) {
784
				fnDateHidChg2(fld, nval, oval, fldMD0034edate);
785
			});
786

    
787
	var fldMD0034loantype = new Ext.form.ComboBox({
788
				allowBlank : false,
789
				cls : 'minova-readonly',
790
				msgTarget : 'side',
791
				fieldLabel : 'Loan Type',
792
				hiddenName : 'loan_type',
793
				typeAhead : false,
794
				editable : false,
795
				triggerAction : 'all',
796
				readOnly : true,
797
				mode : 'local',
798
				store : new Ext.data.JsonStore({
799
							fields : ['code', 'desc'],
800
							url : '/HR_Core/GetAllLoanType/'
801
						}),
802
				valueField : 'code',
803
				displayField : 'desc',
804
				listeners : {
805
					render : function() {
806
						fldMD0034loantype.getStore().load();
807
					}
808
				}
809
			});
810

    
811
	var fldMD0034seq = new Ext.form.TextField({
812
				cls : 'minova-readonly',
813
				fieldLabel : 'Sequence',
814
				name : 'seq',
815
				readOnly : true
816
			});
817

    
818
	var fldMD0034paymenttype = new Ext.form.ComboBox({
819
				allowBlank : false,
820
				cls : 'minova-mandatory',
821
				msgTarget : 'side',
822
				fieldLabel : 'Payment Type',
823
				hiddenName : 'payment_type',
824
				typeAhead : false,
825
				editable : false,
826
				triggerAction : 'all',
827
				mode : 'local',
828
				store : new Ext.data.JsonStore({
829
							fields : ['code', 'desc'],
830
							url : '/HR_Core/GetRegPaymentType/'
831
						}),
832
				valueField : 'code',
833
				displayField : 'desc',
834
				listeners : {
835
					render : function() {
836
						fldMD0034paymenttype.getStore().load();
837
					}
838
				}
839
			});
840

    
841
	var fldMD0034interest = new Ext.form.TextField({
842
				fieldLabel : 'Interest',
843
				name : 'interest',
844
				allowBlank : false,
845
				cls : 'minova-mandatory',
846
				msgTarget : 'side'
847
			});
848

    
849
	var fldMD0034loanseq = new Ext.form.TextField({
850
				fieldLabel : 'Loan Sequence',
851
				name : 'loan_seq',
852
				allowBlank : false,
853
				cls : 'minova-readonly',
854
				msgTarget : 'side',
855
				readOnly : true
856
			});
857

    
858
	// loan payment data left
859
	var pnlFormleft1 = new Ext.Panel({
860
		bodyStyle : 'padding:10px 10px 0',
861
		border : false,
862
		isForm : true,
863
		layout : 'form',
864
		width : 350,
865
		height : 300,
866
		items : [[fldMD0033landscape_key], [fldMD0033empid_key],
867
				[fldMD0033stdate_key], [fldMD0033edate_key],
868
				[fldMD0033loantype_key], [fldMD0033seq_key],
869
				[fldMD0033paymenttype_key], [fldMD0033loanseq_key],
870
				[fldMD0033mdtype], [fldMD0033empid], [fldMD0033stdate],
871
				[fldMD0033stdateHid], [fldMD0033edate], [fldMD0033edateHid],
872
				[fldMD0033loantype], [fldMD0033loanseq], [fldMD0033paymenttype]]
873
	});
874

    
875
	// loan regular payment data left
876
	var pnlFormleft2 = new Ext.Panel({
877
		bodyStyle : 'padding:10px 10px 0',
878
		border : false,
879
		isForm : true,
880
		layout : 'form',
881
		width : 350,
882
		height : 300,
883
		items : [[fldMD0034landscape_key], [fldMD0034empid_key],
884
				[fldMD0034stdate_key], [fldMD0034edate_key],
885
				[fldMD0034loantype_key], [fldMD0034seq_key],
886
				[fldMD0034paymenttype_key], [fldMD0034loanseq_key],
887
				[fldMD0034mdtype], [fldMD0034empid], [fldMD0034stdate],
888
				[fldMD0034stdateHid], [fldMD0034edate], [fldMD0034edateHid],
889
				[fldMD0034loantype], [fldMD0034loanseq], [fldMD0034paymenttype]]
890
	});
891

    
892
	// loan payment data right
893
	var pnlFormright1 = new Ext.Panel({
894
				bodyStyle : 'padding:10px 10px 0',
895
				border : false,
896
				isForm : true,
897
				layout : 'form',
898
				width : 350,
899
				height : 300,
900
				items : [[fldMD0033seq], [fldMD0033paymenttype],
901
						[fldMD0033amount]]
902
			});
903

    
904
	// loan regular payment data right
905
	var pnlFormright2 = new Ext.Panel({
906
				bodyStyle : 'padding:10px 10px 0',
907
				border : false,
908
				isForm : true,
909
				layout : 'form',
910
				width : 350,
911
				height : 300,
912
				items : [[fldMD0034seq], [fldMD0034paymenttype],
913
						[fldMD0034amount], [fldMD0034tenor]]
914
			});
915

    
916
	// loan payment data
917
	var pnlPayData = new Ext.form.FormPanel({
918
				autoScroll : true,
919
				border : true,
920
				isForm : true,
921
				fileUpload: true,
922
				layout : 'hbox',
923
				items : [[pnlFormleft1], [pnlFormright1]]
924
			});
925

    
926
	// loan payment data
927
	var pnlRegPayData = new Ext.form.FormPanel({
928
				autoScroll : true,
929
				border : true,
930
				fileUpload: true,
931
				isForm : true,
932
				layout : 'hbox',
933
				items : [[pnlFormleft2], [pnlFormright2]]
934
			});
935

    
936
	// loan payment detail
937
	var pnlPayDetail = new Ext.Panel({
938
				layout : 'fit',
939
				bbar : [[btnSave1], [btnDel1], [btnCancel1]],
940
				items : [[pnlPayData]]
941
			});
942

    
943
	// loan regular payment detail
944
	var pnlRegPayDetail = new Ext.Panel({
945
				layout : 'fit',
946
				bbar : [[btnSave2], [btnDel2], [btnCancel2]],
947
				items : [[pnlRegPayData]]
948
			});
949

    
950
	// loan payment grid
951
	var pnlPayGrid = new Ext.grid.GridPanel({
952
				store : dataMD0033_Grid,
953
				border : false,
954
				viewConfig : {
955
					emptyText : "No Record"
956
				},
957
				columns : [{
958
							header : "Landscape",
959
							dataIndex : "landscape",
960
							hidden : true
961
						}, {
962
							header : "Employee ID",
963
							dataIndex : "emp_id",
964
							hidden : true
965
						}, {
966
							header : "Payment Date",
967
							dataIndex : "start_date"
968
						}, {
969
							header : "End Date",
970
							dataIndex : "end_date",
971
							hidden : true
972
						}, {
973
							header : "Loan Sequence",
974
							dataIndex : "loan_seq",
975
							hidden : true
976
						}, {
977
							header : "Loan Type",
978
							dataIndex : "loan_type"
979
						}, {
980
							header : "Sequence",
981
							dataIndex : "seq"
982
						}, {
983
							header : "Payment Type",
984
							dataIndex : "payment_type"
985
						}, {
986
							header : "Amount",
987
							dataIndex : "amount",
988
							align : "right"
989
						}, {
990
							header : "Interest",
991
							dataIndex : "interest",
992
							hidden : true
993
						}],
994
				tbar : [[btnAdd1], [btnCopy1]],
995
				listeners : {
996
					render : function() {
997
						pnlPayGrid.getColumnModel()
998
								.setRenderer(2, fnGrid_Date8);
999
						pnlPayGrid.getColumnModel()
1000
								.setRenderer(3, fnGrid_Date8);
1001
						pnlPayGrid.getColumnModel().setRenderer(5,
1002
								fnGrid_loantype);
1003
						pnlPayGrid.getColumnModel().setRenderer(7,
1004
								fnGrid_paymenttype33);
1005
						pnlPayGrid.getColumnModel().setRenderer(8,
1006
								fnGrid_amount);
1007
					}
1008
				}
1009
			});
1010
	pnlPayGrid.on('rowdblclick', function(thisGrid, rowIndex) {
1011
				action1.setValue("update");
1012
				clickgrid1();
1013
			});
1014

    
1015
	function clickgrid1() {
1016
		pnlLoanPay.layout.setActiveItem(1);
1017
		var selected = pnlPayGrid.getSelectionModel().getSelected();
1018
		pnlPayData.getForm().loadRecord(selected);
1019
		pnlPayData.getForm().submit({
1020
			url : "/HR_PA/DefineKeysMasterData/",
1021
			success : function(form, action) {
1022
				var result = action.result;
1023
				var fields = ["key_landscape", "key_emp_id", "key_start_date",
1024
						"key_end_date", "key_loan_type", "key_seq",
1025
						"key_payment_type"];
1026
				var record = fnJsonToRecord(result.data, fields);
1027
				pnlPayData.getForm().loadRecord(record);
1028
			},
1029
			failure : function(form, action) {
1030
			}
1031
		});
1032
	}
1033

    
1034
	// loan regular payment grid
1035
	var pnlRegPayGrid = new Ext.grid.GridPanel({
1036
				store : dataMD0034_Grid,
1037
				border : false,
1038
				viewConfig : {
1039
					emptyText : "No Record"
1040
				},
1041
				columns : [{
1042
							header : "Landscape",
1043
							dataIndex : "landscape",
1044
							hidden : true
1045
						}, {
1046
							header : "Employee ID",
1047
							dataIndex : "emp_id",
1048
							hidden : true
1049
						}, {
1050
							header : "Start Date",
1051
							dataIndex : "start_date"
1052
						}, {
1053
							header : "End Date",
1054
							dataIndex : "end_date"
1055
						}, {
1056
							header : "Loan Sequence",
1057
							dataIndex : "loan_seq",
1058
							hidden : true
1059
						}, {
1060
							header : "Loan Type",
1061
							dataIndex : "loan_type"
1062
						}, {
1063
							header : "Sequence",
1064
							dataIndex : "seq"
1065
						}, {
1066
							header : "Payment Type",
1067
							dataIndex : "payment_type"
1068
						}, {
1069
							header : "Amount",
1070
							dataIndex : "amount",
1071
							align : "right"
1072
						}, {
1073
							header : "Interest",
1074
							dataIndex : "interest",
1075
							hidden : true
1076
						}],
1077
				tbar : [[btnAdd2], [btnCopy2]],
1078
				listeners : {
1079
					render : function() {
1080
						pnlRegPayGrid.getColumnModel().setRenderer(2,
1081
								fnGrid_Date8);
1082
						pnlRegPayGrid.getColumnModel().setRenderer(3,
1083
								fnGrid_Date8);
1084
						pnlRegPayGrid.getColumnModel().setRenderer(5,
1085
								fnGrid_loantype);
1086
						pnlRegPayGrid.getColumnModel().setRenderer(7,
1087
								fnGrid_paymenttype34);
1088
						pnlRegPayGrid.getColumnModel().setRenderer(8,
1089
								fnGrid_amount);
1090
					}
1091
				}
1092
			});
1093
	pnlRegPayGrid.on('rowdblclick', function(thisGrid, rowIndex) {
1094
				action2.setValue("update");
1095
				clickgrid2();
1096
			});
1097

    
1098
	function clickgrid2() {
1099
		pnlLoanRegPay.layout.setActiveItem(1);
1100
		var selected = pnlRegPayGrid.getSelectionModel().getSelected();
1101
		pnlRegPayData.getForm().loadRecord(selected);
1102
		pnlRegPayData.getForm().submit({
1103
			url : "/HR_PA/DefineKeysMasterData/",
1104
			success : function(form, action) {
1105
				var result = action.result;
1106
				var fields = ["key_landscape", "key_emp_id", "key_start_date",
1107
						"key_end_date", "key_loan_type", "key_seq",
1108
						"key_payment_type"];
1109
				var record = fnJsonToRecord(result.data, fields);
1110
				pnlRegPayData.getForm().loadRecord(record);
1111
				fnFilledate34();
1112
			},
1113
			failure : function(form, action) {
1114
			}
1115
		});
1116
	}
1117

    
1118
	// loan payment
1119
	var pnlLoanPay = new Ext.Panel({
1120
				title : "Loan Payment",
1121
				activeItem : 0,
1122
				layout : 'card',
1123
				items : [[pnlPayGrid], [pnlPayDetail]]
1124
			});
1125

    
1126
	// loan regular payment
1127
	var pnlLoanRegPay = new Ext.Panel({
1128
				title : "Loan Regular Repayment",
1129
				activeItem : 0,
1130
				layout : 'card',
1131
				items : [[pnlRegPayGrid], [pnlRegPayDetail]]
1132
			});
1133

    
1134
	// MD benefit
1135
	var pnlMDbnft = new Ext.TabPanel({
1136
				autoScroll : true,
1137
				title : "Master Data Benefit",
1138
				region : "north",
1139
				height : 200,
1140
				activeTab : 0,
1141
				bbar : [[btnSimulate], [btnLoadBalance]],
1142
				items : [[pnlLoanPay], [pnlLoanRegPay]]
1143
			});
1144

    
1145
	// MD grid
1146
	var pnlMDGrid2 = new Ext.grid.GridPanel({
1147
				id : 'pnlMDGrid2',
1148
				autoScroll : true,
1149
				store : dataMD0035_Grid,
1150
				viewConfig : {
1151
					emptyText : "No Record"
1152
				},
1153
				columns : [{
1154
							header : "Landscape",
1155
							dataIndex : "landscape",
1156
							hidden : true
1157
						}, {
1158
							header : "Employee ID",
1159
							dataIndex : "emp_id",
1160
							hidden : true
1161
						}, {
1162
							header : "Start Date",
1163
							dataIndex : "start_date"
1164
						}, {
1165
							header : "End Date",
1166
							dataIndex : "end_date"
1167
						}, {
1168
							header : "Loan Type",
1169
							dataIndex : "loan_type"
1170
						}, {
1171
							header : "Sequence",
1172
							dataIndex : "seq",
1173
							hidden : true
1174
						}, {
1175
							header : "Balance Sequence",
1176
							dataIndex : "balance_seq"
1177
						}, {
1178
							header : "Period",
1179
							dataIndex : "period"
1180
						}, {
1181
							header : "Principal",
1182
							dataIndex : "principal",
1183
							align : "right"
1184
						}, {
1185
							header : "Interest",
1186
							dataIndex : "interest",
1187
							align : "right"
1188
						}, {
1189
							header : "Repayment",
1190
							dataIndex : "repayment",
1191
							align : "right"
1192
						}, {
1193
							header : "Balance",
1194
							dataIndex : "balance",
1195
							align : "right"
1196
						}],
1197
				region : "center",
1198
				title : "Loan Balance",
1199
				listeners : {
1200
					render : function() {
1201
						pnlMDGrid2.getColumnModel()
1202
								.setRenderer(2, fnGrid_Date8);
1203
						pnlMDGrid2.getColumnModel()
1204
								.setRenderer(3, fnGrid_Date8);
1205
						pnlMDGrid2.getColumnModel().setRenderer(4,
1206
								fnGrid_loantype);
1207
						pnlMDGrid2.getColumnModel().setRenderer(8,
1208
								fnGrid_amount);
1209
						pnlMDGrid2.getColumnModel().setRenderer(9,
1210
								fnGrid_amount);
1211
						pnlMDGrid2.getColumnModel().setRenderer(10,
1212
								fnGrid_amount);
1213
						pnlMDGrid2.getColumnModel().setRenderer(11,
1214
								fnGrid_amount);
1215
					}
1216
				}
1217
			});
1218

    
1219
	// main panel
1220
	var idTemp = gen2 + '_temp';
1221
	var pnlTemp = new Ext.Panel({
1222
				autoScroll : true,
1223
				layout : 'border',
1224
				title : "Loan Simulation",
1225
				id : idTemp,
1226
				height : 500,
1227
				items : [[pnlMDbnft], [pnlMDGrid2]]
1228
			});
1229
			
1230
	Ext.getCmp("pnlFormBottom" + gen).add(pnlTemp);
1231
	Ext.getCmp("pnlFormBottom" + gen).doLayout();
1232

    
1233
	// function datefield
1234
	function fnDateChg2(fld, nval, oval, toFld) {
1235
		try {
1236
			if (nval != null) {
1237
				var dt = Date.parseDate(nval, "d/m/Y");
1238
				if (dt == null)
1239
					return;
1240
				var stDate = dt.format("Ymd");
1241
				if (toFld.getValue() != stDate) {
1242
					toFld.setValue(stDate);
1243
				}
1244
			}
1245
		} catch (e) {
1246
		}
1247
	}
1248

    
1249
	function fnDateSelect2(fld, dt, toFld) {
1250
		try {
1251
			var _stDate = dt.format("Ymd");
1252
			toFld.setValue(_stDate);
1253
		} catch (e) {
1254
		}
1255
	}
1256

    
1257
	function fnDateHidChg2(fld, nval, oval, toFld) {
1258
		try {
1259
			var _dt = Date.parseDate(nval, "Ymd");
1260
			toFld.setValue(_dt);
1261
		} catch (e) {
1262
		}
1263
	}
1264
	
1265
	fldMD0033paymenttype.getStore().load();
1266
	fldMD0034loantype.getStore().load();
1267
	fldMD0034paymenttype.getStore().load();
1268

    
1269
	function fnGrid_loantype(val) {
1270
		//fldMD0034loantype.getStore().load();
1271
		var index = fldMD0034loantype.getStore().find('code', val);
1272
		if (index != -1) {
1273
			var rec = fldMD0034loantype.getStore().getAt(index);
1274
			return rec.get("desc");
1275
		} else {
1276
			return val;
1277
		}
1278
	}
1279

    
1280
	function fnGrid_paymenttype33(val) {
1281
		//fldMD0033paymenttype.getStore().load();
1282
		var index = fldMD0033paymenttype.getStore().find('code', val);
1283
		if (index != -1) {
1284
			var rec = fldMD0033paymenttype.getStore().getAt(index);
1285
			return rec.get("desc");
1286
		} else {
1287
			return val;
1288
		}
1289
	}
1290

    
1291
	function fnGrid_paymenttype34(val) {
1292
		//fldMD0034paymenttype.getStore().load();
1293
		var index = fldMD0034paymenttype.getStore().find('code', val);
1294
		if (index != -1) {
1295
			var rec = fldMD0034paymenttype.getStore().getAt(index);
1296
			return rec.get("desc");
1297
		} else {
1298
			return val;
1299
		}
1300
	}
1301

    
1302
	fnInitForm();
1303

    
1304
	function fnFilledate33() {
1305
		try {
1306
			var begda = Ext.getCmp("fldMD0033stdate").getValue();
1307
			Ext.getCmp("fldMD0033edate").setValue(begda);
1308
		} catch (e) {
1309
		}
1310
	}
1311
	
1312
	function fnFilledate34() {
1313
		try {
1314
			Ext.getCmp("fldMD0034edate").setValue("99991231");
1315
		} catch (e) {
1316
		}
1317
	}
1318

    
1319
}
1320

    
1321
else {
1322
}
(5-5/6)