Ext.QuickTips.init(); Ext.define('erp.controller.common.BatchDeal', { extend: 'Ext.app.Controller', requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil', 'erp.util.RenderUtil'], views:[ 'common.batchDeal.Viewport','common.batchDeal.Form','common.batchDeal.GridPanel','core.trigger.AddDbfindTrigger','core.button.CheckCustomerUU', 'core.trigger.DbfindTrigger','core.form.FtField','core.form.FtFindField','core.form.ConDateField','core.button.TurnMeetingButton','core.button.CheckVendorUU', 'core.trigger.TextAreaTrigger','core.form.YnField', 'core.form.MonthDateField','core.form.ConMonthDateField','core.trigger.SchedulerTrigger', 'core.grid.YnColumn','core.form.DateHourMinuteField','core.form.SeparNumber','core.grid.YnColumnNV','core.button.ExportScanLogin' ], BaseUtil: Ext.create('erp.util.BaseUtil'), FormUtil: Ext.create('erp.util.FormUtil'), GridUtil: Ext.create('erp.util.GridUtil'), init:function(){ var me = this; me.resized = false; this.control({ 'erpBatchDealFormPanel': { alladded: function(form){ var grid = Ext.getCmp('batchDealGridPanel'); me.resize(form, grid); var items = form.items.items, autoQuery = false; Ext.each(items, function() { var val = getUrlParam(this.name); if(!Ext.isEmpty(val)) { this.setValue(val); autoQuery = true; if(this.xtype == 'dbfindtrigger') { this.autoDbfind('form', caller, this.name, this.name + " like '%" + val + "%'"); } } }); if(autoQuery) { setTimeout(function(){ form.onQuery(); }, 1000); } } }, 'erpBatchDealGridPanel': { afterrender: function(grid){ var form = Ext.getCmp('dealform'); me.resize(form, grid); grid.store.on('datachanged', function(store){ me.getProductWh(grid); }); if(caller == 'ARBill!ToBillOut!Deal'||caller == 'APBill!ToBillOutAP!Deal'){ grid.plugins[0].on('afteredit',function(){ me.countAmount(grid); }); grid.on('selectionchange',function(){ me.countAmount(grid); }); } } }, 'field[name=differ]': { change: function(field){ var grid = Ext.getCmp('batchDealGridPanel'); me.countAmount(grid); } }, 'erpExportScanLoginButton':{ click:function(btn){ me.beforeExportScanLogin(); } }, 'erpVastDealButton': { click: function(btn){ me.vastDeal(btn.ownerCt.ownerCt.dealUrl); } }, 'erpVastAnalyseButton': { click: function(btn){ me.vastDeal(btn.ownerCt.ownerCt.dealUrl); } }, 'erpVastPrintButton': { click: function(btn){ me.vastDeal(btn.ownerCt.ownerCt.dealUrl); } }, 'erpVastAllotButton':{ click:function(btn){ me.vastDeal(btn.ownerCt.ownerCt.dealUrl); } }, 'erpSaveCostDetailButton':{ click:function(btn){ me.vastDeal('cost/vastSaveCostDetail.action'); } }, 'erpDifferVoucherCreditButton':{ click:function(btn){ me.vastDeal('cost/vastDifferVoucherCredit.action'); } }, 'SchedulerTrigger':{ afterrender:function(trigger){ trigger.setFields=[{field:'va_vecard',mappingfield:'ID'},{field:'va_driver',mappingfield:'VA_DRIVER'}]; } }, 'erpEndCRMButton':{ click:function(btn){ me.vastDeal('crm/chanceTurnEnd.action'); } }, 'monthdatefield': { afterrender: function(f) { var type = '', con = null; if(f.name == 'vo_yearmonth' && caller == 'Voucher!Audit!Deal') { type = 'MONTH-A'; con = Ext.getCmp('condatefield'); } else if(f.name == 'vo_yearmonth' && caller == 'Voucher!ResAudit!Deal') { type = 'MONTH-A'; con = Ext.getCmp('condatefield'); } else if(f.name == 'vo_yearmonth' && caller == 'CashFlowSet') { type = 'MONTH-A'; con = Ext.getCmp('condatefield'); } else if(f.name == 'vm_yearmonth' && caller == 'VendMonth!Cyf!Batch') { type = 'MONTH-V'; con = Ext.getCmp('condatefield'); } else if(f.name == 'cm_yearmonth' && caller == 'CustMonth!Cys!Batch') { type = 'MONTH-C'; con = Ext.getCmp('condatefield'); } else if(f.name == 'cd_yearmonth' && caller == 'Make!Cost!Deal') { type = 'MONTH-T'; con = Ext.getCmp('condatefield'); } if(type != '') { this.getCurrentMonth(f, type, con); } }, change: function(f) { if(f.name == 'vo_yearmonth' &&( caller == 'Voucher!Audit!Deal'||caller == 'Voucher!ResAudit!Deal')){ if(!Ext.isEmpty(f.value)) { var d = Ext.ComponentQuery.query('condatefield'); if(d && d.length > 0) d[0].setMonthValue(f.value); } } } }, 'erpRefreshQtyButton': { click : function() { this.refreshQty(caller); } } }); }, resize: function(form, grid){ if(!this.resized && form && grid && form.items.items.length > 0){ var height = window.innerHeight, fh = form.getEl().down('.x-panel-body>.x-column-inner').getHeight(); if(Ext.isIE){ height = screen.height*0.75; } form.setHeight(35 + fh); grid.setHeight(height - fh - 35); this.resized = true; } }, countGrid: function(){ //重新计算合计栏值 var grid = Ext.getCmp('batchDealGridPanel'); Ext.each(grid.columns, function(column){ if(column.summary){ var sum = 0; Ext.each(grid.store.data.items, function(item){ if(item.value != null && item.value != ''){ sum += Number(item.value); } }); Ext.getCmp(column.dataIndex + '_sum').setText(column.text + '(sum):' + sum); } else if(column.average) { var average = 0; Ext.each(grid.store.data.items, function(item){ if(item.value != null && item.value != ''){ average += Number(item.value); } }); average = average/grid.store.data.items.length; Ext.getCmp(column.dataIndex + '_average').setText(column.text + '(average):' + average); } else if(column.count) { var count = 0; Ext.each(grid.store.data.items, function(item){ if(item.value != null && item.value != ''){ count++; } }); Ext.getCmp(column.dataIndex + '_count').setText(column.text + '(count):' + count); } }); }, vastDeal: function(url){ var me = this, grid = Ext.getCmp('batchDealGridPanel'); var items = grid.selModel.getSelection(); grid.multiselected = []; Ext.each(items, function(item, index){ if(this.data[grid.keyField] != null && this.data[grid.keyField] != '' && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){ item.index = this.data[grid.keyField]; grid.multiselected.push(item); } }); var form = Ext.getCmp('dealform'); var records = Ext.Array.unique(grid.multiselected); if(records.length > 0){ if(contains(url,'common/form/vastPost.action',true)) { this.vastPost(grid, records, url); return; } var params = new Object(); params.id=new Array(); params.caller = caller; var data = new Array(); var bool = false; Ext.each(records, function(record, index){ var f = form.fo_detailMainKeyField; if((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != '' && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0) ||(f && this.data[f] != null && this.data[f] != '' && this.data[f] != '0' && this.data[f] != 0)){ bool = true; var o = new Object(); if(grid.keyField){ o[grid.keyField] = record.data[grid.keyField]; } else { params.id[index] = record.data[form.fo_detailMainKeyField]; } if(grid.toField){ Ext.each(grid.toField, function(f, index){ var v = Ext.getCmp(f).value; if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){ if(Ext.isDate(v)){ v = Ext.Date.toString(v); } o[f] = v; } else { o[f] = ''; } }); } if(grid.necessaryFields){ Ext.each(grid.necessaryFields, function(f, index){ var v = record.data[f]; if(Ext.isDate(v)){ v = Ext.Date.toString(v); } if(Ext.isNumber(v)){ v = (v).toString(); } o[f] = v; }); } data.push(o); } }); if(bool && !me.dealing){ params.data = unescape(Ext.JSON.encode(data).replace(/\\/g,"%")); me.dealing = true; var main = parent.Ext.getCmp("content-panel"); main.getActiveTab().setLoading(true);//loading... Ext.Ajax.request({ url : basePath + url, params: params, method : 'post', timeout: 6000000, callback : function(options,success,response){ main.getActiveTab().setLoading(false); me.dealing = false; var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){ str = str.replace('AFTERSUCCESS', ''); grid.multiselected = new Array(); Ext.getCmp('dealform').onQuery(); } showError(str);return; } if(localJson.success){ if(localJson.log){ showMessage("提示", localJson.log); } grid.multiselected = new Array(); Ext.getCmp('dealform').onQuery(); /*Ext.Msg.alert("提示", "处理成功!", function(){ grid.multiselected = new Array(); Ext.getCmp('dealform').onQuery(); });*/ } } }); } else { showError("没有需要处理的数据!"); } } else { showError("请勾选需要的明细!"); } }, getCurrentMonth: function(f, type, con) { Ext.Ajax.request({ url: basePath + 'fa/getMonth.action', params: { type: type }, callback: function(opt, s, r) { var rs = Ext.decode(r.responseText); if(rs.data) { f.setValue(rs.data.PD_DETNO); if(con != null) { con.setMonthValue(rs.data.PD_DETNO); } } } }); }, vastPost: function(grid, records, url) { var me = this, win = Ext.getCmp('win-post'); grid._postrecords = records; if(!win) { win = Ext.create('Ext.Window', { id: 'win-post', width: '70%', height: '60%', modal: true, layout: 'anchor', items: [{ xtype: 'form', anchor: '100% 100%', bodyStyle: 'background: #f1f1f1;', layout: 'column', defaults: { xtype: 'checkbox', margin: '2 10 2 10', columnWidth: .33 }, items: [{ xtype: 'displayfield', fieldLabel: '当前账套', id: 'ma_name' },{ xtype: 'displayfield', fieldLabel: '账套描述', margin: '2 10 30 10', id: 'ma_function' },{ xtype: 'displayfield', fieldLabel: '目标账套', columnWidth: 1 },{ boxLabel: '全选', columnWidth: 1, listeners: { change: function(f) { var form = f.up('form'); form.getForm().getFields().each(function(a){ if(a.xtype == 'checkbox' && a.id != f.id) { a.setValue(f.value); } }); } } }] }], buttonAlign: 'center', buttons: [{ text: $I18N.common.button.erpConfirmButton, cls: 'x-btn-blue', handler: function(btn) { var w = btn.ownerCt.ownerCt, form = w.down('form'), from = form.down('#ma_name').value, items = form.query('checkbox[checked=true]'), data = new Array(); Ext.each(items, function(item){ if (item.ma_name) data.push(item.ma_name); }); if(data.length > 0) me.post(w, grid, url, from, data.join(',')); } },{ text: $I18N.common.button.erpCloseButton, cls: 'x-btn-blue', handler: function(btn) { btn.ownerCt.ownerCt.hide(); } }] }); if(contains(url,'?_out=1',true)) this.getOutMasters(win); else this.getMasters(win); } win.show(); }, post: function(w, grid, url, from, to) { var records = grid._postrecords; w.setLoading(true); var d = new Array(), f = grid.keyField; Ext.each(records, function(r) { d.push(r.get(f)); }); Ext.Ajax.request({ url: basePath + url, params: { caller: caller, data: d.join(','), to: to }, callback: function(opt, s, r) { w.setLoading(false); if(s) { var rs = Ext.decode(r.responseText); if(rs.data) { showMessage('提示', rs.data); } else { alert('抛转成功!'); } grid.multiselected = new Array(); grid._postrecords = null; Ext.getCmp('dealform').onQuery(); w.hide(); } } }); }, /** * 加载系统所有账套 */ getMasters: function(win){ Ext.Ajax.request({ url: basePath + 'common/getMasters.action', method: 'get', callback: function(opt, s, res){ var r = Ext.decode(res.responseText), c = r.currentMaster; if(r.masters){ var form = win.down('form'), items = new Array(); for(var i in r.masters) { var d = r.masters[i]; if(d.ma_name != c) { if(d.ma_type == 3) { var o = {boxLabel: d.ma_name + '(' + d.ma_function + ')', ma_name: d.ma_name}; items.push(o); } } else { form.down('#ma_name').setValue(c); form.down('#ma_function').setValue(d.ma_function); } } form.add(items); } } }); }, getOutMasters:function(win){ Ext.Ajax.request({ url: basePath + 'common/getOutMasters.action', method: 'get', callback: function(opt, s, res){ var r = Ext.decode(res.responseText), c = r.currentMaster; if(r.data){ var form = win.down('form'), items = new Array(); Ext.Array.each(r.data,function(d){ var o = {boxLabel: d.MO_LOCATION + '(' + d.MO_NAME + ')', ma_name: d.MO_LOCATION}; items.push(o); }); form.down('#ma_name').setValue(c); //form.down('#ma_function').setValue(d.ma_function); form.add(items); } } }); }, refreshQty : function(cal) { var tab = null; switch(cal) { case 'Purchase!ToCheckAccept!Deal' : tab = 'Purchase'; break; case 'Purchase!ToNotify!Deal' : tab = 'Purchase'; break; case 'Sale!ToAccept!Deal': tab = 'Sale'; break; case 'SendNotify!ToProdIN!Deal': tab = 'SendNotify'; break; } var form = Ext.getCmp('dealform'); form.setLoading(true); Ext.Ajax.request({ url : basePath + 'common/resetqty.action', params : { tab : tab }, callback : function(opt, s, res) { form.setLoading(false); var r = Ext.decode(res.responseText); if (r.success) { alert('已转数量重置成功!'); // form.onQuery(); } } }); }, getProductWh: function(grid) { var prodfield = grid.getProdField(); if(prodfield) { var codes = []; grid.store.each(function(d){ codes.push("'" + d.get(prodfield) + "'"); }); Ext.Ajax.request({ url: basePath + 'scm/product/getProductwh.action', params: { codes: codes.join(',') }, callback: function (opt, s, r) { if(s) { var rs = Ext.decode(r.responseText); if(rs.data) { grid.productwh = rs.data; } } } }); } }, countAmount: function(grid){ var me = this; var items = grid.selModel.selected.items; var countamount=0; var taxsum = 0, differ = Ext.getCmp('differ'); priceFormat = grid.down('gridcolumn[dataIndex=abd_thisvoprice]').format, fsize = (priceFormat && priceFormat.indexOf('.') > -1) ? priceFormat.substr(priceFormat.indexOf('.') + 1).length : 6; Ext.each(items,function(item,index){ var a = Number(grid.BaseUtil.numberFormat(Number(item.data['abd_thisvoprice']),fsize)); var b = Number(grid.BaseUtil.numberFormat(Number(item.data['abd_thisvoqty']),2)); var rate = Number(grid.BaseUtil.numberFormat(Number(item.data['abd_taxrate']),2)); countamount = countamount + Number(grid.BaseUtil.numberFormat(a*b,2)); taxsum = taxsum + Number(grid.BaseUtil.numberFormat((a*b*rate/100)/(1+rate/100),2)); }); //金额合计 不能填写 自动显示所选数据条目的本次发票数*本次发票单价 的总和 Ext.getCmp('pi_amounttotal').setValue(Ext.util.Format.number(countamount, "0.00")); if(differ && !Ext.isEmpty(differ.value)){ Ext.getCmp('taxsum').setValue(Ext.util.Format.number(taxsum+differ.value, "0.00")); } else { Ext.getCmp('taxsum').setValue(Ext.util.Format.number(taxsum, "0.00")); } }, //确认投放数量,在修改完计划投放数量时候点击按钮,将选中行的数量保存,并且限制不能超过建议变更数 ConfirmThrowQty:function(){ var grid = Ext.getCmp('batchDealGridPanel'); var count=0; if(grid.multiselected.length==0){ var items = grid.selModel.getSelection(); Ext.each(items, function(item, index){ if(this.data[grid.keyField] != null && this.data[grid.keyField] != '' && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){ grid.multiselected.push(item); } }); } var records = Ext.Array.unique(grid.multiselected); var gridStore = new Array(); var dd; if(records.length>0){ Ext.each(records, function(records, index){ if(records.data.md_prodcode!=''){ dd=new Object(); dd['mr_mpsid']=records.data.mr_mpsid; gridStore[index] = Ext.JSON.encode(dd); count++; } }); this.ConfirmThrow(gridStore); } else { showError("没有需要处理的数据!"); } }, ComfirmThrow:function(store){ if(this.throwing) { alert('正在执行...不要重复点击!'); return; } var me = this, gridstore = store; var main = parent.Ext.getCmp("content-panel"); main.getActiveTab().setLoading(true);//loading... var btn = Ext.getCmp('erpConfirmThrowQtyButton'); if(btn) btn.setDisabled(true); this.throwing = true; Ext.Ajax.request({ url : basePath + "pm/MPSMain/NeedThrow.action", params: { mainCode:Ext.getCmp('md_mpscode').value, caller:caller, gridStore:unescape(gridstore.toString().replace(/\\/g,"%")), toWhere:'AUTO', toCode:Ext.getCmp('md_ordercode').value, condition:'' }, timeout: 60000, method : 'post', callback : function(options,success,response){ btn.setDisabled(false); me.throwing = false; main.getActiveTab().setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); return ""; } if(localJson.success){ if(localJson.log){ showMessage("提示", localJson.log); } Ext.Msg.alert("提示", "处理成功!", function(){ Ext.getCmp('dealform').onQuery(); }); } } }); }, beforeExportScanLogin:function(){ //form里面数据 var me = this; var grid = Ext.getCmp('batchDealGridPanel'); var data=me.GridUtil.getGridSelected(grid); if(data.length == 0 || data == null){ showError("请先选择需要批量导出的人员资料"); return ; } var param = new Array(); Ext.each(data,function(item,index){ param.push(item.em_id); }) param = param == null ? [] : "[" + param.toString().replace(/\\/g,"%") + "]"; var mb = new Ext.window.MessageBox(); mb.wait('正在查询中','请稍后...',{ interval: 10000, //bar will move fast! duration: 50000, increment: 5, /* text: 'Runing...',*/ scope: this }); //me.FormUtil.setLoading(true);//loading... Ext.Ajax.request({ url : basePath+'hr/employee/ExportScanLogin.action', params: { caller:caller, gridStore:param }, method : 'post', timeout:50000, callback : function(options,success,response){ //me.FormUtil.setLoading(false); mb.close(); var localJson = new Ext.decode(response.responseText); if(localJson.success){ showMessage('提示', '操作成功!', 1000); var ids=localJson.ids; //导出 var con="em_id in"+ids; me.BaseUtil.createExcel('ScanCodeLogin!query', 'detailgrid', con); grid.GridUtil.loadNewStore(grid, { caller: caller, condition: 'em_id in'+ids }); } else if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; showError(str);return; } } }); } });