function import_dpp(){ var ds_stva = store_stva(); var ds_stsmt = store_stsmt(); var fields_va = RH.storeFields('idva','tglva','jamva','idstva','nmstva', 'keterangan','nmfile','userid','nmlengkap'); var pageSize = 18; var ds_va = RH.JsonStore({ url : BASE_URL + 'import_dpp_controller/get_va', fields : fields_va, limit: pageSize, enableSearch: true, }); //SEARCH COMPONENT var sb_va = RH.searchComp({ id : 'sb_va', fields : ['tglva:Tanggal','jamva:Jam','nmstva:Status','keterangan:Keterangan','nmlengkap:Importer'], selected : 'tglva', store : ds_va }); // COLUMN MODEL var cm_va = new Ext.grid.ColumnModel([ new Ext.grid.RowNumberer(), { header: RH.h3('Tanggal'),width: 100, dataIndex: 'tglva', sortable: true }, { header: RH.h3('Jam'), width: 100, dataIndex: 'jamva', sortable: true }, { header: RH.h3('Status'), width: 200, dataIndex: 'nmstva', sortable: true }, { header: RH.h3('Keterangan'), width: 300, dataIndex: 'keterangan', sortable: true }, { header: RH.h3('Importer'), width: 200, dataIndex: 'nmlengkap', sortable: true }, RH.EditColumn(), RH.DeleteColumn() ] ); /** THE GRID */ var gp_va = RH.GridPanel_T1({ ds: ds_va, cm: cm_va, singleSelect: true, searchComp: sb_va, allowAdd: true, fnAdd: fnAddVa, pageSize: pageSize, cellclick: onCellVaClick }); var fp_va = RH.GPContainer1({ title: 'Import Pembayaran DPP/DPK via Transfer Bank', iconCls:'silk-house', gridPanel: gp_va, }); SET_PAGE_CONTENT(fp_va); /** FUNCTIONS */ function onCellVaClick(grid, rowIndex, columnIndex, e) { var record = grid.getStore().getAt(rowIndex); // Get the Record RH.EditClick(e, function(){fnEditVa(grid, record)}); RH.DeleteClick(e, function(){fnDeleteVa(grid, record)}); } function reloadVa(){ ds_va.reload(); } function fnAddVa(){ var grid = gp_va; wEntryVa(false, grid, null); } function fnEditVa(grid, record){ wEntryVa(true, grid, record); } function fnDeleteVa(grid, record){ var url = BASE_URL + 'import_dpp_controller/delete_va'; var params = new Object({ idvax : record.data['idva'], filex : record.data['nmfile'] }); RH.deleteGridRecord(url, params, grid ); } /** WIN - FORM ENTRY/EDIT IMPORT DPP */ function wEntryVa(isUpdate, grid, record){ var winTitle = (isUpdate)?'IMPORT DPP/DPK (Edit)':'IMPORT DPP/DPK (Entry)'; /** DATA SOURCE GRUP IMPORT DPP */ var SYS_DATE = new Date(); var ds_grid = new Ext.data.JsonStore({ proxy: new Ext.data.HttpProxy({ url: BASE_URL + 'import_dpp_controller/preview_data', method: 'POST' }), root: 'data', totalProperty: 'results', autoLoad: false, fields: [{ name: "a", mapping: "a" }, { name: "b", mapping: "b" }, { name: "c", mapping: "c" }, { name: "d", mapping: "d" }, { name: "cekkui", mapping: "cekkui" }], listeners: { load: function(store, records, options) { Ext.getCmp('count').setValue(ds_grid.getCount()); } } }); var grid_nya = new Ext.grid.GridPanel({ store: ds_grid, frame: true, height: 200, autoWidth: true, bodyStyle: 'padding:3px 3px 3px 3px', id: 'grid_det_product1', autoScroll: true, autoSizeColumns: true, columnLines: true, columns: [{ header: 'Tanggal Transfer', width: 150, dataIndex: 'a', sortable: true },{ header: 'Jam Transfer', width: 150, dataIndex: 'b', sortable: true },{ header: 'No. Virtual Account', width: 300, dataIndex: 'c', sortable: true },{ header: 'Nominal', width: 150, dataIndex: 'd', sortable: true },{ header: 'Keterangan', width: 250, dataIndex: 'cekkui', sortable: true }] }); /** FORM ENTRY/EDIT IMPORT DPP */ var va_form = new Ext.form.FormPanel({ xtype:'form', id: 'va_form', buttonAlign: 'left', labelWidth: 200, labelAlign: 'right', bodyStyle: 'padding:10px 3px 3px 5px', // atas, kanan, bawah, kiri monitorValid: true, height: 480, width: 1000, layout: 'form', frame: false, fileUpload: true, defaultType:'textfield', items: [{ xtype:'fieldset', title: 'Informasi Import Data', items :[{ layout: 'column', border: false, items: [{ columnWidth: .50, layout: 'form', border: false, items: [{ xtype: 'combo',allowBlank: true,editable: false, id: 'cbstva',name: 'cbstva', fieldLabel: 'Status', store: ds_stva, triggerAction: 'all', valueField: 'idstva', displayField: 'nmstva', forceSelection: true, submitValue: true, mode: 'local', emptyText:'Pilih...',width: 250, }, { xtype: 'textfield', fieldLabel: '', id: 'stvahiden', hidden:true, width: 250, listeners: {} }, { xtype: 'textarea', fieldLabel: 'Keterangan', id: 'keterangan', width: 250, height: 50, listeners: {} }] }, { columnWidth: .50, layout: 'form', border: false, items: [{ xtype: 'combo', fieldLabel: 'Tahun Akademik - Semester', id: 'cb.stsmt-dpp', store: ds_stsmt, width: 200, valueField: 'kdstsemester', displayField: 'nmsmt',//'nmsmt', editable: false, triggerAction: 'all', forceSelection: true, submitValue: true, mode: 'local', emptyText:'Pilih...', value:KDSTSEMESTER, listeners:{ scope: this, 'select': function(){ } } },{ xtype: 'textfield', fieldLabel: 'Importer', id: 'importer', readOnly:true, width: 200, value:USERNAME, listeners: {} }, { xtype: 'compositefield', name: 'time', fieldLabel: 'Tanggal / Jam', id: 'time', items: [{ xtype: 'datefield', fieldLabel: '', id: 'tglva', width: 100, name: 'tglva' }, { xtype: 'textfield', fieldLabel: '', id: 'jamva', readOnly:true, width: 95, name: 'jamva' }] }, { xtype: 'textfield', fieldLabel: '', labelStyle: 'width:160px', id: 'userid', hidden:true, width: 150, value:USERID, listeners: {} }] }] }] }, { xtype:'fieldset', title: 'Data Virtual Account', items :[{ layout: 'column', border: false, items: [{ columnWidth: .63, layout: 'form', border: false, items: [{ xtype: 'fileuploadfield', id: 'f_excel', allowBlank: false, emptyText: 'Select an file', fieldLabel: 'File Excel', name: 'f_excel', anchor: '99%', buttonText: '', buttonCfg: { iconCls: 'silk-page-copy' }, listeners: { valid: function() { } } }, { xtype: 'textfield', fieldLabel: '', labelStyle: 'width:160px', id: 'count', hidden:true, width: 150, listeners: {} }] }, { columnWidth: .37, layout: 'form', border: false, items: [{ xtype: 'button', text: 'Preview Data', id: 'btn_preview', width: 70, handler: function() { get_data('va_form'); } }] }] },grid_nya] }], buttons: [{ text: 'Simpan', iconCls:'silk-save', handler: function() { fnSaveVa(); } }, { text: 'Kembali', iconCls:'silk-arrow-undo', handler: function() { wVa.close(); } }] }); var wVa = new Ext.Window({ title: winTitle, modal: true, closable:false, items: [va_form] }); /** CALL SET FORM AND SHOW THE FORM (WINDOW) */ setVaForm(isUpdate, record); wVa.show(); /** FORM FUNCTIONS */ function setVaForm(isUpdate, record){ if(isUpdate){ if(record != null){ RH.setCompValue('cbstva', record.data['idstva']); RH.setCompValue('stvahiden', record.data['idstva']); RH.setCompValue('keterangan', record.data['keterangan']); RH.setCompValue('userid', record.data['userid']); RH.setCompValue('importer', record.data['nmlengkap']); RH.setCompValue('tglva', record.data['tglva']); RH.setCompValue('jamva', record.data['jamva']); RH.setCompValue('f_excel', record.data['nmfile']); ds_grid.setBaseParam('idva',record.data['idva']); ds_grid.proxy.conn.url = BASE_URL + 'import_dpp_controller/get_vadet'; ds_grid.load(); if (Ext.getCmp('stvahiden').getValue() == 2){ Ext.getCmp('cbstva').disable(); Ext.getCmp('f_excel').disable(); Ext.getCmp('btn_preview').disable(); } else { Ext.getCmp('cbstva').enable(); Ext.getCmp('f_excel').enable(); Ext.getCmp('btn_preview').enable(); } return; } } else { Ext.getCmp('tglva').setValue(SYS_DATE); setInterval(function() { var d = new Date(); var t = d.toLocaleTimeString(); if (Ext.getCmp('jamva')) Ext.getCmp('jamva').setValue(t); }, 1000); } } //ambil record hasil import dari excel====================================== function get_data(namaForm) { var form_nya = Ext.getCmp(namaForm); var xls = Right(Ext.getCmp('f_excel').getValue(),3); if (xls) { if (xls=="xls") { //grid_nya.getStore().removeAll(); ds_grid.removeAll(); form_nya.getForm().submit({ url: BASE_URL + 'import_dpp_controller/upload_data', method: 'POST', waitMsg: 'Tunggu, sedang proses...', success: function(form_nya, o) { ds_grid.setBaseParam('excel',Ext.getCmp('f_excel').getValue()); ds_grid.load(); } , failure: function() { ds_grid.setBaseParam('excel',Ext.getCmp('f_excel').getValue()); ds_grid.load(); } }); } else { Ext.MessageBox.alert('Informasi', 'File Harus Berekstensi .xls'); } } else { Ext.MessageBox.alert('Informasi', 'Pilih File Excel'); } } //ambil record grid====================================== function get_record() { var par=''; var a= 1; var c = ';'; ds_grid.each(function(rec){ var rowData = rec.data; // get record if (a == ds_grid.getCount()) { c = '' } par += rowData['a'] + 'x' + rowData['b'] + 'x' + rowData['c'] + 'x' + rowData['d'] + 'x' + c; a= a+1; }); return par; } /* function fnSaveVa(){ var idForm = 'va_form'; var sUrl = BASE_URL +'import_dpp_controller/insert_va'; var sParams = new Object({ tglva : RH.getCompValue('tglva'), jamva : RH.getCompValue('jamva'), idstva : RH.getCompValue('cbstva'), keterangan : RH.getCompValue('keterangan'), nmfile : RH.getCompValue('f_excel'), }); var msgWait = 'Tunggu, sedang proses menyimpan...'; var msgSuccess = 'Tambah data berhasil'; var msgFail = 'Tambah data gagal'; var msgInvalid = 'Data belum valid (data primer belum terisi)!'; var stva = Ext.getCmp('cbstva').getValue(); var xls = Right(Ext.getCmp('f_excel').getValue(),3); //var xlsx = Right(Ext.getCmp('f_excel').getValue(),4); if (xls && stva) { if (xls=="xls"/* || xlsx=="xlsx" *///) { /* if(isUpdate){ sUrl = BASE_URL +'import_dpp_controller/update_va'; sParams.idvax = record.data['idva']; msgSuccess = 'Update data berhasil'; msgFail = 'Update data gagal'; } */ //call form grid submit function (common function by RH) /* RH.submitGridForm(idForm, sUrl, sParams, grid, reloadVa, msgWait, msgSuccess, msgFail, msgInvalid); wVa.close(); } else { Ext.MessageBox.alert('Informasi', 'File Harus Berekstensi .xls'); } } else { Ext.MessageBox.alert('Informasi', 'Lengkapi Data'); } } */ function fnSaveVa(){ var stva = Ext.getCmp('cbstva').getValue(); var xls = Right(Ext.getCmp('f_excel').getValue(),3); var msgSuccess = ""; var msgFail = ""; var sUrl=""; if(!isUpdate){ sUrl = BASE_URL +'import_dpp_controller/insert_va'; var param_record = get_record(); var sParams = new Object({ record_par : param_record, tglva : RH.getCompValue('tglva'), jamva : RH.getCompValue('jamva'), idstva : RH.getCompValue('cbstva'), keterangan : RH.getCompValue('keterangan'), nmfile : RH.getCompValue('f_excel'), userid : RH.getCompValue('userid'), kdstmester : KDSTSEMESTER }); msgSuccess = "Simpan Data Berhasil"; msgFail = "Simpan Data Gagal"; } else { sUrl = BASE_URL +'import_dpp_controller/update_va'; var param_record = get_record(); var sParams = new Object({ record_par : param_record, idva : record.data['idva'], tglva : RH.getCompValue('tglva'), jamva : RH.getCompValue('jamva'), idstva : RH.getCompValue('cbstva'), idstvahide : RH.getCompValue('stvahiden'), keterangan : RH.getCompValue('keterangan'), nmfile : RH.getCompValue('f_excel'), userid : RH.getCompValue('userid'), kdstmester : KDSTSEMESTER }); msgSuccess = "Update Data Berhasil"; msgFail = "Update Data Gagal"; } if (xls && stva && ds_grid.getCount() !=0) { if (xls=="xls") { Ext.Ajax.request({ url: sUrl, method: 'POST', params: sParams, success: function() { Ext.MessageBox.alert("Informasi", msgSuccess); ds_va.reload(); wVa.close(); }, failure: function() { Ext.MessageBox.alert("Informasi", msgFail); } }); } else { Ext.MessageBox.alert('Informasi', 'File Harus Berekstensi .xls'); } } else { Ext.MessageBox.alert('Informasi', 'Lengkapi Data'); } } function Right(str, n){ if (n <= 0) return ""; else if (n > String(str).length) return str; else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } } } }