瀏覽代碼

Merge branch 'dev' into uat

laiguoran 4 年之前
父節點
當前提交
d3aa7afe0a
共有 3 個文件被更改,包括 6 次插入7 次删除
  1. 1 1
      app/extend/helper.js
  2. 1 1
      app/public/js/material.js
  3. 4 5
      app/service/material_month.js

+ 1 - 1
app/extend/helper.js

@@ -1224,7 +1224,7 @@ module.exports = {
      * @return {Boolean} 匹配结果
      */
     arrayCount(array, val) {
-        const counts = (arr, value) => arr.reduce((a, v) => { return v === value ? a + 1 : a + 0; }, 0);
+        const counts = (arr, value) => arr.reduce((a, v) => { return value.indexOf(v) !== -1 ? a + 1 : a + 0; }, 0);
         return counts(array, val);
     },
 };

+ 1 - 1
app/public/js/material.js

@@ -576,7 +576,7 @@ $(document).ready(() => {
                 let hadnum = 0;
                 for (const m of months) {
                     msg_tp += data[m];
-                    if (data[m] !== null && data[m] !== '') {
+                    if (data[m] !== null && data[m] !== '' && data[m] !== 0) {
                         hadnum++;
                     }
                 }

+ 4 - 5
app/service/material_month.js

@@ -59,7 +59,7 @@ module.exports = app => {
                         insertArray.push(one_month);
                         if (monthList.length !== 0) {
                             const mb_msg_tp_sum = this._.sumBy(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp');
-                            const month_num = material_month.length - this.ctx.helper.arrayCount(this._.concat(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), one_month.msg_tp), null);
+                            const month_num = material_month.length - this.ctx.helper.arrayCount(this._.concat(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), one_month.msg_tp), [null, '', 0]);
                             const new_msg_tp = this.ctx.helper.round(this.ctx.helper.div(this.ctx.helper.add(mb_msg_tp_sum, one_month.msg_tp), month_num), 3);
                             const [newmsg_spread, newm_spread] = await this.ctx.service.materialBills.getSpread(mb, new_msg_tp);
                             updateArray.push({
@@ -107,7 +107,7 @@ module.exports = app => {
                             return data.indexOf(m.yearmonth) !== -1;
                         });
                         const mb_msg_tp_sum = this._.sumBy(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp');
-                        const month_num = material_month.length - this.ctx.helper.arrayCount(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), null);
+                        const month_num = material_month.length - this.ctx.helper.arrayCount(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), [null, '', 0]);
                         const new_msg_tp = month_num !== 0 ? this.ctx.helper.round(this.ctx.helper.div(mb_msg_tp_sum, month_num), 3) : null;
                         const [newmsg_spread, newm_spread] = await this.ctx.service.materialBills.getSpread(mb, new_msg_tp);
                         updateArray.push({
@@ -146,9 +146,8 @@ module.exports = app => {
                 const monthList = await transaction.select(this.tableName, { where: { mb_id: data.mb_id, mid: this.ctx.material.id } });
                 const mbInfo = await transaction.get(this.ctx.service.materialBills.tableName, { id: data.mb_id });
                 if (monthList.length !== 0) {
-                    console.log(monthList);
                     const mb_msg_tp_sum = this._.sumBy(monthList, 'msg_tp');
-                    const month_num = material_month.length - this.ctx.helper.arrayCount(this._.map(monthList, 'msg_tp'), null);
+                    const month_num = material_month.length - this.ctx.helper.arrayCount(this._.map(monthList, 'msg_tp'), [null, '', 0]);
                     const new_msg_tp = month_num !== 0 ? this.ctx.helper.round(this.ctx.helper.div(mb_msg_tp_sum, month_num), 3) : null;
                     const [newmsg_spread, newm_spread] = await this.ctx.service.materialBills.getSpread(mbInfo, new_msg_tp);
                     await transaction.update(this.ctx.service.materialBills.tableName, {
@@ -200,7 +199,7 @@ module.exports = app => {
                     const mbUpdateArray = [];
                     for (const mb of mbList) {
                         const mb_msg_tp_sum = this._.sumBy(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp');
-                        const month_num = material_month.length - this.ctx.helper.arrayCount(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), null);
+                        const month_num = material_month.length - this.ctx.helper.arrayCount(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), [null, '', 0]);
                         const new_msg_tp = month_num !== 0 ? this.ctx.helper.round(this.ctx.helper.div(mb_msg_tp_sum, month_num), 3) : null;
                         const [newmsg_spread, newm_spread] = await this.ctx.service.materialBills.getSpread(mb, new_msg_tp);
                         mbUpdateArray.push({