Explorar el Código

调差多期删除及可修改数目调整

laiguoran hace 3 años
padre
commit
be3d2c61bc

+ 2 - 1
app/public/js/material_checklist.js

@@ -250,7 +250,8 @@ $(document).ready(() => {
     const materialCol = {
         readOnly: {
             isEdit: function (data) {
-                return !(!readOnly && materialBase.isEdit(data));
+                // return !(!readOnly && materialBase.isEdit(data));
+                return readOnly;
             },
         },
     };

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

@@ -331,9 +331,14 @@ $(document).ready(() => {
     };
 
     const materialBase = {
-        isEdit: function (data) {
+        isEdit: function (data, type = 'normal') {
             // 是否本期添加的工料
-            return data.order === stage_order && !openMaterialChecklist;
+            // return data.order === stage_order && !openMaterialChecklist;
+            let flag = true;
+            if (type === 'del') {
+                flag = data.order === stage_order;
+            }
+            return flag && !openMaterialChecklist;
         }
     };
 
@@ -1026,7 +1031,7 @@ $(document).ready(() => {
                             if (!select) {
                                 return true;
                             }
-                            if (!readOnly && select && materialBase.isEdit(select)) {
+                            if (!readOnly && select && materialBase.isEdit(select, 'del')) {
                                 return false;
                             } else {
                                 return true;

+ 2 - 0
app/public/js/measure_material.js

@@ -327,6 +327,8 @@ $(function () {
                                     gcl_id: xmj.gcl_id,
                                     quantity: bill.quantity,
                                     expr: bill.expr,
+                                    old_quantity: bill.quantity,
+                                    old_expr: bill.expr,
                                     mb_id: bill.mb_id,
                                     order: bill.order,
                                 });

+ 6 - 1
app/service/material.js

@@ -179,6 +179,8 @@ module.exports = app => {
                     await this.ctx.service.materialList.copyPreMaterialList2(transaction, data.material_list, preNotJoinList, newMaterial);
                     // 新增或删除list_gcl表
                     await this.ctx.service.materialListGcl.insertOrDelGcl(transaction, data.insertGclList, data.removeGclList, newMaterial.id);
+                    // 设置list_gcl表old=>new更新
+                    await this.ctx.service.materialListGcl.setNewOldData(transaction, this.ctx.tender.id);
                     // 修改本期应耗数量值和有效价差,需要剔除不参与调差的清单数据,并返回总金额
                     const [m_tp, m_tax_tp] = await this.ctx.service.materialBills.updateNewMaterial(transaction, this.ctx.tender.id, newMaterial.id, this.ctx, newMaterial.stage_id, JSON.parse(newMaterial.decimal));
                     // 修改现行价格指数,并返回调差基数json
@@ -260,8 +262,11 @@ module.exports = app => {
                     const sqlParam2 = [this.ctx.tender.id, materialInfo.order - 1];
                     await transaction.query(sql2, sqlParam2);
                 }
+                // 设置list_gcl表old => new更新
+                await this.ctx.service.materialListGcl.setNewOldData(transaction, this.ctx.tender.id, 'old2new');
+                // 还要从material_list表更新gcl的old数据,更新方法
+                await this.ctx.service.materialListGcl.setOldFromLast(transaction, this.ctx.tender.id, materialInfo.order - 2);
                 await transaction.delete(this.tableName, { id });
-
                 // 记录删除日志
                 await this.ctx.service.projectLog.addProjectLog(transaction, projectLogConst.type.material, projectLogConst.status.delete, '第' + materialInfo.order + '期');
                 await transaction.commit();

+ 2 - 2
app/service/material_list.js

@@ -494,7 +494,7 @@ module.exports = app => {
                             },
                             where: {
                                 tid: this.ctx.tender.id,
-                                mid: this.ctx.material.id,
+                                // mid: this.ctx.material.id,
                                 mb_id,
                                 gcl_id: xmj.gcl_id,
                             },
@@ -555,7 +555,7 @@ module.exports = app => {
                                 },
                                 where: {
                                     tid: this.ctx.tender.id,
-                                    mid: this.ctx.material.id,
+                                    // mid: this.ctx.material.id,
                                     mb_id: data.mb_id,
                                     gcl_id: xmj.gcl_id,
                                 },

+ 41 - 0
app/service/material_list_gcl.js

@@ -35,6 +35,8 @@ module.exports = app => {
                         mb_id: d.mb_id,
                         quantity: d.quantity,
                         expr: d.expr,
+                        old_quantity: d.quantity,
+                        old_expr: d.expr,
                     });
                 }
                 if (insertArray.length > 0) await transaction.insert(this.tableName, insertArray);
@@ -62,6 +64,45 @@ module.exports = app => {
                 }
             }
         }
+
+        async setNewOldData(transaction, tid, type = 'new2old') {
+            if (type === 'new2old') {
+                const sql = 'UPDATE ?? SET `old_quantity`=`quantity`, `old_expr`=`expr` WHERE tid=?';
+                const sqlParam = [this.tableName, this.ctx.tender.id];
+                return await transaction.query(sql, sqlParam);
+            }
+            const sql = 'UPDATE ?? SET `quantity`=`old_quantity`, `expr`=`old_expr` WHERE tid=?';
+            const sqlParam = [this.tableName, this.ctx.tender.id];
+            return await transaction.query(sql, sqlParam);
+        }
+
+        async setOldFromLast(transaction, tid, order) {
+            if (order >= 1) {
+                // 获取上一期的list值
+                const materialInfo = await this.ctx.service.material.getDataByCondition({ tid, order });
+                const materialList = await this.ctx.service.materialList.getAllDataByCondition({ where: { mid: materialInfo.id } });
+                console.log(materialList);
+                const lastMaterialGclList = this._.unionWith(materialList, function(item1, item2) {
+                    return item1.gcl_id === item2.gcl_id && item1.mb_id === item2.mb_id;
+                });
+                const updateArray = [];
+                for (const lm of lastMaterialGclList) {
+                    const updateInfo = {
+                        row: {
+                            old_quantity: lm.quantity,
+                            old_expr: lm.expr,
+                        },
+                        where: {
+                            tid: this.ctx.tender.id,
+                            gcl_id: lm.gcl_id,
+                            mb_id: lm.mb_id,
+                        },
+                    };
+                    updateArray.push(updateInfo);
+                }
+                if (updateArray.length > 0) await transaction.updateRows(this.tableName, updateArray);
+            }
+        }
     }
     return MaterialListGcl;
 };

+ 3 - 57
sql/update.sql

@@ -1,58 +1,4 @@
-ALTER TABLE `zh_material` ADD `is_new` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '是否是新建的调差,用于区分清单新建规则' AFTER `in_time`;
+ALTER TABLE `zh_material_list_gcl` ADD `old_quantity` DECIMAL(30,8) NULL DEFAULT NULL COMMENT '数量,用于复原数据' AFTER `expr`,
+ADD `old_expr` VARCHAR(255) NULL DEFAULT NULL COMMENT '公式,用于复原数据' AFTER `old_quantity`;
 
-ALTER TABLE `zh_change_plan` ADD `expr` TEXT NULL DEFAULT NULL COMMENT '工程量数量计算式' AFTER `memo`;
-
-ALTER TABLE `zh_change_plan_list` ADD `new_up` tinyint(1) NOT NULL DEFAULT '0' COMMENT '新增单价' AFTER `spamount`;
-
-ALTER TABLE `zh_change_plan_list` ADD `ex_memo1` VARCHAR(255) NULL DEFAULT NULL COMMENT '备注1' AFTER `new_up`;
-
-ALTER TABLE `zh_change_plan_list` ADD `ex_memo2` VARCHAR(255) NULL DEFAULT NULL COMMENT '备注2' AFTER `ex_memo1`;
-
-ALTER TABLE `zh_project_account` ADD `stamp_path` VARCHAR(255) NULL DEFAULT NULL COMMENT '用户签章oss地址' AFTER `sign_path`;
-
-ALTER TABLE `zh_advance_pay` ADD `pay_time` DATETIME NULL DEFAULT NULL COMMENT '支付时间' AFTER `end_time`;
-UPDATE `zh_advance_pay` SET `pay_time`= `create_time`;
-
-CREATE TABLE `zh_material_list_gcl`  (
-  `id` int(11) NOT NULL AUTO_INCREMENT,
-  `tid` int(11) NOT NULL COMMENT '标段id',
-  `mid` int(11) NOT NULL COMMENT '调差id',
-  `order` tinyint(4) NOT NULL COMMENT '添加的历史期',
-  `gcl_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '工程量id',
-  `mb_id` int(11) NOT NULL COMMENT '工料id',
-  `quantity` decimal(30, 8) NULL DEFAULT NULL COMMENT '数目',
-  `expr` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '公式',
-  PRIMARY KEY (`id`) USING BTREE
-) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '用于新建期时清单关联已使用过的工程量,创建新的工料与清单的联系表';
-
-CREATE TABLE `zh_construction_unit`  (
-  `id` int(11) NOT NULL AUTO_INCREMENT,
-  `pid` int(11) NOT NULL COMMENT '项目id',
-  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '单位名称',
-  `type` tinyint(2) NOT NULL COMMENT '单位类型',
-  `corporation` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '法人代表',
-  `credit_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '企业信用代码',
-  `tel` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '电话',
-  `address` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '地址',
-  `region` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '地区',
-  `website` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '网站',
-  `basic` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '备注',
-  `sign_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '签章图片地址',
-  `create_time` datetime NOT NULL COMMENT '创建时间',
-  PRIMARY KEY (`id`) USING BTREE
-) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '参建单位表';
-
-CREATE TABLE `zh_stage_import_change` (
-  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-  `tid` int(11) unsigned NOT NULL COMMENT '标段id',
-  `sid` int(11) unsigned NOT NULL COMMENT '期id',
-  `lid` varchar(36) COLLATE utf8_unicode_ci NOT NULL COMMENT '台账节点id',
-  `import_lid` varchar(36) COLLATE utf8_unicode_ci NOT NULL COMMENT '导入的最底层项目节id',
-  `rela_tid` int(11) unsigned NOT NULL COMMENT '关联标段id',
-  `rela_sid` int(11) unsigned NOT NULL COMMENT '关联期id',
-  `rela_lid` varchar(36) COLLATE utf8_unicode_ci NOT NULL COMMENT '关联台账id',
-  `rela_cid` varchar(36) CHARACTER SET ascii NOT NULL COMMENT '关联变更令id',
-  `rela_cbid` int(11) unsigned NOT NULL COMMENT '关联变更清单id',
-  `rela_qty` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '关联数量',
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=2278 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+UPDATE `zh_material_list_gcl` SET `old_quantity`=`quantity`,`old_expr`=`expr`

+ 58 - 0
sql/update20220419.sql

@@ -0,0 +1,58 @@
+ALTER TABLE `zh_material` ADD `is_new` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '是否是新建的调差,用于区分清单新建规则' AFTER `in_time`;
+
+ALTER TABLE `zh_change_plan` ADD `expr` TEXT NULL DEFAULT NULL COMMENT '工程量数量计算式' AFTER `memo`;
+
+ALTER TABLE `zh_change_plan_list` ADD `new_up` tinyint(1) NOT NULL DEFAULT '0' COMMENT '新增单价' AFTER `spamount`;
+
+ALTER TABLE `zh_change_plan_list` ADD `ex_memo1` VARCHAR(255) NULL DEFAULT NULL COMMENT '备注1' AFTER `new_up`;
+
+ALTER TABLE `zh_change_plan_list` ADD `ex_memo2` VARCHAR(255) NULL DEFAULT NULL COMMENT '备注2' AFTER `ex_memo1`;
+
+ALTER TABLE `zh_project_account` ADD `stamp_path` VARCHAR(255) NULL DEFAULT NULL COMMENT '用户签章oss地址' AFTER `sign_path`;
+
+ALTER TABLE `zh_advance_pay` ADD `pay_time` DATETIME NULL DEFAULT NULL COMMENT '支付时间' AFTER `end_time`;
+UPDATE `zh_advance_pay` SET `pay_time`= `create_time`;
+
+CREATE TABLE `zh_material_list_gcl`  (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `tid` int(11) NOT NULL COMMENT '标段id',
+  `mid` int(11) NOT NULL COMMENT '调差id',
+  `order` tinyint(4) NOT NULL COMMENT '添加的历史期',
+  `gcl_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '工程量id',
+  `mb_id` int(11) NOT NULL COMMENT '工料id',
+  `quantity` decimal(30, 8) NULL DEFAULT NULL COMMENT '数目',
+  `expr` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '公式',
+  PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '用于新建期时清单关联已使用过的工程量,创建新的工料与清单的联系表';
+
+CREATE TABLE `zh_construction_unit`  (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `pid` int(11) NOT NULL COMMENT '项目id',
+  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '单位名称',
+  `type` tinyint(2) NOT NULL COMMENT '单位类型',
+  `corporation` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '法人代表',
+  `credit_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '企业信用代码',
+  `tel` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '电话',
+  `address` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '地址',
+  `region` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '地区',
+  `website` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '网站',
+  `basic` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '备注',
+  `sign_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '签章图片地址',
+  `create_time` datetime NOT NULL COMMENT '创建时间',
+  PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '参建单位表';
+
+CREATE TABLE `zh_stage_import_change` (
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `tid` int(11) unsigned NOT NULL COMMENT '标段id',
+  `sid` int(11) unsigned NOT NULL COMMENT '期id',
+  `lid` varchar(36) COLLATE utf8_unicode_ci NOT NULL COMMENT '台账节点id',
+  `import_lid` varchar(36) COLLATE utf8_unicode_ci NOT NULL COMMENT '导入的最底层项目节id',
+  `rela_tid` int(11) unsigned NOT NULL COMMENT '关联标段id',
+  `rela_sid` int(11) unsigned NOT NULL COMMENT '关联期id',
+  `rela_lid` varchar(36) COLLATE utf8_unicode_ci NOT NULL COMMENT '关联台账id',
+  `rela_cid` varchar(36) CHARACTER SET ascii NOT NULL COMMENT '关联变更令id',
+  `rela_cbid` int(11) unsigned NOT NULL COMMENT '关联变更清单id',
+  `rela_qty` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '关联数量',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2278 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;