Project

General

Profile

Feature #3389 » PTRFINANCEITEM-GlAccountID-SelectFunction.js

Tri Rizqiaty, 02/05/2025 04:30 PM

 
1
var getPnl = Ext.ComponentQuery.query('[name=panelTabPTRFINANCEITEM]')[0];
2
var getTbl = getPnl.query('[name=gridCELLGRIDPTRFINANCEITEM]')[0];
3
var records = getTbl.getSelectionModel().getSelection()[0];
4
var row = getTbl.store.indexOf(records);
5
records.set('AccountGroup', val.selection.data.AccountClass);
6
var Status = '';
7
if (val.selection.data.Clearing == '1') {
8
    Status = '0';
9
} else if (val.selection.data.Clearing == '0') {
10
    Status = '2';
11
}
12
var menuid = MinovaUtil.GetMenuID();
13
var doctype = undefined;
14
var flag = undefined;
15
var accountvs = '';
16
var accounttax = '';
17
Ext.Ajax.request({
18
    async: false,
19
    method: 'POST',
20
    url: '/UserControl/GetStore',
21
    params: {
22
        tableName: 'PCMEPMODULETYPE',
23
        param: 'MenuID[=]' + menuid
24
    },
25
    success: function (response) {
26
        var results = Ext.decode(response.responseText);
27
        if (results.data.length > 0) {
28
            doctype = results.data[0].ModuleItem;
29
        }
30
    }
31
});
32
if (doctype == 'IP') {
33
    Status = '2';
34
}
35
records.set('ItemStatus', Status);
36
records.set('SubLedgerType', val.selection.data.SLType);
37
records.set('SubLedgerID', '');
38
Ext.Ajax.request({
39
    async: false,
40
    method: 'POST',
41
    url: '/UserControl/GetStore',
42
    params: {
43
        tableName: 'PCMFILODEFAULTACC',
44
        param: 'DocType[=]' + doctype + ',AccountID[=]' + val.selection.data.GlAccount
45
    },
46
    success: function (response) {
47
        var results = Ext.decode(response.responseText);
48
        if (results.data.length > 0) {
49
            flag = results.data[0].Flag;
50
            accountvs = results.data[0].AccountVs;
51
            accounttax = results.data[0].AccountTax;
52
        }
53
    }
54
});
55
var store = Ext.StoreMgr.lookup("storePTRFINANCEITEM");
56
var debet = 0;
57
var credit = 0;
58
var sumcredit = 0;
59
if (flag == 'K') {
60
    for (var i = row - 1; i >= 0; i--) {
61
        credit = store.getAt(i).get('AmountCredit');
62
        credit = Number(Math.round(parseInt(credit) + 'e2') + 'e-2');
63
        if (credit > 0) {
64
            break;
65
        }
66
        debet = store.getAt(i).get('AmountDebet');
67
        debet = Number(Math.round(parseInt(debet) + 'e2') + 'e-2');
68
        sumcredit = sumcredit + debet;
69
    }
70
}
71
store.getAt(row).set('AmountCredit', sumcredit);
72
store.getAt(row).set('AmountCreditCompCurr', store.getAt(row).get('AmountCredit'));
73
if (row > 0) {
74
    if (store.getAt(row - 1).get('AmountCredit') == 0) {
75
        store.getAt(row).set('Description', store.getAt(row - 1).get('Description'));
76
    }
77
}
78
if (accounttax != '') {
79
    Ext.ComponentQuery.query('button[name=addPTRFINANCEITEM]')[0].getEl().dom.click();
80
    store.getAt(row + 1).set('GLAccountID', accounttax);
81
    Ext.Ajax.request({
82
        async: false,
83
        method: 'POST',
84
        url: '/UserControl/GetStore',
85
        params: {
86
            tableName: 'PDSACCCOMP',
87
            param: 'GlAccount[=]' + store.getAt(row + 1).get('GLAccountID')
88
        },
89
        success: function (response) {
90
            var results = Ext.decode(response.responseText);
91
            if (results.data.length > 0) {
92
                if (results.data[0].Clearing == '1') {
93
                    store.getAt(row + 1).set('ItemStatus', '0');
94
                    if (doctype == 'IP') {
95
                        store.getAt(row + 1).set('ItemStatus', '2');
96
                    }
97
                } else if (results.data[0].Clearing == '0') {
98
                    store.getAt(row + 1).set('ItemStatus', '2');
99
                }
100
            }
101
        }
102
    });
103
    Ext.ComponentQuery.query('button[name=addPTRFINANCEITEM]')[0].getEl().dom.click();
104
    store.getAt(row + 2).set('GLAccountID', accountvs);
105
    Ext.Ajax.request({
106
        async: false,
107
        method: 'POST',
108
        url: '/UserControl/GetStore',
109
        params: {
110
            tableName: 'PDSACCCOMP',
111
            param: 'GlAccount[=]' + store.getAt(row + 2).get('GLAccountID')
112
        },
113
        success: function (response) {
114
            var results = Ext.decode(response.responseText);
115
            if (results.data.length > 0) {
116
                if (results.data[0].Clearing == '1') {
117
                    store.getAt(row + 2).set('ItemStatus', '0');
118
                    if (doctype == 'IP') {
119
                        store.getAt(row + 1).set('ItemStatus', '2');
120
                    }
121
                } else if (results.data[0].Clearing == '0') {
122
                    store.getAt(row + 2).set('ItemStatus', '2');
123
                }
124
            }
125
        }
126
    });
127
} else {
128
    if (accountvs != '') {
129
        Ext.ComponentQuery.query('button[name=addPTRFINANCEITEM]')[0].getEl().dom.click();
130
        store.getAt(row + 1).set('GLAccountID', accountvs);
131
        Ext.Ajax.request({
132
            async: false,
133
            method: 'POST',
134
            url: '/UserControl/GetStore',
135
            params: {
136
                tableName: 'PDSACCCOMP',
137
                param: 'GlAccount[=]' + store.getAt(row + 1).get('GLAccountID')
138
            },
139
            success: function (response) {
140
                var results = Ext.decode(response.responseText);
141
                if (results.data.length > 0) {
142
                    if (results.data[0].Clearing == '1') {
143
                        store.getAt(row + 1).set('ItemStatus', '0');
144
                        if (doctype == 'IP') {
145
                            store.getAt(row + 1).set('ItemStatus', '2');
146
                        }
147
                    } else if (results.data[0].Clearing == '0') {
148
                        store.getAt(row + 1).set('ItemStatus', '2');
149
                    }
150
                }
151
            }
152
        });
153
    }
154
}
155
val.ownerCt.completeEdit();
156
Ext.ComponentQuery.query('[name=gridCELLGRIDPTRFINANCEITEM]')[0].view.refresh();
157
var cat = Ext.ComponentQuery.query("[name=CashActivityType]")[0].getValue();
158
var cad = Ext.ComponentQuery.query("[name=CashActivityDetail]")[0].getValue();
159
if (val.selection.data.AccountClass != 'CA') {
160
    store.getAt(row).set('CashActivityType', '');
161
    store.getAt(row).set('CashActivityDetail', '');
162
} else {
163
    store.getAt(row).set('CashActivityType', cat);
164
    store.getAt(row).set('CashActivityDetail', cad);
165
}
(4-4/5)