Browse Source

报表,新增指标

MaiXinRong 2 years ago
parent
commit
bb3f38c202
2 changed files with 99 additions and 0 deletions
  1. 7 0
      app/service/report.js
  2. 92 0
      app/service/rpt_gather_memory.js

+ 7 - 0
app/service/report.js

@@ -14,6 +14,7 @@ const MaterialSource = require('../lib/rm/material');
 const rptCustomData = require('../lib/rptCustomData');
 const bindData = {
     materialGather: ['mem_material_gather_bills', 'mem_material_gather_xmj', 'mem_material_gather_gl'],
+    gatherChange: ['mem_gather_change', 'mem_gather_change_bills'],
 };
 
 
@@ -395,6 +396,12 @@ module.exports = app => {
                             rst[d] = mgResult[d];
                         }
                         break;
+                    case 'gatherChange':
+                        const gcResult = await service.rptGatherMemory.getGatherChange(memFieldKeys[filter],
+                            customDefine.gather_select, customSelect ? customSelect.gather_select : null);
+                        for (const d in gcResult) {
+                            rst[d] = gcResult[d];
+                        }
                     default:
                         break;
                 }

+ 92 - 0
app/service/rpt_gather_memory.js

@@ -13,6 +13,7 @@ const PayCalculator = require('../lib/pay_calc');
 
 const auditConst = require('../const/audit');
 const payConst = require('../const/deal_pay');
+const changeConst = require('../const/change');
 
 const moment = require('moment');
 
@@ -1169,6 +1170,97 @@ module.exports = app => {
             gatherUtils.completeGatherData(this.resultDealBills, completeDatas);
             return this.resultDealBills;
         }
+
+        _getChangeConstName(define, value) {
+            for (const prop in define) {
+                if (define[prop].value === value) {
+                    return define[prop].name;
+                }
+            }
+            return '';
+        }
+
+        async _gatherChange(tender) {
+            const self = this;
+            try {
+                const info = await this.ctx.service.tenderInfo.getTenderInfo(tender.id);
+                const decimal = info.decimal, ctx = this.ctx;
+                const where = { tid, valid: 1 };
+                if (this.ctx.session.sessionProject.page_show.isOnlyChecked) where.status = auditConst.flow.status.checked;
+                const change = await this.ctx.service.change.getAllDataByCondition({ where, orders: [['in_time', 'desc']] });
+                for (const c of change) {
+                    c.tender_name = tender.name;
+                    const types = ctx.helper._.map(c.type.split(','), function (t) {
+                        return self._getChangeConstName(changeConst.type, ctx.helper._.toInteger(t));
+                    });
+                    c.type = types.join(';');
+                    c.class = this._getChangeConstName(changeConst.class, c.class);
+                    c.quality = this._getChangeConstName(changeConst.quality, c.quality);
+                    c.charge = this._getChangeConstName(changeConst.charge, c.charge);
+                    c.attachments = await ctx.service.changeAtt.getChangeAttachment(c.cid);
+                    const names = ctx.helper._.map(c.attachments, function (x) {
+                        return x.filename + x.fileext;
+                    });
+                    c.attNames = names.join('\n');
+                }
+                const changeBills = await this.ctx.service.changeAuditList.getChangeAuditBills(tid, this.ctx.session.sessionProject.page_show.isOnlyChecked);
+                for (const d of changeBills) {
+                    d.tender_name = tender.name;
+                    d.o_qty = d.oamount;
+                    d.o_tp = this.ctx.helper.mul(d.o_qty, d.unit_price, decimal.tp);
+                    d.c_qty = d.camount;
+                    d.c_tp = this.ctx.helper.mul(d.c_qty, d.unit_price, decimal.tp);
+                    d.s_qty = d.samount ? parseFloat(d.samount) : 0;
+                    d.s_tp = this.ctx.helper.mul(d.s_qty, d.unit_price, decimal.tp);
+                    d.sp_qty = d.spamount;
+                    d.sp_tp = this.ctx.helper.mul(d.sp_qty, d.unit_price, decimal.tp);
+
+                    const auditAmount = d.audit_amount ? d.audit_amount.split(',') : [];
+                    const relaChange = ctx.helper._.find(change, {cid: d.cid});
+                    for (const [i, aa] of auditAmount.entries()) {
+                        const amountField = 'qty_' + (i+1), tpField = 'tp_' + (i+1);
+                        d[amountField] = aa ? parseFloat(aa) : 0;
+                        d[tpField] = ctx.helper.mul(d[amountField], d.unit_price, decimal.tp);
+                        if (relaChange) {
+                            relaChange[tpField] = ctx.helper.add(relaChange[tpField], d[tpField]);
+                        }
+                    }
+                }
+
+                change.sort(function (a, b) {
+                    return a.code.localeCompare(b.code);
+                });
+                changeBills.sort(function (a, b) {
+                    const aCIndex = change.findIndex(function (c) {
+                        return c.cid === a.cid;
+                    });
+                    const bCIndex = change.findIndex(function (c) {
+                        return c.cid === b.cid;
+                    });
+                    return aCIndex === bCIndex
+                        ? ctx.helper.compareCode(a.code, b.code)
+                        : aCIndex - bCIndex;
+                });
+                return [change, changeBills];
+            } catch(err) {
+                this.ctx.helper.log(err);
+                throw err;
+                return [[], []];
+            }
+        }
+
+        async getGatherChange(memFieldKeys, gsDefine, gsCustom) {
+            if (!gsDefine || !gsDefine.enable) return [];
+            if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return [];
+
+            const result = { change: [], changeBills: [] };
+            for (const tender of gsCustom.tenders) {
+                const [change, changeBills] = await this._gatherChange(tender);
+                result.change.push(...change);
+                result.changeBills.push(...changeBills);
+            }
+            return result
+        }
     }
 
     return RptGatherMemory;