Browse Source

打开调差期时更新qty值

ellisran 1 year ago
parent
commit
e6fde5ebfe

+ 3 - 0
app/controller/material_controller.js

@@ -1032,6 +1032,9 @@ module.exports = app => {
                     case 'export':
                         responseData.data = await ctx.service.materialBills.exportData(data.postData, data.includeSpec, data.ms_id);
                         break;
+                    case 'qty_update':
+                        responseData.data = await ctx.service.materialList.saveQtyHistory(data.needUpdateList);
+                        break;
                     default: throw '参数有误';
                 }
                 if (ctx.material.material_tax) {

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

@@ -1313,9 +1313,9 @@ $(document).ready(() => {
                         }
                     }
                     console.log(needUpdateList);
-                    // postData(window.location.pathname + '/save', needUpdateList, function (result) {
-                    //     materialListData2 = result.materialListData;
-                    // });
+                    postData(window.location.pathname + '/save', { type: 'qty_update', needUpdateList }, function (result) {
+                        materialListData2 = result.materialListData;
+                    });
                 }
             });
         } else {

+ 3 - 3
app/public/js/material_list.js

@@ -556,9 +556,9 @@ $(document).ready(() => {
                         }
                     }
                     console.log(needUpdateList);
-                    // postData(window.location.pathname + '/save', needUpdateList, function (result) {
-                    //     materialListData2 = result.materialListData;
-                    // });
+                    postData('/tender/' + tenderID + '/measure/material/'+ stage_order + '/save', { type: 'qty_update', needUpdateList }, function (result) {
+                        materialListData = result.materialListData;
+                    });
                 }
             });
         } else {

+ 20 - 0
app/service/material_list.js

@@ -836,6 +836,26 @@ module.exports = app => {
             }
         }
 
+        async saveQtyHistory(updateList) {
+            if (!this.ctx.tender || !this.ctx.material) {
+                throw '数据错误';
+            }
+            // 判断是否可修改
+            // 判断t_type是否为费用
+            const transaction = await this.db.beginTransaction();
+            try {
+                if (updateList.length > 0) await transaction.updateRows(this.tableName, updateList);
+                await transaction.update(this.ctx.service.material.tableName, { id: this.ctx.material.id, is_new_qty: 1 });
+                await transaction.commit();
+                return {
+                    materialListData: await this.getMaterialData(this.ctx.tender.id, this.ctx.material.id)
+                };
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
         async getMbQuantity(transaction, mid, qty_source, qty_decimal, mb_id, ms_id = null, needRound = 1) {
             const msSql = ms_id ? ' AND `ms_id` = ' + ms_id : '';
             const sql = 'SELECT SUM(' + this.ctx.helper.getQtySource(qty_source) + '*`quantity`) as quantity FROM ' + this.tableName + ' WHERE `mid`=? AND `mb_id`=?' + msSql + ' AND `is_join`=1';