Project

General

Profile

Bug #1416 » document.js

Tri Rizqiaty, 07/28/2022 04:54 PM

 
1
Ext.define('MinovaES.controller.filo.document', {
2
    extend: 'Ext.app.ViewController',
3
    alias: 'controller.document',
4
    action: '0',
5
    transType: undefined,
6
    docType: undefined,
7
    docNo: "None",
8
	dataExist: "",
9
	docStatus: "",
10
	docStatusExist: "",
11
	PostingDateExist: "",
12
    init: function () {
13
        this.control({
14
            'button[name=CreateDoc]': {
15
                click: this.createDoc
16
            },
17
            '[name=searchResult]': {
18
                afterrender: this.afterrenderLookupGrid,
19
                itemdblclick: this.displayDoc,
20
                itemclick: this.displayResultInfo
21
            },
22
            'button[name=CreateDocRef]': {
23
                click: this.getLookupRefDoc
24
            },
25
            '[name=FiloDocMain]': {
26
                afterrender: this.afterrenderDoc
27
            },
28
            '[name=SaveCreateDoc]': {
29
                //click: this.saveDoc
30
                click: function () {
31
                    // this == the button, as we are in the local scope
32
                    console.log('SaveCreateDoc!');
33
                    this.SaveCreateDoc() ////////----  edit by Tri nwh 20220203 ////this.backCreateDoc();
34
                }
35
            },
36
            '[name=Create1Doc]': {
37
                //click: this.saveDoc
38
                click: function () {
39
                    // this == the button, as we are in the local scope
40
                    console.log('Create1Doc!');
41
                    this.backDoc();
42
                    this.loadDoc();
43
                }
44
            },
45
            'button[name=SaveCreateDocRef]': {
46
                click: this.backCreateDoc
47
            },
48
            'button[name=Create1DocRef]': {
49
				click: function () {
50
					this.reloadDoc();
51
                    this.createDoc();
52
                    this.getLookupRefDoc();
53
                }
54
            },
55
            '[name=SaveDoc]': {
56
                click: this.saveDoc
57
            },
58
            '[name=DeleteDoc]': {
59
                click: this.deleteDoc
60
            },
61
            '[name=CancelDoc]': {
62
                click: this.cancelDoc
63
            },
64
            '[name=EditDoc]': {
65
                click: this.editDoc
66
            },
67
            '#DocNo': {
68
                "ontriggerclick": this.getLookupDoc,
69
                specialkey: this.specialKey
70
            },
71
            '#mainTab': {
72
                tabchange: this.changeTab
73
            },
74
            '[name=panelTab]': {
75
                afterrender: this.afterrenderTab
76
            },
77
            '[name=searchFilter]': {
78
                afterrender: this.doctyperender
79
            },
80
			'[name=PostingDate]': {
81
				change: this.PostingDate
82
			}
83
        });
84
    },
85
	
86
	PostingDate: function () { 
87
		var tb = Ext.ComponentQuery.query('[name=panelTab]')[0];
88
        var activeTab = tb.activeTab;
89
		var tbl = activeTab.tbl;
90
		var btnadd = Ext.ComponentQuery.query('[name=add' + tbl + ']')[0].setDisabled(false);
91
        var btndelete = Ext.ComponentQuery.query('[name=delete' + tbl + ']')[0].setDisabled(false);		
92
		/*var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
93
        var formheader = panelHead.getForm();
94
        var FiscalPeriod = formheader.findField("FiscalPeriod").getValue();
95
		var FiscalYear = formheader.findField("FiscalYear").getValue();
96
		var DocStatus = formheader.findField("DocStatus").getValue();
97
		if(DocStatus == '1')
98
		{
99
			var grdPanel = Ext.ComponentQuery.query('[name=GRID' + tbl + ']')[0];
100
			var store = Ext.StoreMgr.lookup("store" + tbl);
101
			for (i = 0; i < store.count(); i++) {			
102
				store.data.items[i].data.FiscalPeriod = FiscalPeriod;
103
				store.data.items[i].data.FiscalYear = FiscalYear;
104
			}	
105
		}*/
106
	},
107
    doctyperender: function () {
108
        var menuID = MinovaUtil.GetMenuID();
109
        var notes = '';
110
        Ext.Ajax.request({
111
            async: false,
112
            method: 'POST',
113
            url: '/UserControl/GetStore',
114
            params: {
115
                tableName: 'SMENU',
116
                param: 'MENUID' + '[=]' + menuID
117
            },
118
            success: function (response) {
119
                var results = Ext.decode(response.responseText);
120
                dt = results.data;
121
                notes = dt[0].Notes;
122
            }
123
        });
124
        console.log(notes);
125

    
126
    },
127
    afterrenderLookupGrid: function () {
128
        var store = Ext.data.StoreManager.lookup('storeadvance');
129
        store.sort('ChangeDate', 'DESC');
130
    },
131
    afterrenderDoc: function () {
132
        var me = this;
133
        var pnlSelect = Ext.ComponentQuery.query('[name=DocSelectionJoil]')[0];
134
        var pnlTransaction = Ext.ComponentQuery.query('[name=DocTransaction]')[0];
135
        var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
136
        var panelDisplayHead = Ext.ComponentQuery.query('[name=DisplayMainHeaderDocument]')[0];
137
        var formHead = panelHead.getForm();
138
        var btnSaveCreate = Ext.ComponentQuery.query('[name=SaveCreateDoc]')[0];
139
        var btnCreate = Ext.ComponentQuery.query('[name=Create1Doc]')[0];
140
        var btnSave = Ext.ComponentQuery.query('[name=SaveDoc]')[0];
141
        var btnEdit = Ext.ComponentQuery.query('[name=EditDoc]')[0];
142
        var btnDelete = Ext.ComponentQuery.query('[name=DeleteDoc]')[0];
143
        var btnPost = Ext.ComponentQuery.query('[name=PostDoc]')[0];
144
		
145
		
146
        //var act = getParam("action");
147
        // var act = me.action;
148
        // if(act == '0'){
149
        // pnlSelect.setHidden(false);
150
        // pnlTransaction.setHidden(true);
151
        // } else {
152
        // pnlSelect.setHidden(true);
153
        // pnlTransaction.setHidden(false);
154
        // if(act == '0'){
155
        // panelHead.setHidden(false);
156
        // panelDisplayHead.setHidden(true);
157
        // btnSave.setDisabled(false);
158
        // btnEdit.setDisabled(true);
159
        // btnDelete.setDisabled(true);
160
        // }
161
        // else if(act == '1'){
162
        // panelHead.setHidden(true);
163
        // panelDisplayHead.setHidden(false);
164
        // btnSave.setDisabled(true);
165
        // btnEdit.setDisabled(false);
166
        // btnDelete.setDisabled(false);
167
        // }
168
        //}
169
        me.transType = panelHead.transType;
170
        me.docType = panelHead.docType;
171
        me.transType = panelDisplayHead.transType;
172
        me.docType = panelDisplayHead.docType;
173
        formHead.findField("DocType").setValue(me.docType);
174
        // if(me.transType == 'FIN'){
175
        // btnPost.setHidden(false);
176
        // }
177
    },
178
    afterrenderTab: function () {
179
        var me = this;
180
        var tb = Ext.ComponentQuery.query('[name=panelTab]')[0];
181
        var activeTab = tb.activeTab;
182
        var keyField = "DocNo";
183
        var keyValue = me.docNo;
184
        var act = me.action;
185
        me.loadTabPanel(activeTab, keyField, keyValue, act);
186
    },
187
    changeTab: function (tabPanel, newCard, oldCard, eOpts) {
188
        var me = this;
189
        var keyField = "DocNo";
190
        var keyValue = me.docNo;
191
        var act = me.action;
192
        me.loadTabPanel(newCard, keyField, keyValue, act);
193
    },
194
    loadTabPanel: function (tabObj, keyField, keyValue, act) {
195
        var tbl = tabObj.tbl;
196
        tabObj.getEl().mask("loading...");
197
        if (tabObj.layoutType == 'L001') {
198
            var dt = undefined;
199
            Ext.Ajax.request({
200
                async: false,
201
                method: 'POST',
202
                url: '/UserControl/GetStore',
203
                params: {
204
                    tableName: tbl,
205
                    param: keyField + '[=]' + keyValue
206
                },
207
                success: function (response) {
208
                    var results = Ext.decode(response.responseText);
209
                    dt = results.data;
210
                }
211
            });
212
            var frmDisplay = Ext.ComponentQuery.query('[name=DISPLAY' + tbl + ']')[0];
213
            var frmForm = Ext.ComponentQuery.query('[name=FORM' + tbl + ']')[0];
214
            if (act == '0') {
215
                frmDisplay.setHidden(true);
216
                frmForm.setHidden(false);
217
            } else if (act == '1' || act == '2') {
218
                frmDisplay.reset();
219
                frmForm.reset();
220
                if (dt.length > 0) {
221
                    frmDisplay.getForm().setValues(dt[0]);
222
                    frmForm.getForm().setValues(dt[0]);
223
                }
224
                frmDisplay.setHidden(false);
225
                frmForm.setHidden(true);
226
            }
227
        }
228
        if (tabObj.layoutType == 'L002' || tabObj.layoutType == 'L003') {
229
            var frmDisplay = Ext.ComponentQuery.query('[name=DISPLAY' + tbl + ']')[0];
230
            var frmForm = Ext.ComponentQuery.query('[name=FORM' + tbl + ']')[0];
231
            var grdPanel = Ext.ComponentQuery.query('[name=GRID' + tbl + ']')[0];
232
            var store = Ext.StoreMgr.lookup("store" + tbl);
233
            store.proxy.extraParams = {
234
                tableName: tbl,
235
                param: keyField + '[=]' + keyValue
236
            };
237
            store.removeAll();
238
            store.reload();
239
            store.loadPage(1);
240
            frmDisplay.reset();
241
            frmForm.reset();
242
            frmDisplay.setHidden(true);
243
            frmForm.setHidden(true);
244
            grdPanel.setHidden(false);
245
        }
246
        if (tabObj.layoutType == 'L005') {
247
            var grdPanel = Ext.ComponentQuery.query('[name=GRID' + tbl + ']')[0];
248
            var store = Ext.StoreMgr.lookup("store" + tbl);
249
            store.proxy.extraParams = {
250
                tableName: tbl,
251
                param: keyField + '[=]' + keyValue
252
            };
253
            store.removeAll();
254
            store.reload();
255
            store.loadPage(1);
256
            grdPanel.setHidden(false);
257
        }
258
        if (tabObj.layoutType == 'L006' || tabObj.layoutType == 'L007') {
259
            var grdPanel = Ext.ComponentQuery.query('[name=CELLGRID' + tbl + ']')[0];
260
            grdPanel.setHidden(false);
261
            if (act == '0') {
262
                var btnadd = Ext.ComponentQuery.query('[name=add' + tbl + ']')[0].setDisabled(false);
263
                var btndelete = Ext.ComponentQuery.query('[name=delete' + tbl + ']')[0].setDisabled(false);
264
                if (tabObj.layoutType == 'L007') {
265
                    var btnupload = Ext.ComponentQuery.query('[name=upload' + tbl + ']')[0].setDisabled(false);
266
                    var btndownload = Ext.ComponentQuery.query('[name=download' + tbl + ']')[0].setDisabled(false);
267
                }
268
            } else if (act == '2') {
269
                var btnadd = Ext.ComponentQuery.query('[name=add' + tbl + ']')[0].setDisabled(true);
270
                var btndelete = Ext.ComponentQuery.query('[name=delete' + tbl + ']')[0].setDisabled(true);
271
                if (tabObj.layoutType == 'L007') {
272
                    var btnupload = Ext.ComponentQuery.query('[name=upload' + tbl + ']')[0].setDisabled(true);
273
                    var btndownload = Ext.ComponentQuery.query('[name=download' + tbl + ']')[0].setDisabled(true);
274
                }
275
                var store = Ext.StoreMgr.lookup("store" + tbl);
276
                store.proxy.url = '/UserControl/GetStore';
277
                store.proxy.extraParams = {
278
                    tableName: tbl,
279
                    param: keyField + '[=]' + keyValue
280
                };
281
                store.removeAll();
282
                store.reload();
283
                store.loadPage(1);
284
            } else {
285
                var btnadd = Ext.ComponentQuery.query('[name=add' + tbl + ']')[0].setDisabled(false);
286
                var btndelete = Ext.ComponentQuery.query('[name=delete' + tbl + ']')[0].setDisabled(false);
287
                if (tabObj.layoutType == 'L007') {
288
                    var btnupload = Ext.ComponentQuery.query('[name=upload' + tbl + ']')[0].setDisabled(false);
289
                    var btndownload = Ext.ComponentQuery.query('[name=download' + tbl + ']')[0].setDisabled(false);
290
                }
291
            }
292

    
293
            if (tabObj.layoutType == 'L007') {
294
                var sumPanel = Ext.ComponentQuery.query('[name=SUM' + tbl + ']')[0];
295
                var sumForm = sumPanel.getForm();
296
                var itm = sumForm.getFields().items;
297
                Ext.Ajax.request({
298
                    async: false,
299
                    method: 'POST',
300
                    url: '/UserControl/GetStore',
301
                    params: {
302
                        tableName: tbl,
303
                        param: keyField + '[=]' + keyValue
304
                    },
305
                    success: function (response) {
306
                        var results = Ext.decode(response.responseText);
307
                        dtgrid = results.data;
308
                    }
309
                });
310
                Ext.each(itm, function (i) {
311
                    var fld = i.name;
312
                    var fldValue = 0;
313
                    Ext.each(dtgrid, function (d) {
314
                        var fValue = d[fld];
315
                        fldValue = fldValue + parseFloat(fValue);
316
                    });
317
                    fldValue = Ext.util.Format.number(fldValue, '0,000.00');
318
                    sumForm.findField(fld).setValue(fldValue);
319
                });
320
            }
321
        }
322
        tabObj.getEl().unmask();
323
    },
324
    buildMultiGrid: function () {
325
        var PanelData = Ext.ComponentQuery.query('[name=panelTab]')[0];
326
        var GridData = PanelData.query('docgrid');
327
        var GridLength = GridData.length;
328
        var GridBuildStrings = [];
329
        for (var i = 0; i < GridLength; i++) {
330
            var records = [];
331
            var grd = GridData[i].query('grid')[0];
332
            if (grd.hasOwnProperty('CRUDflag')) {
333
                records = grd.CRUDflag.getAllRecords(GridData[i].store)
334
            } else {
335
                var recC = grd.store.getNewRecords();
336
                Ext.each(recC, function (rec) {
337
                    rec.data.FlagCrud = "I";
338
                    records.push(rec);
339
                });
340
                var recU = grd.store.getUpdatedRecords();
341
                Ext.each(recU, function (rec) {
342
                    rec.data.FlagCrud = "U";
343
                    records.push(rec);
344
                });
345
                var recD = grd.store.getRemovedRecords();
346
                Ext.each(recD, function (rec) {
347
                    rec.data.FlagCrud = "D";
348
                    records.push(rec);
349
                });
350
            }
351
            Ext.each(records, function (rec) {
352
                var name = GridData[i].tableName;
353
                var obj = Ext.decode('{' + name + ':' + Ext.encode(rec.data) + '}');
354
                GridBuildStrings.push(obj);
355
            });
356
        }
357
        return GridBuildStrings;
358
    },
359
    buildMultiGridEditCell: function () {
360
        var PanelData = Ext.ComponentQuery.query('[name=panelTab]')[0];
361
        var GridData = PanelData.query('docgridcelledit');
362
        var GridLength = GridData.length;
363
        var GridBuildStrings = [];
364
        for (var i = 0; i < GridLength; i++) {
365
            var records = [];
366
            var grd = GridData[i].query('grid')[0];
367
            if (grd.hasOwnProperty('CRUDflag')) {
368
                records = grd.CRUDflag.getAllRecords(GridData[i].store)
369
            } else {
370
                var recC = grd.store.getNewRecords();
371
                Ext.each(recC, function (rec) {
372
                    rec.data.FlagCrud = "I";
373
                    records.push(rec);
374
                });
375
                var recU = grd.store.getUpdatedRecords();
376
                Ext.each(recU, function (rec) {
377
                    rec.data.FlagCrud = "U";
378
                    records.push(rec);
379
                });
380
                var recD = grd.store.getRemovedRecords();
381
                Ext.each(recD, function (rec) {
382
                    rec.data.FlagCrud = "D";
383
                    records.push(rec);
384
                });
385
            }
386
            Ext.each(records, function (rec) {
387
                var name = GridData[i].tableName;
388
                var obj = Ext.decode('{' + name + ':' + Ext.encode(rec.data) + '}');
389
                GridBuildStrings.push(obj);
390
            });
391
        }
392
        return GridBuildStrings;
393
    },
394
    buildMultiGridEditCellSum: function () {
395
        var PanelData = Ext.ComponentQuery.query('[name=panelTab]')[0];
396
        var GridData = PanelData.query('docgridcelleditsum');
397
        var GridLength = GridData.length;
398
        var GridBuildStrings = [];
399
        for (var i = 0; i < GridLength; i++) {
400
            var records = [];
401
            var grd = GridData[i].query('grid')[0];
402
            if (grd.hasOwnProperty('CRUDflag')) {
403
                records = grd.CRUDflag.getAllRecords(GridData[i].store)
404
            } else {
405
                var recC = grd.store.getNewRecords();
406
                Ext.each(recC, function (rec) {
407
                    rec.data.FlagCrud = "I";
408
                    records.push(rec);
409
                });
410
                var recU = grd.store.getUpdatedRecords();
411
                Ext.each(recU, function (rec) {
412
                    rec.data.FlagCrud = "U";
413
                    records.push(rec);
414
                });
415
                var recD = grd.store.getRemovedRecords();
416
                Ext.each(recD, function (rec) {
417
                    rec.data.FlagCrud = "D";
418
                    records.push(rec);
419
                });
420
            }
421
            Ext.each(records, function (rec) {
422
                var name = GridData[i].tableName;
423
                var obj = Ext.decode('{' + name + ':' + Ext.encode(rec.data) + '}');
424
                GridBuildStrings.push(obj);	
425
            });
426
        }
427
        return GridBuildStrings;
428
		
429
    },
430
    loadTabPanelDocRef: function (dtheader, dtitems) {
431
        var me = this;
432
        var tb = Ext.ComponentQuery.query('[name=panelTab]')[0];
433
        var tabObj = tb.activeTab;
434
        var docno = me.docNo;
435
        var act = me.action;
436

    
437
        var tbl = tabObj.tbl;
438
        tabObj.getEl().mask("loading...");
439
        if (tabObj.layoutType == 'L001') {
440
            var frmDisplay = Ext.ComponentQuery.query('[name=DISPLAY' + tbl + ']')[0];
441
            var frmForm = Ext.ComponentQuery.query('[name=FORM' + tbl + ']')[0];
442
            frmDisplay.reset();
443
            frmForm.reset();
444
            if (dtheader.length > 0) {
445
                frmDisplay.getForm().setValues(dtheader[0]);
446
                frmForm.getForm().setValues(dtheader[0]);
447
            }
448
            frmDisplay.setHidden(true);
449
            frmForm.setHidden(false);
450
        }
451
        if (tabObj.layoutType == 'L002' || tabObj.layoutType == 'L003') {
452
            var frmDisplay = Ext.ComponentQuery.query('[name=DISPLAY' + tbl + ']')[0];
453
            var frmForm = Ext.ComponentQuery.query('[name=FORM' + tbl + ']')[0];
454
            var grdPanel = Ext.ComponentQuery.query('[name=GRID' + tbl + ']')[0];
455
            var store = Ext.StoreMgr.lookup("store" + tbl);
456
            store.removeAll();
457
            Ext.each(dtitems, function (item) {
458
                store.add(item);
459
            });
460
            frmDisplay.reset();
461
            frmForm.reset();
462
            frmDisplay.setHidden(true);
463
            frmForm.setHidden(true);
464
            grdPanel.setHidden(false);
465
        }
466
        if (tabObj.layoutType == 'L005') {
467
            var grdPanel = Ext.ComponentQuery.query('[name=GRID' + tbl + ']')[0];
468
            var store = Ext.StoreMgr.lookup("store" + tbl);
469
            store.removeAll();
470
            Ext.each(dtitems, function (item) {
471
                store.add(item);
472
            });
473
            grdPanel.setHidden(false);
474
        }
475
        if (tabObj.layoutType == 'L006' || tabObj.layoutType == 'L007') {
476
            var grdPanel = Ext.ComponentQuery.query('[name=CELLGRID' + tbl + ']')[0];
477
            grdPanel.setHidden(false);
478
            var btnadd = Ext.ComponentQuery.query('[name=add' + tbl + ']')[0].setDisabled(false);
479
            var btndelete = Ext.ComponentQuery.query('[name=delete' + tbl + ']')[0].setDisabled(false);
480
            var store = Ext.StoreMgr.lookup("store" + tbl);
481
            store.removeAll();
482
            Ext.each(dtitems, function (item) {
483
                store.add(item);
484
            });
485
            if (tabObj.layoutType == 'L007') {
486
                var sumPanel = Ext.ComponentQuery.query('[name=SUM' + tbl + ']')[0];
487
                var sumForm = sumPanel.getForm();
488
                var itm = sumForm.getFields().items;
489
                Ext.each(itm, function (i) {
490
                    var fld = i.name;
491
                    var fldValue = 0;
492
                    Ext.each(dtitems, function (dt) {
493
                        Ext.each(dt, function (d) {
494
                            var fValue = d[fld];
495
                            fldValue = fldValue + parseFloat(fValue);
496
                        });
497
                    });
498
                    fldValue = Ext.util.Format.number(fldValue, '0,000.00');
499
                    sumForm.findField(fld).setValue(fldValue);
500
                });
501
            }
502
        }
503
        tabObj.getEl().unmask();
504
    },
505
    createDocRef: function (dtheader, dtitems, intdocref) {
506
        var me = this;
507
        me.action = '0';
508
        me.docNo = 'None'
509
        var pnlSelect = Ext.ComponentQuery.query('[name=DocSelectionJoil]')[0];
510
        var pnlTransaction = Ext.ComponentQuery.query('[name=DocTransaction]')[0];
511
        var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
512
        var panelDisplayHead = Ext.ComponentQuery.query('[name=DisplayMainHeaderDocument]')[0];
513
        var formHead = panelHead.getForm();
514
        formHead.reset();
515
        var formHeadDisplay = panelDisplayHead.getForm();
516
        formHeadDisplay.reset();
517
        var btnSaveCreate = Ext.ComponentQuery.query('[name=SaveCreateDoc]')[0];
518
        var btnCreate = Ext.ComponentQuery.query('[name=Create1Doc]')[0];
519
        var btnSave = Ext.ComponentQuery.query('[name=SaveDoc]')[0];
520
        var btnEdit = Ext.ComponentQuery.query('[name=EditDoc]')[0];
521
        var btnDelete = Ext.ComponentQuery.query('[name=DeleteDoc]')[0];
522
        pnlSelect.setHidden(true);
523
        pnlTransaction.setHidden(false);
524
        panelHead.setHidden(false);
525
        panelDisplayHead.setHidden(true);
526
        btnSaveCreate.setDisabled(false);
527
        btnCreate.setDisabled(false);
528
        btnSave.setDisabled(false);
529
        formHead.findField("DocType").setValue(me.docType);
530
        if (dtheader.length > 0) {
531
            formHead.setValues(dtheader[0]);
532
            formHeadDisplay.setValues(dtheader[0]);
533
        }
534
        var docnoref = "";
535
        Ext.each(intdocref, function (doc) {
536
            docnoref = docnoref + "," + doc;
537
        });
538
        var lg = docnoref.length;
539
        if (lg > 0) {
540
            docnoref = docnoref.substring(1, lg);
541
        }
542
        formHead.findField("IntDocRef").setValue(docnoref);
543
        formHead.findField("RefType").setValue("01");
544
        me.loadTabPanelDocRef(dtheader, dtitems);
545
    },
546
    createDoc: function () {
547
        var me = this;
548
        me.action = '0';
549
        me.docNo = 'None';
550
		me.dataExist= "";
551
		me.docStatus= "";
552
		me.docStatusExist= "";
553
		me.PostingDateExist= "";
554
        var pnlSelect = Ext.ComponentQuery.query('[name=DocSelectionJoil]')[0];
555
        var pnlTransaction = Ext.ComponentQuery.query('[name=DocTransaction]')[0];
556
        var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
557
        var panelDisplayHead = Ext.ComponentQuery.query('[name=DisplayMainHeaderDocument]')[0];
558
        var formHead = panelHead.getForm();
559
        formHead.reset();
560
        var formHeadDisplay = panelDisplayHead.getForm();
561
        formHeadDisplay.reset();
562
        var btnSaveCreate = Ext.ComponentQuery.query('[name=SaveCreateDoc]')[0];
563
        var btnCreate = Ext.ComponentQuery.query('[name=Create1Doc]')[0];
564
        var btnSave = Ext.ComponentQuery.query('[name=SaveDoc]')[0];
565
        var btnEdit = Ext.ComponentQuery.query('[name=EditDoc]')[0];
566
        var btnDelete = Ext.ComponentQuery.query('[name=DeleteDoc]')[0];
567
        pnlSelect.setHidden(true);
568
        pnlTransaction.setHidden(false);
569
        panelHead.setHidden(false);
570
        panelDisplayHead.setHidden(true);
571
        btnSaveCreate.setDisabled(false);
572
        btnCreate.setDisabled(false);
573
        btnSave.setDisabled(false);
574
		btnEdit.setDisabled(true);  // nwh tri
575
        formHead.findField("DocType").setValue(me.docType);
576
        me.afterrenderTab();
577
		
578
		var tb = Ext.ComponentQuery.query('[name=panelTab]')[0];
579
		var tbl = tb.activeTab.tbl;
580
		if(me.TransType == 'FIN')
581
		{
582
			var btnadd = Ext.ComponentQuery.query('[name=add' + tbl + ']')[0].setDisabled(true);
583
			var btndelete = Ext.ComponentQuery.query('[name=delete' + tbl + ']')[0].setDisabled(true);
584
		}
585
		
586
    },
587
    displayDoc: function () {
588
        var me = this;
589
        //var documentNo = Ext.ComponentQuery.query('triggerfield[name=DocNo]')[0];
590
        //var tbl = documentNo.tableName;
591
        //me.loadDoc(documentNo.getValue(), tbl);
592
        var grid = Ext.ComponentQuery.query('[name=searchResult]')[0];
593
        var selection = grid.getView().getSelectionModel().getSelection()[0];
594
        var documentno = selection.data.DocNo;
595
        LookupFunction = this.LookupFunction;
596
        eval(LookupFunction);
597
        me.loadDoc(documentno, grid.tableName);
598
    },
599
    loadDoc: function (documentno, tbl) {
600
        var me = this;
601
        me.action = '2';
602
        me.docNo = documentno;
603
        var pnlSelect = Ext.ComponentQuery.query('[name=DocSelectionJoil]')[0];
604
        var pnlTransaction = Ext.ComponentQuery.query('[name=DocTransaction]')[0];
605
        var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
606
        var panelDisplayHead = Ext.ComponentQuery.query('[name=DisplayMainHeaderDocument]')[0];
607
        var formHead = panelHead.getForm();
608
        var formHeadDisplay = panelDisplayHead.getForm();
609
        var btnSaveCreate = Ext.ComponentQuery.query('[name=SaveCreateDoc]')[0];
610
        var btnCreate = Ext.ComponentQuery.query('[name=Create1Doc]')[0];
611
        var btnSave = Ext.ComponentQuery.query('[name=SaveDoc]')[0];
612
        var btnEdit = Ext.ComponentQuery.query('[name=EditDoc]')[0];
613
        var btnDelete = Ext.ComponentQuery.query('[name=DeleteDoc]')[0];
614
        var dt = undefined;
615
        Ext.Ajax.request({
616
            async: false,
617
            method: 'POST',
618
            url: '/UserControl/GetStore',
619
            params: {
620
                tableName: tbl,
621
                param: 'DocNo[=]' + me.docNo
622
            },
623
            success: function (response) {
624
                var results = Ext.decode(response.responseText);
625
                dt = results.data;
626
            }
627
        });
628
        formHead.setValues(dt[0]);
629
        formHeadDisplay.setValues(dt[0]);
630
        me.afterrenderTab();
631
        pnlSelect.setHidden(true);
632
        pnlTransaction.setHidden(false);
633
        panelHead.setHidden(false);
634
        panelDisplayHead.setHidden(true);
635
        btnSaveCreate.setDisabled(true);
636
        btnCreate.setDisabled(true);
637
        btnSave.setDisabled(true);
638
        btnEdit.setDisabled(false);
639
        btnDelete.setDisabled(false);
640
		me.dataExist = "Y";
641
		me.docStatusExist = formHead.findField("DocStatus").getValue();
642
		me.PostingDateExist = formHead.findField("PostingDate").getValue();
643
    },
644
    editDoc: function () {
645
        var me = this;
646
        var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
647
        var formheader = panelHead.getForm();
648
        var status = formheader.findField("DocStatus").getValue();
649
        if (status == "5") {
650
            Ext.Ajax.request({
651
                async: false,
652
                method: 'POST',
653
                url: '/UserControl/GetStore',
654
                params: {
655
                    tableName: 'PCMBSDOCSTATUS',
656
                    param: 'DocStatus[=]' + status
657
                },
658
                success: function (response) {
659
                    var results = Ext.decode(response.responseText);
660
                    dt = results.data[0];
661
                }
662
            });
663
            MinovaMessage('000006', 'FILO01', dt.Description, 'W');
664
			/*me.dataExist = "Y";
665
			me.docStatusExist = formheader.findField("DocStatus").getValue();
666
			me.PostingDateExist = formheader.findField("PostingDate").getValue();*/
667
        } else {
668
            me.action = '1';
669
            var panelDisplayHead = Ext.ComponentQuery.query('[name=DisplayMainHeaderDocument]')[0];
670
            var btnSaveCreate = Ext.ComponentQuery.query('[name=SaveCreateDoc]')[0];
671
            var btnCreate = Ext.ComponentQuery.query('[name=Create1Doc]')[0];
672
            var btnSave = Ext.ComponentQuery.query('[name=SaveDoc]')[0];
673
            var btnEdit = Ext.ComponentQuery.query('[name=EditDoc]')[0];
674
            var btnDelete = Ext.ComponentQuery.query('[name=DeleteDoc]')[0];
675
            panelHead.setHidden(false);
676
            panelDisplayHead.setHidden(true);
677
            btnSaveCreate.setDisabled(false);
678
            btnCreate.setDisabled(false);
679
            btnSave.setDisabled(false);
680
            me.afterrenderTab();
681
			/*me.dataExist = "Y";
682
			me.docStatusExist = formheader.findField("DocStatus").getValue();
683
			me.PostingDateExist = formheader.findField("PostingDate").getValue();*/			
684
        }
685
    },
686
    saveDoc: function () {
687
        var me = this;
688
        var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
689
        var tbl = panelHead.tableName;
690
        var formHead = panelHead.getForm();
691
		var docStatus = formHead.findField("DocStatus").getValue();
692
		var DocNo = formHead.findField("DocNo").getValue();
693
				
694
        if (me.transType == 'FIN') {
695
			
696
			var FiscalYear = formHead.findField("FiscalYear").getValue(); //// dipindahkan by Tri nwh 20220224
697
			var FiscalPeriod = formHead.findField("FiscalPeriod").getValue(); //// dipindahkan by Tri nwh 20220224			
698
			var pd = formHead.findField("PostingDate").getValue();
699
            var debet = Ext.ComponentQuery.query('displayfield[name=AmountDebet]')[0];
700
            var kredit = Ext.ComponentQuery.query('displayfield[name=AmountCredit]')[0];
701
			
702
            if (pd == null || pd == "" || pd == undefined) {
703
				if(docStatus == '9')
704
				{
705
					MinovaMessage("", "FILO05", "", "E");
706
					return;
707
				}
708
            }
709
            if (debet !== undefined && kredit !== undefined) {
710
                if (debet.getValue() !== kredit.getValue()) {
711
                    MinovaMessage("", "FILO10", "", "E");
712
                    return;
713
                }
714
            }
715
			
716
            console.log('FIN!'); 
717

    
718
			if (debet.getValue() == 0 && kredit.getValue() == 0 && docStatus == '9' ) {
719
				if(me.dataExist == 'Y')
720
				{
721
					formHead.findField("DocStatus").setValue("3");
722
					Ext.Ajax.request({
723
					async: false,
724
					method: 'POST',
725
					url: '/UserControl/GetStore',
726
					params: {
727
						tableName: 'PDSFILODELETEDATATABLEPOST',
728
						param: DocNo
729
					},
730
					success: function (response) {
731
					}
732
					});
733
				}
734
				else 
735
				{
736
					MinovaMessage("", "FILO11", "", "E");
737
					return;
738
				}
739
            }
740
			
741
			if(me.docStatusExist == '9' || me.docStatusExist == '3')
742
			{
743
				if(docStatus == '1' || docStatus == '2')
744
				{
745
					MinovaMessage("", "FILO12", "", "E");
746
					return;
747
				}
748
				if(pd != me.PostingDateExist)
749
				{
750
					MinovaMessage("", "FILO13", "", "E");
751
					return;
752
				}
753
				if(docStatus == '3')//if(me.docStatus == '3')
754
				{	
755
					Ext.Ajax.request({
756
					async: false,
757
					method: 'POST',
758
					url: '/UserControl/GetStore',
759
					params: {
760
						tableName: 'PDSFILODELETEDATATABLEPOST',
761
						param: DocNo
762
					},
763
					success: function (response) {
764
					}
765
					});
766
				}
767
			}
768
			
769
			if(me.docStatusExist == '1' && docStatus == '1')
770
			{
771
				if(pd != me.PostingDateExist)
772
				{
773
					Ext.Ajax.request({
774
					async: false,
775
					method: 'POST',
776
					url: '/UserControl/GetStore',
777
					params: {
778
						tableName: 'PDSFILOUPDATEPERIODFINANCEITEM',
779
						param: DocNo + ',' + FiscalYear + ',' + FiscalPeriod
780
					},
781
					success: function (response) {
782
					}
783
					});
784
				}
785
			}
786
			
787
			if(me.docStatusExist == '1' && docStatus == '9')
788
			{
789
				if(pd != me.PostingDateExist)
790
				{
791
					
792
					Ext.Ajax.request({
793
					async: false,
794
					method: 'POST',
795
					url: '/UserControl/GetStore',
796
					params: {
797
						tableName: 'PDSFILOUPDATEPERIODFINANCEITEM',
798
						param: DocNo + ',' + FiscalYear + ',' + FiscalPeriod
799
					},
800
					success: function (response) {
801
					}
802
					});
803
				}
804
			}
805
        }
806
		
807
        if (formHead.isValid()) {
808
            panelHead.mask("Loading...");
809
            var dataHeader = Ext.encode(formHead.getValues());
810
            var token = MinovaUtil.SESSIONS.Token;
811
            var objGrid;
812
            var objGridCell;
813
            var objGridCellSum;
814
            try {
815
                objGrid = me.buildMultiGrid();
816
                objGridCell = me.buildMultiGridEditCell();
817
                objGridCellSum = me.buildMultiGridEditCellSum();
818
                for (var i = 0; i < objGridCell.length; i++) {
819
                    objGrid.push(objGridCell[i]);
820
                }
821
                for (var i = 0; i < objGridCellSum.length; i++) {
822
                    objGrid.push(objGridCellSum[i]);
823
                }
824
            } catch (e) {
825
                Ext.Msg.alert('Build Grid error', e);
826
                return;
827
            }
828
            var dataDetail = Ext.encode(objGrid);
829
			
830
			var PanelData = Ext.ComponentQuery.query('[name=panelTab]')[0];
831
			var GridData = PanelData.query('docgridcelleditsum');
832
			var GridLength = GridData.length;
833
			var glaccount = '';
834
			var glaccount_ = '';
835
			var currency = '';
836
			var currency_ = '';
837
			var sltype = '';
838
			var sltype_ = '';
839
			var slid = '';
840
			var slid_ = '';
841
			
842
			if (me.transType == 'FIN') {  //// add by Tri nwh 20211201
843
				for (var i = 0; i < GridLength; i++) {
844
					glaccount_ = '';
845
					var records = [];
846
					var grd = GridData[i].query('grid')[0];
847
					
848
					var recC = grd.store.getNewRecords();
849
					Ext.each(recC, function (rec) {
850
						glaccount = rec.data.GLAccountID.toString();
851
						//glaccount = glaccount + ',' + rec.data.GLAccountID.toString();
852
					});
853
					var recU = grd.store.getUpdatedRecords();
854
					Ext.each(recU, function (rec) {
855
						glaccount = rec.data.GLAccountID.toString();
856
						//glaccount = glaccount + ',' + rec.data.GLAccountID.toString();
857
					});
858
					
859
					var recCurC = grd.store.getNewRecords();
860
					Ext.each(recCurC, function (recC) {
861
						currency = recC.data.Currency.toString();
862
						Ext.Ajax.request({		//// add by Tri nwh 20211228
863
							async : false,
864
							method : 'POST',
865
							url : '/UserControl/GetStore',
866
							params : {
867
								tableName : 'PHRPYCURR',
868
								param : 'Currency[equal]' + currency
869
							},
870
							success : function (response) {
871
								var results = Ext.decode(response.responseText);
872
								if( results.totalRecords == '0')
873
								{ currency_ = 'None'; console.log(currency_); }
874
							}
875
						});
876
					});
877
					
878
					var recCurU = grd.store.getUpdatedRecords(); 
879
					Ext.each(recCurU, function (recC) {
880
						currency = recC.data.Currency.toString();
881
						Ext.Ajax.request({		//// add by Tri nwh 20211228
882
							async : false,
883
							method : 'POST',
884
							url : '/UserControl/GetStore',
885
							params : {
886
								tableName : 'PHRPYCURR',
887
								param : 'Currency[equal]' + currency
888
							},
889
							success : function (response) {
890
								var results = Ext.decode(response.responseText);
891
								if( results.totalRecords == '0')
892
								{ currency_ = 'None'; console.log(currency_); }
893
							}
894
						});
895
					});
896
					
897
					var recSLTypeC = grd.store.getNewRecords();
898
					Ext.each(recSLTypeC, function (recSLType) {
899
						sltype = recSLType.data.SubLedgerType.toString();
900
						Ext.Ajax.request({		//// add by Tri nwh 20211230
901
							async : false,
902
							method : 'POST',
903
							url : '/UserControl/GetStore',
904
							params : {
905
								tableName : 'PCMFILOSLTYPE',
906
								param : 'SubLedgerType[equal]' + sltype
907
							},
908
							success : function (response) {
909
								var results = Ext.decode(response.responseText);
910
								if( results.totalRecords == '0')
911
								{ sltype_ = 'None'; console.log(sltype_); }
912
							}
913
						});
914
					});
915
					
916
					var recSLTypeU = grd.store.getUpdatedRecords(); 
917
					Ext.each(recSLTypeU, function (recSLType) {
918
						sltype = recSLType.data.SubLedgerType.toString();
919
						Ext.Ajax.request({		//// add by Tri nwh 20211230
920
							async : false,
921
							method : 'POST',
922
							url : '/UserControl/GetStore',
923
							params : {
924
								tableName : 'PCMFILOSLTYPE',
925
								param : 'SubLedgerType[equal]' + sltype
926
							},
927
							success : function (response) {
928
								var results = Ext.decode(response.responseText);
929
								if( results.totalRecords == '0')
930
								{ sltype_ = 'None'; console.log(sltype_); }
931
							}
932
						});
933
					});
934
					
935
					var recSLIDC = grd.store.getNewRecords();
936
					Ext.each(recSLIDC, function (recSLID) {
937
						slid = recSLID.data.SubLedgerID.toString();
938
						Ext.Ajax.request({		//// add by Tri nwh 20211230
939
							async : false,
940
							method : 'POST',
941
							url : '/UserControl/GetStore',
942
							params : {
943
								tableName : 'PMDSL0001',
944
								param : 'SubLedgerID[equal]' + slid
945
							},
946
							success : function (response) {
947
								var results = Ext.decode(response.responseText);
948
								if( results.totalRecords == '0')
949
								{ slid_ = 'None'; console.log(slid_); }
950
							}
951
						});
952
					});
953
					
954
					var recSLIDU = grd.store.getUpdatedRecords(); 
955
					Ext.each(recSLIDU, function (recSLID) {
956
						slid = recSLID.data.SubLedgerID.toString();
957
						Ext.Ajax.request({		//// add by Tri nwh 20211230
958
							async : false,
959
							method : 'POST',
960
							url : '/UserControl/GetStore',
961
							params : {
962
								tableName : 'PMDSL0001',
963
								param : 'SubLedgerID[equal]' + slid
964
							},
965
							success : function (response) {
966
								var results = Ext.decode(response.responseText);
967
								if( results.totalRecords == '0')
968
								{ slid_ = 'None'; console.log(slid_); }
969
							}
970
						});
971
					});
972
					
973
					/*if(glaccount == '')
974
					{
975
						MinovaMessage("", "FILO15", "", "E");
976
						//alert('nwh');
977
						panelHead.unmask();
978
						return;
979
					}*/ ////comment krn tidak bisa rubah status 20210830 by Tri
980
					
981
					Ext.Ajax.request({
982
						async : false,
983
						method : 'POST',
984
						url : '/UserControl/GetStore',
985
						params : {
986
							tableName : 'PCMFILOCOAGL',
987
							param : 'GlAccount[equal]' + glaccount
988
						},
989
						success : function (response) {
990
							var results = Ext.decode(response.responseText);
991
							if( results.totalRecords != '0')
992
							{ glaccount_ = results.data[0].GlAccount; }
993
						}
994
					});
995
					
996
					Ext.Ajax.request({		//// add by Tri nwh 20211202
997
						async : false,
998
						method : 'POST',
999
						url : '/UserControl/GetStore',
1000
						params : {
1001
							tableName : 'PHRPYCURR',
1002
							param : 'Currency[equal]' + currency
1003
						},
1004
						success : function (response) {
1005
							var results = Ext.decode(response.responseText);
1006
							if( results.totalRecords != '0')
1007
							{ currency_ = results.data[0].Currency; }
1008
						}
1009
					});
1010
					
1011
					if(glaccount_ == '')
1012
					{
1013
						MinovaMessage("", "FILO14", "", "E");
1014
						panelHead.unmask();
1015
						return;
1016
					};
1017
					
1018
					if(currency_ == '') 	//// add by Tri nwh 20211202
1019
					{
1020
						MinovaMessage("", "FILO17", "", "E");
1021
						panelHead.unmask();
1022
						return;
1023
					};
1024
					
1025
					if(sltype_ == 'None') 	//// add by Tri nwh 20211230
1026
					{
1027
						MinovaMessage("", "FILO18", "", "E");
1028
						panelHead.unmask();
1029
						return;
1030
					};
1031
					
1032
					if(slid_ == 'None') 	//// add by Tri nwh 20211230
1033
					{
1034
						MinovaMessage("", "FILO19", "", "E");
1035
						panelHead.unmask();
1036
						return;
1037
					};
1038
				}	
1039
			}
1040
			
1041
            var params = {
1042
                serviceName: 'Filo.asmx',
1043
                methodName: 'SaveTableDoc',
1044
                parameter: 'transType=' + me.transType + '&docType=' + me.docType +
1045
                '&header=' + dataHeader + '&detail=' + dataDetail + '&action=' + me.action + '&token=' + token
1046
            };
1047
            MinovaAjaxPost('/InvokeService/Invoke/', params, function (xhr) {
1048
                console.log('Post!');
1049
                var result = Ext.decode(xhr.responseText);
1050
                if (result.success) {
1051
                    var idNo = result.data;
1052
                    formHead.findField("DocNo").setValue(idNo);
1053
                    /* add by mae 20200702 */
1054
                    /* #region update item status */
1055
                    if (me.transType == "FIN" && me.docType == "IP" && formHead.getValues().DocTypeRef == "AR") {
1056
                        Ext.Ajax.request({
1057
                            async: false,
1058
                            method: 'POST',
1059
                            url: '/Devt/SaveTable',
1060
                            params: {
1061
                                tableName: 'PTRFINANCEITEM',
1062
                                data: Ext.encode({
1063
                                    DocNo: formHead.getValues().DocIDRef,
1064
                                    ItemStatus: '2'
1065
                                }),
1066
                                action: 1
1067
                            },
1068
                            waitMsg: 'Saving Data...',
1069
                            success: function (response) {
1070
                                var result = Ext.decode(response.responseText);
1071
                                if (result.success) {
1072
                                    console.log('update item status');
1073
                                }
1074
                            },
1075
                            failure: function (response) {}
1076
                        });
1077
                    }
1078
                    /* #endregion update item status */
1079
                    MinovaMessage('Not Null', '000006', '', 'S');
1080
                    panelHead.unmask();
1081
                    me.loadDoc(idNo, tbl);
1082
                } else {
1083
                    MinovaMessage('', '000005', result.message.text, 'E');
1084
                    panelHead.unmask();
1085
                }
1086
            });
1087
        }
1088
    },
1089
    deleteDoc: function () {},
1090
    cancelDoc: function () {
1091
        var me = this;
1092
        me.action = '2';
1093
        me.docNo = 'None';
1094
        MinovaMessage('Message', '000011', '', 'C', function (respone) {
1095
            if (respone == "yes") {
1096
                me.afterrenderTab();
1097
                var pnlSelect = Ext.ComponentQuery.query('[name=DocSelectionJoil]')[0];
1098
                var tes = Ext.ComponentQuery.query('[name=searchResultInfo]')[0];
1099
                var pnlTransaction = Ext.ComponentQuery.query('[name=DocTransaction]')[0];
1100
                var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
1101
                var panelDisplayHead = Ext.ComponentQuery.query('[name=DisplayMainHeaderDocument]')[0];
1102
                var formHead = panelHead.getForm();
1103
                formHead.reset();
1104
                var formHeadDisplay = panelDisplayHead.getForm();
1105
                formHeadDisplay.reset();
1106
                var btnCreate = Ext.ComponentQuery.query('[name=CreateDoc]')[0];
1107
                var btnSave = Ext.ComponentQuery.query('[name=SaveDoc]')[0];
1108
                var btnEdit = Ext.ComponentQuery.query('[name=EditDoc]')[0];
1109
                var btnDelete = Ext.ComponentQuery.query('[name=DeleteDoc]')[0];
1110
                pnlSelect.setHidden(false);
1111
                tes.setHidden(true);
1112
                pnlTransaction.setHidden(true);
1113
                panelHead.setHidden(false);
1114
                panelDisplayHead.setHidden(true);
1115

    
1116
            }
1117
        });
1118
    },
1119
    createNew: function () {
1120
        console.log('CreateNew!');
1121
        var me = this;
1122
        me.action = '0';
1123
        me.docNo = 'None'
1124
            var pnlSelect = Ext.ComponentQuery.query('[name=DocSelectionJoil]')[0];
1125
        var pnlTransaction = Ext.ComponentQuery.query('[name=DocTransaction]')[0];
1126
        var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
1127
        var panelDisplayHead = Ext.ComponentQuery.query('[name=DisplayMainHeaderDocument]')[0];
1128
        var formHead = panelHead.getForm();
1129
        formHead.reset();
1130
        var formHeadDisplay = panelDisplayHead.getForm();
1131
        formHeadDisplay.reset();
1132
        var btnSaveCreate = Ext.ComponentQuery.query('[name=SaveCreateDoc]')[0];
1133
        var btnCreate = Ext.ComponentQuery.query('[name=Create1Doc]')[0];
1134
        var btnSave = Ext.ComponentQuery.query('[name=SaveDoc]')[0];
1135
        var btnEdit = Ext.ComponentQuery.query('[name=EditDoc]')[0];
1136
        var btnDelete = Ext.ComponentQuery.query('[name=DeleteDoc]')[0];
1137
        pnlSelect.setHidden(true);
1138
        pnlTransaction.setHidden(false);
1139
        panelHead.setHidden(false);
1140
        panelDisplayHead.setHidden(true);
1141
        btnSaveCreate.setDisabled(false);
1142
        btnCreate.setDisabled(false);
1143
        btnSave.setDisabled(false);
1144
        formHead.findField("DocType").setValue(me.docType);
1145
        me.afterrenderTab();
1146
    },
1147
    reloadDoc: function () {
1148
        console.log('reloadDoc');
1149
        var me = this;
1150
        me.action = '2';
1151
        me.docNo = 'None';
1152
        //MinovaMessage('Message', '000011', '', 'C', function (respone) {
1153
        //if (respone == "yes") {
1154
        me.afterrenderTab();
1155
        var pnlSelect = Ext.ComponentQuery.query('[name=DocSelectionJoil]')[0];
1156
        var pnlTransaction = Ext.ComponentQuery.query('[name=DocTransaction]')[0];
1157
        var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
1158
        var panelDisplayHead = Ext.ComponentQuery.query('[name=DisplayMainHeaderDocument]')[0];
1159
        var formHead = panelHead.getForm();
1160
        formHead.reset();
1161
        var formHeadDisplay = panelDisplayHead.getForm();
1162
        formHeadDisplay.reset();
1163
        var btnCreate = Ext.ComponentQuery.query('[name=CreateDoc]')[0];
1164
        var btnSave = Ext.ComponentQuery.query('[name=SaveDoc]')[0];
1165
        var btnEdit = Ext.ComponentQuery.query('[name=EditDoc]')[0];
1166
        var btnDelete = Ext.ComponentQuery.query('[name=DeleteDoc]')[0];
1167
        pnlSelect.setHidden(false);
1168
        pnlTransaction.setHidden(true);
1169
        panelHead.setHidden(false);
1170
        panelDisplayHead.setHidden(true);
1171
        //}
1172
        //});
1173
    },
1174
    backDoc: function () {
1175
        var me = this;
1176
        var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
1177
        var tbl = panelHead.tableName;
1178
        var formHead = panelHead.getForm();
1179

    
1180
        if (me.transType == 'FIN') {
1181
            var pd = formHead.findField("PostingDate").getValue();
1182
            var debet = Ext.ComponentQuery.query('displayfield[name=AmountDebet]')[0];
1183
            var kredit = Ext.ComponentQuery.query('displayfield[name=AmountCredit]')[0];
1184

    
1185
            if (pd == null || pd == "" || pd == undefined) {
1186
                MinovaMessage("", "FILO05", "", "E");
1187
                return;
1188
            }
1189
            if (debet !== undefined && kredit !== undefined) {
1190
                if (debet.getValue() !== kredit.getValue()) {
1191
                    MinovaMessage("", "FILO10", "", "E");
1192
                    return;
1193
                }
1194
            }
1195
        }
1196
        if (formHead.isValid()) {
1197
            panelHead.mask("Loading...");
1198
            var dataHeader = Ext.encode(formHead.getValues());
1199
            var token = MinovaUtil.SESSIONS.Token;
1200
            var objGrid;
1201
            var objGridCell;
1202
            var objGridCellSum;
1203
            try {
1204
                objGrid = me.buildMultiGrid();
1205
                objGridCell = me.buildMultiGridEditCell();
1206
                objGridCellSum = me.buildMultiGridEditCellSum();
1207
                for (var i = 0; i < objGridCell.length; i++) {
1208
                    objGrid.push(objGridCell[i]);
1209
                }
1210
                for (var i = 0; i < objGridCellSum.length; i++) {
1211
                    objGrid.push(objGridCellSum[i]);
1212
                }
1213
            } catch (e) {
1214
                Ext.Msg.alert('Build Grid error', e);
1215
                return;
1216
            }
1217
            var dataDetail = Ext.encode(objGrid);
1218
            var params = {
1219
                serviceName: 'Filo.asmx',
1220
                methodName: 'SaveTableDoc',
1221
                parameter: 'transType=' + me.transType + '&docType=' + me.docType +
1222
                '&header=' + dataHeader + '&detail=' + dataDetail + '&action=' + me.action + '&token=' + token
1223
            };
1224
            MinovaAjaxPost('/InvokeService/Invoke/', params, function (xhr) {
1225
                var result = Ext.decode(xhr.responseText);
1226
                if (result.success) {
1227
                    var idNo = result.data;
1228
                    formHead.findField("DocNo").setValue(idNo);
1229
                    MinovaMessage('Not Null', '000006', '', 'S');
1230
                    panelHead.unmask();
1231
                    me.loadDoc(idNo, tbl);
1232

    
1233
                    me.reloadDoc();
1234

    
1235
                } else {
1236
                    MinovaMessage('', '000005', result.message.text, 'E');
1237
                    panelHead.unmask();
1238
                }
1239
            });
1240
        }
1241
        console.log('backDoc');
1242

    
1243
    },
1244
    backCreateDoc: function () {
1245
        console.log('backCreateDoc!');
1246
        var me = this;
1247
        var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
1248
        var tbl = panelHead.tableName;
1249
        var formHead = panelHead.getForm();
1250

    
1251
        if (me.transType == 'FIN') {
1252
            var pd = formHead.findField("PostingDate").getValue();
1253
            var debet = Ext.ComponentQuery.query('displayfield[name=AmountDebet]')[0];
1254
            var kredit = Ext.ComponentQuery.query('displayfield[name=AmountCredit]')[0];
1255

    
1256
            if (pd == null || pd == "" || pd == undefined) {
1257
                MinovaMessage("", "FILO05", "", "E");
1258
                return;
1259
            }
1260
            if (debet !== undefined && kredit !== undefined) {
1261
                if (debet.getValue() !== kredit.getValue()) {
1262
                    MinovaMessage("", "FILO10", "", "E");
1263
                    return;
1264
                }
1265
            }
1266
        }
1267
        if (formHead.isValid()) {
1268
            panelHead.mask("Loading...");
1269
            var dataHeader = Ext.encode(formHead.getValues());
1270
            var token = MinovaUtil.SESSIONS.Token;
1271
            var objGrid;
1272
            var objGridCell;
1273
            var objGridCellSum;
1274
            try {
1275
                objGrid = me.buildMultiGrid();
1276
                objGridCell = me.buildMultiGridEditCell();
1277
                objGridCellSum = me.buildMultiGridEditCellSum();
1278
                for (var i = 0; i < objGridCell.length; i++) {
1279
                    objGrid.push(objGridCell[i]);
1280
                }
1281
                for (var i = 0; i < objGridCellSum.length; i++) {
1282
                    objGrid.push(objGridCellSum[i]);
1283
                }
1284
            } catch (e) {
1285
                Ext.Msg.alert('Build Grid error', e);
1286
                return;
1287
            }
1288
            var dataDetail = Ext.encode(objGrid);
1289
            var params = {
1290
                serviceName: 'Filo.asmx',
1291
                methodName: 'SaveTableDoc',
1292
                parameter: 'transType=' + me.transType + '&docType=' + me.docType +
1293
                '&header=' + dataHeader + '&detail=' + dataDetail + '&action=' + me.action + '&token=' + token
1294
            };
1295
            MinovaAjaxPost('/InvokeService/Invoke/', params, function (xhr) {
1296
                var result = Ext.decode(xhr.responseText);
1297
                if (result.success) {
1298
                    var idNo = result.data;
1299
                    formHead.findField("DocNo").setValue(idNo);
1300
                    /* add by mae 20200702 */
1301
                    /* #region update item status */
1302
                    if (me.transType == "FIN" && me.docType == "IP" && formHead.getValues().DocTypeRef == "AR") {
1303
                        Ext.Ajax.request({
1304
                            async: false,
1305
                            method: 'POST',
1306
                            url: '/Devt/SaveTable',
1307
                            params: {
1308
                                tableName: 'PTRFINANCEITEM',
1309
                                data: Ext.encode({
1310
                                    DocNo: formHead.getValues().DocIDRef,
1311
                                    ItemStatus: '2'
1312
                                }),
1313
                                action: 1
1314
                            },
1315
                            waitMsg: 'Saving Data...',
1316
                            success: function (response) {
1317
                                var result = Ext.decode(response.responseText);
1318
                                if (result.success) {
1319
                                    console.log('update item status');
1320
                                }
1321
                            },
1322
                            failure: function (response) {}
1323
                        });
1324
                    }
1325
                    /* #endregion update item status */
1326
                    MinovaMessage('Not Null', '000006', '', 'S');
1327
                    panelHead.unmask();
1328
                    me.loadDoc(idNo, tbl);
1329
                    me.reloadDoc();
1330
                    me.createDoc();
1331
					me.getLookupRefDoc();
1332
                } else {
1333
                    MinovaMessage('', '000005', result.message.text, 'E');
1334
                    panelHead.unmask();
1335
                }
1336
            });
1337
        }
1338
        console.log('backDoc');
1339

    
1340
    },
1341
	
1342
	SaveCreateDoc: function () {		////////---- add by Tri nwh 20220203
1343
        console.log('SaveCreateDoc!');
1344
        var me = this;
1345
        var panelHead = Ext.ComponentQuery.query('[name=MainHeaderDocument]')[0];
1346
        var tbl = panelHead.tableName;
1347
        var formHead = panelHead.getForm();
1348

    
1349
        if (me.transType == 'FIN') {
1350
            var pd = formHead.findField("PostingDate").getValue();
1351
            var debet = Ext.ComponentQuery.query('displayfield[name=AmountDebet]')[0];
1352
            var kredit = Ext.ComponentQuery.query('displayfield[name=AmountCredit]')[0];
1353

    
1354
            if (pd == null || pd == "" || pd == undefined) {
1355
                MinovaMessage("", "FILO05", "", "E");
1356
                return;
1357
            }
1358
            if (debet !== undefined && kredit !== undefined) {
1359
                if (debet.getValue() !== kredit.getValue()) {
1360
                    MinovaMessage("", "FILO10", "", "E");
1361
                    return;
1362
                }
1363
            }
1364
        }
1365
        if (formHead.isValid()) {
1366
            panelHead.mask("Loading...");
1367
            var dataHeader = Ext.encode(formHead.getValues());
1368
            var token = MinovaUtil.SESSIONS.Token;
1369
            var objGrid;
1370
            var objGridCell;
1371
            var objGridCellSum;
1372
            try {
1373
                objGrid = me.buildMultiGrid();
1374
                objGridCell = me.buildMultiGridEditCell();
1375
                objGridCellSum = me.buildMultiGridEditCellSum();
1376
                for (var i = 0; i < objGridCell.length; i++) {
1377
                    objGrid.push(objGridCell[i]);
1378
                }
1379
                for (var i = 0; i < objGridCellSum.length; i++) {
1380
                    objGrid.push(objGridCellSum[i]);
1381
                }
1382
            } catch (e) {
1383
                Ext.Msg.alert('Build Grid error', e);
1384
                return;
1385
            }
1386
            var dataDetail = Ext.encode(objGrid);
1387
            var params = {
1388
                serviceName: 'Filo.asmx',
1389
                methodName: 'SaveTableDoc',
1390
                parameter: 'transType=' + me.transType + '&docType=' + me.docType +
1391
                '&header=' + dataHeader + '&detail=' + dataDetail + '&action=' + me.action + '&token=' + token
1392
            };
1393
            MinovaAjaxPost('/InvokeService/Invoke/', params, function (xhr) {
1394
                var result = Ext.decode(xhr.responseText);
1395
                if (result.success) {
1396
                    var idNo = result.data;
1397
                    formHead.findField("DocNo").setValue(idNo);
1398
                    /* add by mae 20200702 */
1399
                    /* #region update item status */
1400
                    if (me.transType == "FIN" && me.docType == "IP" && formHead.getValues().DocTypeRef == "AR") {
1401
                        Ext.Ajax.request({
1402
                            async: false,
1403
                            method: 'POST',
1404
                            url: '/Devt/SaveTable',
1405
                            params: {
1406
                                tableName: 'PTRFINANCEITEM',
1407
                                data: Ext.encode({
1408
                                    DocNo: formHead.getValues().DocIDRef,
1409
                                    ItemStatus: '2'
1410
                                }),
1411
                                action: 1
1412
                            },
1413
                            waitMsg: 'Saving Data...',
1414
                            success: function (response) {
1415
                                var result = Ext.decode(response.responseText);
1416
                                if (result.success) {
1417
                                    console.log('update item status');
1418
                                }
1419
                            },
1420
                            failure: function (response) {}
1421
                        });
1422
                    }
1423
                    /* #endregion update item status */
1424
                    MinovaMessage('Not Null', '000006', '', 'S');
1425
                    panelHead.unmask();
1426
                    me.loadDoc(idNo, tbl);
1427
                    me.reloadDoc();
1428
                    me.createDoc();
1429
                } else {
1430
                    MinovaMessage('', '000005', result.message.text, 'E');
1431
                    panelHead.unmask();
1432
                }
1433
            });
1434
        }
1435
        console.log('SaveCreateDoc');
1436

    
1437
    },
1438

    
1439
    getLookupDoc: function (obj) {
1440
        var popup = Ext.ComponentQuery.query('[name=LookupDocumentTrans]').length;
1441

    
1442
        if (popup == 1) {
1443
            Ext.ComponentQuery.query('[name=LookupDocumentTrans]')[0].targetField = "DocNo";
1444
            Ext.ComponentQuery.query('[name=LookupDocumentTrans]')[0].show();
1445
        } else {
1446
            Ext.create('MinovaUtil.MinovaES.LookupDoc', {
1447
                tableName: obj.tableName,
1448
                targetField: "DocNo",
1449
                fieldValue: "",
1450
                LookupFunction: "",
1451
                filterParam: "DocType[=]" + obj.docType,
1452
            }).show()
1453
        }
1454
    },
1455
    getLookupRefDoc: function () {
1456

    
1457
        var me = this;
1458
        var popup = Ext.ComponentQuery.query('[name=LookupDocRef]')[0];
1459
        if (popup === undefined) {
1460
            popup = Ext.create('MinovaUtil.MinovaES.LookupDocRef', {
1461
                targetField: "DocNo",
1462
                fieldValue: "",
1463
                LookupFunction: "",
1464
                filterParam: "DocType[=]" + me.docType,
1465
            });
1466
        }
1467
        popup.show();
1468
        var btnSelect = popup.query('button[name=select]')[0];
1469
        if (btnSelect !== undefined)
1470
            btnSelect.on('click', me.selectDocRef, me);
1471
    },
1472
    selectDocRef: function () {
1473
        var me = this;
1474
        var popup = Ext.ComponentQuery.query('[name=LookupDocRef]')[0];
1475
        var grid = Ext.ComponentQuery.query('[name=gridlookupdocref]')[0];
1476
        if (grid !== undefined) {
1477
            var selection = grid.getView().getSelectionModel();
1478
            var dt = selection.getSelection();
1479
            if (dt.length > 0) {
1480
                var intdocref = [];
1481
                var refheader = [];
1482
                var refitems = [];
1483
                for (var i = 0; i < dt.length; i++) {
1484
                    var d = dt[i];
1485
                    var trtype = d.data.TransType;
1486
                    var dctype = d.data.DocType;
1487
                    var trtyperef = d.data.TransTypeRef;
1488
                    var dctyperef = d.data.DocTypeRef;
1489
                    var dcno = d.data.DocNo;
1490
                    var company = d.data.CompanyID;
1491
                    var bu = d.data.BusinessUnit;
1492
                    var params = {
1493
                        serviceName: 'Filo.asmx',
1494
                        methodName: 'GetReferenceDoc',
1495
                        parameter: 'transType=' + trtype + '&docType=' + dctype +
1496
                        '&transTypeRef=' + trtyperef + '&docTypeRef=' + dctyperef + '&docNo=' + dcno
1497
                    };
1498
                    MinovaAjaxPostSync('/InvokeService/Invoke/', params, function (xhr) {
1499
                        var result = Ext.decode(xhr.responseText);
1500
                        var dtref = Ext.decode(result.data);
1501
                        refheader.push(dtref.Header);
1502
                        if (trtype == "FIN" && dctype == "IP" && trtyperef == "FIN" && dctyperef == "AR") {
1503
                            var a = dtref.Items[0];
1504
                            var b = JSON.parse(JSON.stringify(dtref.Items[0]));
1505
                            a.GLAccountID = '';
1506
                            a.ItemStatus = '2';
1507
                            b.AmountCredit = b.AmountDebet;
1508
                            b.AmountCreditCompCurr = b.AmountDebetCompCurr;
1509
                            b.AmountDebet = '0';
1510
                            b.AmountDebetCompCurr = '0';
1511
                            b.ItemStatus = '2';
1512
                            var c = [a, b];
1513
                            refitems.push(c);
1514
                        } else {
1515
                            refitems.push(dtref.Items);
1516
                        }
1517
                        intdocref.push(dcno);
1518
                    });
1519
                };
1520
                if (trtype = 'FIN') {
1521
                    popup.hide();
1522
                    me.createDocRef(refheader, refitems, intdocref);
1523
                } else {
1524
                    me.getLookupItemDetailRef(trtype, dctype, trtyperef, dctyperef, refheader, refitems, intdocref);
1525
                }
1526
            }
1527
        }
1528
    },
1529
    getLookupItemDetailRef: function (trtype, dctype, trtyperef, dctyperef, refheader, refitems, intdocref) {
1530
        var me = this;
1531
        var refTable = '';
1532
        Ext.Ajax.request({
1533
            async: false,
1534
            method: 'POST',
1535
            url: '/UserControl/GetStore',
1536
            params: {
1537
                tableName: 'PCMBSTRANSLIST',
1538
                param: 'ItemDetailRef[=]' + '1' + ',TransType[=]' + trtyperef
1539
            },
1540
            success: function (response) {
1541
                var results = Ext.decode(response.responseText);
1542
                data_ = results.data;
1543
                refTable = data_[0].TableName;
1544
            }
1545
        });
1546
        var popupitemref = Ext.ComponentQuery.query('[name=LookupItemDetailRef]')[0];
1547
        if (popupitemref === undefined) {
1548
            popupitemref = Ext.create('MinovaUtil.MinovaES.LookupItemDetailRef', {
1549
                targetField: "DocNo",
1550
                fieldValue: "",
1551
                LookupFunction: "",
1552
                tableName: refTable,
1553
            });
1554
        }
1555
        popupitemref.show();
1556
        var storeItemm = Ext.data.StoreManager.lookup('storeadvanceitem');
1557
        var p = [];
1558
        for (var i = 0; i < intdocref.length; i++) {
1559
            p.push('value == ' + '\'' + intdocref[i] + '\'');
1560
        }
1561
        storeItemm.filter(function (r) {
1562
            var value = r.get('DocNo');
1563
            return (eval(p.join(' || ')));
1564
        });
1565

    
1566
        var btnSelect = popupitemref.query('button[name=select]')[0];
1567
        if (btnSelect !== undefined)
1568
            btnSelect.on('click', me.selectItemDetailRef, me);
1569
    },
1570
    selectItemDetailRef: function () {
1571
        var me = this;
1572
        var popup = Ext.ComponentQuery.query('[name=LookupDocRef]')[0];
1573
        var popupitemref = Ext.ComponentQuery.query('[name=LookupItemDetailRef]')[0];
1574
        var grid = Ext.ComponentQuery.query('[name=gridlookupdocref]')[0];
1575
        var griditemref = Ext.ComponentQuery.query('[name=gridlookupitemdetailref]')[0];
1576
        if (grid !== undefined) {
1577
            if (griditemref !== undefined) {
1578
                var selection = grid.getView().getSelectionModel();
1579
                var selectionitemref = griditemref.getView().getSelectionModel();
1580
                var dt = selection.getSelection();
1581
                var dtitemref = selectionitemref.getSelection();
1582
                if (dt.length > 0 && dtitemref.length > 0) {
1583
                    var intdocref = [];
1584
                    var refheader = [];
1585
                    var refitems = [];
1586
                    var refitems2 = [];
1587
                    var dtref;
1588
                    for (var i = 0; i < dt.length; i++) {
1589
                        var d = dt[i];
1590
                        var trtype = d.data.TransType;
1591
                        var dctype = d.data.DocType;
1592
                        var trtyperef = d.data.TransTypeRef;
1593
                        var dctyperef = d.data.DocTypeRef;
1594
                        var dcno = d.data.DocNo;
1595
                        var params = {
1596
                            serviceName: 'Filo.asmx',
1597
                            methodName: 'GetReferenceDoc',
1598
                            parameter: 'transType=' + trtype + '&docType=' + dctype +
1599
                            '&transTypeRef=' + trtyperef + '&docTypeRef=' + dctyperef + '&docNo=' + dcno
1600
                        };
1601
                        MinovaAjaxPostSync('/InvokeService/Invoke/', params, function (xhr) {
1602
                            var result = Ext.decode(xhr.responseText);
1603
                            dtref = Ext.decode(result.data);
1604
                            refheader.push(dtref.Header);
1605
                            //refitems.push(dtref.Items);
1606
                            for (var j = 0; j < dtref.Items.length; j++) {
1607
                                refitems.push(dtref.Items[j]);
1608
                            }
1609
                            intdocref.push(dcno);
1610
                        });
1611
                    };
1612
                    for (var k = 0; k < refitems.length; k++) {
1613
                        for (var l = 0; l < dtitemref.length; l++) {
1614
                            if (refitems[k].hasOwnProperty('MaterialID') == true && dtitemref[l].data.hasOwnProperty('MaterialID') == true) {
1615
                                if (refitems[k].MaterialID == dtitemref[l].data.MaterialID /*&& refitems[k].DocItemRef == dtitemref[l].data.DocItemID*/) {
1616
                                    refitems2.push(refitems[k]);
1617
                                }
1618
                            } else if (refitems[k].hasOwnProperty('Material') == true && dtitemref[l].data.hasOwnProperty('MaterialID') == true) {
1619
                                if (refitems[k].Material == dtitemref[l].data.MaterialID /*&& refitems[k].DocItemRef == dtitemref[l].data.DocItemID*/) {
1620
                                    refitems2.push(refitems[k]);
1621
                                }
1622
                            } else if (refitems[k].hasOwnProperty('MaterialID') == true && dtitemref[l].data.hasOwnProperty('Material') == true) {
1623
                                if (refitems[k].MaterialID == dtitemref[l].data.Material /*&& refitems[k].DocItemRef == dtitemref[l].data.DocItemID*/) {
1624
                                    refitems2.push(refitems[k]);
1625
                                }
1626
                            } else {
1627
                                if (refitems[k].Material == dtitemref[l].data.Material /*&& refitems[k].DocItemRef == dtitemref[l].data.DocItemID*/) {
1628
                                    refitems2.push(refitems[k]);
1629
                                }
1630
                            }
1631
                        }
1632
                    }
1633
                    popup.hide();
1634
                    popupitemref.hide();
1635
                    me.createDocRef(refheader, refitems2, intdocref);
1636
                }
1637
            }
1638
        }
1639
    },
1640
    specialKey: function (f, e) {
1641
        var me = this;
1642
        if (e.getKey() == e.ENTER) {
1643
            getLookupDoc(f);
1644
        }
1645
    },
1646
    displayResultInfo: function () {
1647
        var me = this;
1648
        var gridInfo = Ext.ComponentQuery.query('[name=searchResultInfo]')[0];
1649
        var grid = Ext.ComponentQuery.query('[name=searchResult]')[0];
1650
        var selection = grid.getView().getSelectionModel().getSelection()[0];
1651
        var documentno = selection.data.DocNo;
1652
        //me.action = '2';
1653
        me.docNo = documentno;
1654
        var store = Ext.StoreMgr.lookup("storeadvance2");
1655

    
1656
        var menuid = MinovaUtil.GetMenuID();
1657
        var module = undefined;
1658
        var tableItem = undefined;
1659
        Ext.Ajax.request({
1660
            async: false,
1661
            method: 'POST',
1662
            url: '/UserControl/GetStore',
1663
            params: {
1664
                tableName: 'PCMEPMODULETYPE',
1665
                param: 'MenuID[=]' + menuid
1666
            },
1667
            success: function (response) {
1668
                var results = Ext.decode(response.responseText);
1669
                if (results.data.length > 0) {
1670
                    module = results.data[0].ModuleItem;
1671
                }
1672
            }
1673
        });
1674
        Ext.Ajax.request({
1675
            async: false,
1676
            method: 'POST',
1677
            url: '/UserControl/GetStore',
1678
            params: {
1679
                tableName: 'PCMBSTRANSLIST',
1680
                param: "TransType[=]" + module + ",Sequence[=]1"
1681
            },
1682
            success: function (response) {
1683
                var results = Ext.decode(response.responseText);
1684
                if (results.data.length > 0) {
1685
                    tableItem = results.data[0].TableName;
1686
                }
1687
            }
1688
        });
1689
        store.proxy.url = '/UserControl/GetStore';
1690
        store.proxy.extraParams = {
1691
            tableName: tableItem,
1692
            param: "DocNo" + '[=]' + me.docNo
1693
        };
1694
        store.removeAll();
1695
        store.reload();
1696
        gridInfo.setHidden(false);
1697
    },
1698
});
(2-2/3)