其他入库 extjs 3
** *************1.变量声明******************* */
// 页面传参的值 var ishanId = (requestDecode("ishanId") == "" ? "" : requestDecode("ishanId")); var ishanCode = (requestDecode("ishanCode") == "" ? "" : requestDecode("ishanCode")); var storeroomCode = (requestDecode("storeroomCode") == "" ? "" : requestDecode("storeroomCode")); var storeroomName = (requestDecode("storeroomName") == "" ? "" : requestDecode("storeroomName")); var empCode = (requestDecode("empCode") == "" ? "" : requestDecode("empCode")); var empName = (requestDecode("empName") == "" ? "" : requestDecode("empName")); var inDate = (requestDecode("inDate") == "" ? (new Date().format('Ymd')) : changeDateFormate(requestDecode("inDate"))); var srCode = (requestDecode("srCode") == "" ? "LB002" : requestDecode("srCode")); var srName = (requestDecode("srName") == "" ? "生产完工入库" : requestDecode("srName")); var sourceBillCode = (requestDecode("sourceBillCode") == "" ? "" : requestDecode("sourceBillCode")); var remark = (requestDecode("remark") == "" ? "" : requestDecode("remark")); var status = (requestDecode("status") == "" ? "" : requestDecode("status")); var createPerson = (requestDecode("createPerson") == "" ? "" : requestDecode("createPerson")); var createDate = (requestDecode("createDate") == "" ? (new Date().format('Ymd')) : requestDecode("createDate")); // 凭证相关的字段 var voucherId = (requestDecode("voucherId") == "" ? "" :requestDecode("voucherId")); Ext.ns('Ufida', 'Ufida.data', 'Ufida.excel'); /** *************2.组件初始化************************* */ // 货品编码 var goodsNum = new Ext.form.ComboBox({ store : new Ext.data.SimpleStore({ fields : ['code', 'val'], data : [[1, '11111'], [2, '22222']] }), displayField : 'val', typeAhead : true, mode : 'local', triggerAction : 'all', allowBlank : false, selectOnFocus : true, readOnly : true, tpl : new Ext.XTemplate('<div class="add-item"><a href="javascript:addSub();" style="text-decoration:underline;">增加货品......</a></div><div class="add-item"><a href="javascript:selectSub();" style="text-decoration:underline;">选择货品......</a></div>' + '</tpl>'), anchor : '90%' }); var hid_ishanId = new Ext.form.Hidden({ value : ishanId, id : 'hid_ishanId' }); // 凭证id var hid_voucherId = new Ext.form.Hidden({ id : 'hid_voucherId', value : voucherId }); // 单据编号 var txt_code = new Ext.form.TextField({ id : 'txt_code', fieldLabel : '单据编号', anchor : '85%', allowBlank : true, readOnly : true, value : ishanCode, fieldClass : 'textReadOnly' }); // 仓库Code var hid_storeroom = new Ext.form.Hidden({ id : 'hid_storeroom', value : storeroomCode }); // 仓库Name var txt_storeroom = new NewAddTriggerField({ id : 'txt_storeroom', anchor : '80%', readOnly : true, cls : 'MandatoryCmp', value : storeroomName, fieldLabel : '仓库<font color=red>*</font>', onTrigger1Click : function() { popAddStoreroom(hid_storeroom, txt_storeroom); }, onTrigger2Click : function() { popSelectStoreroom([['1', 'hid_storeroom'], ['2', 'txt_storeroom']]); } }); // 经手人Code var hid_emp = new Ext.form.Hidden({ id : 'hid_emp', value : empCode }) // 经手人Name var txt_emp = new NewAddTriggerField({ id : 'txt_emp', anchor : '80%', readOnly : true, value : empName, fieldLabel : '经手人', onTrigger1Click : function() { popAddEmployee(hid_emp, txt_emp); }, onTrigger2Click : function() { popSelectEmployee([['1', 'hid_emp'], ['2', 'txt_emp']]); } }); // 出入库类别code var hid_sr = new Ext.form.Hidden({ id : 'hid_sr', value : srCode }); // 出入库类别Name var txt_sr = new NewAddTriggerField({ id : 'txt_sr', anchor : '85%', readOnly : true, value : srName, trigger1Class : 'hideTrigger', fieldLabel : '出入库类别', onTrigger2Click : function() { popSelectSR([['1', 'hid_sr'], ['2', 'txt_sr']], null, null, 'R'); } }); // 入库日期 var dt_inDate = new Ext.form.DateField({ id : 'dt_inDate', fieldLabel : '入库日期<font color=red>*</font>', anchor : '85%', cls : 'MandatoryCmp', format : 'Ymd', value : inDate }); // 备注 var txt_remark = new Ext.form.TextArea({ id : 'txt_remark', fieldLabel : '备注', allowBlank : true, height : 45, anchor : '98%', maxLength : 50, value : remark, enableKeyEvents : true, listeners : { 'keypress' : function(field) { validate_ControlLength(field, 50) } } }); // 制单人 var txt_createPerson = new Ext.form.TextField({ anchor : '95%', id : 'txt_createPerson', allowBlank : true, value : createPerson, readOnly : true, style : statusBarStyle, fieldClass : 'textReadOnly' }); // 制单时间 var txt_createDate = new Ext.form.TextField({ id : 'txt_createDate', anchor : '95%', allowBlank : true, value : createDate, readOnly : true, style : statusBarStyle, fieldClass : 'textReadOnly' }); // 数量合计 var txt_totQty = new Ext.form.TextField({ id : 'txt_totQty', anchor : '95%', allowBlank : true, value : 0, readOnly : true, style : bkStyle, fieldClass : 'textReadOnly' }); // 金额合计 var txt_totAmt = new Ext.form.TextField({ id : 'txt_totAmt', anchor : '95%', allowBlank : true, value : 0, readOnly : true, style : bkStyle, fieldClass : 'textReadOnly' }); var hid_autoVoucher = new Ext.form.Hidden({ id : 'hid_autoVoucher' }); // 是否生成自动凭证 var ckb_voucher = new Ext.form.Checkbox({ id : 'ckb_voucher', labelSeparator : '', boxLabel : '生成自动凭证', checked : true, listeners : { 'check' : function(checkbox, checked) { if (checked) { hid_autoVoucher.setValue('Y'); } else { hid_autoVoucher.setValue('N'); } } } });
// 入库单明细模板
var Item = Ext.data.Record.create([{ name : 'itemId' }, { name : 'stockCode' }, { name : 'stockName' }, { name : 'spec' }, { name : 'basePer' }, { name : 'changePer' }, { name : 'changeRate', type : 'float' }, { name : 'qty', type : 'float' }, { name : 'price', type : 'float' }, { name : 'amt', type : 'float' }, { name : 'stockMacAccId' }]); // 列表ds var dsList = new Ext.data.Store({ url : '../ishan.do?method=findItemsByIShanId', baseParams : { ishanId : hid_ishanId.getValue() }, autoLoad : false, reader : new Ext.data.JsonReader({ totalProperty : 'result.totalCount', root : 'result.result' }, Item), listeners : { 'load' : sumFields, 'add' : sumFields, 'remove' : sumFields, 'update' : sumFields } }); // 列表cm var cmList = new Ext.grid.ColumnModel([{ header : '操作<font color=red>*</font>', align : 'center', renderer : function(value, cellmeta, record, rowIndex, columnIndex, store) { var id = record.id; return '<a href="javascript:void(0)" onClick=removeItem("' + id + '","' + hid_ishanId.getValue() + '")><u>删除</u></a>'; } }, { header : '货品编码<font color=red>*</font>', dataIndex : 'stockCode', align : 'left', width : 150, sortable : true, editor : goodsNum }, { header : '货品名称<font color=red>*</font>',// + addHelpIconHtml('tip_name'), dataIndex : 'stockName', align : 'left', sortable : true }, { header : '规格', dataIndex : 'spec', align : 'left', sortable : true }, { header : '计量单位', dataIndex : 'changePer', align : 'left', sortable : true }, { header : '数量<font color=red>*</font>', dataIndex : 'qty', align : 'right', sortable : true, renderer : money, editor : new Ext.form.NumberField({ allowBlank : false, allowNegative : false, decimalPercision : 4, style : 'text-align:left' }) }, { header : '单价', dataIndex : 'price', align : 'right', sortable : true, renderer : money, editor : new Ext.form.NumberField({ allowBlank : false, allowNegative : false, allowDecimals : true, decimalPercision : 4, style : 'text-align:right' }) }, { header : '金额', dataIndex : 'amt', align : 'right', sortable : true, renderer : function(value, cellmeta, record, rowIndex, columnIndex, store) { var price = record.get('price'); var qty = record.get('qty'); record.set('amt', price * qty); return money(record.get('amt')); } }]); // 列表Panel var listPanel = new Ext.grid.EditorGridPanel({ id : "destPanel", height : 300, width : 970, // titleCollapse : true, cm : cmList, ds : dsList, clicksToEdit : 1, stripeRows : true, // 让基数行和偶数行的颜色不一样 // bodyStyle : 'border-bottom: 0px', // customized the grid // autoScroll : true, viewConfig : { forceFit : true }, border : true, iconCls : 'icon-grid', tbar : new Ext.Toolbar({ cls : 'u-toolbar-t', style : 'background:#E7E7E8', items : [{ cls : 'u-btn', text : "[ <a onClick='addItem(listPanel, dsList, Item)' class='u-btn' href='javascript:void(0)'>新增行</a> ]", xtype : 'tbtext' }, ' ', { cls : 'u-btn', text : "[ <a onClick='removeAllLines()' class='u-btn' href='javascript:void(0)'>删除所有行</a> ]", xtype : 'tbtext' }, ' ', { cls : 'u-btn', text : "[ <a οnclick=batchAddNew() class='u-btn' href='javascript:void(0)'>批量新增</a> ]", xtype : 'tbtext' }] }), bbar : new Ext.Toolbar({ cls : 'u-toolbar-b', style : bkStyle, items : ['合计:', '->', '数量:', txt_totQty, '金额:', txt_totAmt] }) }); /** *************3.布局定位**************************** */ // 底层panel var newPanel = new Ext.form.FormPanel({ border : false, width : 980, height : 420, labelAlign : 'right', labelWidth : 80, maskDisabled : false, bodyStyle : 'padding:10px', bbar : new Ext.Toolbar({ style : statusBarStyle, items : ['制单人:', txt_createPerson, '制单时间:', txt_createDate] }), items : [{ width : 980, border : false, items : [{ layout : 'column', border : false, bodyStyle : 'padding:5px 0px 10px 0px', items : [{ columnWidth : .3, border : false, layout : 'form', items : [txt_code, txt_storeroom, txt_emp] }, { columnWidth : .3, border : false, layout : 'form', items : [{ border : false, layout : 'form', items : [ckb_voucher] }, dt_inDate, txt_sr] }, { columnWidth : .4, border : false, layout : 'form', items : [{ border : false, height : 25 }, txt_remark] }] }] }, listPanel] }); var pageBarbbar = function() { return new Ext.Toolbar({ style : 'background:#ffffff;padding-top:5px;', items : [{ text : '保存', cls : 'Mod',// 编辑时可用 pressed : true, handler : function() { saveItem(dsList); } }, { text : '保存并新增', pressed : true, cls : 'Mod',// 编辑时可用 handler : function() { saveItem(dsList, true); // prepareload('scmMng/store/IShan.html'); } }, { text : '修改', cls : 'Ret',// 查看时可用 pressed : true, handler : function() { changeBtnStatus('Modify', '其他入库-编辑-C01', newPanel); dsList.baseParams.ishanId = hid_ishanId.getValue(); dsList.load(); } }, { text : '撤销', cls : 'Mod', pressed : true, handler : function() { loadBack() } }, { text : '删除', cls : 'Ret', pressed : true, handler : function() { removeIShan(); } }, { text : '其他入库单列表', pressed : true, handler : function() { prepareload('scmMng/store/IShanList.html'); } }, { text : '上一页', cls : 'pageUp', pressed : true, handler : findPrePage }, { text : '下一页', cls : 'pageDown', pressed : true, handler : findAftPage }] }); } var pageBar = function() { return new Ext.Toolbar({ style : 'background:#ffffff url(../../images/0602_07.gif) no-repeat left;padding-bottom:5px;', items : [{ text : '保存', cls : 'Mod',// 编辑时可用 pressed : true, handler : function() { saveItem(dsList); } }, { text : '保存并新增', pressed : true, cls : 'Mod',// 编辑时可用 handler : function() { saveItem(dsList, true); // prepareload('scmMng/store/IShan.html'); } }, { text : '修改', cls : 'Ret',// 查看时可用 pressed : true, handler : function() { changeBtnStatus('Modify', '其他入库-编辑-C01', newPanel); dsList.baseParams.ishanId = hid_ishanId.getValue(); dsList.load(); } }, { text : '撤销', cls : 'Mod', pressed : true, handler : function() { loadBack() } }, { text : '删除', cls : 'Ret', pressed : true, handler : function() { removeIShan(); } }, { text : '其他入库单列表', pressed : true, handler : function() { prepareload('scmMng/store/IShanList.html'); } }, { text : '上一页', cls : 'pageUp', pressed : true, handler : findPrePage }, { text : '下一页', cls : 'pageDown', pressed : true, handler : findAftPage }] }); } /** ***************5.主函数*********************** */ Ext.onReady(function() { var basePanel = new Ext.Panel({ border : true, // autoWidth:true, // autoHeight:true, width : 999, height : 490, applyTo : 'div_basePanel', tbar : pageBar(), bbar : pageBarbbar(), items : [newPanel] }); dsList.load(); changeBtnStatus('Modify', '其他入库-编辑-C01', newPanel); // 判断当前用户的服务列表,是否板块账务模块 haveFinanceService('../../', ['txt_sr', 'ckb_voucher']); validatePageUpDownStatus(txt_code.getValue()); showHelpTip('1', '提示', '其他入库单主要用于处理采购入库以外的杂项入库业务,例如制造业的产成品入库、生产报废入库、受赠入库等等。', 69, 'scmmngHelp/_68.htm'); }); /** *************4.函数**************************** */ var currentRecord; var stockArray = new Array([1, "stockCode"], [2, "stockName"], [4, 'spec'], [9, 'changePer'], [10, 'basePer'], [15, 'changeRate']); listPanel.on('rowclick', function(listPanel, rowIndex) { currentRecord = dsList.getAt(rowIndex); }); function addSub() { goodsNum.collapse(); stockFormWin(CallbackFn, currentRecord); }; function CallbackFn(ReturnedObj, currentRecord) { currentRecord.set('stockCode', ReturnedObj.stockCode) currentRecord.set('stockName', ReturnedObj.stockName) currentRecord.set('spec', ReturnedObj.spec) currentRecord.set('changePer', ReturnedObj.storePerName) currentRecord.set('basePer', ReturnedObj.basePerName) currentRecord.set('changeRate', ReturnedObj.storeChangeRate) } function selectSub() { goodsNum.collapse(); popSelectStock('stockCode', dsList, stockArray, 800, 300); } // 删除列表grid中所选的明细 function removeItem(id, ishanId) { var record = dsList.getById(id); //var itemId = record.data.itemId; displayMessageBox('提示', '确实要删除所有记录?', Ext.MessageBox.YESNOCANCEL, function( btn) { if (btn == 'yes') dsList.remove(record); }); /*if ('' == itemId) { dsList.remove(record); return; }*/ /*if (Ext.MessageBox.confirm('提示', '删除本条记录,是否确认?', function(btn) { if (btn == 'yes') { msgRun('单据明细删除及相关单据自动修改中,请稍候...', '提示'); Ext.Ajax.request({ url : '../ishan.do?method=removeItemByIdTA', params : { itemId : itemId, ishanId : ishanId, autoVoucher : hid_autoVoucher.getValue() }, success : function(result, request) { msgStop(); var jsonData = Ext.util.JSON.decode(result.responseText); if (!jsonData.success) { return displayMessageBox("提示", jsonData.message); } dsList.load(); messageloaded('删除成功'); txt_createPerson.setValue(jsonData.result.createPerson); hid_voucherId.setValue(jsonData.result.voucherId); }, failure : function(result, request) { msgStop(); displayMessageBox("提示", "未知的原因造成此次删除没有成功,请重试"); } }); } }));*/ }; // 增加一条记录 function addItem(grid, ds, Plant) { var p = new Plant({ itemId : '', stockCode : '', stockName : '', spec : '', basePer : '', changePer : '', changeRate : 1, qty : 0, price : 0, amt : 0, stockMacAccId : '' }); ds.insert(ds.getCount(), p); grid.startEditing(ds.getCount(), 0); // 光标停留在第几行几列 }; var viewMaskBounds = [0,10,970,122]; // mask区域 [top,left,width,height] var scrollBarBounds = [967,40,15,43] ; // 滚动条区域 [left,top,width,height] // 保存入库单 function saveItem(dsItems, flag) { if(dsItems.getCount()==0) return displayMessageBox("提示", "单据无明细记录"); var newPageFlag = (flag == null ? false : flag); if ((validateMandatoryCmp() == false) || (validateItem(dsList) == false)) return; // 逻辑验证,失败则终止方法 var itemParams = "";// 存放明细记录的参数 var i; for (i = 0; i < dsItems.getCount(); i++) { var record = dsItems.getAt(i); if (record.get('stockCode') == '' || record.get('stockCode') == null)// 空行跳过 continue; /*if (i != 0) itemParams += '&';// 从第一个记录后为每条记录添加一条'&' itemParams += 'itemId=' + record.get('itemId'); itemParams += '&stockCode=' + record.get('stockCode'); itemParams += '&stockName=' + record.get('stockName'); itemParams += '&spec=' + record.get('spec'); itemParams += '&basePer=' + record.get('basePer'); itemParams += '&changePer=' + record.get('changePer'); itemParams += '&changeRate=' + record.get('changeRate'); itemParams += '&qty=' + record.get('qty'); itemParams += '&price=' + record.get('price'); itemParams += '&amt=' + record.get('amt'); itemParams += '&stockMacAccId=' + record.get('stockMacAccId');*/ itemParams += getDataFromRecord( record ); } // alert(itemParams); msgRun('数据保存及相关单据自动生成中,请稍候...', '提示'); Ext.Ajax.request({ url : '../ishan.do?method=saveTA', method : 'post', params : { ishanId : hid_ishanId.getValue(), ishanCode : txt_code.getValue(), storeroomCode : hid_storeroom.getValue(), storeroomName : Ext.get('txt_storeroom').getValue(), srCode : hid_sr.getValue(), srName : Ext.getCmp('txt_sr').getValue(), empCode : hid_emp.getValue(), empName : Ext.get('txt_emp').getValue(), inDate : dt_inDate.getValue().format('Ymd'), remark : txt_remark.getValue(), voucherId : hid_voucherId.getValue(), itemParams : itemParams, autoVoucher : hid_autoVoucher.getValue() }, failure : function(result, request) { msgStop(); displayMessageBox("提示", "保存失败"); changeBtnStatus('Modify', '其他入库-编辑-C01', newPanel);// 保存失败页面变为编辑状态 }, success : function(result, request) { msgStop(); var jsonData = Ext.util.JSON.decode(result.responseText); if (!jsonData.success) { return displayMessageBox('提示', jsonData.message); } messageloaded("保存成功"); hid_ishanId.setValue(jsonData.result.ishanId); txt_code.setValue(jsonData.result.ishanCode); if (newPageFlag == true) return prepareload('scmMng/store/IShan.html'); txt_createPerson.setValue(jsonData.result.createPerson); hid_voucherId.setValue(jsonData.result.voucherId); dsItems.baseParams.ishanId = hid_ishanId.getValue(); dsItems.load(); changeBtnStatus('Retrieve', '其他入库-查看-C01', newPanel,viewMaskBounds,scrollBarBounds,listPanel,txt_remark,txt_code);// 保存成功后页面变为查看状态 validatePageUpDownStatus(txt_code.getValue()); } }); }
|