|
@@ -14,6 +14,7 @@ class loadStageExcelTree {
|
|
|
constructor(ctx) {
|
|
|
this.ctx = ctx;
|
|
|
|
|
|
+ this.info = ctx.tender.info;
|
|
|
this.decimal = ctx.tender.info.decimal;
|
|
|
this.settleStatus = ctx.service.settle.settleStatus;
|
|
|
|
|
@@ -39,6 +40,8 @@ class loadStageExcelTree {
|
|
|
this.stagePos = source.stagePos;
|
|
|
|
|
|
this.stageBillsDgn = source.stageBillsDgn;
|
|
|
+
|
|
|
+ this.preStageBills = source.preStageBills;
|
|
|
}
|
|
|
findNode(node, parent) {
|
|
|
const _ = this.ctx.helper._;
|
|
@@ -59,6 +62,21 @@ class loadStageExcelTree {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ calcContractTp(node, contract_qty, qc_minus_qty) {
|
|
|
+ if (this.info.calc_type === 'tp') {
|
|
|
+ const preSb = this.preStageBills.find(x => { return x.lid === node.id; });
|
|
|
+ let activeQty = this.ctx.helper.add(node.quantity, qc_minus_qty);
|
|
|
+ let end_contract_qty = contract_qty;
|
|
|
+ if (preSb) {
|
|
|
+ activeQty = this.ctx.helper.add(activeQty, preSb.qc_minus_qty);
|
|
|
+ end_contract_qty = this.ctx.helper.add(end_contract_qty, preSb.contract_qty);
|
|
|
+ }
|
|
|
+ const end_contract_tp = this.ctx.helper.mul(this.ctx.helper.div(end_contract_qty, activeQty), node.total_price, this.decimal.tp);
|
|
|
+ return preSb ? this.ctx.helper.sub(end_contract_tp, preSb.pre_contract_tp) : end_contract_tp;
|
|
|
+ } else if (this.info.calc_type === 'up') {
|
|
|
+ return this.ctx.helper.mul(contract_qty, node.unit_price, this.decimal.tp);
|
|
|
+ }
|
|
|
+ }
|
|
|
loadLeaf(node, source) {
|
|
|
const curStageBills = this.stageBills.find(csb => { return csb.lid === source.id; });
|
|
|
if (node.has_pos) {
|
|
@@ -86,7 +104,7 @@ class loadStageExcelTree {
|
|
|
for (const ssp of sourceStagePos) {
|
|
|
contract_qty = this.ctx.helper.add(contract_qty, ssp.contract_qty);
|
|
|
}
|
|
|
- const contract_tp = this.ctx.helper.mul(contract_qty, source.unit_price, this.decimal.tp);
|
|
|
+ const contract_tp = this.calcContractTp(source, contract_qty, curStageBills ? curStageBills.qc_minus_qty : 0);
|
|
|
if (curStageBills) {
|
|
|
this.updateBills.push({ id: curStageBills.id, contract_qty, contract_tp, postil: node.postil || curStageBills.postil || '' });
|
|
|
} else {
|
|
@@ -99,7 +117,7 @@ class loadStageExcelTree {
|
|
|
if (!node.contract_qty && !node.contract_tp) return;
|
|
|
const contract_qty = source.is_tp ? 0 : node.contract_qty;
|
|
|
const contract_tp = contract_qty
|
|
|
- ? this.ctx.helper.mul(contract_qty, source.unit_price, this.decimal.tp)
|
|
|
+ ? this.calcContractTp(source, contract_qty, curStageBills ? curStageBills.qc_minus_qty : 0)
|
|
|
: source.is_tp ? this.ctx.helper.round(node.contract_tp, this.decimal.tp) : 0;
|
|
|
|
|
|
if (curStageBills) {
|
|
@@ -249,7 +267,20 @@ module.exports = app => {
|
|
|
return data.bills;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
async reCalcStashData(stage, data) {
|
|
|
+ const calcContractTp = function(helper, info, stageBills, bills) {
|
|
|
+ if (info.calc_type === 'tp') {
|
|
|
+ let activeQty = helper.add(bills.quantity, stageBills.qc_minus_qty);
|
|
|
+ let end_contract_qty = stageBills.contract_qty;
|
|
|
+ activeQty = helper.add(activeQty, bills.pre_qc_minus_qty);
|
|
|
+ end_contract_qty = helper.add(end_contract_qty, bills.pre_contract_qty);
|
|
|
+ const end_contract_tp = helper.mul(helper.div(end_contract_qty, activeQty), bills.total_price, decimal.tp);
|
|
|
+ return helper.sub(end_contract_tp, bills.pre_contract_tp);
|
|
|
+ } else if (info.calc_type === 'up') {
|
|
|
+ return helper.mul(bills.unit_price, stageBills.contract_qty, info.decimal.tp);
|
|
|
+ }
|
|
|
+ };
|
|
|
const decimal = this.ctx.tender.info.decimal;
|
|
|
const insertBillsData = [], insertPosData = [], insertChangeData = [];
|
|
|
const settleStatus = this.ctx.service.settle.settleStatus;
|
|
@@ -257,9 +288,11 @@ module.exports = app => {
|
|
|
const bills = await this.ctx.service.ledger.getAllDataByCondition({ where: { tender_id: stage.tid, is_leaf: true } });
|
|
|
const extraData = await this.ctx.service.ledgerExtra.getData(stage.tid, ['id', 'is_tp']);
|
|
|
const settleStatusBills = stage.readySettle ? await this.ctx.service.settleBills.getAllDataByCondition({ where: { settle_id: stage.readySettle.id }}) : [];
|
|
|
+ const preStageBills = stage.preCheckedStage ? await this.ctx.service.stageBillsFinal.getFinalData(stage.tid, this.ctx.stage.preCheckedStage.order) : [];
|
|
|
this.ctx.helper.assignRelaData(bills, [
|
|
|
{ data: extraData, fields: ['is_tp'], prefix: '', relaId: 'id' },
|
|
|
{ data: settleStatusBills, fields: ['settle_status'], prefix: '', relaId: 'lid' },
|
|
|
+ { data: preStageBills, field: ['contract_qty', 'contract_tp', 'qc_minus_qty'], prefix: 'pre_', relaId: 'lid'},
|
|
|
]);
|
|
|
const pos = await this.ctx.service.pos.getAllDataByCondition({ where: { tid: stage.tid } });
|
|
|
const settleStatusPos = stage.readySettle ? await this.ctx.service.settlePos.getAllDataByCondition({ where: { settle_id: stage.readySettle.id }}) : [];
|
|
@@ -324,7 +357,7 @@ module.exports = app => {
|
|
|
nbs.positive_qc_qty = this.ctx.helper.add(nbs.positive_qc_qty, nps.positive_qc_qty);
|
|
|
nbs.negative_qc_qty = this.ctx.helper.add(nbs.negative_qc_qty, nps.negative_qc_qty);
|
|
|
}
|
|
|
- nbs.contract_tp = this.ctx.helper.mul(nbs.contract_qty, b.unit_price, decimal.tp);
|
|
|
+ nbs.contract_tp = calcContractTp(this.ctx.helper, this.ctx.tender.info, nbs, b);
|
|
|
nbs.qc_tp = this.ctx.helper.mul(nbs.qc_qty, b.unit_price, decimal.tp);
|
|
|
nbs.positive_qc_tp = this.ctx.helper.mul(nbs.positive_qc_qty, b.unit_price, decimal.tp);
|
|
|
nbs.negative_qc_tp = this.ctx.helper.mul(nbs.negative_qc_qty, b.unit_price, decimal.tp);
|
|
@@ -333,7 +366,6 @@ module.exports = app => {
|
|
|
nbs.contract_tp = this.ctx.helper.round(d.contract_tp, decimal.tp);
|
|
|
} else {
|
|
|
nbs.contract_qty = this.ctx.helper.round(d.contract_qty, decimal.qty);
|
|
|
- nbs.contract_tp = this.ctx.helper.mul(nbs.contract_qty, b.unit_price, decimal.tp);
|
|
|
if (d.change) {
|
|
|
for (const c of d.change) {
|
|
|
if (!c.qty) continue;
|
|
@@ -353,6 +385,7 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ nbs.contract_tp = calcContractTp(this.ctx.helper, this.ctx.tender.info, nbs, b);
|
|
|
nbs.qc_tp = this.ctx.helper.mul(nbs.qc_qty, b.unit_price, decimal.tp);
|
|
|
nbs.positive_qc_tp = this.ctx.helper.mul(nbs.positive_qc_qty, b.unit_price, decimal.tp);
|
|
|
nbs.negative_qc_tp = this.ctx.helper.mul(nbs.negative_qc_qty, b.unit_price, decimal.tp);
|
|
@@ -405,7 +438,7 @@ module.exports = app => {
|
|
|
const cacheTree = analysisExcel.analysisData(excelData, tempData, { filterZeroGcl: false });
|
|
|
|
|
|
const ledgerData = await this.ctx.service.ledger.getAllDataByCondition({
|
|
|
- columns: ['id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', 'code', 'b_code', 'name', 'unit', 'unit_price'],
|
|
|
+ columns: ['id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', 'code', 'b_code', 'name', 'unit', 'unit_price', 'quantity', 'total_price'],
|
|
|
where: { tender_id: stage.tid},
|
|
|
});
|
|
|
const extraData = await this.ctx.service.ledgerExtra.getData(this.ctx.tender.id, ['is_tp']);
|
|
@@ -425,9 +458,10 @@ 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 stageBillsDgn = await this.ctx.service.stageBillsDgn.getAllDataByCondition({ where: { tid: stage.tid } });
|
|
|
+ const preStageBills = stage.preCheckedStage ? await this.ctx.service.stageBillsFinal.getFinalData(stage.tid, this.ctx.stage.preCheckedStage.order) : [];
|
|
|
|
|
|
const loadModal = new loadStageExcelTree(this.ctx);
|
|
|
- loadModal.load(cacheTree, { ledgerData, posData, stageBills, stagePos, stageBillsDgn, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } });
|
|
|
+ loadModal.load(cacheTree, { ledgerData, posData, stageBills, stagePos, stageBillsDgn, preStageBills, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } });
|
|
|
|
|
|
const conn = await this.db.beginTransaction();
|
|
|
try {
|
|
@@ -463,7 +497,7 @@ module.exports = app => {
|
|
|
dealPos.loadDatas(dealData.pos);
|
|
|
|
|
|
const ledgerData = await this.ctx.service.ledger.getAllDataByCondition({
|
|
|
- columns: ['id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', 'code', 'b_code', 'name', 'unit', 'unit_price'],
|
|
|
+ columns: ['id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', 'code', 'b_code', 'name', 'unit', 'unit_price', 'quantity', 'total_price'],
|
|
|
where: { tender_id: stage.tid},
|
|
|
});
|
|
|
const extraData = await this.ctx.service.ledgerExtra.getData(this.ctx.tender.id, ['is_tp']);
|
|
@@ -483,9 +517,10 @@ 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 stageBillsDgn = await this.ctx.service.stageBillsDgn.getAllDataByCondition({ where: { tid: stage.tid } });
|
|
|
+ const preStageBills = stage.preCheckedStage ? await this.ctx.service.stageBillsFinal.getFinalData(stage.tid, this.ctx.stage.preCheckedStage.order) : [];
|
|
|
|
|
|
const loadModal = new loadStageExcelTree(this.ctx);
|
|
|
- loadModal.loadDeal(dealTree, dealPos, { ledgerData, posData, stageBills, stagePos, stageBillsDgn, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } });
|
|
|
+ loadModal.loadDeal(dealTree, dealPos, { ledgerData, posData, stageBills, stagePos, stageBillsDgn, preStageBills, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } });
|
|
|
|
|
|
const conn = await this.db.beginTransaction();
|
|
|
try {
|