|
@@ -100,10 +100,36 @@ class autoUseChange {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ _calculateQty(detail, minus, bills) {
|
|
|
+ if (bills.is_valuation) {
|
|
|
+ detail.qty = this.helper.add(detail.qty, bills.valid_qty);
|
|
|
+ if (minus) {
|
|
|
+ detail.negative_qc_qty = this.helper.add(detail.negative_qc_qty, bills.valid_qty);
|
|
|
+ } else {
|
|
|
+ detail.positive_qc_qty = this.helper.add(detail.positive_qc_qty, bills.valid_qty);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ detail.qc_minus_qty = this.helper.add(detail.qc_minus_qty, bills.valid_qty);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _calculateUsedQty(detail, bills) {
|
|
|
+ if (!bills.no_value) {
|
|
|
+ detail.qty = this.helper.add(detail.qty, bills.qty);
|
|
|
+ if (detail.minus) {
|
|
|
+ detail.negative_qc_qty = this.helper.add(detail.negative_qc_qty, bills.qty);
|
|
|
+ } else {
|
|
|
+ detail.positive_qc_qty = this.helper.add(detail.positive_qc_qty, bills.qty);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ detail.qc_minus_qty = this.helper.add(detail.qc_minus_qty, bills.valid_qty);
|
|
|
+ }
|
|
|
+ }
|
|
|
useBills(bills) {
|
|
|
if (bills.billsPos) bills.billsPos.bills = this.ledgerTree.datas.find(x => {return x.id === bills.billsPos.lid; });
|
|
|
const billsPos = bills.billsPos || this.findBillsPos(bills);
|
|
|
if (!billsPos) return;
|
|
|
+ if (!this.minusNoValue && !bills.is_valuation) return;
|
|
|
+
|
|
|
const bamount = parseFloat(bills.samount);
|
|
|
const minus = bamount < 0;
|
|
|
this.changeDetail.push({
|
|
@@ -112,31 +138,20 @@ class autoUseChange {
|
|
|
qty: bills.valid_qty, stimes: 1, sorder: 0, unit_price: bills.unit_price, minus, no_value: !bills.is_valuation,
|
|
|
});
|
|
|
|
|
|
- if (!bills.is_valuation) return;
|
|
|
if (billsPos.pid !== '-1') {
|
|
|
let cp = this.changePos[billsPos.pid];
|
|
|
if (!cp) {
|
|
|
- cp = { lid: billsPos.lid, pid: billsPos.pid, qty: 0, bills: billsPos.bills };
|
|
|
- this.changePos[billsPos.pid] = cp
|
|
|
- }
|
|
|
- cp.qty = this.helper.add(cp.qty, bills.valid_qty);
|
|
|
- if (minus) {
|
|
|
- cp.negative_qc_qty = cp.qty;
|
|
|
- } else {
|
|
|
- cp.positive_qc_qty = cp.qty;
|
|
|
+ cp = { lid: billsPos.lid, pid: billsPos.pid, qty: 0, negative_qc_qty: 0, positive_qc_qty: 0, qc_minus_qty: 0, bills: billsPos.bills };
|
|
|
+ this.changePos[billsPos.pid] = cp;
|
|
|
}
|
|
|
+ this._calculateQty(cp, minus, bills);
|
|
|
} else {
|
|
|
let cb = this.changeBills[billsPos.lid];
|
|
|
if (!cb) {
|
|
|
cb = { lid: billsPos.lid, qty: 0, bills: billsPos.bills };
|
|
|
this.changeBills[billsPos.lid] = cb;
|
|
|
}
|
|
|
- cb.qty = this.helper.add(cb.qty, bills.valid_qty);
|
|
|
- if (minus) {
|
|
|
- cb.negative_qc_qty = this.helper.add(cb.negative_qc_qty, bills.valid_qty);
|
|
|
- } else {
|
|
|
- cb.positive_qc_qty = this.helper.add(cb.positive_qc_qty, bills.valid_qty);
|
|
|
- }
|
|
|
+ this._calculateQty(cb, minus, bills);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -154,16 +169,8 @@ class autoUseChange {
|
|
|
}
|
|
|
}
|
|
|
for (const sc of this.stageChange) {
|
|
|
- if (sc.no_value) continue;
|
|
|
const cp = this.changePos[sc.pid];
|
|
|
- if (cp) {
|
|
|
- cp.qty = this.helper.add(cp.qty, sc.qty);
|
|
|
- if (sc.minus) {
|
|
|
- cp.negative_qc_qty = this.helper.add(cp.negative_qc_qty, sc.qty);
|
|
|
- } else {
|
|
|
- cp.positive_qc_qty = this.helper.add(cp.positive_qc_qty, sc.qty);
|
|
|
- }
|
|
|
- }
|
|
|
+ if (cp) this._calculateUsedQty(cp, sc);
|
|
|
}
|
|
|
for (const pid in this.changePos) {
|
|
|
const cp = this.changePos[pid];
|
|
@@ -173,37 +180,31 @@ class autoUseChange {
|
|
|
const qc_qty = this.helper.round(cp.qty, precision.value);
|
|
|
const positive_qc_qty = this.helper.round(cp.positive_qc_qty || 0, precision.value);
|
|
|
const negative_qc_qty = this.helper.round(cp.negative_qc_qty || 0, precision.value);
|
|
|
+ const qc_minus_qty = this.helper.round(cp.qc_minus_qty || 0, precision.value);
|
|
|
const sp = this.stagePos.find(x => {return x.pid === pid});
|
|
|
if (sp) {
|
|
|
- this.updatePos.push({ id: sp.id, qc_qty, positive_qc_qty, negative_qc_qty });
|
|
|
+ this.updatePos.push({ id: sp.id, qc_qty, positive_qc_qty, negative_qc_qty, qc_minus_qty });
|
|
|
} else {
|
|
|
this.insertPos.push({
|
|
|
tid: this.default.tid, sid: this.default.sid, said: this.default.said,
|
|
|
- lid: cp.lid, pid, qc_qty, positive_qc_qty, negative_qc_qty, times: 1, order: 0
|
|
|
+ lid: cp.lid, pid, qc_qty, positive_qc_qty, negative_qc_qty, qc_minus_qty, times: 1, order: 0
|
|
|
});
|
|
|
}
|
|
|
const cb = this.changeBills[cp.lid];
|
|
|
if (!cb) {
|
|
|
- this.changeBills[cp.lid] = { lid: cp.lid, qty: qc_qty, positive_qc_qty, negative_qc_qty, bills: cp.bills };
|
|
|
+ this.changeBills[cp.lid] = { lid: cp.lid, qty: qc_qty, positive_qc_qty, negative_qc_qty, qc_minus_qty, bills: cp.bills };
|
|
|
} else {
|
|
|
cb.qty = this.helper.add(cb.qty, qc_qty);
|
|
|
cb.positive_qc_qty = this.helper.add(cb.positive_qc_qty, positive_qc_qty);
|
|
|
cb.negative_qc_qty = this.helper.add(cb.negative_qc_qty, negative_qc_qty);
|
|
|
+ cb.qc_minus_qty = this.helper.add(cb.qc_minus_qty, qc_minus_qty);
|
|
|
}
|
|
|
}
|
|
|
for (const sc of this.stageChange) {
|
|
|
- if (sc.no_value) continue;
|
|
|
const cp = this.changePos[sc.pid];
|
|
|
if (cp) continue;
|
|
|
const cb = this.changeBills[sc.lid];
|
|
|
- if (cb) {
|
|
|
- cb.qty = this.helper.add(cb.qty, sc.qty);
|
|
|
- if (sc.minus) {
|
|
|
- cb.negative_qc_qty = this.helper.add(cb.negative_qc_qty, sc.qty);
|
|
|
- } else {
|
|
|
- cb.positive_qc_qty = this.helper.add(cb.positive_qc_qty, sc.qty);
|
|
|
- }
|
|
|
- }
|
|
|
+ if (cb) this._calculateUsedQty(cb, sc);
|
|
|
}
|
|
|
for (const lid in this.changeBills) {
|
|
|
const cb = this.changeBills[lid];
|
|
@@ -215,20 +216,22 @@ class autoUseChange {
|
|
|
const positive_qc_tp = this.helper.mul(positive_qc_qty, cb.bills.unit_price, this.decimal.tp);
|
|
|
const negative_qc_qty = this.helper.round(cb.negative_qc_qty || 0, precision.value);
|
|
|
const negative_qc_tp = this.helper.mul(negative_qc_qty, cb.bills.unit_price, this.decimal.tp);
|
|
|
+ const qc_minus_qty = this.helper.round(cb.qc_minus_qty || 0, precision.value);
|
|
|
const sb = this.stageBills.find(x => {return x.lid === lid});
|
|
|
if (sb) {
|
|
|
- this.updateBills.push({ id: sb.id, qc_qty, qc_tp, positive_qc_qty, positive_qc_tp, negative_qc_qty, negative_qc_tp });
|
|
|
+ this.updateBills.push({ id: sb.id, qc_qty, qc_tp, positive_qc_qty, positive_qc_tp, negative_qc_qty, negative_qc_tp, qc_minus_qty });
|
|
|
} else {
|
|
|
this.insertBills.push({
|
|
|
tid: this.default.tid, sid: this.default.sid, said: this.default.said,
|
|
|
- lid, qc_qty, qc_tp, positive_qc_qty, positive_qc_tp, negative_qc_qty, negative_qc_tp, times: 1, order: 0
|
|
|
+ lid, qc_qty, qc_tp, positive_qc_qty, positive_qc_tp, negative_qc_qty, negative_qc_tp, qc_minus_qty, times: 1, order: 0
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- use(source, validChangeBills) {
|
|
|
+ use(source, validChangeBills, minusNoValue) {
|
|
|
this.init(source);
|
|
|
+ this.minusNoValue = minusNoValue;
|
|
|
|
|
|
for (const bills of validChangeBills) {
|
|
|
this.useBills(bills);
|
|
@@ -806,7 +809,9 @@ module.exports = app => {
|
|
|
const stageChange = await this.ctx.service.stageChange.getAllDataByCondition({ where: { sid: stage.id, lid }});
|
|
|
|
|
|
const useModal = new autoUseChange(this.ctx.helper, tender.info);
|
|
|
- useModal.use({ledgerData, posData, stageBills, stagePos, stageChange, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills);
|
|
|
+ const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
|
|
|
+ const minusNoValue = projectFunInfo.minusNoValue && ctx.tender.info.fun_rela.stage_change.minusNoValue;
|
|
|
+ useModal.use({ledgerData, posData, stageBills, stagePos, stageChange, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills, minusNoValue);
|
|
|
|
|
|
const conn = await this.db.beginTransaction();
|
|
|
try {
|
|
@@ -853,7 +858,9 @@ module.exports = app => {
|
|
|
const stageBills = await this.ctx.service.stageBills.getAllDataByCondition({ where: { sid: stage.id } });
|
|
|
const stagePos = await this.ctx.service.stagePos.getAllDataByCondition({ where: { sid: stage.id } });
|
|
|
const useModal = new autoUseChange(this.ctx.helper, tender.info, this.ctx.service.settle.settleStatus);
|
|
|
- useModal.use({ledgerData, posData, stageBills, stagePos, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills);
|
|
|
+ const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
|
|
|
+ const minusNoValue = projectFunInfo.minusNoValue && ctx.tender.info.fun_rela.stage_change.minusNoValue;
|
|
|
+ useModal.use({ledgerData, posData, stageBills, stagePos, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills, minusNoValue);
|
|
|
|
|
|
// if (useModal.insertChange.length === 0) return '无可调用的清单或计量单元';
|
|
|
|