Procházet zdrojové kódy

feat: 材料调差-调差清单新增列本期差价

lanjianrong před 4 roky
rodič
revize
03a39fb92b
2 změnil soubory, kde provedl 51 přidání a 34 odebrání
  1. 19 5
      app/public/js/material_list.js
  2. 32 29
      app/service/stage_bills.js

+ 19 - 5
app/public/js/material_list.js

@@ -56,6 +56,18 @@ function getPasteHint (str, row = '') {
     return returnObj;
 }
 
+function calculateJiaCha(Data) {
+    for(const gcld of Data) {
+        let total_jiacha = 0;
+        for (const [index, xmj] of gcld.leafXmjs.entries()) {
+            const jiacha = calcOneBQJC(xmj);
+            gcld.leafXmjs[index].jiacha = jiacha !== 0 ? ZhCalc.round(jiacha, 2) : null;
+            total_jiacha += jiacha;
+        }
+        gcld.total_jiacha = ZhCalc.round(total_jiacha, 2)
+    }
+}
+
 const is_numeric = (value) => {
     if (typeof(value) === 'object') {
         return false;
@@ -113,6 +125,7 @@ $(document).ready(() => {
             {title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 120, type: 'Number'},
             {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 120, type: 'Number'},
             {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 120, type: 'Number'},
+            {title: '本期差价', colSpan: '1', rowSpan: '2', field: 'total_jiacha', hAlign:3, width: 150, type: 'Number'}
         ],
         emptyRows: 0,
         headRows: 2,
@@ -127,9 +140,11 @@ $(document).ready(() => {
     gclGatherModel.loadPosData(pos, curPosData);
     let gclGatherData = gclGatherModel.gatherGclData().filter(item => {
         return item.qc_qty || item.contract_qty
-    });
+    })
+
+
+    calculateJiaCha(gclGatherData)
     // let gclGatherData = gclGatherModel.gatherGclData()
-    // console.log(gclGatherData);
     // 获取项目节数据
     function loadLeafXmjData(iGclRow) {
         const gcl = gclGatherData[iGclRow];
@@ -138,7 +153,6 @@ $(document).ready(() => {
                 const jiacha = calcOneBQJC(xmj);
                 gcl.leafXmjs[index].jiacha = jiacha !== 0 ? ZhCalc.round(jiacha, 2) : null;
             }
-            // console.log(gcl.leafXmjs);
             SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gcl.leafXmjs);
             // 对清单调差工料table的单位数量进行改变
             materialSpreadSetting.cols[materialSpreadSetting.cols.length - 1].title = '|' + gcl.unit + '数量 �';
@@ -214,7 +228,6 @@ $(document).ready(() => {
     const materialBase = {
         isEdit: function (data) {
             // 是否本期添加的工料
-            console.log(data);
             return data.order === stage_order;
         }
     };
@@ -230,7 +243,6 @@ $(document).ready(() => {
         },
     };
     SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
-
     // 获取项目节数据
     let materialList = [];
     function loadMaterialData(iGclRow, iLXmjRow) {
@@ -355,9 +367,11 @@ $(document).ready(() => {
                         notJoinList.push(result);
                     }
                     gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
+                    calculateJiaCha(gclGatherData)
                     SpreadJsObj.reLoadRowData(sheet, iRow);
                     sheet.getRange(iRow, -1, 1, -1).backColor(color);
                     loadMaterialData(iGclRow, iRow);
+                    SpreadJsObj.reLoadSheetData(ledgerSpread.getActiveSheet());
                 });
             },
         }

+ 32 - 29
app/service/stage_bills.js

@@ -29,10 +29,11 @@ module.exports = app => {
          * @param {Number} tid - 标段id
          * @param {Number} sid - 期id
          * @param {Number|Array} lid - 台账节点id(可以为空)
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          */
         async getLastestStageData(tid, sid, lid) {
-            let lidSql = '', result;
+            let lidSql = '',
+                result;
             if (lid) {
                 if (lid instanceof Array) {
                     lidSql = lid.length > 0 ? ' And lid in (' + this.ctx.helper.getInArrStrSqlFilter(lid) + ')' : '';
@@ -52,9 +53,9 @@ module.exports = app => {
                 return await this.db.query(sql, sqlParam);
             } else if (lid instanceof Array) {
                 return await this.db.query(sql, sqlParam);
-            } else {
-                return await this.db.queryOne(sql, sqlParam);
             }
+            return await this.db.queryOne(sql, sqlParam);
+
         }
 
         /**
@@ -64,7 +65,7 @@ module.exports = app => {
          * @param {Number} times - 第几轮
          * @param {Number} order - 流程
          * @param {Number|Array} lid - 台账节点id(可以为空)
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          */
         async getAuditorStageData(tid, sid, times, order, lid) {
             const lidSql = lid ? ' And Bills.lid in (?)' : '';
@@ -82,14 +83,15 @@ module.exports = app => {
             } else if (lid instanceof Array) {
                 sqlParam.push(lid.join(', '));
                 return await this.db.query(sql, sqlParam);
-            } else {
-                sqlParam.push(lid);
-                return await this.db.queryOne(sql, sqlParam);
             }
+            sqlParam.push(lid);
+            return await this.db.queryOne(sql, sqlParam);
+
         }
 
         async getLastestStageData2(tid, sid, lid) {
-            let lidSql = '', result;
+            let lidSql = '',
+                result;
             if (lid) {
                 if (lid instanceof Array) {
                     lidSql = lid.length > 0 ? ' And lid in (' + this.ctx.helper.getInArrStrSqlFilter(lid) + ')' : '';
@@ -109,9 +111,9 @@ module.exports = app => {
                 return await this.db.query(sql, sqlParam);
             } else if (lid instanceof Array) {
                 return await this.db.query(sql, sqlParam);
-            } else {
-                return await this.db.queryOne(sql, sqlParam);
             }
+            return await this.db.queryOne(sql, sqlParam);
+
         }
 
         async getStageUsedBills(tid, sid) {
@@ -163,9 +165,9 @@ module.exports = app => {
                 return await this.db.query(sql, sqlParam);
             } else if (lid instanceof Array) {
                 return await this.db.query(sql, sqlParam);
-            } else {
-                return await this.db.queryOne(sql, sqlParam);
             }
+            return await this.db.queryOne(sql, sqlParam);
+
         }
 
         async getStageBills(tid, sid, lid) {
@@ -235,7 +237,7 @@ module.exports = app => {
         /**
          * 前端提交数据
          * @param {Object|Array} data - 提交的数据
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          */
         async updateStageData(data) {
             const datas = data instanceof Array ? data : [data];
@@ -267,7 +269,7 @@ module.exports = app => {
          * @param ledgerBills
          * @param stageBills
          * @param data
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async updateStageBillsQty(transaction, ledgerBills, stageBills, data) {
@@ -285,14 +287,14 @@ module.exports = app => {
             } else {
                 await this._insertStageBillsData(transaction, data, stageBills, ledgerBills);
             }
-        };
+        }
         /**
          * 重算 本期计量 数量 (根据部位明细)
          * @param {Number} tid - 标段id
          * @param {Number} id - 需要计算的节点的id
          * @param {Number} lid - 台账id
          * @param {Object} transaction - 操作所属事务
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          */
         async calc(tid, sid, lid, transaction) {
             const info = this.ctx.tender.info;
@@ -317,14 +319,14 @@ module.exports = app => {
             if (stageBills) {
                 if (stageBills.contract_qty === posGather.contract_qty && stageBills.qc_qty === posGather.qc_qty) {
                     return;
+                }
+                if (stageBills.times === this.ctx.stage.curTimes && stageBills.order === this.ctx.stage.curOrder) {
+                    posGather.id = stageBills.id;
+                    await transaction.update(this.tableName, posGather);
                 } else {
-                    if (stageBills.times === this.ctx.stage.curTimes && stageBills.order === this.ctx.stage.curOrder) {
-                        posGather.id = stageBills.id;
-                        await transaction.update(this.tableName, posGather);
-                    } else {
-                        await this._insertStageBillsData(transaction, posGather, stageBills, ledgerBills);
-                    }
+                    await this._insertStageBillsData(transaction, posGather, stageBills, ledgerBills);
                 }
+
             } else {
                 await this._insertStageBillsData(transaction, posGather, stageBills, ledgerBills);
             }
@@ -332,7 +334,7 @@ module.exports = app => {
 
         async updateStageBillsCalcType(data) {
             const stageBills = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, data.id);
-            const updateData = {contract_qty: null, contract_tp: null};
+            const updateData = { contract_qty: null, contract_tp: null };
 
             const transaction = await this.db.beginTransaction();
             try {
@@ -354,7 +356,7 @@ module.exports = app => {
 
             const bills = await this.ctx.service.ledger.getDataById(data.id);
             const curStageData = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, [data.id]);
-            return {bills: [bills], curStageData: curStageData};
+            return { bills: [bills], curStageData };
         }
 
         async getSumTotalPrice(stage) {
@@ -389,9 +391,9 @@ module.exports = app => {
         async getSumTotalPriceGcl(stage, regText) {
             if (regText) {
                 return await this.getSumTotalPriceFilter(stage, 'REGEXP', regText);
-            } else {
-                return await this.getSumTotalPriceFilter(stage, '<>', this.db.escape(''));
             }
+            return await this.getSumTotalPriceFilter(stage, '<>', this.db.escape(''));
+
         }
 
         async getSumTotalPriceNotGcl(stage) {
@@ -402,7 +404,7 @@ module.exports = app => {
          * 多期清单数据整合 (材料调差调用)
          * @param {Number} tid - 标段id
          * @param {String} stage_id_list - 期id列表
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          */
         async getStagesData(tid, stage_id_list) {
             let stage_id_listSql = '';
@@ -419,6 +421,7 @@ module.exports = app => {
                 stage_id_listSql + ' GROUP BY `lid`';
             const sqlParam = [tid];
             const result = await this.db.query(sql, sqlParam);
+            console.log('result', result);
             return result;
         }
 
@@ -428,7 +431,7 @@ module.exports = app => {
          * @param {String} stage_id_list - 期id列表
          * @param {String} lid - 台账id
          * @param {String} xid - 项目节id
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          */
         async getGatherQtyByMaterial(tid, stage_id_list, lid) {
             stage_id_list = stage_id_list !== null ? stage_id_list.split(',') : [];