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/MvcShipping/Viewsjs/MsFeeTemplate/FeeTemplateAdd.js

788 lines
27 KiB
JavaScript

Ext.namespace('Shipping');
Shipping.FeeTemplateAdd = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.Shipping.FeeTemplateAdd.superclass.constructor.call(this);
};
Ext.extend(Shipping.FeeTemplateAdd, Ext.Panel, {
PageSize: 100,
ParentWin: null,
feeType: 0,
feeTypeRef: '',
OprationStatus: null, //仅当弹出界面时使用
SelectedRecord: null,
StoreFee: null,
StoreFeeUnit: null,
StoreFeeCust: null,
StoreDateCurr: null,
storeCustomerNameRef: null,
StoreCurr: null,
EditRecord: null,
stroplb: '',
strGID: '',
initUIComponents: function () {
this.DEFORDERCUST = "";
this.SALECORP = "";
this.ACCTAXRATESAMETAXRATE = 0;
//定义数据集
this.storeList = Ext.create('Ext.data.Store', {
pageSize: this.PageSize,
model: 'MsFeeTemplate',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/MsFeeTemplate/GetDataList',
reader: {
id: 'GID',
root: 'data',
totalProperty: 'totalCount'
}
}
});
//#region 主grid
this.gridListCheckBoxModel = Ext.create('Ext.selection.CheckboxModel');
this.gridList = new Ext.grid.GridPanel({
store: this.storeList,
enableHdMenu: false,
region: 'north',
height: 350,
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
disableSelection: false,
selModel: this.gridListCheckBoxModel,
columns: [{
sortable: true,
dataIndex: 'Name',
header: '模板名称',
width: 130
}, {
sortable: true,
dataIndex: 'Description',
header: '模板说明',
width: 160
}, {
sortable: true,
dataIndex: 'OpTyperef',
header: '业务类型',
width: 230
}, {
sortable: true,
dataIndex: 'FeeTyperef',
header: '费用类型',
width: 120
}, {
sortable: true,
dataIndex: 'Remark',
header: '备注',
width: 220
}
],
// paging bar on the bottom
bbar: Ext.create('Ext.PagingToolbar', {
store: this.storeList,
displayInfo: true,
displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录',
emptyMsg: "没有数据"
})
});
//#endregion
//#region 固定费用明细表
//#region 费用表
//明细表-数据集
this.storeBodyChFee = Ext.create('Ext.data.Store', {
model: 'MsFeeTemplateDetail',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/MsFeeTemplate/GetDetailDataList',
reader: {
id: 'GID',
root: 'data',
totalProperty: 'totalCount'
}
}
});
//明细表表格
// this.feeGridCheckBoxModel = Ext.create('Ext.selection.CheckboxModel');
_this = this;
this.gridListChFee = new Ext.grid.GridPanel({
store: this.storeBodyChFee,
enableHdMenu: false,
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
disableSelection: false,
// selModel: this.feeGridCheckBoxModel,
selType: 'cellmodel',
columns: [{
sortable: true,
dataIndex: 'GID',
header: '惟一编号',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'FeeName',
header: '费用名称',
width: 120
}, {
sortable: true,
dataIndex: 'FEEDESCRIPTION',
header: '费用英文名称',
width: 120
}, {
sortable: true,
dataIndex: 'CustomerType',
header: '客户类别',
width: 120
}, {
sortable: true,
dataIndex: 'CustomerName',
header: '结算对象',
width: 120
}, {
sortable: true,
dataIndex: 'UnitPrice',
header: '单价',
width: 60
}, {
sortable: true,
dataIndex: 'Unit',
header: '单位标准',
width: 60
}, {
sortable: true,
dataIndex: 'Currency',
header: '币别',
width: 60
}, {
sortable: true,
dataIndex: 'ExchangeRate',
header: '汇率',
width: 60
}, {
sortable: true,
dataIndex: 'TaxRate',
header: '税率',
width: 60
}, {
sortable: true,
dataIndex: 'TaxUnitPrice',
header: '含税单价',
width: 60
}, {
sortable: true,
dataIndex: 'Tax',
header: '税额',
width: 60
}, {
sortable: true,
dataIndex: 'AccTaxRate',
header: '财务税率',
width: 60
}, {
sortable: true,
dataIndex: 'FEEFRT',
header: 'FRT',
width: 20
}, {
sortable: true,
dataIndex: 'SALECORP',
header: '核算单位',
width: 120
}, {
sortable: true,
dataIndex: 'Remark',
header: '备注',
width: 150
}
],
// paging bar on the bottom
bbar: [{
xtype: "button",
id: "button_add",
iconCls: "btnadd",
text: "引入费用",
handler: function (button, event) {
_this.onAddDetailClick(button, event);
}
},
'-',
{
xtype: "button",
id: "button_close",
text: "取消退出",
handler: function (button, event) {
window.close();
}
}
]
});
//#endregion
//#region formSearch
//#region formSearch枚举参照相关
//#endregion
this.formSearch = Ext.widget('form', {
frame: true,
region: 'center',
bodyPadding: 5,
fieldDefaults: {
margins: '2 2 2 2',
labelAlign: 'right',
flex: 1,
labelWidth: 90,
msgTarget: 'qtip'
},
items: [
{//fieldset 1
xtype: 'container',
defaultType: 'textfield',
layout: 'anchor',
defaults: {
anchor: '100%'
},
items: [{
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '模板名称',
name: 'NAME'
}, {
fieldLabel: '模板说明',
name: 'DESCRIPTION'
}, {
xtype: 'button',
width: 90,
text: "执行查询",
iconCls: "btnrefresh",
handler: function (button, event) {
this.onRefreshClick(button, event);
},
scope: this
}
]
}]
}]
});
//#endregion formSearch
//#region 按钮ToolBar
//#endregion
//#region 布局
this.panelTop = new Ext.Panel({
layout: "border",
region: "north",
height: 55,
items: [this.formSearch]
});
this.panelBodyChFee = new Ext.Panel({
title: '费用明细',
layout: "border",
region: 'center',
margin: '5 10',
items: [this.gridListChFee]
});
this.panelFee = new Ext.Panel({
layout: "border",
region: "center",
items: [
this.panelBodyChFee
]
});
this.storeDefValue = Ext.create('Ext.data.Store', {
model: 'DsShipping.ux.OpDefValue',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/MsCodeOpDef/GetDataList',
reader: {
id: 'GID',
root: 'data',
totalProperty: 'totalCount'
}
}
});
this.storeDefValue.load({ params: { condition: "BSTYPE='费用信息'" } });
Ext.apply(this, {
items: [this.panelTop, this.gridList, this.panelFee]
});
//#endregion
this.parentWin = window.parent.opener._thisfee;
if (this.parentWin) {
this.feeType = this.parentWin.feeType;
if (this.feeType == 1) {
this.StoreFee = this.parentWin.storeDrChFee;
} else if (this.feeType == 2) {
this.StoreFee = this.parentWin.storeCrChFee;
} else {
this.StoreFee = this.parentWin.storeBodyChFee;
}
this.StoreFeeUnit = this.parentWin.StoreUnit;
this.StoreFeeCust = this.parentWin.StoreCustType;
this.StoreDateCurr = this.parentWin.StoreDateCurr;
this.StoreCurr = this.parentWin.StoreCurr;
this.EditRecord = this.parentWin.EditRecord;
this.stroplb = this.parentWin.stroplb;
this.storeCustomerNameRef = this.parentWin.storeCustomerNameRef;
this.SALECORP = this.parentWin.SALECORP;
}
if (this.stroplb == 'op_SeaeOrder') {
var OP = this.EditRecord.get('OP');
Ext.Ajax.request({
waitMsg: '',
url: '/MvcShipping/MsSeaeOrder/GetDeptName',
params: {
op: OP
},
callback: function (options, success, response) {
if (success) {
var result = Ext.JSON.decode(response.responseText);
if (result.Success == true) {
this.DEFORDERCUST = result.Data;
} else {
}
} else {
}
},
scope: this
});
}
this.storeManagerModify = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsShipping.ux.UserRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetUserLinkRefList' }
});
this.storeManagerModify.load({ params: { condition: ""} });
//#region 事件绑定
this.storeList.on('beforeload', function (store) {
var sql = this.getCondition();
Ext.apply(store.proxy.extraParams, { condition: sql });
}, this);
this.storeList.on('load', function (store, records) {
if (store.getCount() > 0) {
this.gridList.getSelectionModel().select(0);
//this.gridListCheckBoxModel.selectAll();
}
}, this);
this.gridList.getSelectionModel().on('select', function (model, record, index) {
//alert(record.data.BillNo);
var bsno = record.data.GID;
this.strGID = record.data.GID;
feeType = record.data.FeeType;
feeTypeRef = record.data.FeeTyperef;
this.storeBodyChFee.load({ params: { TemplateID: bsno} });
}, this);
//#endregion
//#region 自动刷新(已经提交但是尚未审核的业务,哪怕一票货中有一笔费用没审核也显示)
this.onAutoRefresh();
//#endregion
Ext.Ajax.request({
waitMsg: '',
url: '/MvcShipping/MsSysParamSet/GetData',
params: {
condition: "PARAMNAME='ACCTAXRATESAMETAXRATE'"
},
callback: function (options, success, response) {
if (success) {
var result = Ext.JSON.decode(response.responseText);
if (result.Success != true) {
} else {
var data = result.data;
if (data.PARAMVALUE == '1') {
this.ACCTAXRATESAMETAXRATE = 1;
} else {
}
}
} else {
}
},
scope: this
});
// this.SetBtnRight();
}, //end initUIComponents
onAutoRefresh: function () {
var sql = '';
if (this.stroplb == 'op_Seae' || this.stroplb == 'op_SeaeOrder') {
sql = ' OpType=1 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_Seai') {
sql = ' OpType=2 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_Aire') {
sql = ' OpType=3 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_Airi') {
sql = ' OpType=7 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_Apply') {
sql = ' OpType=4 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_Bulk') {
sql = ' OpType=5 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_other') {
sql = ' OpType=6 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_truck') {
sql = ' OpType=8 ';
}
this.storeList.load({
params: { start: 0, limit: this.PageSize, sort: '', condition: sql },
waitMsg: "正在查询数据...",
scope: this
});
},
onRefreshClick: function (button, event) {
var sql = this.getCondition();
this.storeList.load({
params: { start: 0, limit: this.PageSize, sort: '', condition: sql },
waitMsg: "正在查询数据...",
scope: this
});
},
onAddDetailClick: function (button, event) {
var MANAGER = '';
var MANAGERREF = '';
if (this.StoreFee.getCount() > 0) {
var memberbody = this.StoreFee.getAt(this.StoreFee.getCount() - 1);
MANAGER = memberbody.data.MANAGER;
MANAGERREF = memberbody.data.MANAGERREF;
}
if (MANAGER == '') {
var SALE = this.EditRecord.get('SALE');
if (SALE != undefined && SALE != NaN && SALE != '') {
var records = DsStoreQueryBy(this.storeManagerModify, 'UserName', SALE);
if (records.getCount() > 0) {
var data = records.getAt(0).data;
MANAGER = data.GID;
MANAGERREF = SALE;
} else {
MANAGER = '';
MANAGERREF = '';
}
}
}
var iscrmorder = '0';
if (this.stroplb == 'op_SeaeOrder') {
iscrmorder = '1';
}
for (i = 0; i < this.storeBodyChFee.getCount(); i += 1) {
var memberyf = this.storeBodyChFee.getAt(i);
var record = null;
var records = DsStoreQueryBy(this.StoreFeeUnit, 'UNIT', memberyf.data.Unit);
// var feeType = memberyf.data.FeeType;
if (((memberyf.data.ISCTN && (records.getCount() > 0)) || (!memberyf.data.ISCTN))) {
if (records.getCount() > 0) {
var data = records.getAt(0).data;
var quantity = data.QUANTITY;
} else {
var quantity = 1;
}
var taxrate = memberyf.data.TaxRate;
// var taxrate = 0;
var acctaxrate = 0;
if (taxrate == null) taxrate = 0;
var taxrateb = Add(1, Div(taxrate, 100, 4), 4);
var TaxUnitPrice = 0;
if (memberyf.data.TaxUnitPrice == 0) {
TaxUnitPrice = Mul(memberyf.data.UnitPrice, taxrateb,4);
} else TaxUnitPrice = memberyf.data.TaxUnitPrice;
var amount = Mul(TaxUnitPrice, quantity); //(parseFloat(unitPrice).mul(quantity)).toFixed(2);
var notaxamount = 0;
if (amount > 0) {
notaxamount = Div(amount, taxrateb);
} else {
notaxamount = Div(Math.abs(amount), taxrateb);
notaxamount = -notaxamount;
}
var tax = Add(amount, -notaxamount); //parseFloat(notaxamount).mul(taxrate);
var curr = memberyf.data.Currency;
if (this.ACCTAXRATESAMETAXRATE == 1) acctaxrate = taxrate; else acctaxrate = memberyf.data.AccTaxRate;
if (this.stroplb != 'op_truck') {
var exrate = 0;
if (curr == LOCALCURR) { exrate = 1 } else {
exrate = memberyf.data.ExchangeRate;
if (exrate == 0) {
var FFrecords = DsStoreQueryBy(this.StoreDateCurr, 'CURR', curr);
if (FFrecords.getCount() > 0) {
var ffdata = FFrecords.getAt(0).data;
if (feeType == 2)
exrate = ffdata.CRDEFRATE;
else
exrate = ffdata.DEFRATE;
} else {
var DFrecords = DsStoreQueryBy(this.StoreCurr, 'CURR', curr);
if (DFrecords.getCount() > 0) {
var dfdata = DFrecords.getAt(0).data;
if (feeType == 2)
exrate = dfdata.CRDEFRATE;
else
exrate = dfdata.DEFRATE;
} else {
}
}
}
};
if (memberyf.data.CustomerName == '') {
var custtype = memberyf.data.CustomerType;
if (custtype == '') {
if (feeType == 1)
custtype = '委托单位'
else
custtype = '订舱代理'
};
var records = DsStoreQueryBy(this.StoreFeeCust, 'CUSTTYPE', custtype);
if (records.getCount() > 0) {
var data = records.getAt(0).data;
var custname = this.EditRecord.get(data.CUSTNAME);
} else {
var custname = '';
}
} else {
var custtype = memberyf.data.CustomerType;
var custname = memberyf.data.CustomerName;
}
} else {
var custtype = memberyf.data.CustomerType;
var custname = memberyf.data.CustomerName;
if (this.stroplb == 'op_truck') {
if (custtype == '车队')
custname = this.EditRecord.get('TruckSpec');
else if (custtype == '委托单位')
custname = this.EditRecord.get('CustomerName')
}
}
if (this.feeType == 1 && this.stroplb == 'op_SeaeOrder' && this.DEFORDERCUST != '') {
custname = this.DEFORDERCUST;
}
var custfullname = '';
if (custname != '') {
var records = DsStoreQueryBy(this.storeCustomerNameRef, 'CustName', custname);
if (records.getCount() > 0) {
var data = records.getAt(0).data;
var DESCRIPTION = data.DESCRIPTION;
if (DESCRIPTION != '')
custfullname = DESCRIPTION;
}
}
var newsort = this.StoreFee.getCount() + 1;
record = Ext.create('MsChFee', {
GId: NewGuid(),
// BsNo: this.StoreBill.getAt(0).get('BSNO'),
BsNo: '*',
FeeStatus: 1,
FeeStatus_Ref: '录入状态',
FeeType: feeType,
FeeType_Ref: feeTypeRef,
FeeName: memberyf.data.FeeName,
FeeDescription: memberyf.data.FEEDESCRIPTION,
CustomerType: custtype,
CustomerName: custname,
CustomerFullName: custfullname,
Unit: memberyf.data.Unit,
UnitPrice: memberyf.data.UnitPrice,
TaxUnitPrice: TaxUnitPrice,
Quantity: quantity,
TaxRate: memberyf.data.TaxRate,
NoTaxAmount: notaxamount,
Amount: amount,
Tax: tax,
AccTaxRate: acctaxrate,
Currency: memberyf.data.Currency,
ExChangerate: exrate,
Reason: '',
Remark: memberyf.data.Remark,
Commissionrate: 0,
Settlement: 0,
Invoice: 0,
OrderAmount: 0,
OrderInvoice: 0,
SubmitDate: null,
Auditoperator: '',
AuditDate: null,
EnteroPerator: GetCookie_UserId(),
EnterDate: null,
DebitNo: '',
IsDebit: "0",
IsOpen: "0",
ISACC: "0",
IsAdvancedpay: memberyf.data.ISADVANCEDPAY,
Sort: newsort,
IsInvoice: memberyf.data.ISINVOICE,
FeeFrt: memberyf.data.FEEFRT,
SALECORP: this.SALECORP,
IsCrmOrderFee: iscrmorder,
AuditStatus: 0,
InvoiceNum: '',
ChequeNum: '',
MANAGER: MANAGER,
MANAGERREF: MANAGERREF,
LOCALCURR: LOCALCURR,
WmsOutBsNo: ''
});
if (this.storeDefValue.getCount() > 0) {
for (var j = 0; j < this.storeDefValue.getCount() ; j += 1) {
var member = this.storeDefValue.getAt(j);
if (record.get(member.data.FIELDNAME) == '' || record.get(member.data.FIELDNAME) == null || record.get(member.data.FIELDNAME) == NaN || record.get(member.data.FIELDNAME) ==0)
record.set(member.data.FIELDNAME, member.data.DEFVALUE);
};
};
record.id = NewGuid();
record.internalId = NewGuid();
this.StoreFee.add(record);
}
};
_this = this;
Ext.Ajax.request({
waitMsg: '正在添加数据...',
url: '/MvcShipping/MsFeeTemplate/UpdateTemplate',
async: false,
params: {
templateid: _this.strGID
},
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;
} else {
}
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
}
},
scope: this
});
if (this.stroplb != 'op_truck') {
this.parentWin.onPostDetailClick(NaN, NaN, this.feeType);
this.parentWin.calcDetailTotal();
} else {
}
window.closeAction = 'destroy';
window.close();
},
getCondition: function () {
var form = this.formSearch.getForm();
if (!form.isValid()) {
Ext.Msg.alert('提示', '查询条件赋值错误,请检查。');
return '';
}
var sql = '';
if (this.stroplb == 'op_Seae') {
sql = ' OpType=1 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_Seai') {
sql = ' OpType=2 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_Aire') {
sql = ' OpType=3 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_Airi') {
sql = ' OpType=4 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_Apply') {
sql = ' OpType=4 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_Bulk') {
sql = ' OpType=5 and FeeType=' + this.feeType;
} else if (this.stroplb == 'op_other') {
sql = ' OpType=6 and FeeType=' + this.feeType;
}
var custName = form.findField('NAME').getValue();
sql = sql + getAndConSql(sql, custName, " Name like '%" + custName + "%'");
var mblNo = form.findField('DESCRIPTION').getValue();
sql = sql + getAndConSql(sql, mblNo, " Description like '%" + mblNo + "%'");
return sql;
}
});