You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/Import/Viewsjs/CWAdvancePayment/CWAdvancePaymentEdit.js

695 lines
24 KiB
JavaScript

2 years ago
///<reference path="../../../../Views/../TruckMng/Scripts/vswd-ext_2.0.2.js" />
Ext.namespace('DsTruck');
DsTruck.CWAdvancePaymentEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.DsTruck.CWAdvancePaymentEdit.superclass.constructor.call(this);
};
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1, //month
"d+": this.getDate(), //day
"h+": this.getHours(), //hour
"m+": this.getMinutes(), //minute
"s+": this.getSeconds(), //second
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
"S": this.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
(this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o) if (new RegExp("(" + k + ")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length == 1 ? o[k] :
("00" + o[k]).substr(("" + o[k]).length));
return format;
}
var xhr = new XMLHttpRequest();
var currdate = new Date();
if (!xhr) {
//...其他生成xmlhttprequest方法
}
xhr.open("HEAD", location.href, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var datestr = xhr.getResponseHeader("Date");
currdate = new Date(datestr);
// alert(currdate.format('yyyy-MM-dd'));
}
}
xhr.send(null);
function getSaved(){
if (panelEdit.formEdit.getForm().isDirty()== true )
{
return true;
}
else return false;
}
Ext.extend(DsTruck.CWAdvancePaymentEdit, Ext.Panel, {
parentWin: null,
OpStatus: 'add',
StoreList: null,
editRecord: null,
// parentfunction: null,
_First: true,
initUIComponents: function () {
this.bodyDel = [];
this.CargoDel = [];
this.AppstateDel = [];
this.KCDel = [];
this.feeSerialNo = 0;
this.feeBodyDel = [];
this.MsPeriod = null;
//#region 枚举参照相关(编辑form)
this.storeFEETYPE = Ext.create('DsExt.ux.RefEnumStore', {});
this.storeFEETYPE.load({ params: { enumTypeId: 99020} });
this.comboxFEETYPE = Ext.create('DsExt.ux.RefEnumCombox', {
fieldLabel: '收付类型',
store: this.storeFEETYPE,
name: 'FEETYPE',
allowBlank: false, id: "FEETYPE"
, value: '1'
});
this.storeCUSTOMERNAME = Ext.create('DsExt.ux.RefTableStore', {
model: 'Tradermb',
proxy: { url: '/CommMng/BasicDataRef/GetTrader' }
});
this.storeCUSTOMERNAME.load({ params: { condition: " 1=1"} });
this.comboxCUSTOMERNAME = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '结算对象',
store: this.storeCUSTOMERNAME,
name: 'CUSTOMERNAME', id: "CUSTOMERNAME",
valueField: 'name',
displayField: 'codename'
});
//this.storecurr = Ext.create('DsExt.ux.RefTableStore', {
// model: 'currRef',
// proxy: { url: '/CommMng/BasicDataRef/GetcurrRefList' }
//});
//this.storecurr.load({ params: { condition: "" } });
Ext.define('MsFeeCurr', {
extend: 'Ext.data.Model',
idProperty: 'CURR',
fields: [
{ name: 'CURR', type: 'string' },
{ name: 'DEFRATE', type: 'number' },
{ name: 'CRDEFRATE', type: 'number' }
]
});
this.StoreDateCurr = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsFeeCurr',
proxy: { url: '/MvcShipping/MsChFee/GetFeeNowCurrList' }
});
this.StoreDateCurr.load();
this.comboxcurr = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '币别',
store: this.StoreDateCurr,
name: 'CURRENCY', id: "CURRENCY",
valueField: 'CURR',
displayField: 'CURR',
listeners: {
scope: this,
'select': function (combo, records, eOpts) {
if (records.length > 0) {
this.formEdit.getForm().findField('EXCHANGERATE').setValue(records[0].data.DEFRATE);
}
}
}
//币别
});
this.storeAccitems = Ext.create('DsExt.ux.RefTableStore', {
model: 'Accitemsmb',
proxy: { url: '/CommMng/BasicDataRef/GetCwAccitemsGl' }
});
this.storeAccitems.load({ params: { condition: ""} });
this.comboxBANK = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '收支银行', //收支的银行账户
store: this.storeAccitems,
name: 'BANKACCID', id: "BANKACCID",
valueField: 'ACCID',
displayField: 'ACCIDNAME',
flex: 1
});
this.storeCompany = Ext.create('DsExt.ux.RefTableStore', {
model: 'companymb',
proxy: { url: '/CommMng/BasicDataRef/GetcompanyList' }
});
this.storeCompany.load({ params: { condition: ""} });
this.comboxCompany = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '公司',
store: this.storeCompany,
flex: 1,
name: 'COMPANYID', id: "COMPANYID",
valueField: 'gid',
displayField: 'name'
});
this.storeUser = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.UserRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetUserRefList' }
});
this.storeUser.load({ params: { condition: ""} });
this.comboxCreator = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '建立人',
store: this.storeUser,
name: 'CREATEUSER', id: "CREATEUSER",
valueField: 'GID',
displayField: 'CodeAndName',
allowBlank: false
});
//#endregion
//编辑form:formEdit
this.formEdit = Ext.widget('form', {
// layout: "border",
region: 'center',
frame: true,
bodyPadding: 5,
trackResetOnLoad: true, //不加的话load之后isdirty即变为true
fieldDefaults: {
margins: '2 2 2 2',
labelAlign: 'right',
flex: 1,
labelWidth: 90,
msgTarget: 'qtip'
//,split:true
},
items: [
{//fieldset 1
xtype: 'fieldset',
defaultType: 'textfield',
layout: 'anchor',
defaults: {
anchor: '100%'
},
items: [{//container_1
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '预收付编号',
// allowBlank: false,
disabled: true,
name: 'GID'
}, this.comboxCreator, {
fieldLabel: '建立时间', id: "CREATETIME",
format: 'Y-m-d H:i:s',
xtype: 'datefield',
renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s'),
name: 'CREATETIME'
}, {
fieldLabel: '状态',
readOnly:true,
name: 'BLSTATUS', flex: 1
}]
}, //container_1 end
{
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [this.comboxFEETYPE, this.comboxCUSTOMERNAME, this.comboxCompany]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [this.comboxcurr, {
fieldLabel: '汇率', selectOnFocus: true,
allowBlank: false,
disabled: false,
id: "EXCHANGERATE",
name: 'EXCHANGERATE'
}, {
fieldLabel: '金额', id: "AMOUNT", selectOnFocus: true,
name: 'AMOUNT',
listeners: {
keyup: function (obj, evt) {
var val = src.getValue().toString().replace(/[^\d\.]/g, '');
src.setValue(val);
}
}
}, {
fieldLabel: '已核销金额', id: "DOAMOUNT", readOnly: true,
name: 'DOAMOUNT',
listeners: {
keyup: function (obj, evt) {
var val = src.getValue().toString().replace(/[^\d\.]/g, '');
src.setValue(val);
}
}
}]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [this.comboxBANK, {
fieldLabel: '是否生成凭证',
readOnly: true,
name: 'ISVOU'
}, {
fieldLabel: '凭证号', id: "VOUCHERNO",
name: 'VOUCHERNO'
}]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '备注',
name: 'REMARK', flex: 1
}]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: 'LINKGID', hidden: true,
name: 'LINKGID', id: "LINKGID"
}, {
fieldLabel: '备注', hidden: true,
name: 'BILLNO', id: "BILLNO"
}]
}
]
}
]
});
//公共按钮Toolbar:panelBtn
this.panelBtn = new Ext.Panel({
region: "north",
tbar: [
{
// id: "saveandclose",
text: "保存", id: "savebtn",
handler: function (button, event) {
this.Save('0');
},
scope: this
}, {
// id: "saveandclose",
text: "保存并关闭", id: "save&closebtn",
handler: function (button, event) {
this.Save('1');
},
scope: this
},
{
// id: "saveandclose",
text: "保存并新建", id: "save&newbtn",
handler: function (button, event) {
this.Save('2');
},
scope: this
}, '-',
{
// id: "saveandclose",
text: "关闭",
handler: function (button, event) {
window.close();
},
scope: this
}, '-',
{
text: "打印",
handler: function (button, event) {
this.Print();
},
scope: this
}
]
}); //end 按钮Toolbar
//布局
/* 3 */
this.panelTop = new Ext.Panel({
layout: "border",
region: "north",
height: 32,
items: [this.panelBtn]//, this.formEdit]
});
Ext.apply(this, {
items: [this.panelTop, this.formEdit]
});
parentWin = window.parent.opener;
this.InitData();
//集中绑定编辑后事件
}, //end initUIComponents
parentfunction: function (button, event) {
var ret1 = window.parent.opener.OprationSwap();
// alert(this.First);
ret1[3]();
},
InitData: function () {
this.opStatus = 'add';
var condition = '';
if (parentWin) {
var ret = parentWin.OprationSwap();
this.opStatus = ret[0];
this.StoreList = ret[1];
this.editRecord = ret[2];
// this.parentfunction = ret[3];
}
if (this.opStatus == 'edit') {
condition = " gid='" + this.editRecord.get('GID') + "'";
}
this.LoadData(this.opStatus, condition);
}, //end InitData
//载入数据
LoadData: function (opstatus, condition) {
this.opStatus = opstatus;
var GID = "";
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/Import/CWAdvancePayment/GetData',
async: false,
params: {
handle: opstatus,
condition: condition
},
callback: function (options, success, response) {
if (success) {
var result = Ext.JSON.decode(response.responseText);
if (!result.Success) {
Ext.Msg.show({
title: '提示',
msg: result.Message,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
return;
}
data = result.data;
// this.formEdit.getForm().reset();
if (data.CREATETIME == "") { data.CREATETIME = currdate.format('yyyy-MM-dd hh:mm:ss') };
if (data.CREATEUSER == "") { data.CREATEUSER = USERID };
if (data.FEETYPEREF == "") { data.FEETYPE = "1" };
if (data.AMOUNT == "") { data.AMOUNT = "0" };
if (data.EXCHANGERATE == "") { data.EXCHANGERATE = "1" };
if (data.COMPANYID == "") { data.COMPANYID = COMPANYID };
if (data.CURRENCY == "") { data.CURRENCY = "RMB" };
if (data.DOAMOUNT == "") { data.DOAMOUNT = "0" };
GID = data.GID;
this.formEdit.getForm().setValues(data);
this.LoadPeriod(this.opStatus);
/*formisDirtyTrue使
if (data.ContractStatus=='True'){
this.formEdit.getForm().findField('ContractStatus').setValue('1');
}else{this.formEdit.getForm().findField('ContractStatus').setValue('0');}
*/
/*
var task = new Ext.util.DelayedTask(setsave);
task.delay(500);*/
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
}
},
scope: this
}); //request over
if (this.opStatus == 'edit') {
var headword = GID.substr(0, 4);
if (headword != "YSYF") {
Ext.getCmp("CREATEUSER").disable();
Ext.getCmp("CREATETIME").disable();
Ext.getCmp("FEETYPE").disable();
Ext.getCmp("CUSTOMERNAME").disable();
Ext.getCmp("COMPANYID").disable();
Ext.getCmp("CURRENCY").disable();
Ext.getCmp("AMOUNT").disable();
Ext.getCmp("EXCHANGERATE").disable();
Ext.getCmp("BANKACCID").disable();
}
}
},
LoadPeriod: function (opstatus) {
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/Account/ChMonthClose/GetNowPeriod',
params: {
condition: ''
},
callback: function (options, success, response) {
if (success) {
var result = Ext.JSON.decode(response.responseText);
if (!result.Success) {
return;
}
data = result.data;
this.MsPeriod = data;
this.LoadPeriodStatus(opstatus);
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
}
},
scope: this
});
},
LoadPeriodStatus: function (opstatus) {
var CREATETIME = this.formEdit.getForm().findField('CREATETIME').getValue();
if (CREATETIME == '') {
this.formEdit.getForm().findField('CREATETIME').setMinValue(this.MsPeriod.FDAY);
this.formEdit.getForm().findField('CREATETIME').setReadOnly(false);
} else {
var oDate1 = new Date(CREATETIME);
var oDate2 = new Date(this.MsPeriod.FDAY);
if (oDate1.getTime() >= oDate2.getTime()) {
this.formEdit.getForm().findField('CREATETIME').setMinValue(this.MsPeriod.FDAY);
this.formEdit.getForm().findField('CREATETIME').setReadOnly(false);
} else {
if (opstatus == 'add' || opstatus == 'copyadd') {
this.formEdit.getForm().findField('CREATETIME').setMinValue(this.MsPeriod.FDAY);
this.formEdit.getForm().findField('CREATETIME').setReadOnly(false);
}
else {
this.formEdit.getForm().findField('CREATETIME').setMinValue('');
this.formEdit.getForm().findField('CREATETIME').setReadOnly(true);
this.setSaveBtnStatus(false);
}
}
}
},
// end LoadDate
checkedit: function () {
/*
if(this.HTHCount>0){
alert("合同号重复");
return false;
}else{
var ContractStatus = this.formEdit.getForm().findField('ContractStatus').getValue()?1:0
if (ContractStatus==1) {
alert("已经锁定");
return false;
}else
{return true;}
}
if (this.storeCargo.getCount()==0){return true;}
else{
for (var i = 0; i < this.storeCargo.getCount(); i += 1) {
var cargomember = this.storeCargo.getAt(i).data;
if (cargomember.weight=="0") {
alert("请填写货物重量,请注意单位是千克");
return false;
}else
if (cargomember.name=="") {
alert("请填写货名。");
return false;
}
}//end for
}//end if*/
},
Save: function (type) {
var basicForm = this.formEdit.getForm();
if (!basicForm.isValid()) {
return;
}
Ext.getCmp("CREATEUSER").enable();
Ext.getCmp("CREATETIME").enable();
Ext.getCmp("FEETYPE").enable();
Ext.getCmp("CUSTOMERNAME").enable();
Ext.getCmp("COMPANYID").enable();
Ext.getCmp("CURRENCY").enable();
Ext.getCmp("AMOUNT").enable();
Ext.getCmp("EXCHANGERATE").enable();
Ext.getCmp("BANKACCID").enable();
Ext.getCmp("LINKGID").show();
Ext.getCmp("BILLNO").show();
Ext.getCmp("LINKGID").enable();
Ext.getCmp("BILLNO").enable();
// alert('save');
basicForm.findField('GID').setDisabled(false);
var data = this.formEdit.getForm().getValues();
var headword = data.GID.substr(0, 4);
if (headword != "YSYF" && this.opStatus == "edit") {
Ext.getCmp("CREATEUSER").disable();
Ext.getCmp("CREATETIME").disable();
Ext.getCmp("FEETYPE").disable();
Ext.getCmp("CUSTOMERNAME").disable();
Ext.getCmp("COMPANYID").disable();
Ext.getCmp("CURRENCY").disable();
Ext.getCmp("AMOUNT").disable();
Ext.getCmp("EXCHANGERATE").disable();
Ext.getCmp("BANKACCID").disable();
}
basicForm.findField('GID').setDisabled(true);
Ext.getCmp("LINKGID").hide();
Ext.getCmp("BILLNO").hide();
//将复选框值转化为1/0
//data.ContractStatus = this.formEdit.getForm().findField('ContractStatus').getValue() ? 1 : 0;
var _this = this;
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/Import/CWAdvancePayment/Save',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data)
},
callback: function (options, success, response) {
if (success) {
Ext.MessageBox.hide();
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
var returnData = jsonresult.Data;
this.formEdit.getForm().setValues(returnData);
if (this.opStatus == 'add') {
var arrNewRecords = this.StoreList.add(returnData);
this.editRecord = arrNewRecords[0];
// alert(editRecord.get('ContractNo'));
}
else if (this.opStatus == 'edit') {
var editp = Ext.create('CWAdvancePaymentmb', returnData);
this.editRecord.fields.each(function (field) {
if (field.persist) {
name = field.name;
//alert(name + ' -- ' + editp.get(name));
//if (name != 'id')
this.editRecord.set(name, editp.get(name));
}
}, this);
this.editRecord.commit();
}
if (type == '0') {
this.opStatus = 'edit';
basicForm.findField('GID').setDisabled(false);
//_this.storeApp.load({ params: { condition: this.editRecord.get('GID')} });
basicForm.findField('GID').setDisabled(true);
this.LoadPeriodStatus(this.opStatus);
} else if (type == '1') {//保存并关闭
window.close();
} else if (type == '2') {//保存并全部新建
this.LoadData('add', '');
//this.storeCargo.removeAll();
}
} else {
Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
}
} else {
Ext.Msg.show({ title: '请重试',
msg: '服务器响应出错',
icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK
});
}
//alert('03');
}
});
}
//end save
,
Print: function () {
var basicForm = this.formEdit.getForm();
var billNo = basicForm.findField('GID').value;
if (billNo == '*' || billNo == '') {
Ext.Msg.show({ title: '错误', msg: '单据还没有保存,请保存后再打印', icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
return;
}
function GetDateStr(AddDayCount) {
var dd = new Date();
dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期
var y = dd.getFullYear();
var m = dd.getMonth() + 1; //获取当前月份的日期
var d = dd.getDate();
return y + "-" + m + "-" + d;
}
//alert(GetDateStr(+5));
var madedate = GetDateStr(0);
var CUSTOMERNAME = basicForm.findField('CUSTOMERNAME').value;
var printType = 'CH_fee_AdvancePayment';
var sql1 = "select CUSTOMERNAME 客户,CREATETIME 汇款日期,(select showname from [user] where gid=CREATEUSER) 认款人 ";
sql1 = sql1 + ",(select ACCNAME from cw_accitems where ACCID=BANKACCID) 银行,Amount 认款金额 ";
sql1 = sql1 + " from ch_fee_advance_payment WHERE GID='" + billNo + "' ";
var sql2 = "";
// var sql3 = " select * from company where gid=(select top 1 companyid from ch_fee_do where BILLNO='" + billNo + "') ";
var sql3 = " select enname 公司英文名称,ENADDRESS 公司英文地址,ORGANIZATIONCODE 组织机构代码 ";
sql3 = sql3 + " ,* from company where gid=(select CORPID from v_op_bs where bsno= (select top 1 bsno from ch_fee_do where BILLNO='" + billNo + "')) ";
var sql4 = "select '" + madedate + "' as madedate,'" + CUSTOMERNAME + "' as CUSTOMERNAME,'" + SHOWNAME + "' as SHOWNAME";
var sql5 = "";
var sql6 = "";
PrintComm(printType, sql1, sql2, sql3, sql4, sql5, sql6);
}
});