You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

554 lines
24 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

define(function (require, exports, module) {
//引入业务类基类
let BaseBiz = require('apps/rht/base/rhtBiz');
let rhtComm = require('apps/rht/comm/rhtComm');
//引入业务服务
let Service = require('./wsl160101service');
/**
* 全局变量
*/
//取部门核算级别
let accLength = rhtComm.getOptionOrgAccLevel();
/**
* 定义业务类对象
* @param vm 界面相关ViewModule
*/
function Biz(vm) {
//继承第一步,构造继承
BaseBiz.call(this, vm);
}
//继承第二步,方法继承
inherits(Biz, BaseBiz);
let Wsl_IsUsePfJgZc = rhtComm.getRhtOptionValue('*', 'WSL', 'Wsl_IsUsePfJgZc', '0');
let Wsl_IsPfPrcNotMin = rhtComm.getRhtOptionValue('*', 'WSL', 'Wsl_IsPfPrcNotMin', '0');
let IsMdKwMng = rhtComm.getRhtOptionValue(Store.logOn.orgCode, 'STK', 'IsMdKwMng', '1');
//保存前校验 计算主表合计数量等字段
Biz.prototype.beforeSave = function () {
let curRow = this.dsMaster.currentRow;
if (curRow) {
let PfCount = 0.0;
let PfTotal = 0.0;
let YhTotal = 0.0;
let SsTotal = 0.0;
let XTaxTotal = 0.0;
let vi_MainZeroTotal = 0.0;
let vi_MainSsTotal = 0.0;
let vi_ListSsTotal = 0.0;
let vi_UpTotal = 0.0;
let vEndSsTotal = 0.0;
let vEndXTaxTotal = 0.0;
let ZeroTotal = TypeUtil.toFloat(curRow['ZeroTotal']);
vi_MainZeroTotal = ZeroTotal;
let FhMode = TypeUtil.toString(curRow['FhMode']);
let DhDate = TypeUtil.toString(curRow['DhDate']);
let EtpTel = TypeUtil.toString(curRow['EtpTel']);
let Address = TypeUtil.toString(curRow['Address']);
let AreaCode = TypeUtil.toString(curRow['AreaCode']);
let ZdDate = TypeUtil.toString(curRow['ZdDate']);
let YxDate = TypeUtil.toString(curRow['YxDate']);
let JsCode = TypeUtil.toString(curRow['JsCode']);
let YqDate = TypeUtil.toString(curRow['YqDate']);
if (FhMode == "1") {
if (DhDate == "") {
curRow.setColumnError("DhDate", "发货方式为1-送货,必须指定到货日期!");
return false;
}
else if ((this._state == "add") && (DhDate < rhtComm.GetServerDate(0))) {
curRow.setColumnError("DhDate", "发货方式为1-送货,到货日期必须大于等于今天!");
return false;
}
if (EtpTel == "") {
curRow.setColumnError("EtpTel", "发货方式为1-送货,必须指定联系电话!");
return false;
}
if (Address == "") {
curRow.setColumnError("Address", "发货方式为1-送货,必须指定送货地址!");
return false;
}
if (AreaCode == "") {
curRow.setColumnError("AreaCode", "发货方式为1-送货,必须指定送货区域!");
return false;
}
}
else if (FhMode == "0") {
if (ZdDate == "") {
curRow.setColumnError("ZdDate", "发货方式为0-自提,必须指定提货日期!");
return false;
}
else if ((this._state == "add") && (ZdDate < rhtComm.GetServerDate(0))) {
curRow.setColumnError("ZdDate", "发货方式为0-自提,提货日期必须大于等于今天!");
return false;
}
if (YxDate == "") {
curRow.setColumnError("YxDate", "发货方式为0-自提,必须指定提货有效日期!");
return false;
}
else if ((this._state == "add") && (YxDate < rhtComm.GetServerDate(0))) {
curRow.setColumnError("YxDate", "发货方式为0-自提,提货有效日期必须大于等于今天!");
return false;
}
}
if ((JsCode == "02") && (YqDate == "")) {
curRow.setColumnError("YqDate", "延期付款,必须指定付款日期!");
return false;
}
for (let i = 0; i < this.dsDetail.rows.length; i++) {
let row = this.dsDetail.rows[i];
let Tag = TypeUtil.toString(row['Tag']);
if (Tag != "Z") {
vi_MainSsTotal = vi_MainSsTotal + TypeUtil.toFloat(row['YsTotal']) - TypeUtil.toFloat(row['YhTotal']);
}
}
if (vi_MainSsTotal != 0) {
for (let i = 0; i < this.dsDetail.rows.length; i++) {
let row = this.dsDetail.rows[i];
let Tag = TypeUtil.toString(row['Tag']);
let YsTotal = TypeUtil.toFloat(row['YsTotal']);
YhTotal = TypeUtil.toFloat(row['YhTotal']);
let XTaxRate = TypeUtil.toFloat(row['XTaxRate']);
let rowSsTotal = 0.0;
let rowXTaxTotal = 0.0;
if (Tag != "Z") {
vi_ListSsTotal = YsTotal - YhTotal;
if (vi_ListSsTotal != 0) {
vi_UpTotal = (vi_MainZeroTotal * (vi_ListSsTotal / vi_MainSsTotal)).round(2);
let vi_TxRate = XTaxRate;
rowSsTotal = YsTotal - YhTotal - vi_UpTotal;
rowXTaxTotal = (rowSsTotal * (vi_TxRate / 100 / (1 + vi_TxRate / 100)).round(2));
row.setColumnValue('ZeroTotal', vi_UpTotal);
row.setColumnValue('SsTotal', rowSsTotal);
row.setColumnValue('XTaxTotal', rowXTaxTotal);
}
}
vEndSsTotal = vEndSsTotal + rowSsTotal;
vEndXTaxTotal = vEndXTaxTotal + rowXTaxTotal;
}
curRow.setColumnValue('SsTotal', vEndSsTotal);
curRow.setColumnValue('XTaxTotal', vEndXTaxTotal);
}
for (let i = 0; i < this.dsDetail.rows.length; i++) {
let row = this.dsDetail.rows[i];
let Tag = TypeUtil.toString(row['Tag']);
let YsTotal = TypeUtil.toFloat(row['YsTotal']);
let rowSsTotal = TypeUtil.toFloat(row['SsTotal']);
let rowHCost = TypeUtil.toFloat(row['HCost']);
if (Tag != "Z") {
vi_MainSsTotal = vi_MainSsTotal + YsTotal - TypeUtil.toFloat(row['YhTotal']);
}
PfCount = PfCount + TypeUtil.toFloat(row['PfCount']);
PfTotal = PfTotal + TypeUtil.toFloat(row['YsTotal']);
YhTotal = YhTotal + TypeUtil.toFloat(row['YhTotal']);
SsTotal = SsTotal + rowSsTotal;
XTaxTotal = XTaxTotal + TypeUtil.toFloat(row['XTaxTotal']);
row.setColumnValue('HMTotal', rowSsTotal - rowHCost);
if (TypeUtil.toFloat(row['SsTotal']) == 0) {
row.setColumnValue('PfMlRate', "0");
}
else {
row.setColumnValue('PfMlRate', ((rowSsTotal - rowHCost) / rowSsTotal).round(2));
}
}
curRow.setColumnValue('PfCount', PfCount);
curRow.setColumnValue('PfTotal', PfTotal);
curRow.setColumnValue('YhTotal', YhTotal);
curRow.setColumnValue('SsTotal', SsTotal);
curRow.setColumnValue('XTaxTotal', XTaxTotal);
}
return this.super('beforeSave');
}
//明细行单行提交触发的校验
Biz.prototype.dataRowValidate = function (dataSrc, dr) {
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
let HJPrice = TypeUtil.toFloat(dr['HJPrice']);
let PfCount = TypeUtil.toFloat(dr['PfCount']);
let SsTotal = TypeUtil.toFloat(dr['SsTotal']);
let PackUnit = TypeUtil.toString(dr['PackUnit']);
let PfPrice = TypeUtil.toFloat(dr['PfPrice']);
let PfZdPrice = TypeUtil.toFloat(dr['PfZdPrice']);
if (PfCount <= 0) {
return "批发数量应该大于0";
}
if (PackUnit == "") {
dr.setColumnValue('PackCount', "0");
}
if ((Wsl_IsUsePfJgZc == "0") && (Wsl_IsPfPrcNotMin == "1")) {
if (PfPrice < PfZdPrice) {
return "批发价不能小于批发指导价,请检查!";
}
}
dr.setColumnValue('HCost', (HJPrice * PfCount).round(2));
dr.setColumnValue('HMTotal', SsTotal - (HJPrice * PfCount).round(2));
if (SsTotal == 0) {
dr.setColumnValue('PfMlRate', "0");
}
else {
dr.setColumnValue('PfMlRate', ((SsTotal - (HJPrice * PfCount).round(2)) / SsTotal).round(2));
}
}
return true;
};
/**
* 列校验,列赋值时调用,发生异常表示校验失败
* @param {DataSource} dataSrc [description]
* @param {DataRow} dr [description]
* @param {DataColumn} dc [description]
* @param {Object} value [description]
* @return {Boolean} [description]
*/
Biz.prototype.dataColumnValidate = function (dataSrc, dr, dc, value) {
let self = this;
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
let currentRow = self.dsMaster.currentRow;
let DepCodeHead = TypeUtil.toString(currentRow['DepCode']);
if ((accLength > 0) && (DepCodeHead.length == 0)) {
return "核算到部门,必须录入主表部门!";
}
}
return this.super('dataColumnValidate');
};
/**
* @description 数据发生变化时调用
* @param dataSrc 数据集
* @param dr 数据行
* @param dc 数据列
*/
Biz.prototype.fieldChanged = function (dataSrc, dr, dc) {
let self = this;
let currentRow = self.dsMaster.currentRow;
if (currentRow === null) return false;
if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) {
switch (dc.fieldName) {
case 'EtpCode':
this.fieldChangedEtpCode(dataSrc, dr, dc);
break;
case 'FhMode':
this.fieldChangedFhMode(dataSrc, dr, dc);
break;
}
}
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
switch (dc.fieldName) {
case 'PluCode':
this.fieldChangedPluCode(dataSrc, dr, dc);
break;
case 'PfPrice':
this.fieldChangedPfPrice(dataSrc, dr, dc);
break;
case 'SsTotal':
this.fieldChangedSsTotal(dataSrc, dr, dc);
break;
case 'SglCount':
this.fieldChangedSglCount(dataSrc, dr, dc);
break;
case 'PackCount':
this.fieldChangedPackCount(dataSrc, dr, dc);
break;
case 'YhTotal':
this.fieldChangedYhTotal(dataSrc, dr, dc);
break;
case 'XTaxRate':
this.fieldChangedXTaxRate(dataSrc, dr, dc);
break;
}
}
this.super('fieldChanged');
};
//EtpCode 字段变化执行事件
Biz.prototype.fieldChangedEtpCode = function (dataSrc, dr, dc) {
let self = this;
let currentRow = self.dsMaster.currentRow;
let EtpCode = currentRow['EtpCode'];
let ret = Service.getSlideMenuData("DoOnMasterRule", "EtpCode", EtpCode, "", "", "", "");
if (ret.result === 1) {
if (ret.data != null) {
dr.setColumnValue('Address', ret.data.Address);
dr.setColumnValue('EtpTel', ret.data.Telephone);
}
}
else {
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
return true;
};
//FhMode 字段变化执行事件
Biz.prototype.fieldChangedFhMode = function (dataSrc, dr, dc) {
let self = this;
let currentRow = self.dsMaster.currentRow;
if (currentRow['FhMode'] === '0') {
let ZdDate = currentRow ? TypeUtil.toString(currentRow['ZdDate']) : '';
let YxDate = currentRow ? TypeUtil.toString(currentRow['YxDate']) : '';
dr.setColumnText('Address', "");
if (ZdDate == "") {
dr.setColumnText('ZdDate', rhtComm.GetServerDate(0));
}
if (YxDate == "") {
dr.setColumnText('YxDate', rhtComm.GetServerDate(1));
}
}
if (currentRow['FhMode'] === '1') {
dr.setColumnText('ThAddress', "");
}
return true;
};
//PluCode 字段变化执行事件
Biz.prototype.fieldChangedPluCode = function (dataSrc, dr, dc) {
let self = this;
let currentRow = self.dsMaster.currentRow;
let PluId = dr['PluId'];
let PluCode = dr['PluCode'];
let DepCode = currentRow['DepCode'];
let EtpCode = currentRow['EtpCode'];
let CkCode = currentRow['CkCode'];
let PriceType = currentRow['PriceType'];
let ZkRate = TypeUtil.toFloat(currentRow['ZkRate']);
if (PluCode.length > 0) {
let pfPrice = 0.0;
let pfZdPrice = 0.0;
let json = { OrgCode: Store.logOn.orgCode, EtpCode: EtpCode, PluID: PluId };
let retPluPfPrice = Service.getSlideMenuData("pubsysBaseBL", "UWslGetPluPfPrice", json, "", "", "", "");
if (retPluPfPrice.result === 1) {
if (retPluPfPrice.data != null) {
dr.setColumnValue('HJPrice', retPluPfPrice.data[0].hjprice);
dr.setColumnValue('Price', retPluPfPrice.data[0].price);
dr.setColumnValue('PfZdPrice', retPluPfPrice.data[0].pfprice);
pfZdPrice = TypeUtil.toFloat(retPluPfPrice.data[0].pfprice);
pfPrice = TypeUtil.toFloat(retPluPfPrice.data[0].price);
}
}
else {
dr.setColumnError(dc.fieldName, "查询商品价格信息出错:" + retPluPfPrice.message);
return false;
}
if ((Wsl_IsUsePfJgZc == "1") || (Wsl_IsPfPrcNotMin == "1")) {
let ret = Service.getSlideMenuData("DoOnDetailCalcRule", "PluCode", PluCode, EtpCode, Store.logOn.orgCode, "", "");
if (ret.result !== 1) {
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
if (ret.data != null) {
pfPrice = TypeUtil.toFloat(ret.data.Price);
}
}
if (Wsl_IsUsePfJgZc == "1") {
dr.setColumnValue('PfPrice', pfPrice);
}
else {
if (PriceType == "3") {
dr.setColumnValue('PfPrice', ((pfPrice * ZkRate) / 100).round(4));
}
else {
dr.setColumnValue('PfPrice', pfZdPrice);
}
}
if ((Wsl_IsUsePfJgZc == "0") && (Wsl_IsPfPrcNotMin == "1")) {
dr.setColumnValue('PfZdPrice', pfPrice);
dr.setColumnValue('PfPrice', pfPrice);
}
json = { psPluCode: PluCode, psYwType: "1603" };
let retPacket = Service.getSlideMenuData("pubsysBaseBL", "GetDefaultPluPackUnitByYwType", json, PluCode, "", "", "");
if (retPacket.result === 1) {
if (retPacket.data != null) {
dr.setColumnValue('PackUnit', retPacket.data.Unit);
dr.setColumnValue('PackQty', retPacket.data.Qty);
}
}
dr.setColumnValue("PackCount", "0");
dr.setColumnText("SglCount", "0");
let InOrgCode = rhtComm.GetInOrgCode(Store.logOn.orgCode).message;
json = { OrgCode: InOrgCode, PluCode: PluCode, DepCode: DepCode };
let retdep = Service.getSlideMenuData("pubsysBaseBL", "UQryPluDepInfo", json, "", "", "", "");
if (retdep.result === 1) {
if (retdep.data != null) {
dr.setColumnValue('DepId', retdep.data.DepID);
dr.setColumnValue('DepCode', retdep.data.DepCode);
dr.setColumnValue('DepName', retdep.data.DepName);
}
}
else {
dr.setColumnError(dc.fieldName, retdep.message);
return false;
}
if (IsMdKwMng == "1") {
json = { CurInOrgCode: InOrgCode, CkCode: CkCode, PluID: PluId };
let retKwCode = Service.getSlideMenuData("pubsysBaseBL", "GetPluKw", json, "", "", "", "");
if (retKwCode.result === 1) {
if (retKwCode.data != null) {
dr.setColumnValue('KwCode', retKwCode.data.KwCode);
}
}
else {
dr.setColumnError(dc.fieldName, retKwCode.message);
return false;
}
}
let retPfPrice = Service.getSlideMenuData("DoOnDetailCalcRule", "GetLastPfPrice", PluCode, EtpCode, "", "", "");
if (retPfPrice.result === 1) {
if (retPfPrice.data != null) {
dr.setColumnValue('LPfPrice', retPfPrice.data.PfPrice);
}
}
else {
dr.setColumnError(dc.fieldName, retPfPrice.message);
return false;
}
}
return true;
};
//PfPrice 字段变化执行事件
Biz.prototype.fieldChangedPfPrice = function (dataSrc, dr, dc) {
let PfPrice = TypeUtil.toString(dr['PfPrice']);
let PfZdPrice = TypeUtil.toFloat(dr['PfZdPrice']);
let YhTotal = TypeUtil.toFloat(dr['YhTotal']);
let XTaxRate = TypeUtil.toFloat(dr['XTaxRate']);
let PfCount = TypeUtil.toFloat(dr['PfCount']);
let SsTotal = 0.0;
SsTotal = (PfCount * PfPrice).round(2) - YhTotal;
if ((Wsl_IsUsePfJgZc == "0") && (Wsl_IsPfPrcNotMin == "1")) {
if (PfPrice < PfZdPrice) {
dr.setColumnError(dc.fieldName, "批发价不能小于批发指导价,请检查!");
return false;
}
}
dr.setColumnValue("YsTotal", (PfCount * PfPrice).round(2));
dr.setColumnValue("SsTotal", SsTotal);
dr.setColumnValue("XTaxTotal", (SsTotal * (XTaxRate / 100 / (1 + XTaxRate / 100))).round(2));
return true;
};
//SsTotal 字段变化执行事件
Biz.prototype.fieldChangedSsTotal = function (dataSrc, dr, dc) {
let SsTotal = TypeUtil.toFloat(dr['SsTotal']);
let PfCount = TypeUtil.toFloat(dr['PfCount']);
let PfZdPrice = TypeUtil.toFloat(dr['PfZdPrice']);
if (PfCount == 0) {
dr.setColumnError(dc.fieldName, "批发数量不能为0");
return false;
}
if ((SsTotal / PfCount).round(4) < PfZdPrice) {
dr.setColumnError(dc.fieldName, "批发价不能小于批发指导价,请检查!");
return false;
}
let XTaxRate = TypeUtil.toFloat(dr['XTaxRate']);
let PfPrice = 0.0;
PfPrice = (SsTotal / PfCount + 0.00004).round(4);
dr.setColumnValue("PfPrice", PfPrice);
dr.setColumnValue("YsTotal", (PfPrice * PfCount).round(2));
dr.setColumnValue("YhTotal", (PfPrice * PfCount).round(2) - SsTotal);
dr.setColumnValue("XTaxTotal", (SsTotal * (XTaxRate / 100 / (1 + XTaxRate / 100))).round(2));
return true;
};
//SglCount 字段变化执行事件
Biz.prototype.fieldChangedSglCount = function (dataSrc, dr, dc) {
let PackQty = TypeUtil.toFloat(dr['PackQty']);
let PackCount = TypeUtil.toFloat(dr['PackCount']);
let SglCount = TypeUtil.toFloat(dr['SglCount']);
let PfPrice = TypeUtil.toFloat(dr['PfPrice']);
let YhTotal = TypeUtil.toFloat(dr['YhTotal']);
let XTaxRate = TypeUtil.toFloat(dr['XTaxRate']);
let PfCount = 0.0;
let SsTotal = 0.0;
PfCount = (PackCount * PackQty) + SglCount;
SsTotal = (PfCount * PfPrice).round(2) - YhTotal;
dr.setColumnValue("PfCount", PfCount);
dr.setColumnValue("YsTotal", (PfCount * PfPrice).round(2));
dr.setColumnValue("SsTotal", SsTotal);
dr.setColumnValue("XTaxTotal", (SsTotal * (XTaxRate / 100 / (1 + XTaxRate / 100))).round(2));
return true;
};
//PackCount 字段变化执行事件
Biz.prototype.fieldChangedPackCount = function (dataSrc, dr, dc) {
let PackQty = TypeUtil.toFloat(dr['PackQty']);
let PackCount = TypeUtil.toFloat(dr['PackCount']);
let SglCount = TypeUtil.toFloat(dr['SglCount']);
let PfPrice = TypeUtil.toFloat(dr['PfPrice']);
let YhTotal = TypeUtil.toFloat(dr['YhTotal']);
let XTaxRate = TypeUtil.toFloat(dr['XTaxRate']);
let PfCount = 0.0;
let SsTotal = 0.0;
PfCount = (PackCount * PackQty) + SglCount;
SsTotal = (PfCount * PfPrice).round(2) - YhTotal;
dr.setColumnValue("PfCount", PfCount);
dr.setColumnValue("YsTotal", (PfCount * PfPrice).round(2));
dr.setColumnValue("SsTotal", SsTotal);
dr.setColumnValue("XTaxTotal", (SsTotal * (XTaxRate / 100 / (1 + XTaxRate / 100))).round(2));
return true;
};
//YhTotal 字段变化执行事件
Biz.prototype.fieldChangedYhTotal = function (dataSrc, dr, dc) {
let YsTotal = TypeUtil.toString(dr['YsTotal']);
let YhTotal = TypeUtil.toFloat(dr['YhTotal']);
let XTaxRate = TypeUtil.toFloat(dr['XTaxRate']);
let SsTotal = 0.0;
SsTotal = YsTotal - YhTotal;
dr.setColumnValue("SsTotal", YsTotal - YhTotal);
dr.setColumnValue("XTaxTotal", (SsTotal * (XTaxRate / 100 / (1 + XTaxRate / 100))).round(2));
return true;
};
//XTaxRate 字段变化执行事件
Biz.prototype.fieldChangedXTaxRate = function (dataSrc, dr, dc) {
let XTaxRate = TypeUtil.toFloat(dr['XTaxRate']);
let SsTotal = TypeUtil.toFloat(dr['SsTotal']);
dr.setColumnValue("XTaxTotal", (SsTotal * (XTaxRate / 100 / (1 + XTaxRate / 100))).round(2));
return true;
};
//按钮事件控制
Biz.prototype.doOp = function (opCode) {
let self = this;
if (opCode == 'change') {
let ds = self.dsMaster;
this.onchange(self, ds);
}
};
//按钮事件
Biz.prototype.onchange = function (biz, ds) {
let dsrow = ds.currentRow;
let BillNo = dsrow ? TypeUtil.toString(dsrow['BillNo']) : '';
let ret = Service.getSlideMenuData("actExecute", "onchange", BillNo, "1603", Store.logOn.userId, Store.logOn.userCode, Store.logOn.userName);
if (ret.result !== 1) {
dsrow.setColumnError('BillNo', '转化失败:' + ret.message);
return false;
}
else {
Store.messager.tip('转化成功!');
//刷新当前页面
this.opRouter('refresh');
}
return true;
};
//控制主界面按钮状态
Biz.prototype.getOpEnabled = function (opCode) {
let isOk = this.super('getOpEnabled', opCode);
if (!isOk) return false;
let curRow = this.dsMaster.currentRow;
if (opCode == 'change') {
let JzDate = curRow ? TypeUtil.toString(curRow['JzDate']) : '';
if (!curRow)
return false;
if (JzDate == '')
return false;
}
return true;
};
return Biz;
});