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.

452 lines
19 KiB

4 years ago
define(function (require, exports, module) {
//引入业务类基类
let BaseBiz = require('apps/rht/base/rhtBiz');
let rhtComm = require('apps/rht/comm/rhtComm');
//引入业务服务
let Service = require('./stk180303service');
/**
* 定义业务类对象
* @param vm 界面相关ViewModule
*/
function Biz(vm) {
//继承第一步,构造继承
BaseBiz.call(this, vm);
}
//继承第二步,方法继承
inherits(Biz, BaseBiz);
let OrgType = rhtComm.GetOrgType(Store.logOn.orgCode);
let IsMdKwMng = rhtComm.getRhtOptionValue(Store.logOn.orgCode,'STK','IsMdKwMng','1');
//新增行后处理,默认值已经处理
Biz.prototype.afterNewRow = function (dataSrc, newRow) {
if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) {
let InOrgCode = rhtComm.GetInOrgCode(Store.logOn.orgCode).message;
newRow.setColumnText('InOrgCode', InOrgCode);
}
this.super('afterNewRow', dataSrc, newRow);
};
//保存前校验 计算主表合计数量等字段
Biz.prototype.beforeSave = function () {
let masterRow = this.dsMaster.currentRow;
if(masterRow){
let BillType = masterRow ? TypeUtil.toString(masterRow['BillType']) : '';
let CsCount = 0.0;
if (BillType == "1"){
masterRow.setColumnValue('YwType',"1805");
}
else{
masterRow.setColumnValue('YwType',"1806");
}
for(let i=0;i<this.dsDetail.rows.length;i++){
let row = this.dsDetail.rows[i];
CsCount = CsCount + TypeUtil.toFloat(row['CsCount']);
}
masterRow.setColumnValue('CsCount',CsCount);
}
return this.super('beforeSave');
};
//明细行单行提交触发的校验
Biz.prototype.dataRowValidate = function (dataSrc, dr) {
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
let masterRow = this.dsMaster.currentRow;
let BillNo = masterRow ? TypeUtil.toString(masterRow['BillNo']) : '';
let HtCode = masterRow ? TypeUtil.toString(masterRow['HtCode']) : '';
let IsPcNo = masterRow ? TypeUtil.toString(masterRow['IsPcNo']) : '';
let InOrgCode = masterRow ? TypeUtil.toString(masterRow['InOrgCode']) : '';
let CkCode = masterRow ? TypeUtil.toString(masterRow['CkCode']) : '';
let CntID = masterRow ? TypeUtil.toString(masterRow['CntID']) : '';
let EtpCode = masterRow ? TypeUtil.toString(masterRow['EtpCode']) : '';
let JyMode = masterRow ? TypeUtil.toString(masterRow['JyMode']) : '';
let JsCode = masterRow ? TypeUtil.toString(masterRow['JsCode']) : '';
let PluCode = dr ? TypeUtil.toString(dr['PluCode']) : '';
if (HtCode.length <= 0){
if (OrgType == "1001") {
return "总部必须录入合同!";
}
let JSONObject={OrgCode:Store.logOn.orgCode};
let ret = Service.getSlideMenuData("pubsysBaseBL","GetFOrgAndZbForg",JSONObject,"","","","");
if (ret.result !== 1) {
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
if (ret.data != null){
if (ret.data.FOrgCode != ret.data.ZbFOrgCode){
return "独立核算组织必须录入合同!";
}
}
}
if (PluCode.length <= 0) {
return "商品编码不能为空!";
}
let DepId = dr ? TypeUtil.toString(dr['DepId']) : '';
let DepCode = dr ? TypeUtil.toString(dr['DepCode']) : '';
let PcNo = dr ? TypeUtil.toString(dr['PcNo']) : '';
let CsCount = TypeUtil.toFloat(dr['CsCount']);
if (DepId == "") {
return "请录入部门!";
}
if (DepCode == "") {
return "表体部门必须录入!";
}
if (CsCount <= 0) {
return "残损数量不能小于或等于零!";
}
if (PcNo != "*") {
let retPc = Service.getSlideMenuData("DoOnDetailCalcRule","GetPcNo",PcNo,"","","","");
if (retPc.result === 1) {
if (retPc.data == null) {
return "此批次不存在。请重新选择。";
}
else{
dr.setColumnText('PluType', retPc.data.PluType);
}
}
}
if ((PcNo == "*") && (IsPcNo == "1")) {
return "请重新选择批次!";
}
let PluId = dr ? TypeUtil.toString(dr['PluId']) : '';
let PluType = TypeUtil.toString(dr['PluType']);
let ExPluCode = TypeUtil.toString(dr['ExPluCode']);
if (PcNo == "*") {
let Params = BillNo+";"+"1805;*;"+InOrgCode+";"+DepId+";"+CkCode+";"+PluId+";"+ExPluCode+";"+PluType+";"+CntID+";"+EtpCode+";"+JyMode+";"+JsCode;
let JSONObject={DataType:"8",Params:Params};
let retKyCount = Service.getSlideMenuData("pubsysBaseBL","MSysGetLsKcKyCount",JSONObject,"","","","");
if (retKyCount.result === 1) {
if (CsCount > TypeUtil.toFloat(retKyCount.message)){
let errmsg = "商品"+PluCode+"的残损数量大于当前可用数量:"+retKyCount.message;
return errmsg;
}
}
else{
return "查询商品库存失败:"+retKyCount.message;
}
}
else{
let Params = BillNo+";"+"1805;*;"+InOrgCode+";"+DepId+";"+CkCode+";"+PluId+";"+ExPluCode+";"+PluType+";"+PcNo;
let JSONObject={DataType:"6",Params:Params};
let retKyCount = Service.getSlideMenuData("pubsysBaseBL","MSysGetLsKcKyCount",JSONObject,"","","","");
if (retKyCount.result === 1) {
if (CsCount > TypeUtil.toFloat(retKyCount.message)){
let errmsg = "商品"+PluCode+"的残损数量大于当前可用数量:"+retKyCount.message;
return errmsg;
}
}
else{
return "查询商品库存失败:"+retKyCount.message;
}
}
}
return true;
};
/**
* @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 'HtCode':
this.fieldChangedHtCode(dataSrc, dr, dc);
break;
}
}
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
switch (dc.fieldName) {
case 'PluCode':
this.fieldChangedPluCode(dataSrc, dr, dc);
break;
case 'SglCount':
this.fieldChangedSglCount(dataSrc, dr, dc);
break;
case 'PackCount':
this.fieldChangedPackCount(dataSrc, dr, dc);
break;
case 'PcNo':
this.fieldChangedPcNo(dataSrc, dr, dc);
break;
case 'HJPrice':
this.fieldChangedHJPrice(dataSrc, dr, dc);
break;
case 'WJPrice':
this.fieldChangedWJPrice(dataSrc, dr, dc);
break;
case 'NewHJPrice':
this.fieldChangedNewHJPrice(dataSrc, dr, dc);
break;
case 'NewWJPrice':
this.fieldChangedNewWJPrice(dataSrc, dr, dc);
break;
}
}
this.super('fieldChanged');
};
//HtCode 字段变化执行事件
Biz.prototype.fieldChangedHtCode = function (dataSrc, dr, dc) {
let HtCode = dr ? TypeUtil.toString(dr['HtCode']) : '';
if (HtCode.length > 0){
let JSONObject={CntId:"", HtCode:HtCode, UsOrgCode:Store.logOn.orgCode};
let ret = Service.getSlideMenuData("pubsysBaseBL","UCntGetJyMode",JSONObject,"","","","");
if (ret.result !== 1) {
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
if (ret.data != null){
dr.setColumnText('JsCode', ret.data.JsCode);
dr.setColumnText('JyMode', ret.data.JyMode);
}
}
return true;
};
//PluCode 字段变化执行事件
Biz.prototype.fieldChangedPluCode = function (dataSrc, dr, dc) {
let PluCode = dr['PluCode'];
if (PluCode.length > 0){
let self = this;
let currentRow = self.dsMaster.currentRow;
let InOrgCode = currentRow ? TypeUtil.toString(currentRow['InOrgCode']) : '';
let CkCode = currentRow ? TypeUtil.toString(currentRow['CkCode']) : '';
if (IsMdKwMng == "1"){
let PluId = dr ? TypeUtil.toString(dr['PluId']) : '';
let retKw= Service.getSlideMenuData("DoOnMasterRule","GetPluKw",CkCode,InOrgCode,PluId,"","");
if (retKw.result === 1) {
if (retKw.data !== null) {
dr.setColumnValue('KwCode', retKw.data.KwCode);
}
}
}
}
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 HJPrice = TypeUtil.toFloat(dr['HJPrice']);
let NewHJPrice = TypeUtil.toFloat(dr['NewHJPrice']);
let JTaxRate = TypeUtil.toFloat(dr['JTaxRate']);
let R_JTaxCalType = dr ? TypeUtil.toString(dr['R_JTaxCalType']) : '';
let CsCount = (PackCount*PackQty)+SglCount;
let HCost = (HJPrice*CsCount).round(2);
let NewHCost = (NewHJPrice*CsCount).round(2);
dr.setColumnValue("CsCount", CsCount);
dr.setColumnValue("HCost", HCost);
dr.setColumnValue("NewHCost", NewHCost);
if (R_JTaxCalType == "0"){
dr.setColumnValue("WCost", (HCost/(1+JTaxRate/100)).round(2));
}
else{
dr.setColumnValue("WCost", (HCost*(1-JTaxRate/100)).round(2));
}
if (R_JTaxCalType == "0"){
dr.setColumnValue("NewWCost", (NewHCost/(1+JTaxRate/100)).round(2));
}
else{
dr.setColumnValue("NewWCost", (NewHCost*(1-JTaxRate/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 HJPrice = TypeUtil.toFloat(dr['HJPrice']);
let NewHJPrice = TypeUtil.toFloat(dr['NewHJPrice']);
let JTaxRate = TypeUtil.toFloat(dr['JTaxRate']);
let R_JTaxCalType = dr ? TypeUtil.toString(dr['R_JTaxCalType']) : '';
let CsCount = (PackCount*PackQty)+SglCount;
let HCost = (HJPrice*CsCount).round(2);
let NewHCost = (NewHJPrice*CsCount).round(2);
dr.setColumnValue("CsCount", CsCount);
dr.setColumnValue("HCost", HCost);
dr.setColumnValue("NewHCost", NewHCost);
if (R_JTaxCalType == "0"){
dr.setColumnValue("WCost", (HCost/(1+JTaxRate/100)).round(2));
}
else{
dr.setColumnValue("WCost", (HCost*(1-JTaxRate/100)).round(2));
}
if (R_JTaxCalType == "0"){
dr.setColumnValue("NewWCost", (NewHCost/(1+JTaxRate/100)).round(2));
}
else{
dr.setColumnValue("NewWCost", (NewHCost*(1-JTaxRate/100)).round(2));
}
return true;
};
//HJPrice 字段变化执行事件
Biz.prototype.fieldChangedHJPrice = function (dataSrc, dr, dc) {
let CsCount = TypeUtil.toFloat(dr['CsCount']);
let HJPrice = TypeUtil.toFloat(dr['HJPrice']);
let JTaxRate = TypeUtil.toFloat(dr['JTaxRate']);
let R_JTaxCalType = dr ? TypeUtil.toString(dr['R_JTaxCalType']) : '';
let HCost = (HJPrice*CsCount).round(2);
dr.setColumnValue("HCost", HCost);
if (R_JTaxCalType == "0"){
dr.setColumnValue("WJPrice", (HJPrice/(1+JTaxRate/100)).round(4));
}
else{
dr.setColumnValue("WJPrice", (HJPrice*(1-JTaxRate/100)).round(4));
}
if (R_JTaxCalType == "0"){
dr.setColumnValue("WCost", (HCost/(1+JTaxRate/100)).round(2));
}
else{
dr.setColumnValue("WCost", (HCost*(1-JTaxRate/100)).round(2));
}
return true;
};
//WJPrice 字段变化执行事件
Biz.prototype.fieldChangedWJPrice = function (dataSrc, dr, dc) {
let CsCount = TypeUtil.toFloat(dr['CsCount']);
let WJPrice = TypeUtil.toFloat(dr['WJPrice']);
let JTaxRate = TypeUtil.toFloat(dr['JTaxRate']);
let R_JTaxCalType = dr ? TypeUtil.toString(dr['R_JTaxCalType']) : '';
let HJPrice =0.0;
if (R_JTaxCalType == "0"){
HJPrice =(WJPrice*(1+JTaxRate/100)).round(4);
}
else{
HJPrice =(WJPrice/(1-JTaxRate/100)).round(4);
}
let HCost = (HJPrice*CsCount).round(2);
if (R_JTaxCalType == "0"){
dr.setColumnValue("WCost", (HCost/(1+JTaxRate/100)).round(2));
}
else{
dr.setColumnValue("WCost", (HCost*(1-JTaxRate/100)).round(2));
}
dr.setColumnValue("HJPrice", HJPrice);
dr.setColumnValue("HCost", HCost);
return true;
};
//NewHJPrice 字段变化执行事件
Biz.prototype.fieldChangedNewHJPrice = function (dataSrc, dr, dc) {
let CsCount = TypeUtil.toFloat(dr['CsCount']);
let NewHJPrice = TypeUtil.toFloat(dr['NewHJPrice']);
let JTaxRate = TypeUtil.toFloat(dr['JTaxRate']);
let R_JTaxCalType = dr ? TypeUtil.toString(dr['R_JTaxCalType']) : '';
let NewHCost = (NewHJPrice*CsCount).round(2);
dr.setColumnValue("NewHCost", NewHCost);
if (R_JTaxCalType == "0"){
dr.setColumnValue("NewWJPrice", (NewHJPrice/(1+JTaxRate/100)).round(4));
}
else{
dr.setColumnValue("NewWJPrice", (NewHJPrice*(1-JTaxRate/100)).round(4));
}
if (R_JTaxCalType == "0"){
dr.setColumnValue("NewWCost", (NewHCost/(1+JTaxRate/100)).round(2));
}
else{
dr.setColumnValue("NewWCost", (NewHCost*(1-JTaxRate/100)).round(2));
}
return true;
};
//NewWJPrice 字段变化执行事件
Biz.prototype.fieldChangedNewWJPrice = function (dataSrc, dr, dc) {
let CsCount = TypeUtil.toFloat(dr['CsCount']);
let NewWJPrice = TypeUtil.toFloat(dr['NewWJPrice']);
let JTaxRate = TypeUtil.toFloat(dr['JTaxRate']);
let R_JTaxCalType = dr ? TypeUtil.toString(dr['R_JTaxCalType']) : '';
let NewHJPrice =0.0;
if (R_JTaxCalType == "0"){
NewHJPrice =(NewWJPrice*(1+JTaxRate/100)).round(4);
}
else{
NewHJPrice =(NewWJPrice/(1-JTaxRate/100)).round(4);
}
let NewHCost = (NewHJPrice*CsCount).round(2);
if (R_JTaxCalType == "0"){
dr.setColumnValue("NewWCost", (NewHCost/(1+JTaxRate/100)).round(2));
}
else{
dr.setColumnValue("NewWCost", (NewHCost*(1-JTaxRate/100)).round(2));
}
dr.setColumnValue("NewHJPrice", NewHJPrice);
dr.setColumnValue("NewHCost", NewHCost);
return true;
};
//PcNo 字段变化执行事件
Biz.prototype.fieldChangedPcNo = function (dataSrc, dr, dc) {
let self = this;
let currentRow = self.dsMaster.currentRow;
let IsPcNo = currentRow ? TypeUtil.toString(currentRow['IsPcNo']) : '';
let PcNo = TypeUtil.toString(dr['PcNo']);
if (IsPcNo == "0"){
if (PcNo != "*"){
dr.setColumnText("PcNo", "*");
dr.setColumnError(dc.fieldName, "不指定批次时不需要录入批次信息!");
return false;
}
}
return true;
};
//控制主界面按钮状态
Biz.prototype.getOpEnabled = function (opCode) {
let isOk = this.super('getOpEnabled', opCode);
if (!isOk) return false;
let curRow = this.dsMaster.currentRow;
if (opCode == 'newacc') {
let JzDate = curRow ? TypeUtil.toString(curRow['JzDate']) : '';
let DataStatus = curRow ? TypeUtil.toString(curRow['DataStatus']) : '';
if (!curRow)
return false;
if ((this._state =="add") || (this._state =="edit"))
return false;
if (JzDate != '')
return false;
if (DataStatus != '0')
return false;
}
return true;
};
//按钮事件控制
Biz.prototype.doOp = function (opCode) {
let self = this;
if (opCode == 'newacc') {
let ds = self.dsMaster;
this.onnewacc(self, ds);
}
};
//newacc 按钮事件
Biz.prototype.onnewacc = function (biz, ds) {
let dsrow=ds.currentRow;
let BillNo = dsrow ? TypeUtil.toString(dsrow['BillNo']) : '';
let YwType = dsrow ? TypeUtil.toString(dsrow['YwType']) : '';
let ret= Service.getSlideMenuData("doAccount","doAccount",BillNo,YwType);
if (ret.result === 1) {
Store.messager.tip("记账成功!");
biz.dsMaster.updateRow();
}
else
{
Store.messager.err("记账失败!"+ret.message);
return false;
}
return true;
};
return Biz;
});