ebu_ecology_dev1/javascript/xuanran.wang/bme/js/PayApply.js

160 lines
6.5 KiB
JavaScript
Raw Normal View History

2023-03-15 13:50:48 +08:00
// 主表预计付款日期
const yjfksj = WfForm.convertFieldNameToId('yjfksj');
// 主表比例
const bl = WfForm.convertFieldNameToId('bcfkbl');
// 明细要求付款日期
const detail3Yqfkrq = WfForm.convertFieldNameToId('yqfkrq', "detail_3");
2023-03-15 13:50:48 +08:00
// 明细本次付款比例
const detailBl = WfForm.convertFieldNameToId('bcfkbl', "detail_3");
// 关联订单
const relationOrder = WfForm.convertFieldNameToId("gldd");
// 明细4施工合同字段
const detail4SgField = WfForm.convertFieldNameToId("sght", "detail_4");
// 明细4采购合同字段
const detail4CgField = WfForm.convertFieldNameToId("cght", "detail_4");
// 明细4发票字段
const detail4FpField = WfForm.convertFieldNameToId("fpje", "detail_4");
// 明细4合同发票金额和
let detail4Map = new Map();
// 明细3施工合同字段
const detail3SgField = WfForm.convertFieldNameToId("sght", "detail_3");
// 明细3采购合同字段
const detail3CgField = WfForm.convertFieldNameToId("cght", "detail_3");
// 明细3 含税金额
const detail3TaxField = WfForm.convertFieldNameToId("ddhsje", "detail_3");
// 明细3以收票金额
const detail3YspField = WfForm.convertFieldNameToId("yspje", "detail_3");
2023-03-15 13:50:48 +08:00
WfForm.registerCheckEvent(WfForm.OPER_ADDROW + "3", function (callback) {
callback();
setTimeout(() => {
initDeatail3Date();
}, 5)
});
// 关联订单变化时将明细四的合同-金额map进行初始化
WfForm.bindFieldChangeEvent(relationOrder, function (obj, id, value) {
setTimeout(() => {
initDetail4Map();
changeDetail3SpMoney();
}, 2000);
2023-03-15 13:50:48 +08:00
});
WfForm.bindFieldChangeEvent(`${yjfksj},${bl}`, function (obj, id, value) {
2023-03-15 13:50:48 +08:00
initDeatail3Date();
});
// 计算明细三开票金额
function changeDetail3SpMoney() {
let detail3RowArr = WfForm.getDetailAllRowIndexStr('detail_3').split(",");
for (let i = 0; i < detail3RowArr.length; i++) {
let rowIndex = detail3RowArr[i];
if (rowIndex !== "") {
let detail3SgFieldVal = WfForm.getFieldValue(`${detail3SgField}_${rowIndex}`);
let detail3CgFieldVal = WfForm.getFieldValue(`${detail3CgField}_${rowIndex}`);
let fpje = detail4Map.get(detail3SgFieldVal) ?? detail4Map.get(detail3CgFieldVal);
let mapVal = detail4Map.get(detail3SgFieldVal);
let key = detail3SgFieldVal;
if (!mapVal) {
key = detail3CgFieldVal;
}
console.log('key ', key);
if (fpje) {
console.log('fpje => ', fpje);
// 0.1 0.3
let detail3TaxVal = WfForm.getFieldValue(`${detail3TaxField}_${rowIndex}`);
console.log('detail3TaxVal => ', detail3TaxVal);
let tempJe = fpje - detail3TaxVal;
console.log('tempJe => ', tempJe);
if (fpje > detail3TaxVal) {
WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: detail3TaxVal});
} else if (tempJe <= 0 && fpje == 0) {
WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: 0});
} else if (tempJe < 0) {
WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: fpje});
tempJe = 0;
}
detail4Map.set(key, tempJe);
console.log('detail4Map ', detail4Map)
} else {
WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: 0});
}
}
}
}
function initDeatail3Date() {
2023-03-15 13:50:48 +08:00
let dateVal = WfForm.getFieldValue(yjfksj);
let blVal = WfForm.getFieldValue(bl);
let detail3RowArr = WfForm.getDetailAllRowIndexStr('detail_3').split(",");
for (let i = 0; i < detail3RowArr.length; i++) {
let rowIndex = detail3RowArr[i];
if (rowIndex !== "") {
WfForm.changeFieldValue(`${detail3Yqfkrq}_${rowIndex}`, {value: dateVal});
WfForm.changeFieldValue(`${detailBl}_${rowIndex}`, {value: blVal});
}
}
}
function initDetail4Map() {
let detail4RowArr = WfForm.getDetailAllRowIndexStr('detail_4').split(",");
console.log('detail4RowArr ', detail4RowArr);
for (let i = 0; i < detail4RowArr.length; i++) {
let rowIndex = detail4RowArr[i];
if (rowIndex !== "") {
let detail4SgFieldVal = WfForm.getFieldValue(`${detail4SgField}_${rowIndex}`);
let detail4CgFieldVal = WfForm.getFieldValue(`${detail4CgField}_${rowIndex}`);
let detail4FpFieldVal = WfForm.getFieldValue(`${detail4FpField}_${rowIndex}`);
let key = -1;
console.log('detail4SgFieldVal ', detail4SgFieldVal);
console.log('detail4CgFieldVal ', detail4CgFieldVal);
console.log('detail4FpFieldVal ', detail4FpFieldVal);
if (!detail4FpFieldVal) {
continue;
}
key = detail4CgFieldVal ?? detail4SgFieldVal;
console.log('key ', key);
let tempVal = parseFloat(detail4Map.get(key) ?? 0);
tempVal += parseFloat(detail4FpFieldVal);
detail4Map.set(key, tempVal);
2023-03-15 13:50:48 +08:00
}
}
console.log('detail4Map ', detail4Map)
}
const detail3ApplyMoneyField = WfForm.convertFieldNameToId("bcfkje", "detail_3");
const detail3CgId = WfForm.convertFieldNameToId("cgddzbid", "detail_3");
const detail3Bl = WfForm.convertFieldNameToId('bcfkbl', "detail_3");
let detailBlMap = new Map();
const detail1Bl = WfForm.convertFieldNameToId('fkbl', "detail_1");
const detail1CgId = WfForm.convertFieldNameToId("cgddzbid", "detail_1");
WfForm.bindDetailFieldChangeEvent(detail3ApplyMoneyField, (id, rowIndex, value) => {
let detail3RowArr = WfForm.getDetailAllRowIndexStr('detail_3').split(",");
detailBlMap = new Map();
for (let i = 0; i < detail3RowArr.length; i++) {
let rowIndex = detail3RowArr[i];
if (rowIndex !== "") {
let bl = parseFloat(WfForm.getFieldValue(`${detail3Bl}_${rowIndex}`));
let cg = WfForm.getFieldValue(`${detail3CgId}_${rowIndex}`);
let mapVal = parseFloat(detailBlMap.get(cg) ?? 0) + bl;
detailBlMap.set(cg, mapVal);
}
}
console.log('detailBlMap ', detailBlMap)
let detail1RowArr = WfForm.getDetailAllRowIndexStr('detail_1').split(",");
for (let i = 0; i < detail1RowArr.length; i++) {
let rowIndex = detail1RowArr[i];
if (rowIndex !== "") {
let cg = WfForm.getFieldValue(`${detail1CgId}_${rowIndex}`);
let val = detailBlMap.get(cg) === '' ? 0 : detailBlMap.get(cg);
WfForm.changeFieldValue(`${detail1Bl}_${rowIndex}`, {value: val})
}
}
});