|
|
@@ -0,0 +1,185 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Mai
|
|
|
+ * @date
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+
|
|
|
+const RptMemBase = require('./base');
|
|
|
+const bindData = {};
|
|
|
+const Ledger = require('../ledger');
|
|
|
+const calcFields = ['in_tp', 'in_excl_tax_tp'];
|
|
|
+
|
|
|
+class rptMemChange extends RptMemBase {
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx, bindData);
|
|
|
+ }
|
|
|
+
|
|
|
+ async doCheckCostStage(stage_id) {
|
|
|
+ if (this.ctx.costStage) return;
|
|
|
+ this.ctx.costStage = await this.ctx.service.costStage.getStage(stage_id);
|
|
|
+ await this.ctx.service.costStage.doCheckStage(this.ctx.costStage);
|
|
|
+ if (this.ctx.costStage.rela_stage && this.ctx.costStage.rela_stage.sid)
|
|
|
+ this.ctx.costStage.relaStage = await this.ctx.service.costStage.getStage(this.ctx.costStage.rela_stage.sid);
|
|
|
+ }
|
|
|
+
|
|
|
+ async doCheckTender(tenderId) {
|
|
|
+ if (this.ctx.tender) return;
|
|
|
+ this.ctx.tender = { id: tenderId };
|
|
|
+ this.ctx.tender.data = await this.ctx.service.tender.getTender(tenderId);
|
|
|
+ this.ctx.tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
|
|
|
+ }
|
|
|
+
|
|
|
+ async doBeforeLoadReport(params) {
|
|
|
+ await this.doCheckCostStage(params.cost_stage_id);
|
|
|
+ await this.doCheckTender(this.ctx.costStage.tid);
|
|
|
+ }
|
|
|
+
|
|
|
+ async getCostStageBook() {
|
|
|
+ const ledger = await this.ctx.service.costStageLedger.getReadData(this.ctx.costStage.relaStage);
|
|
|
+ ledger.forEach(l => { delete l.postil; delete l.memo; });
|
|
|
+ const book = this.ctx.costStage.readOnly
|
|
|
+ ? await this.ctx.service.costStageBook.getReadData(this.ctx.costStage)
|
|
|
+ : await this.ctx.service.costStageBook.getEditData(this.ctx.costStage);
|
|
|
+ this.ctx.helper.assignRelaData(ledger, [
|
|
|
+ { data: book, fields: ['pre_in_tp', 'pre_in_excl_tax_tp', 'in_tp', 'in_excl_tax_tp', 'postil', 'memo'], prefix: '', relaId: 'ledger_id' },
|
|
|
+ { data: book, fields: ['id'], prefix: 'book_', relaId: 'ledger_id' },
|
|
|
+ ]);
|
|
|
+
|
|
|
+ const setting = {
|
|
|
+ id: 'tree_id',
|
|
|
+ pid: 'tree_pid',
|
|
|
+ order: 'tree_order',
|
|
|
+ level: 'tree_level',
|
|
|
+ isLeaf: 'tree_is_leaf',
|
|
|
+ fullPath: 'tree_full_path',
|
|
|
+ rootId: -1,
|
|
|
+ calcFields: ['pre_in_tp', 'pre_in_excl_tax_tp', 'in_tp', 'in_excl_tax_tp'],
|
|
|
+ };
|
|
|
+ const billsTree = new Ledger.billsTree(this.ctx, setting);
|
|
|
+ billsTree.loadDatas(ledger);
|
|
|
+ billsTree.calculateAll();
|
|
|
+ return billsTree.getDefaultDatas();
|
|
|
+ }
|
|
|
+ async getCostStageBookDetail() {
|
|
|
+ const detail = await this.ctx.service.costStageDetail.getReadData(this.ctx.costStage.relaStage);
|
|
|
+ detail.forEach(l => { delete l.postil; delete l.memo; });
|
|
|
+ const bookDetail = this.ctx.costStage.readOnly
|
|
|
+ ? await this.ctx.service.costStageBookDetail.getReadData(this.ctx.costStage)
|
|
|
+ : await this.ctx.service.costStageBookDetail.getEditData(this.ctx.costStage);
|
|
|
+ this.ctx.helper.assignRelaData(detail, [
|
|
|
+ { data: bookDetail, fields: ['in_tp', 'in_excl_tax_tp', 'postil', 'memo'], prefix: '', relaId: 'detail_id' },
|
|
|
+ { data: bookDetail, fields: ['id'], prefix: 'book_', relaId: 'detail_id' },
|
|
|
+ ]);
|
|
|
+ return detail;
|
|
|
+ }
|
|
|
+ _analysisCompareData(datas, roles) {
|
|
|
+ const findHis = function(role, history) {
|
|
|
+ let his = null;
|
|
|
+ for (const h of history) {
|
|
|
+ if (h.times < role.times || (h.audit_times === role.audit_times && h.active_order <= role.active_order)) {
|
|
|
+ his = h;
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return his;
|
|
|
+ };
|
|
|
+ for (const d of datas) {
|
|
|
+ if (!d.tree_is_leaf) continue;
|
|
|
+ for (const prop of calcFields) {
|
|
|
+ d[`his_${prop}`] = [];
|
|
|
+ }
|
|
|
+ d.calc_his.sort((x, y) => { return x.audit_times === y.audit_times ? x.active_order - y.active_order : x.audit_times - y.audit_times; });
|
|
|
+ for (const r of roles) {
|
|
|
+ if (r.latest) {
|
|
|
+ for (const prop of calcFields) {
|
|
|
+ d[`r_${prop}_${r.audit_order}`] = d[prop];
|
|
|
+ d[`his_${prop}`].push(d[prop]);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const rHis = findHis(r, d.calc_his);
|
|
|
+ if (rHis) {
|
|
|
+ for (const prop of calcFields) {
|
|
|
+ d[`r_${prop}_${r.audit_order}`] = rHis[prop];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (const prop of calcFields) {
|
|
|
+ d[`his_${prop}`].push(rHis ? rHis[prop] : 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ async getCostStageBookCompare() {
|
|
|
+ const ledger = await this.ctx.service.costStageLedger.getReadData(this.ctx.costStage.relaStage);
|
|
|
+ ledger.forEach(l => { delete l.postil; delete l.memo; });
|
|
|
+ const book = await this.ctx.service.costStageBook.getCompareData(this.ctx.costStage);
|
|
|
+ this.ctx.helper.assignRelaData(ledger, [
|
|
|
+ { data: book, fields: ['pre_in_tp', 'pre_in_excl_tax_tp', 'calc_his', 'postil', 'memo'], prefix: '', relaId: 'ledger_id' },
|
|
|
+ { data: book, fields: ['id'], prefix: 'book_', relaId: 'ledger_id' },
|
|
|
+ ]);
|
|
|
+ const roles = await this.ctx.service.costStageAudit.getViewFlow(this.ctx.costStage);
|
|
|
+ this._analysisCompareData(ledger, roles);
|
|
|
+ const setting = {
|
|
|
+ id: 'tree_id',
|
|
|
+ pid: 'tree_pid',
|
|
|
+ order: 'tree_order',
|
|
|
+ level: 'tree_level',
|
|
|
+ isLeaf: 'tree_is_leaf',
|
|
|
+ fullPath: 'tree_full_path',
|
|
|
+ rootId: -1,
|
|
|
+ calcFields: ['in_tp', 'in_excl_tax_tp']
|
|
|
+ };
|
|
|
+ for(const r of roles) {
|
|
|
+ for (const f of calcFields) {
|
|
|
+ setting.calcFields.push(`r_${f}_${r.audit_order}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const compareTree = new Ledger.billsTree(this.ctx, setting);
|
|
|
+ compareTree.loadDatas(ledger);
|
|
|
+ compareTree.calculateAll();
|
|
|
+ return compareTree.getDefaultDatas();
|
|
|
+ }
|
|
|
+ async getCostStageBookDetailCompare() {
|
|
|
+ const detail = await this.ctx.service.costStageLedger.getReadData(this.ctx.costStage.relaStage);
|
|
|
+ detail.forEach(l => { delete l.postil; delete l.memo; });
|
|
|
+ const bookDetail = await this.ctx.service.costStageBook.getCompareData(this.ctx.costStage);
|
|
|
+ this.ctx.helper.assignRelaData(detail, [
|
|
|
+ { data: bookDetail, fields: ['pre_in_tp', 'pre_in_excl_tax_tp', 'calc_his', 'postil', 'memo'], prefix: '', relaId: 'detail_id' },
|
|
|
+ ]);
|
|
|
+ const roles = await this.ctx.service.costStageAudit.getViewFlow(this.ctx.costStage);
|
|
|
+ this._analysisCompareData(detail, roles);
|
|
|
+ return detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ getCommonData(params, tableName, fields, customDefine, customSelect) {
|
|
|
+ switch (tableName) {
|
|
|
+ case 'mem_project':
|
|
|
+ return this.ctx.service.project.getDataByCondition({ id: this.ctx.session.sessionProject.id });
|
|
|
+ case 'mem_tender':
|
|
|
+ return [this.ctx.tender.data];
|
|
|
+ case 'mem_tender_info':
|
|
|
+ return [this.ctx.tender.info];
|
|
|
+ case 'mem_cost_stage':
|
|
|
+ return [this.ctx.costStage];
|
|
|
+ case 'mem_cost_stage_audit':
|
|
|
+ return this.ctx.service.costStageAudit.getFinalUniqAuditors(this.ctx.costStage);
|
|
|
+ case 'mem_cost_stage_book':
|
|
|
+ return this.getCostStageBook();
|
|
|
+ case 'mem_cost_stage_book_detail':
|
|
|
+ return this.getCostStageBookDetail();
|
|
|
+ case 'mem_cost_stage_book_compare':
|
|
|
+ return this.getCostStageBookCompare();
|
|
|
+ case 'mem_cost_stage_book_detail_compare':
|
|
|
+ return this.getCostStageBookDetailCompare();
|
|
|
+ default:
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+module.exports = rptMemChange;
|