|
@@ -24,6 +24,31 @@ const stageImVersion = '1.0';
|
|
|
|
|
|
const Ledger = require('../lib/ledger');
|
|
|
|
|
|
+const billsFields = (function () {
|
|
|
+ const cur = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil'];
|
|
|
+ const pre = ['pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp'];
|
|
|
+ const end = ['end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp'];
|
|
|
+ const final = ['final_tp', 'final_ratio'];
|
|
|
+
|
|
|
+ const stage = cur.concat(pre, end, final);
|
|
|
+ const stageEnd = pre.concat(end, final);
|
|
|
+ const bgl = ['qc_bgl_code'];
|
|
|
+
|
|
|
+ return {cur, pre, end, final, stage, stageEnd, bgl};
|
|
|
+})();
|
|
|
+const posFields = (function () {
|
|
|
+ const cur = ['contract_qty', 'qc_qty', 'gather_qty', 'postil'];
|
|
|
+ const pre = ['pre_contract_qty', 'pre_qc_qty', 'pre_gather_qty'];
|
|
|
+ const end = ['end_contract_qty', 'end_qc_qty', 'end_gather_qty'];
|
|
|
+ const final = ['final_ratio'];
|
|
|
+
|
|
|
+ const stage = cur.concat(pre, end, final);
|
|
|
+ const stageEnd = pre.concat(end, final);
|
|
|
+ const bgl = ['qc_bgl_code'];
|
|
|
+
|
|
|
+ return {cur, pre, end, final, stage, stageEnd, bgl};
|
|
|
+})();
|
|
|
+
|
|
|
const curFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil'];
|
|
|
const preFields = ['pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp'];
|
|
|
const endFields = ['end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp'];
|
|
@@ -89,6 +114,7 @@ module.exports = app => {
|
|
|
// 需要缓存的数据
|
|
|
this.stageImData = null;
|
|
|
this.changeData = null;
|
|
|
+ this.stageValidRole = [];
|
|
|
}
|
|
|
|
|
|
_checkFieldsExist(source, check) {
|
|
@@ -342,7 +368,7 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
|
|
|
- if (this._checkFieldsExist(fields, stageFields)) {
|
|
|
+ if (this._checkFieldsExist(fields, billsFields.stage)) {
|
|
|
if (this.ctx.stage.readOnly) {
|
|
|
const curStage = await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id,
|
|
|
this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
|
|
@@ -356,7 +382,7 @@ module.exports = app => {
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
- if (this._checkFieldsExist(fields, preFields.concat(endFields, finalFields))) {
|
|
|
+ if (this._checkFieldsExist(fields, billsFields.stageEnd)) {
|
|
|
const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
|
|
|
this.ctx.helper.assignRelaData(billsData, [
|
|
|
{data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
|
|
@@ -365,7 +391,7 @@ module.exports = app => {
|
|
|
this.billsTree.loadDatas(billsData);
|
|
|
this.billsTree.calculateAll();
|
|
|
|
|
|
- if (this._checkFieldsExist(fields, bglFields)) {
|
|
|
+ if (this._checkFieldsExist(fields, billsFields.bgl)) {
|
|
|
await this._calcBillsBgl();
|
|
|
}
|
|
|
|
|
@@ -385,35 +411,67 @@ module.exports = app => {
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ async _calcPosBgl() {
|
|
|
+ if (!this.ctx.stage) return;
|
|
|
+
|
|
|
+ const helper = this.ctx.helper;
|
|
|
+ const tender = this.ctx.tender;
|
|
|
+ const stage = this.ctx.stage;
|
|
|
+ const bglData = this.ctx.stage.readOnly
|
|
|
+ ? 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 p of this.pos.datas) {
|
|
|
+ p.qc_bgl_code = '';
|
|
|
+
|
|
|
+ const pBgl = helper._.filter(bglData, {lid: p.lid, pid: p.id});
|
|
|
+ if (pBgl.length === 0) continue;
|
|
|
+ helper._.pullAll(bglData, pBgl);
|
|
|
+ const validBgl = helper._.filter(pBgl, function (x) {
|
|
|
+ return !helper.checkZero(x.qty);
|
|
|
+ });
|
|
|
+ p.qc_bgl_code = helper._.uniq(helper._.map(validBgl, 'c_code')).join(';');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async getStagePosData(tid, sid, fields) {
|
|
|
await this.ctx.service.tender.checkTender(tid);
|
|
|
await this.ctx.service.stage.checkStage(sid);
|
|
|
|
|
|
const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
|
|
|
- if (this.ctx.stage.readOnly) {
|
|
|
- const curPosStage = await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id,
|
|
|
- this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
|
|
|
- this.ctx.helper.assignRelaData(posData, [
|
|
|
- {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
|
|
|
- ]);
|
|
|
- } else {
|
|
|
- const curPosStage = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
|
|
|
+ if (this._checkFieldsExist(fields, posFields.stage)) {
|
|
|
+ if (this.ctx.stage.readOnly) {
|
|
|
+ const curPosStage = await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id,
|
|
|
+ this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
|
|
|
+ this.ctx.helper.assignRelaData(posData, [
|
|
|
+ {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ const curPosStage = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
|
|
|
+ this.ctx.helper.assignRelaData(posData, [
|
|
|
+ {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (this._checkFieldsExist(fields, posFields.stageEnd)) {
|
|
|
+ const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
|
|
|
this.ctx.helper.assignRelaData(posData, [
|
|
|
- {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
|
|
|
+ {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
|
|
|
]);
|
|
|
}
|
|
|
- const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
|
|
|
- this.ctx.helper.assignRelaData(posData, [
|
|
|
- {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
|
|
|
- ]);
|
|
|
this.pos.loadDatas(posData);
|
|
|
this.pos.calculateAll();
|
|
|
|
|
|
+ if (this._checkFieldsExist(fields, posFields.bgl)) {
|
|
|
+ await this._calcPosBgl();
|
|
|
+ }
|
|
|
+
|
|
|
return this.pos.getDatas();
|
|
|
}
|
|
|
|
|
|
_getStageValidRole () {
|
|
|
if (!this.ctx.stage) throw '期数据错误,请重试';
|
|
|
+ if (this.stageValidRole && this.stageValidRole.length > 0) return;
|
|
|
|
|
|
const result = [{dataOrder: 0, flowOrder: 0, uid: this.ctx.stage.user_id}];
|
|
|
for (const auditor of this.ctx.stage.auditors) {
|
|
@@ -433,15 +491,16 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return result;
|
|
|
+ this.stageValidRole = result;
|
|
|
};
|
|
|
|
|
|
async getStageBillsCompareData(tid, sid, fields) {
|
|
|
await this.ctx.service.tender.checkTender(tid);
|
|
|
await this.ctx.service.stage.checkStage(sid);
|
|
|
+ await this._getStageValidRole();
|
|
|
|
|
|
const stage = this.ctx.stage, helper = this.ctx.helper;
|
|
|
- const validRole = this._getStageValidRole();
|
|
|
+ const validRole = this.stageValidRole;
|
|
|
const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
|
|
|
const allStageBills = await this.ctx.service.stageBills.getAllDataByCondition({where: {sid: sid}});
|
|
|
|
|
@@ -521,6 +580,56 @@ module.exports = app => {
|
|
|
// ]);
|
|
|
}
|
|
|
|
|
|
+ async getStagePosCompareData(tid, sid, fields) {
|
|
|
+ await this.ctx.service.tender.checkTender(tid);
|
|
|
+ await this.ctx.service.stage.checkStage(sid);
|
|
|
+ await this._getStageValidRole();
|
|
|
+
|
|
|
+ const stage = this.ctx.stage, helper = this.ctx.helper;
|
|
|
+ const validRole = this.stageValidRole;
|
|
|
+
|
|
|
+ const allStagePos = await this.ctx.service.stagePos.getAllDataByCondition({where: {sid: sid}});
|
|
|
+ const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
|
|
|
+ const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
|
|
|
+ this.ctx.helper.assignRelaData(posData, [
|
|
|
+ {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
|
|
|
+ ]);
|
|
|
+ const stagePosIndex = {}, timesLen = 100;
|
|
|
+ for (const role of validRole) {
|
|
|
+ const stagePos = this.ctx.helper._.filter(allStagePos, function (x) {
|
|
|
+ return x.times < stage.curTimes || (x.times === stage.curTimes && x.order <= role.dataOrder);
|
|
|
+ });
|
|
|
+ this.ctx.helper._.pullAll(allStagePos, stagePos);
|
|
|
+ for (const sp of stagePos) {
|
|
|
+ const key = 'sp-' + sp.pid;
|
|
|
+ const spi = stagePosIndex[key];
|
|
|
+ if (spi) {
|
|
|
+ if ((spi.times * timesLen + spi.order) < (sp.times * timesLen + sp.order)) stagePosIndex[key] = sp;
|
|
|
+ } else {
|
|
|
+ stagePosIndex[key] = sp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const filterStagePos = [];
|
|
|
+ for (const prop in stagePosIndex) {
|
|
|
+ filterStagePos.push(stagePosIndex[prop]);
|
|
|
+ }
|
|
|
+ this.ctx.helper.assignRelaData(posData, [
|
|
|
+ {data: filterStagePos, fields: ['contract_qty', 'qc_qty'], prefix: 'r' + role.flowOrder + '_', relaId: 'pid'}
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ this.pos.loadDatas(posData);
|
|
|
+ this.pos.calculateAll(function (p) {
|
|
|
+ p.pre_gather_qty = helper.add(p.pre_contract_qty, p.pre_qc_qty);
|
|
|
+ for (const role of validRole) {
|
|
|
+ const prefix = 'r' + role.flowOrder + '_';
|
|
|
+ p[prefix + 'gather_qty'] = helper.add(p[prefix + 'contract_qty'], p[prefix + 'qc_qty']);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ return this.pos.getDatas();
|
|
|
+ }
|
|
|
+
|
|
|
async getStagePayData(tid, sid, fields) {
|
|
|
await this.ctx.service.tender.checkTender(tid);
|
|
|
await this.ctx.service.stage.checkStage(sid);
|