|  | @@ -222,13 +222,13 @@ module.exports = app => {
 | 
	
		
			
				|  |  |           * @param mid
 | 
	
		
			
				|  |  |           * @returns {Promise<number>}
 | 
	
		
			
				|  |  |           */
 | 
	
		
			
				|  |  | -        async updateNewMaterial(transaction, tid, mid, ctx, stage_id) {
 | 
	
		
			
				|  |  | +        async updateNewMaterial(transaction, tid, mid, ctx, stage_id, decimal) {
 | 
	
		
			
				|  |  |              const materialBillsData = await this.getAllDataByCondition({ where: { tid } });
 | 
	
		
			
				|  |  |              let m_tp = 0;
 | 
	
		
			
				|  |  |              let m_tax_tp = 0;
 | 
	
		
			
				|  |  |              const materialCalculator = new MaterialCalculator(ctx, stage_id, ctx.tender.info);
 | 
	
		
			
				|  |  |              for (const mb of materialBillsData) {
 | 
	
		
			
				|  |  | -                const [one_tp, one_tax_tp] = await this.calcQuantityByMB(transaction, mid, mb, materialCalculator);
 | 
	
		
			
				|  |  | +                const [one_tp, one_tax_tp] = await this.calcQuantityByMB(transaction, mid, mb, materialCalculator, decimal);
 | 
	
		
			
				|  |  |                  m_tp = this.ctx.helper.add(m_tp, one_tp);
 | 
	
		
			
				|  |  |                  m_tax_tp = this.ctx.helper.add(m_tax_tp, one_tax_tp);
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -242,16 +242,16 @@ module.exports = app => {
 | 
	
		
			
				|  |  |           * @param mb
 | 
	
		
			
				|  |  |           * @returns {Promise<*>}
 | 
	
		
			
				|  |  |           */
 | 
	
		
			
				|  |  | -        async calcQuantityByMB(transaction, mid, mb, materialCalculator) {
 | 
	
		
			
				|  |  | -            const [newmsg_spread, newm_spread] = await this.getSpread(mb, null);
 | 
	
		
			
				|  |  | +        async calcQuantityByMB(transaction, mid, mb, materialCalculator, decimal) {
 | 
	
		
			
				|  |  | +            const [newmsg_spread, newm_spread] = await this.getSpread(mb, null, decimal.up);
 | 
	
		
			
				|  |  |              if (mb.t_type === materialConst.t_type[0].value) {
 | 
	
		
			
				|  |  |                  const sql = 'SELECT SUM(`gather_qty`*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `is_join`=1';
 | 
	
		
			
				|  |  |                  const sqlParam = [mid, mb.id];
 | 
	
		
			
				|  |  |                  const mb_quantity = await transaction.queryOne(sql, sqlParam);
 | 
	
		
			
				|  |  |                  console.log(mb_quantity);
 | 
	
		
			
				|  |  |                  // 取历史期记录获取截止上期调差金额,并清空本期单价和时间,来源地,重新计算价差和有效价差
 | 
	
		
			
				|  |  | -                const newQuantity = this.ctx.helper.round(mb_quantity.quantity, this.ctx.material.decimal.qty);
 | 
	
		
			
				|  |  | -                const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, newm_spread), this.ctx.material.decimal.tp);
 | 
	
		
			
				|  |  | +                const newQuantity = this.ctx.helper.round(mb_quantity.quantity, decimal.qty);
 | 
	
		
			
				|  |  | +                const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, newm_spread), decimal.tp);
 | 
	
		
			
				|  |  |                  const updateData = {
 | 
	
		
			
				|  |  |                      id: mb.id,
 | 
	
		
			
				|  |  |                      quantity: newQuantity,
 | 
	
	
		
			
				|  | @@ -261,33 +261,33 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                      m_spread: newm_spread,
 | 
	
		
			
				|  |  |                      origin: null,
 | 
	
		
			
				|  |  |                      m_tp: newTp,
 | 
	
		
			
				|  |  | -                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), this.ctx.material.decimal.tp) : mb.pre_tp,
 | 
	
		
			
				|  |  | -                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp),
 | 
	
		
			
				|  |  | -                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), this.ctx.material.decimal.tp) : mb.tax_pre_tp,
 | 
	
		
			
				|  |  | +                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), decimal.tp) : mb.pre_tp,
 | 
	
		
			
				|  |  | +                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp),
 | 
	
		
			
				|  |  | +                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), decimal.tp) : mb.tax_pre_tp,
 | 
	
		
			
				|  |  |                  };
 | 
	
		
			
				|  |  |                  await transaction.update(this.tableName, updateData);
 | 
	
		
			
				|  |  | -                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(mb_quantity.quantity, newm_spread), this.ctx.material.decimal.tp) : 0;
 | 
	
		
			
				|  |  | -                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp);
 | 
	
		
			
				|  |  | +                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(mb_quantity.quantity, newm_spread), decimal.tp) : 0;
 | 
	
		
			
				|  |  | +                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp);
 | 
	
		
			
				|  |  |                  return [m_tp, m_tax_tp];
 | 
	
		
			
				|  |  |              } else if (mb.t_type === materialConst.t_type[1].value) {
 | 
	
		
			
				|  |  |                  const quantity = await materialCalculator.calculateExpr(mb.expr);
 | 
	
		
			
				|  |  | -                const newTp = quantity !== 0 && quantity !== null ? this.ctx.helper.round(this.ctx.helper.mul(this.ctx.helper.round(quantity, this.ctx.material.decimal.qty), newm_spread), this.ctx.material.decimal.tp) : null;
 | 
	
		
			
				|  |  | +                const newTp = quantity !== 0 && quantity !== null ? this.ctx.helper.round(this.ctx.helper.mul(this.ctx.helper.round(quantity, decimal.qty), newm_spread), decimal.tp) : null;
 | 
	
		
			
				|  |  |                  const updateData = {
 | 
	
		
			
				|  |  |                      id: mb.id,
 | 
	
		
			
				|  |  | -                    quantity: quantity !== 0 && quantity !== null ? this.ctx.helper.round(quantity, this.ctx.material.decimal.qty) : null,
 | 
	
		
			
				|  |  | +                    quantity: quantity !== 0 && quantity !== null ? this.ctx.helper.round(quantity, decimal.qty) : null,
 | 
	
		
			
				|  |  |                      msg_tp: null,
 | 
	
		
			
				|  |  |                      msg_times: null,
 | 
	
		
			
				|  |  |                      msg_spread: newmsg_spread,
 | 
	
		
			
				|  |  |                      m_spread: newm_spread,
 | 
	
		
			
				|  |  |                      origin: null,
 | 
	
		
			
				|  |  |                      m_tp: newTp,
 | 
	
		
			
				|  |  | -                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), this.ctx.material.decimal.tp) : mb.pre_tp,
 | 
	
		
			
				|  |  | -                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp),
 | 
	
		
			
				|  |  | -                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), this.ctx.material.decimal.tp) : mb.tax_pre_tp,
 | 
	
		
			
				|  |  | +                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), decimal.tp) : mb.pre_tp,
 | 
	
		
			
				|  |  | +                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp),
 | 
	
		
			
				|  |  | +                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), decimal.tp) : mb.tax_pre_tp,
 | 
	
		
			
				|  |  |                  };
 | 
	
		
			
				|  |  |                  await transaction.update(this.tableName, updateData);
 | 
	
		
			
				|  |  | -                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(quantity, newm_spread), this.ctx.material.decimal.tp) : 0;
 | 
	
		
			
				|  |  | -                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp);
 | 
	
		
			
				|  |  | +                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(quantity, newm_spread), decimal.tp) : 0;
 | 
	
		
			
				|  |  | +                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp);
 | 
	
		
			
				|  |  |                  return [m_tp, m_tax_tp];
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 |