|
@@ -67,33 +67,6 @@ module.exports = app => {
|
|
|
this.tableName = 'report_memory';
|
|
|
// 基础数据类
|
|
|
// mainData
|
|
|
- this.billsTree = new Ledger.billsTree(this.ctx, {
|
|
|
- id: 'ledger_id',
|
|
|
- pid: 'ledger_pid',
|
|
|
- order: 'order',
|
|
|
- level: 'level',
|
|
|
- rootId: -1,
|
|
|
- keys: ['id', 'tender_id', 'ledger_id'],
|
|
|
- stageId: 'id',
|
|
|
- calcFields: ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'],
|
|
|
- calc: function (node) {
|
|
|
- if (node.children && node.children.length === 0) {
|
|
|
- node.pre_gather_qty = self.ctx.helper.add(node.pre_contract_qty, node.pre_qc_qty);
|
|
|
- node.gather_qty = self.ctx.helper.add(node.contract_qty, node.qc_qty);
|
|
|
- node.end_contract_qty = self.ctx.helper.add(node.pre_contract_qty, node.contract_qty);
|
|
|
- node.end_qc_qty = self.ctx.helper.add(node.pre_qc_qty, node.qc_qty);
|
|
|
- node.end_gather_qty = self.ctx.helper.add(node.pre_gather_qty, node.gather_qty);
|
|
|
- }
|
|
|
- node.pre_gather_tp = self.ctx.helper.add(node.pre_contract_tp, node.pre_qc_tp);
|
|
|
- node.gather_tp = self.ctx.helper.add(node.contract_tp, node.qc_tp);
|
|
|
- node.end_contract_tp = self.ctx.helper.add(node.pre_contract_tp, node.contract_tp);
|
|
|
- node.end_qc_tp = self.ctx.helper.add(node.pre_qc_tp, node.qc_tp);
|
|
|
- node.end_gather_tp = self.ctx.helper.add(node.pre_gather_tp, node.gather_tp);
|
|
|
-
|
|
|
- node.final_tp = self.ctx.helper.add(node.total_price, node.end_qc_tp);
|
|
|
- node.final_ratio = self.ctx.helper.mul(self.ctx.helper.div(node.end_gather_tp, node.final_tp, 4), 100);
|
|
|
- }
|
|
|
- });
|
|
|
this.pos = new Ledger.pos({
|
|
|
id: 'id', ledgerId: 'lid',
|
|
|
updateFields: ['contract_qty', 'qc_qty', 'postil'],
|
|
@@ -111,6 +84,36 @@ module.exports = app => {
|
|
|
this.stageValidRole = [];
|
|
|
}
|
|
|
|
|
|
+ _getNewBillsTree(calcFields) {
|
|
|
+ return new Ledger.billsTree(this.ctx, {
|
|
|
+ id: 'ledger_id',
|
|
|
+ pid: 'ledger_pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ rootId: -1,
|
|
|
+ keys: ['id', 'tender_id', 'ledger_id'],
|
|
|
+ stageId: 'id',
|
|
|
+ calcFields: calcFields || ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'],
|
|
|
+ calc: function (node, helper) {
|
|
|
+ if (node.children && node.children.length === 0) {
|
|
|
+ node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty);
|
|
|
+ node.gather_qty = helper.add(node.contract_qty, node.qc_qty);
|
|
|
+ node.end_contract_qty = helper.add(node.pre_contract_qty, node.contract_qty);
|
|
|
+ node.end_qc_qty = helper.add(node.pre_qc_qty, node.qc_qty);
|
|
|
+ node.end_gather_qty = helper.add(node.pre_gather_qty, node.gather_qty);
|
|
|
+ }
|
|
|
+ node.pre_gather_tp = helper.add(node.pre_contract_tp, node.pre_qc_tp);
|
|
|
+ node.gather_tp = helper.add(node.contract_tp, node.qc_tp);
|
|
|
+ node.end_contract_tp = helper.add(node.pre_contract_tp, node.contract_tp);
|
|
|
+ node.end_qc_tp = helper.add(node.pre_qc_tp, node.qc_tp);
|
|
|
+ node.end_gather_tp = helper.add(node.pre_gather_tp, node.gather_tp);
|
|
|
+
|
|
|
+ node.final_tp = helper.add(node.total_price, node.end_qc_tp);
|
|
|
+ node.final_ratio = helper.mul(helper.div(node.end_gather_tp, node.final_tp, 4), 100);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
_checkFieldsExist(source, check) {
|
|
|
for (const s of source) {
|
|
|
if (check.indexOf(s) >= 0) {
|
|
@@ -321,7 +324,7 @@ module.exports = app => {
|
|
|
return monthProgress;
|
|
|
}
|
|
|
|
|
|
- async _calcBillsBgl() {
|
|
|
+ async _calcBillsBgl(billsTree) {
|
|
|
if (!this.ctx.stage) return;
|
|
|
|
|
|
const helper = this.ctx.helper;
|
|
@@ -331,7 +334,7 @@ module.exports = app => {
|
|
|
? await this.ctx.service.stageChange.getAuditorAllStageData(tender.id, stage.id, stage.curTimes, stage.curOrder)
|
|
|
: await this.ctx.service.stageChange.getLastestAllStageData(tender.id, stage.id);
|
|
|
|
|
|
- for (const node of this.billsTree.nodes) {
|
|
|
+ for (const node of billsTree.nodes) {
|
|
|
node.qc_bgl_code = '';
|
|
|
if (node.children && node.children.length > 0) continue;
|
|
|
|
|
@@ -345,10 +348,10 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- _calcLeafXmjRela() {
|
|
|
- for (const node of this.billsTree.nodes) {
|
|
|
+ _calcLeafXmjRela(billsTree) {
|
|
|
+ for (const node of billsTree.nodes) {
|
|
|
if (node.b_code) {
|
|
|
- const leafXmj = this.billsTree.getLeafXmjParent(node);
|
|
|
+ const leafXmj = billsTree.getLeafXmjParent(node);
|
|
|
node.leaf_xmj_id = leafXmj ? leafXmj.id : -1;
|
|
|
}
|
|
|
}
|
|
@@ -390,19 +393,20 @@ module.exports = app => {
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- this.billsTree.loadDatas(billsData);
|
|
|
- this.billsTree.setting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'];
|
|
|
- this.billsTree.calculateAll();
|
|
|
+ const billsTree = this._getNewBillsTree();
|
|
|
+ billsTree.loadDatas(billsData);
|
|
|
+ billsTree.calculateAll();
|
|
|
|
|
|
if (this._checkFieldsExist(fields, billsFields.bgl)) {
|
|
|
- await this._calcBillsBgl();
|
|
|
+ await this._calcBillsBgl(billsTree);
|
|
|
}
|
|
|
|
|
|
if (this._checkFieldsExist(fields, billsFields.leafXmj)) {
|
|
|
- this._calcLeafXmjRela();
|
|
|
+ this._calcLeafXmjRela(billsTree);
|
|
|
}
|
|
|
|
|
|
- return this.billsTree.getDatas([
|
|
|
+ console.log(billsTree.nodes.length);
|
|
|
+ return billsTree.getDatas([
|
|
|
'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
|
|
|
'code', 'b_code', 'name', 'unit', 'unit_price',
|
|
|
'deal_qty', 'deal_tp',
|
|
@@ -420,6 +424,7 @@ module.exports = app => {
|
|
|
'deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2',
|
|
|
]);
|
|
|
} catch(err) {
|
|
|
+ console.log(err);
|
|
|
return []
|
|
|
}
|
|
|
}
|
|
@@ -554,15 +559,15 @@ module.exports = app => {
|
|
|
{data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
|
|
|
]);
|
|
|
}
|
|
|
- this.billsTree.loadDatas(billsData);
|
|
|
+ const billsTree = this._getNewBillsTree();
|
|
|
+ billsTree.loadDatas(billsData);
|
|
|
|
|
|
- this.billsTree.setting.calcFields = ['deal_tp', 'total_price', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'];
|
|
|
for (const role of validRole) {
|
|
|
const prefix = 'r' + role.flowOrder + '_';
|
|
|
- this.billsTree.setting.calcFields.push(prefix + 'contract_tp', prefix + 'qc_tp', prefix + 'gather_tp');
|
|
|
+ billsTree.setting.calcFields.push(prefix + 'contract_tp', prefix + 'qc_tp', prefix + 'gather_tp');
|
|
|
}
|
|
|
|
|
|
- this.billsTree.calculateAll(function(node) {
|
|
|
+ billsTree.calculateAll(function(node) {
|
|
|
let prefix = '';
|
|
|
if (node.children && node.children.length === 0) {
|
|
|
node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty);
|
|
@@ -579,11 +584,11 @@ module.exports = app => {
|
|
|
});
|
|
|
|
|
|
if (this._checkFieldsExist(fields, billsFields.leafXmj)) {
|
|
|
- this._calcLeafXmjRela();
|
|
|
+ this._calcLeafXmjRela(billsTree);
|
|
|
}
|
|
|
|
|
|
- return this.billsTree.getDefaultDatas();
|
|
|
- // return this.billsTree.getDatas([
|
|
|
+ return billsTree.getDefaultDatas();
|
|
|
+ // return billsTree.getDatas([
|
|
|
// 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', //8
|
|
|
// 'code', 'b_code', 'name', 'unit', 'unit_price', //5
|
|
|
// 'deal_qty', 'deal_tp', 'quantity', 'total_price', 'dgn_qty1', 'dgn_qty2', //6
|