|
|
@@ -212,11 +212,8 @@ module.exports = app => {
|
|
|
const insertData = [], insertDetailData = [];
|
|
|
let maxId = 0;
|
|
|
|
|
|
- const preBills = await this.getAllDataByCondition({
|
|
|
- where: { stage_id: preStage.id },
|
|
|
- columns: costFields.readQueryFields
|
|
|
- });
|
|
|
- const preLedger = Ledger.baseTree(this.ctx, {
|
|
|
+ const preBills = await this.getReadData(preStage);
|
|
|
+ const preLedger = new Ledger.baseTree(this.ctx, {
|
|
|
id: 'tree_id', pid: 'tree_pid', order: 'tree_order',
|
|
|
level: 'tree_level', isLeaf: 'tree_is_leaf', fullPath: 'tree_full_path',
|
|
|
rootId: -1, calcField: [],
|
|
|
@@ -232,6 +229,7 @@ module.exports = app => {
|
|
|
const idata = {};
|
|
|
this._getDefaultData(idata, stage);
|
|
|
idata.cost_id = pl.cost_id;
|
|
|
+ idata.node_type = pl.node_type;
|
|
|
for (const prop of costFields.preCopyFields) {
|
|
|
idata[prop] = pl[prop];
|
|
|
}
|
|
|
@@ -239,7 +237,7 @@ module.exports = app => {
|
|
|
insertData.push(idata);
|
|
|
}
|
|
|
|
|
|
- const relaStage = await this.service.costStage.getStage(stage.rela_stage.sid);
|
|
|
+ const relaStage = await this.service.costStage.getStage(JSON.parse(stage.rela_stage).sid);
|
|
|
const costStageLedger = await this.getCostStageData(relaStage);
|
|
|
const costNode = insertData.find(x => { return x.node_type === 2 && x.tree_level === 1; });
|
|
|
if (costStageLedger.nodes.length > 0) costNode.tree_is_leaf = 0;
|
|
|
@@ -261,15 +259,17 @@ module.exports = app => {
|
|
|
ln.name = node.name;
|
|
|
ln.unit = node.unit;
|
|
|
ln.tax = node.tax;
|
|
|
- ln.yf_excl_tax_tp = node.end_yf_excl_tax_tp;
|
|
|
- ln.in_excl_tax_tp = node.end_in_excl_tax_tp;
|
|
|
- ln.sf_excl_tax_tp = node.end_sf_excl_tax_tp;
|
|
|
+ ln.yf_excl_tax_tp = node.end_yf_excl_tax_tp || 0;
|
|
|
+ ln.in_excl_tax_tp = node.end_in_excl_tax_tp || 0;
|
|
|
+ ln.sf_excl_tax_tp = node.end_sf_excl_tax_tp || 0;
|
|
|
+ ln.postil = '';
|
|
|
+ ln.sf_percent = 0;
|
|
|
insertData.push(ln);
|
|
|
const preSource = preLedger.nodes.find(x => { return x.cost_id === node.cost_id; });
|
|
|
for (const prop of costFields.selfTextFields) {
|
|
|
ln[prop] = preSource ? preSource[prop] : '';
|
|
|
}
|
|
|
- if (!node.detail) {
|
|
|
+ if (!node.detail || node.detail.length === 0) {
|
|
|
for (const prop of costFields.selfCalcFields) {
|
|
|
ln[prop] = preSource ? preSource[prop] : 0;
|
|
|
}
|
|
|
@@ -281,15 +281,15 @@ module.exports = app => {
|
|
|
ledger_id: ln.id, cost_id: ln.cost_id, source_id: d.source_cid,
|
|
|
d_order: i+1,
|
|
|
code: d.code, name: d.name, party_b: d.party_b || '', tax: ln.tax || 0,
|
|
|
- yf_excl_tax_tp: d.yf_excl_tax_tp, in_excl_tax_tp: d.in_excl_tax_tp, sf_excl_tax_tp: d.sf_excl_tax_tp,
|
|
|
+ yf_excl_tax_tp: d.yf_excl_tax_tp || 0, in_excl_tax_tp: d.in_excl_tax_tp || 0, sf_excl_tax_tp: d.sf_excl_tax_tp || 0,
|
|
|
is_deal: d.is_deal,
|
|
|
};
|
|
|
- const preDetailSource = preSource ? preSource.detail.find(x => { return x.source_id === d.source_cid; }) : null;
|
|
|
+ const preDetailSource = preSource ? preSource.detail.find(x => { return x.source_id === d.source_cid; }) : undefined;
|
|
|
for (const prop of costFields.selfTextFields) {
|
|
|
ld[prop] = preDetailSource ? preDetailSource[prop] : '';
|
|
|
}
|
|
|
for (const prop of costFields.selfCalcFields) {
|
|
|
- ld[prop] = preDetailSource ? preDetailSource[prop] : 0;
|
|
|
+ ld[prop] = preDetailSource ? preDetailSource[prop] || 0 : 0;
|
|
|
ln[prop] = this.ctx.helper.add(ln[prop], ld[prop]);
|
|
|
}
|
|
|
insertDetailData.push(ld);
|
|
|
@@ -675,8 +675,20 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
async getSum(stage) {
|
|
|
- const sumFields = costFields.calcFields.map(f => { return `SUM(${f}) AS ${f}`});
|
|
|
- const result = await this.db.queryOne(`SELECT ${sumFields.join(', ')} FROM ${this.tableName} where stage_id = ?`, [stage.id]);
|
|
|
+ const field = 'num_h';
|
|
|
+ const topNode = await this.db.query(`SELECT * FROM ${this.tableName} where stage_id = ? and tree_level = 1`, [stage.id]);
|
|
|
+ const result = {};
|
|
|
+ for (const tn of topNode) {
|
|
|
+ if (topNode.node_type === 2) {
|
|
|
+ result.out_tp = tn[field];
|
|
|
+ } else if (topNode.node_type === 3) {
|
|
|
+ result.profit = tn[field];
|
|
|
+ } else if (topNode.node_type === 4) {
|
|
|
+ result.profit_percent = tn[field];
|
|
|
+ } else {
|
|
|
+ result.in_tp = tn[field];
|
|
|
+ }
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
}
|