Project

General

Profile

Bug #2863 » CtrlUploadJurnal.js

Tri Rizqiaty, 07/09/2024 10:02 AM

 
1
Ext.define('MinovaES.controller.UploadERP.CtrlUploadJurnal', {
2
    extend: 'Ext.app.ViewController',
3
    alias: 'controller.CtrlUploadJurnal',
4
    init: function () {
5
        this.control({
6
            'button[name=Import]': {
7
                click: this.UploadExcel
8
            },
9
			'button[name=DownloadTemplate]': {
10
                click: this.DownloadTemplate
11
            },
12
            '[name=Simulate]': {
13
                afterrender: this.Simulate
14
            },
15
            '[name=Table]': {
16
                change: this.hideColFullName
17
            },
18
            '[action=export]': {
19
                click: this.exportResult
20
            },
21
        });
22
    },
23
	DownloadTemplate: function () {
24
        window.open(origin+"/Extended/UploadJurnal.xlsx");       
25
    },
26
    UploadExcel: function () {
27
			
28
        var panel = Ext.ComponentQuery.query('panel[name=PanelResult]')[0];
29
        var frm = Ext.ComponentQuery.query('form[name=ImportMasterData]')[0];
30
        var grid = Ext.ComponentQuery.query('grid[name=gridresultuploadMD]')[0];
31
        var storegrid = Ext.StoreMgr.lookup("storeresultupload");
32
        var frmValue = Ext.encode(frm.getValues());
33
        if (Ext.ComponentQuery.query('[name=File]')[0].getValue() == "") {
34
            MinovaMessage('Not Null', '000009', "File", 'E');
35
        }
36
        else if (Ext.ComponentQuery.query('[name=Table]')[0].getValue() == "") {
37
            MinovaMessage('Not Null', '000009', "Table", 'E');
38
        }
39
        else {
40
            if (frm.getForm().isValid()) {
41

    
42
                frm.el.mask("Uploading data...");
43
                frm.getForm().submit({
44
                    //url: '/InvokeService/UploadMasterDataNew', //by taufan
45
					url: '/Upload/UploadJurnal', //by tri
46
                    //waitMsg: "Uploading data...",
47
                    method: "POST",
48
                    success: function (pnlParam, response) {
49
                        var result = Ext.decode(response.response.responseText);
50
                        var d = Ext.decode(result.data);
51

    
52
                        storegrid.loadData(d.data);
53
                        Ext.ComponentQuery.query('displayfield[name=Success]')[0].setValue(d.totalSucces);
54
                        Ext.ComponentQuery.query('displayfield[name=Error]')[0].setValue(d.totalError);
55
                        Ext.ComponentQuery.query('displayfield[name=Warning]')[0].setValue(d.totalWarning);
56
                        frm.el.unmask();
57
                        //if (d.message.id != null) {
58
                        //    MinovaMessage('', "MDCKTABLEFIELD", Ext.ComponentQuery.query('[name=Table]')[0].getValue(), 'E');
59
                        //} else {
60
                        //    MinovaMessage('', 'UPLOADMD', '', 'S');
61
                        //}
62
                        if (d.totalError > 0) {
63
                            MinovaMessage('', 'UPLOADMD', ' Total Succes: ' + d.totalSucces + ' Total Error: ' + d.totalError, 'E');
64
							} else {
65
                            if (d.message.id == '000005') {//(d.message.id != null) {
66
                                MinovaMessage('', "MDCKTABLEFIELD", Ext.ComponentQuery.query('[name=Table]')[0].getValue(), 'E');
67
                            } 
68
							else if (d.message.id == 'UPLOADSTATUS')
69
							{
70
								MinovaMessage('', "UPLOADSTATUS", '', 'E');
71
							}
72
							else if (d.message.id == 'UPLOADSTATUSPERIOD')
73
							{
74
								MinovaMessage('Not Null', "UPLOADSTATUSPERIOD", '', 'E');
75
								console.log(d.message.id);
76
							}	
77
							else if (d.message.id == 'UPLOADMAXROW')
78
							{
79
								MinovaMessage('', "UPLOADMAXROW", '', 'E');
80
							}							
81
							else {
82
                                MinovaMessage('', 'UPLOADMD', ' Total Succes: ' + d.totalSucces, 'S');
83
                            }
84
                        }
85
						/*if (d.totalError > 0) {
86
                            MinovaMessage('', 'UPLOADMD', ' Total Succes: ' + d.totalSucces + ' Total Error: ' + d.totalError, 'E');
87
                        } else {
88
                            if (d.message.id != null) {
89
                                MinovaMessage('', "MDCKTABLEFIELD", Ext.ComponentQuery.query('[name=Table]')[0].getValue(), 'E');
90
                            } else {
91
                                MinovaMessage('', 'UPLOADMD', ' Total Succes: ' + d.totalSucces, 'S');
92
                            }
93
                        }*/
94

    
95
                    },
96
                    failure: function (pnlParam, response) {
97
                        frm.el.unmask();
98

    
99
                        MinovaMessage('', '000005', 'Error Upload', "E");
100
                    }
101
                });
102
            }
103
        }
104
        
105
    },
106
    Simulate: function () {
107
        var s = Ext.ComponentQuery.query('[boxLabel=Simulate]')[0];
108
        s.setValue(true);
109
    },
110
    hideColFullName: function () {
111
        var grid = Ext.ComponentQuery.query('[name=gridresultuploadMD]');
112
        for (i = 0; i < grid[0].columns.length; i++) {
113
            var dataIndex = grid[0].columnManager.getColumns()[i].dataIndex;
114
            if (dataIndex == 'FullName') {
115
                grid[0].columnManager.getColumns()[i].setVisible(false);
116
            }
117
        }
118
    },
119
    exportResult: function () {
120
        var listresult = Ext.data.StoreManager.lookup('storeresultupload');
121
        var UserData = Ext.encode(Ext.pluck(listresult.data.items, 'data'));
122
        var DateTime = MinovaUtil.GetNowDateTime();
123
        if (listresult.data.length > 0) {
124
            Ext.Ajax.request({
125
                async: false,
126
                method: 'POST',
127
                url: '/UserControl/ExportMassUserResult',
128
                params: {
129
                    UserData: UserData,
130
                    DateTime: DateTime,
131
                    TableName: 'PDSUPLOADGRID'
132
                },
133
                waitMsg: 'Saving Data...',
134
                success: function (response) {
135
                    var result = Ext.decode(response.responseText);
136
                    if (!result.success) {
137
                        var result = Ext.decode(response.responseText);
138
                        console.log(result);
139
                        MinovaMessage('Not Null', '000005', result.message.text, "E")
140
                    } else {
141
                        var href = '/Devt/DownloadFileExcel?filename=User_Generate_Result_' + DateTime;
142
                        top.location = href;
143
                    }
144
                },
145
                failure: function (response) {
146
                    var result = Ext.decode(response.responseText);
147

    
148
                }
149
            });
150
        }
151

    
152
    },
153
});
(2-2/3)