|
@@ -0,0 +1,96 @@
|
|
|
+'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);
|
|
|
+ }
|
|
|
+
|
|
|
+ async _anaylisChange(change) {
|
|
|
+ const types = ctx.helper._.map(change.type.split(','), function (t) {
|
|
|
+ return self._getChangeConstName(changeConst.type, 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({ where: { 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.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 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 = 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]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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;
|