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.

963 lines
43 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('./wsl160102service');
/**
* 全局变量
*/
//取部门核算级别
let accLength = rhtComm.getOptionOrgAccLevel();
/**
* 定义业务类对象
* @param vm 界面相关ViewModule
*/
function Biz(vm) {
//继承第一步,构造继承
BaseBiz.call(this, vm);
}
//继承第二步,方法继承
inherits(Biz, BaseBiz);
let LsCkIsMngPsArea = rhtComm.getRhtOptionValue('*','SUPP','LsCkIsMngPsArea','0');
let PFPriceLimit = rhtComm.getRhtOptionValue('*','WSL','PFPriceLimit','0');
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');
let WSL_PFJSXYCTRL = rhtComm.getRhtOptionValue('*','WSL','WSL_PFJSXYCTRL','0');
//新增行后处理,默认值已经处理
Biz.prototype.afterNewRow = function (dataSrc, newRow) {
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
let masterRow = this.dsMaster.currentRow;
if(masterRow){
let DepCodeHead = TypeUtil.toString(masterRow['DepCode']);
let PriceType = masterRow['PriceType'];
let ZkRate = TypeUtil.toFloat(masterRow['ZkRate']);
if ((accLength > 0) && (DepCodeHead.length == 0)){
Store.messager.tip('核算到部门,必须录入主表部门!');
return false;
}
if (PriceType == "3"){
if (ZkRate == 0){
if (!Store.confirm("零售价折扣的折扣率为0是否继续录入")) {
newRow.delete();
return false;
}
}
else{
if ((ZkRate > 100) || (ZkRate < 0)){
Store.messager.tip('折扣率必须介于0到100之间请重新输入');
return false;
}
}
}
}
}
if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) {
let sdate = rhtComm.GetServerDate(0);
newRow.setColumnValue('DhDate',sdate);
newRow.setColumnValue('IsKFp', '0');
newRow.setColumnValue('IsEc',"0");
newRow.setColumnValue('BillType', "0");
newRow.setColumnText('FhMode', "0");
}
this.super('afterNewRow', dataSrc, newRow);
};
//单据编辑前处理
Biz.prototype.beforeEdit = function () {
let masterRow = this.dsMaster.currentRow;
let JsCode = TypeUtil.toString(masterRow['JsCode']);
let QkTotal = TypeUtil.toFloat(masterRow['QkTotal']);
let SkTotal = TypeUtil.toFloat(masterRow['SkTotal']);
let IsEc = TypeUtil.toFloat(masterRow['IsEc']);
if (IsEc == "1") {
masterRow.setColumnError("BillNo", '电商生成的批发销售单,不允许编辑。');
return false;
}
if ((QkTotal == 0) && (SkTotal != 0) && (JsCode == "00")) {
masterRow.setColumnError("BillNo", '此批发销售单已经收款,不能编辑。');
return false;
}
return this.super('beforeEdit');
};
//单据删除前处理
Biz.prototype.beforeDelete = function () {
let masterRow = this.dsMaster.currentRow;
let JsCode = TypeUtil.toString(masterRow['JsCode']);
let QkTotal = TypeUtil.toFloat(masterRow['QkTotal']);
let SkTotal = TypeUtil.toFloat(masterRow['SkTotal']);
let IsEc = TypeUtil.toFloat(masterRow['IsEc']);
if (IsEc == "1") {
masterRow.setColumnError("BillNo", '电商生成的批发销售单,不允许删除。');
return false;
}
if ((QkTotal == 0) && (SkTotal != 0) && (JsCode == "00")) {
masterRow.setColumnError("BillNo", '此批发销售单已经收款,不能删除。');
return false;
}
let BillNo = masterRow ? TypeUtil.toString(masterRow['BillNo']) : '';
let ret= Service.getSlideMenuData("LockLsKcByYwBill","",BillNo,"1601","1","","");
if (ret.result !== 1) {
masterRow.setColumnError('BillNo', '删除锁定库存失败:'+ret.message);
return false;
}
return this.super('beforeDelete');
};
//保存前校验 计算主表合计数量等字段
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']);
let PriceType = TypeUtil.toString(curRow['PriceType']);
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 == "00") && (PriceType == "1")){
curRow.setColumnError("JsCode", "使用成本价批发时在出库后才能确定成本,因此不能使用先款后货,建议使用货到付款!");
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']);
let fYhTotal = TypeUtil.toFloat(row['YhTotal']);
let XTaxRate = TypeUtil.toFloat(row['XTaxRate']);
let rowSsTotal = 0.0;
let rowXTaxTotal = 0.0;
if (Tag != "Z" ){
vi_ListSsTotal = YsTotal - fYhTotal;
if (vi_ListSsTotal != 0){
vi_UpTotal = (vi_MainZeroTotal * (vi_ListSsTotal / vi_MainSsTotal)).round(2);
let vi_TxRate = XTaxRate;
rowSsTotal = YsTotal-fYhTotal-vi_UpTotal;
rowXTaxTotal = (rowSsTotal*(vi_TxRate/100/(1+vi_TxRate/100)).round(2)).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);
curRow.setColumnValue('QkTotal',SsTotal);
curRow.setColumnValue('SkTotal',"0");
curRow.setColumnValue('YfQkTotal',TypeUtil.toString(curRow['YfYsTotal']));
curRow.setColumnValue('SkTotal',"0");
if ((JsCode != "00") && (WSL_PFJSXYCTRL == "1")){
let BillNo = curRow ? TypeUtil.toString(curRow['BillNo']) : '';
let DepCode = curRow ? TypeUtil.toString(curRow['DepCode']) : '';
let EtpCode = curRow ? TypeUtil.toString(curRow['EtpCode']) : '';
let EtpName = curRow ? TypeUtil.toString(curRow['EtpName']) : '';
//let SsTotal = TypeUtil.toFloat(row['SsTotal'])
let KyCredit = TypeUtil.toFloat("0.0");
//可用信用额度检查 YwBillNo, YwType, OrgCode,DepCode,OppOrgCode,StlCurrCode
let JSONObject={YwBillNo:BillNo,YwType:"1601",OrgCode:Store.logOn.orgCode,DepCode:DepCode,OppOrgCode:EtpCode,StlCurrCode:"0"};
let ret= Service.getSlideMenuData("pubsysBaseBL","UWslGetCustCredit",JSONObject,"","","","");
if (ret.result === 1) {
if (ret.data != null) {
KyCredit = TypeUtil.toFloat(ret.data.KyCredit);
}
if (KyCredit < TypeUtil.toFloat(curRow['SsTotal'])){
curRow.setColumnError('BillNo', "客户("+EtpCode+"-"+EtpName+")的结算币金额不能大于可用信用额度:"+KyCredit);
return false;
}
}
else{
curRow.setColumnError('BillNo', '可用信用额度出错:'+ret.message);
return false;
}
}
}
return this.super('beforeSave');
};
//保存后
Biz.prototype.afterSave = function() {
this.super('afterSave');
let curRow = this.dsMaster.currentRow;
if(curRow){
let BillNo = curRow ? TypeUtil.toString(curRow['BillNo']) : '';
let ret= Service.getSlideMenuData("LockLsKcByYwBill","",BillNo,"1601","0","","");
if (ret.result !== 1) {
curRow.setColumnError('BillNo', '锁定库存失败:'+ret.message);
return false;
}
}
};
//明细行单行提交触发的校验
Biz.prototype.dataRowValidate = function (dataSrc, dr) {
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
let self = this;
let curMaster = self.dsMaster.currentRow;
let BillNo = TypeUtil.toString(curMaster['BillNo']);
let WlAreaCode = TypeUtil.toString(curMaster['WlAreaCode']);
let InOrgCode = TypeUtil.toString(curMaster['InOrgCode']);
let CkCode = TypeUtil.toString(curMaster['CkCode']);
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']);
let PluType = TypeUtil.toString(dr['PluType']);
let PluID = TypeUtil.toString(dr['PluId']);
let PluCode = TypeUtil.toString(dr['PluCode']);
let PluName = TypeUtil.toString(dr['PluName']);
let DepId = TypeUtil.toString(dr['DepId']);
let DepCode = TypeUtil.toString(dr['DepCode']);
let DepName = TypeUtil.toString(dr['DepName']);
let ExPluCode = TypeUtil.toString(dr['ExPluCode']);
if (PluCode.length <= 0) {
return "商品编码不能为空!";
}
if (PfCount <= 0) {
return "批发数量应该大于0";
}
if (PackUnit == "") {
dr.setColumnValue('PackCount', "0");
}
if ((Wsl_IsUsePfJgZc == "0") && (Wsl_IsPfPrcNotMin == "1")) {
if (PfPrice < PfZdPrice) {
return "批发价不能小于批发指导价,请检查!";
}
}
let sPluType = "";
if (PluType == "0"){
sPluType = '0-正品';
}
if (PluType == "1"){
sPluType = '1-赠品';
}
if (PluType == "2"){
sPluType = '2-促销品';
}
if (PluType == "3"){
sPluType = '3-不良品';
}
let Params = BillNo+";"+"1601;"+WlAreaCode+";"+InOrgCode+";"+DepId+";"+CkCode+";"+PluID+";"+ExPluCode+";"+PluType;
let JSONObject={DataType:"7",Params:Params};
let retKyCount = Service.getSlideMenuData("pubsysBaseBL","MSysGetLsKcKyCount",JSONObject,"","","","");
if (retKyCount.result === 1) {
if (PfCount > TypeUtil.toFloat(retKyCount.message)){
let errmsg = "商品["+PluCode+"-"+PluName+"]的批发数量不能多于商品的库存[组织:"+InOrgCode+"、仓库:"+
CkCode+"、部门:"+DepCode+"-"+DepName+"、商品类型:"+sPluType+"] <br> 当前可用数量:"+retKyCount.message;
return errmsg;
}
}
else{
return "查询商品库存失败:"+retKyCount.message;
}
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;
};
/**
* @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;
case 'CkCode':
this.fieldChangedCkCode(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 CkCode = currentRow['CkCode'];
let OrgCode = currentRow['OrgCode'];
let FhMode = currentRow['FhMode'];
if ((LsCkIsMngPsArea == "1") && (EtpCode.length > 0) && (CkCode.length > 0)){
let ret= Service.getSlideMenuData("DoOnMasterRule","EtpCode",OrgCode,EtpCode,CkCode,"","");
if (ret.result === 1) {
if (ret.data != null) {
if (FhMode == "1"){
dr.setColumnValue('Address', ret.data.Address);
}
dr.setColumnValue('EtpTel', ret.data.Telephone);
dr.setColumnValue('BankBook', ret.data.KhhNo);
}
}
else{
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
}
return true;
};
//CkCode 字段变化执行事件
Biz.prototype.fieldChangedCkCode = function (dataSrc, dr, dc) {
let self = this;
let currentRow = self.dsMaster.currentRow;
let EtpCode = currentRow['EtpCode'];
let CkCode = currentRow['CkCode'];
let OrgCode = currentRow['OrgCode'];
if ((LsCkIsMngPsArea == "1") && (EtpCode.length > 0) && (CkCode.length > 0)){
let ret= Service.getSlideMenuData("DoOnMasterRule","CkCode",OrgCode,EtpCode,CkCode,"","");
if (ret.result !== 1) {
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
}
dr.setColumnText('WlAreaCode', "*");
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'){
let EtpCode = currentRow ? TypeUtil.toString(currentRow['EtpCode']) : '';
dr.setColumnValue('ZdDate', "");
dr.setColumnValue('YxDate', "");
dr.setColumnText('ThAddress', "");
if (EtpCode.length > 0){
let ret= Service.getSlideMenuData("DoOnMasterRule","FhMode",EtpCode,"","","","");
if (ret.result === 1) {
if (ret.data != null) {
dr.setColumnValue('Address', ret.data.Address);
dr.setColumnValue('EtpTel', ret.data.Telephone);
dr.setColumnValue('BankBook', ret.data.KhhNo);
}
}
else{
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
}
}
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 JSONObject={OrgCode:Store.logOn.orgCode,EtpCode:EtpCode,PluID:PluId};
let retPluPfPrice = Service.getSlideMenuData("pubsysBaseBL","UWslGetPluPfPrice",JSONObject,"","","","");
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);
dr.setColumnText('SglCount', TypeUtil.toString(dr['SglCount']));
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);
}
JSONObject={psPluCode:PluCode,psYwType:"1601"};
let retPacket= Service.getSlideMenuData("pubsysBaseBL","GetDefaultPluPackUnitByYwType",JSONObject,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;
JSONObject={OrgCode:InOrgCode,PluCode:PluCode,DepCode:DepCode};
let retdep = Service.getSlideMenuData("pubsysBaseBL","UQryPluDepInfo",JSONObject,"","","","");
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"){
JSONObject={CurInOrgCode:InOrgCode,CkCode:CkCode,PluID:PluId};
let retKwCode = Service.getSlideMenuData("pubsysBaseBL","GetPluKw",JSONObject,"","","","");
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 PluType = TypeUtil.toString(dr['PluType']);
let PriceType = TypeUtil.toString(dr['PriceType']);
let PluCode = TypeUtil.toString(dr['PluCode']);
let PfPrice = TypeUtil.toFloat(dr['PfPrice']);
let HJPrice = TypeUtil.toFloat(dr['HJPrice']);
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;
if ((PluType != "1") && (PriceType != "1") && (HJPrice != 0) && (PluCode.length > 0)){
if ((PFPriceLimit == "2") || (PFPriceLimit == "1")){
if (PfPrice < HJPrice){
if (PFPriceLimit == "1"){
dr.setColumnError(dc.fieldName, "商品的批发价格"+PfPrice+"不允许低于最新进价"+HJPrice);
return false;
}
else{
if (!Store.confirm("商品的批发价格"+PfPrice+"不允许低于最新进价"+HJPrice+",请确认?")) {
return false;
}
}
}
}
}
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;
let DotDecimal = TypeUtil.toFloat(dr['R_DotDecimal']);
let sdl= 0;
if (SglCount.toString().indexOf(".") !== -1){
sdl= SglCount.toString().split(".")[1].length || 0;
}
if (DotDecimal < sdl){
dr.setColumnError(dc.fieldName, "此商品的小数精度是" + dr['R_DotDecimal'] );
return false;
}
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;
let DotDecimal = TypeUtil.toFloat(dr['R_DotDecimal']);
let sdl= 0;
if (PackCount.toString().indexOf(".") !== -1){
sdl= PackCount.toString().split(".")[1].length || 0;
}
if (DotDecimal < sdl){
dr.setColumnError(dc.fieldName, "此商品的小数精度是" + dr['R_DotDecimal'] );
return false;
}
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.getOpEnabled = function (opCode) {
let isOk = this.super('getOpEnabled', opCode);
if (!isOk) return false;
let curRow = this.dsMaster.currentRow;
if (opCode == 'acc') {
let JzDate = curRow ? TypeUtil.toString(curRow['JzDate']) : '';
let QkTotal = curRow ? TypeUtil.toFloat(curRow['QkTotal']) : '';
let SkTotal = curRow ? TypeUtil.toFloat(curRow['SkTotal']) : '';
let FhMode = curRow ? TypeUtil.toString(curRow['FhMode']) : '';
let JsCode = curRow ? TypeUtil.toString(curRow['JsCode']) : '';
let ThDate = curRow ? TypeUtil.toString(curRow['ThDate']) : '';
if (!curRow)
return false;
if (JsCode == "00"){
if (FhMode == "0"){
if (SkTotal == 0)
return false;
if (ThDate == '')
return false;
}
else{
if (SkTotal < 0)
return false;
}
if (QkTotal != 0)
return false;
if (JzDate != '')
return false;
}
else{
if (FhMode == "0"){
if (ThDate == '')
return false;
}
if (JzDate != '')
return false;
}
}
if (opCode == 'change') {
let JzDate = curRow ? TypeUtil.toString(curRow['JzDate']) : '';
if (!curRow)
return false;
if (JzDate == '')
return false;
}
if (opCode == 'actth') {
let ThDate = curRow ? TypeUtil.toString(curRow['ThDate']) : '';
let ThrName = curRow ? TypeUtil.toString(curRow['ThrName']) : '';
let QkTotal = curRow ? TypeUtil.toFloat(curRow['QkTotal']) : '';
let SkTotal = curRow ? TypeUtil.toFloat(curRow['SkTotal']) : '';
let FhMode = curRow ? TypeUtil.toString(curRow['FhMode']) : '';
let JsCode = curRow ? TypeUtil.toString(curRow['JsCode']) : '';
if (!curRow)
return false;
if (JsCode == "00"){
if ((ThDate != '') || (ThrName != '') || (FhMode != "0"))
return false;
}else{
if (FhMode == "1"){
return false;
}
}
if ((QkTotal != 0) || (SkTotal < 0))
return false;
if (this.isEdit())
return false;
}
if (opCode == 'actsk') {
let TjDate = curRow ? TypeUtil.toString(curRow['TjDate']) : '';
let SkTotal = curRow ? TypeUtil.toFloat(curRow['SkTotal']) : '';
let JsCode = curRow ? TypeUtil.toString(curRow['JsCode']) : '';
if (!curRow)
return false;
if ((JsCode != '00') || (TjDate != ''))
return false;
if (SkTotal > 0)
return false;
if (this.isEdit())
return false;
}
if (opCode == 'acttk') {
let TjDate = curRow ? TypeUtil.toString(curRow['TjDate']) : '';
let SkTotal = curRow ? TypeUtil.toFloat(curRow['SkTotal']) : '';
let JsCode = curRow ? TypeUtil.toString(curRow['JsCode']) : '';
if (!curRow)
return false;
if ((JsCode != '00') || (TjDate != ''))
return false;
if (SkTotal <= 0)
return false;
if (this.isEdit())
return false;
}
return true;
};
//按钮事件控制
Biz.prototype.doOp = function (opCode) {
let self = this;
if (opCode == 'change') {
let ds = self.dsMaster;
this.onchange(self, ds);
}
if (opCode == 'actth') {
let ds = self.dsMaster;
this.onactth(self, ds);
}
if (opCode == 'actsk') {
let ds = self.dsMaster;
this.onactsk(self, ds);
}
if (opCode == 'acttk') {
let ds = self.dsMaster;
this.onacttk(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.onactth = function (biz, ds) {
let dsrow=ds.currentRow;
let ThrName = dsrow ? TypeUtil.toString(dsrow['ThrName']) : '';
if (ThrName != '') {
dsrow.setColumnError("ThrName",ThrName+"已经提货!");
return false;
}
//直接弹出窗口
let InRemark = prompt("请输入提货人姓名","");
if (InRemark.length > 0){
if (InRemark.length > 5){
dsrow.setColumnError("ThrName","提货人姓名长度不能大于5");
return false;
}
dsrow.setColumnValue('ThrName', InRemark);
dsrow.setColumnValue('ThDate', rhtComm.GetServerDate(0));
ds.save();
biz.dsMaster.updateRow();
//Store.messager.tip("提货成功!");
}
else{
dsrow.setColumnError("ThrName","必须录入提货人!");
return false;
}
return true;
};
//收款按钮
Biz.prototype.onactsk = function (biz, ds) {
if (Store.confirm("您确认要进行批发客户的收款吗?")) {
let dsrow=ds.currentRow;
let BillNo = dsrow ? TypeUtil.toString(dsrow['BillNo']) : '';
let ret= Service.getSlideMenuData("actExecute","onactsk",Store.logOn.orgCode,BillNo,Store.logOn.userId,Store.logOn.userCode,Store.logOn.userName);
if (ret.result !== 1) {
dsrow.setColumnError('BillNo', '收款失败:'+ret.message);
return false;
}
else{
Store.messager.tip('收款成功!');
biz.dsMaster.updateRow();
}
}
return true;
};
//退款按钮
Biz.prototype.onacttk = function (biz, ds) {
if (Store.confirm("您确认要进行批发客户的退款吗?")) {
let dsrow=ds.currentRow;
let BillNo = dsrow ? TypeUtil.toString(dsrow['BillNo']) : '';
//收款和退款后台都是一个过程处理 onactsk
let ret= Service.getSlideMenuData("actExecute","onactsk",Store.logOn.orgCode,BillNo,Store.logOn.userId,Store.logOn.userCode,Store.logOn.userName);
if (ret.result !== 1) {
dsrow.setColumnError('BillNo', '退款失败:'+ret.message);
return false;
}
else{
Store.messager.tip('退款成功!');
biz.dsMaster.updateRow();
}
}
return true;
};
return Biz;
});