| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 | 
							- 'use strict';
 
- /**
 
-  *
 
-  *
 
-  * @author Mai
 
-  * @date
 
-  * @version
 
-  */
 
- const RptMemBase = require('./base');
 
- const bindData = {};
 
- const changeConst = require('../../const/change');
 
- class rptMemChange extends RptMemBase {
 
-     constructor(ctx) {
 
-         super(ctx, bindData);
 
-     }
 
-     _getChangeConstName(define, value) {
 
-         for (const prop in define) {
 
-             if (define[prop].value === value) {
 
-                 return define[prop].name;
 
-             }
 
-         }
 
-         return '';
 
-     }
 
-     async _anaylisChange(change) {
 
-         const self = this;
 
-         const types = this.ctx.helper._.map(change.type.split(','), function (t) {
 
-             return self._getChangeConstName(changeConst.type, self.ctx.helper._.toInteger(t));
 
-         });
 
-         change.type = types.join(';');
 
-         change.class = this._getChangeConstName(changeConst.class, change.class);
 
-         change.quality = this._getChangeConstName(changeConst.quality, change.quality);
 
-         change.charge = this._getChangeConstName(changeConst.charge, change.charge);
 
-     }
 
-     async doCheckChange(changeId) {
 
-         if (this.ctx.change) return;
 
-         this.ctx.change = await this.ctx.service.change.getDataByCondition({ cid: changeId });
 
-         this._anaylisChange(this.ctx.change);
 
-     }
 
-     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.doCheckChange(params.change_id);
 
-         await this.doCheckTender(this.ctx.change.tid);
 
-     }
 
-     async _getChangeBills() {
 
-         const decimal = this.ctx.tender.info.decimal;
 
-         const changeBills = await this.ctx.service.changeAuditList.getAllDataByCondition({ where: { cid: this.ctx.change.cid} });
 
-         for (const d of changeBills) {
 
-             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 = this.ctx.helper._.find(this.ctx.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] = this.ctx.helper.mul(d[amountField], d.unit_price, decimal.tp);
 
-                 if (relaChange) {
 
-                     relaChange[tpField] = this.ctx.helper.add(relaChange[tpField], d[tpField]);
 
-                 }
 
-             }
 
-         }
 
-         return changeBills;
 
-     }
 
-     getCommonData(params, tableName, fields, customDefine, customSelect) {
 
-         switch (tableName) {
 
-             case 'mem_change':
 
-                 return [this.ctx.change];
 
-             case 'mem_change_bills':
 
-                 return this._getChangeBills();
 
-             case 'mem_change_audit':
 
-                 return this.ctx.service.changeAudit.getListGroupByTimes(this.ctx.change.cid, this.ctx.change.times);
 
-             case 'mem_change_att':
 
-                 return this.ctx.service.changeAtt.getChangeAttachment(this.ctx.change.cid);
 
-             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];
 
-             default:
 
-                 return [];
 
-         }
 
-     }
 
- }
 
- module.exports = rptMemChange;
 
 
  |