Ver código fonte

Merge branch 'dev' into uat

MaiXinRong 3 anos atrás
pai
commit
7fa814010e

+ 3 - 3
app/const/spread.js

@@ -205,7 +205,7 @@ const stageTz = {
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
             {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
-            {title: '|完成率(%)', colSpan: '1', rowSpan: '|1', field: 'end_gather_1_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
+            {title: '|完成率(%)', colSpan: '1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
             {title: '合同|项目节数量1',  colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
             {title: '|项目节数量2',  colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
             {title: '变更|项目节数量1',  colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
@@ -283,7 +283,7 @@ const stageCl = {
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
             {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
-            {title: '|完成率(%)', colSpan: '1', rowSpan: '|1', field: 'end_gather_1_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
+            {title: '|完成率(%)', colSpan: '1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
             {title: '合同|项目节数量1',  colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
             {title: '|项目节数量2',  colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
             {title: '变更|项目节数量1',  colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
@@ -360,7 +360,7 @@ const stageNoCl = {
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
             {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, readOnly: true, type: 'Number'},
-            {title: '|完成率(%)', colSpan: '1', rowSpan: '|1', field: 'end_gather_1_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
+            {title: '|完成率(%)', colSpan: '1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
             {title: '合同|项目节数量1',  colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
             {title: '|项目节数量2',  colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
             {title: '变更|项目节数量1',  colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},

+ 1 - 1
app/controller/change_controller.js

@@ -763,7 +763,7 @@ module.exports = app => {
                     return item.qty !== null;
                 })
                 renderData.changeUsedData = changeUsedData;
-                renderData.stageChangeNum = this.ctx.helper.sum(changeUsedData.map(x => { return Math.abs(x.used_qty); }));
+                renderData.stageChangeNum = this.ctx.helper.sum(changeUsedData.map(x => { return Math.abs(x.qty); }));
                 await this.layout('change/information.ejs', renderData, 'change/information_modal.ejs');
             } catch (err) {
                 this.log(err);

+ 1 - 1
app/controller/material_controller.js

@@ -1471,7 +1471,7 @@ module.exports = app => {
                         responseData.data = await ctx.service.materialList.adds(data.postData, data.checklist);
                         break;
                     case 'dels':
-                        responseData.data = await ctx.service.materialList.dels(data.postData, data.checklist);
+                        responseData.data = await ctx.service.materialList.dels(data.postData, data.checklist, true);
                         break;
                     case 'updates':
                         if (data.updateData.quantity === '' || data.updateData.quantity === null) {

+ 1 - 18
app/controller/stage_controller.js

@@ -350,9 +350,6 @@ module.exports = app => {
                         case 'changeBills':
                             responseData.data.changeBills = await this.ctx.service.changeAuditList.checkedChangeBills(ctx.stage.tid);
                             break;
-                        case 'minus_change':
-                            responseData.data.minus_change = await this.ctx.service.stageChangeFinal.getPreMinusChange(ctx.stage.tid, ctx.stage.order);
-                            break;
                         case 'import_change':
                             responseData.data.import_change = await this.ctx.service.stageImportChange.getStageImportData(this.ctx.stage);
                             break;
@@ -527,22 +524,18 @@ module.exports = app => {
                 if (!data.target || (!data.target.bills && !data.target.pos) || !data.change) {
                     throw '调用变更令数据错误';
                 }
-                let result, minus;
+                let result, minus, posMinus;
                 if (data.target.pos) {
                     result = await ctx.service.stageChange.posChange(data.target.pos, data.change);
                     result.change = { target: { lid: data.target.pos.lid, pid: data.target.pos.id } };
                     result.change.data = await ctx.service.stageChange.getLastestStageData(ctx.tender.id,
                         ctx.stage.id, data.target.pos.lid, data.target.pos.id);
-                    minus = await this.ctx.service.stageChange.getBillsMinusQty(ctx.stage, data.target.pos.lid);
                 } else {
                     result = await ctx.service.stageChange.billsChange(data.target.bills, data.change);
                     result.change = { target: { lid: data.target.bills.id, pid: '-1' } };
                     result.change.data = await ctx.service.stageChange.getLastestStageData(ctx.tender.id,
                         ctx.stage.id, data.target.bills.id, '-1');
-                    minus = await this.ctx.service.stageChange.getBillsMinusQty(ctx.stage, data.target.bills.id);
                 }
-                const bills = result.bills.curStageData.find(x => { return x.lid === minus.lid });
-                if (bills) bills.minus_qc_qty = minus.qty;
                 await ctx.service.stage.updateCheckCalcFlag(ctx.stage, true);
                 await ctx.service.stage.updateCacheTime(ctx.stage.id);
                 ctx.body = { err: 0, msg: '', data: result };
@@ -1417,16 +1410,6 @@ module.exports = app => {
                 const ledgerData = await this._getStageLedgerData(ctx);
                 const posData = await this._getStagePosData(ctx);
                 const changeData = await this._getStageChangeData(ctx);
-                const preMinusChange = await this.ctx.service.stageChangeFinal.getPreMinusChange(ctx.stage.tid, ctx.stage.order);
-                const minusChange = changeData.filter(x => { return x.minus });
-                this.ctx.helper.assignSumRelaData(ledgerData, 'id', [
-                    {data: preMinusChange, fields: [{source: 'qty', target: 'pre_minus_qc_qty'}], relaField: 'lid'},
-                    {data: minusChange, fields: [{source: 'qty', target: 'minus_qc_qty'}], relaField: 'lid'},
-                ]);
-                this.ctx.helper.assignSumRelaData(posData, 'id', [
-                    {data: preMinusChange, fields: [{source: 'qty', target: 'pre_minus_qc_qty'}], relaField: 'pid'},
-                    {data: minusChange, fields: [{source: 'qty', target: 'minus_qc_qty'}], relaField: 'pid'},
-                ]);
                 const convert = new billsPosConvert(ctx);
                 convert.loadData(ledgerData, posData, changeData);
                 const result = convert.convert(data.filter);

+ 4 - 1
app/controller/wap_controller.js

@@ -120,7 +120,10 @@ module.exports = app => {
             // 获取待审批的期
             const auditStages = await ctx.service.stageAudit.getAuditStageByWap(ctx.session.sessionUser.accountId);
             for (const audit of auditStages) {
-                await this.ctx.service.stage.checkStageGatherData(audit);
+                if (audit.status !== auditConst.stage.status.uncheck) {
+                    const isLastage = await ctx.service.stage.isLastStage(audit.tid, audit.id);
+                    if (isLastage) await this.ctx.service.stage.checkStageGatherData(audit);
+                }
                 audit.gather_tp = ctx.helper.add(audit.contract_tp, audit.qc_tp);
                 audit.end_contract_tp = ctx.helper.add(audit.contract_tp, audit.pre_contract_tp);
                 audit.end_qc_tp = ctx.helper.add(audit.qc_tp, audit.pre_qc_tp);

+ 0 - 16
app/lib/bills_pos_convert.js

@@ -98,9 +98,6 @@ class BillsPosConvert {
         node.pre_gather_qty = this.ctx.helper.add(node.pre_gather_qty, data.pre_gather_qty);
 
         node.real_qty = this.ctx.helper.add(node.real_qty, data.real_qty);
-
-        node.minus_qc_qty = this.ctx.helper.add(node.minus_qc_qty, data.minus_qc_qty);
-        node.pre_minus_qc_qty = this.ctx.helper.add(node.pre_minus_qc_qty, data.pre_minus_qc_qty);
     }
     _loadBillsCalcFields(node, data) {
         node.quantity = this.ctx.helper.add(node.quantity, data.quantity);
@@ -117,9 +114,6 @@ class BillsPosConvert {
         node.pre_qc_qty = this.ctx.helper.add(node.pre_qc_qty, data.pre_qc_qty);
         node.pre_qc_tp = this.ctx.helper.add(node.pre_qc_tp, data.pre_qc_tp);
         node.pre_gather_qty = this.ctx.helper.add(node.pre_gather_qty, data.pre_gather_qty);
-
-        node.minus_qc_qty = this.ctx.helper.add(node.minus_qc_qty, data.minus_qc_qty);
-        node.pre_minus_qc_qty = this.ctx.helper.add(node.pre_minus_qc_qty, data.pre_minus_qc_qty);
     }
     _convertGcl(node, xmj) {
         if (!xmj) return;
@@ -241,13 +235,6 @@ class BillsPosConvert {
         child.estimate_tp = this.ctx.helper.mul(child.estimate_qty, child.unit_price, tpDecimal);
 
         child.bgl_code = this.ctx.helper._.uniq(this.ctx.helper._.map(child.changes, 'c_code')).join(';');
-
-        // 1#台账相关
-        child.end_minus_qc_qty = this.ctx.helper.add(child.pre_minus_qc_qty, child.minus_qc_qty); // 1#台账 台账+负变更
-        child.end_1_qty = this.ctx.helper.add(child.end_minus_qc_qty, child.quantity); // 1#台账 台账+负变更
-        child.end_1_tp = this.ctx.helper.mul(child.unit_price, child.end_1_qty, tpDecimal);
-        child.end_final_1_tp = this.ctx.helper.add(child.end_qc_tp, child.end_1_tp);
-        child.end_gather_1_percent = this.ctx.helper.mul(this.ctx.helper.div(child.end_gather_tp, child.end_final_1_tp, 4), 100);
     }
     _calculateNode(node, children) {
         for (const child of children) {
@@ -263,14 +250,11 @@ class BillsPosConvert {
             node.end_gather_tp = this.ctx.helper.add(node.end_gather_tp, child.end_gather_tp);
             node.real_tp = this.ctx.helper.add(node.real_tp, child.real_tp);
             node.estimate_tp = this.ctx.helper.add(node.estimate_tp, child.estimate_tp);
-            node.end_1_tp = this.ctx.helper.add(node.end_1_tp, child.end_1_tp);
         }
         if (node.dgn_qty1)
             node.dgn_price = this.ctx.helper.div(node.total_price, node.dgn_qty1, this.ctx.tender.info.decimal.up);
         node.final_tp = this.ctx.helper.add(node.total_price, node.end_qc_tp);
         node.end_gather_percent = this.ctx.helper.mul(this.ctx.helper.div(node.end_gather_tp, node.final_tp, 4), 100);
-        node.end_final_1_tp = this.ctx.helper.add(node.end_qc_tp, node.end_1_tp);
-        node.end_gather_1_percent = this.ctx.helper.mul(this.ctx.helper.div(node.end_gather_tp, node.end_final_1_tp, 4), 100);
     }
     _recursiveCalcUnitNodes(nodes) {
         if (!nodes || !nodes instanceof Array || nodes.length === 0) return;

+ 1 - 1
app/lib/ledger.js

@@ -616,7 +616,7 @@ class checkData {
             if (ratio === 0) {
                 if (!data.contract_tp && !data.pre_contract_tp) return 2; // 漏计
             } else {
-                const tp = this.ctx.helper.mul(data.total_price, this.ctx.helper.div(ratio, 100, 4), this.ctx.tender.info.decimal.tp);
+                const tp = this.ctx.helper.mul(data.final_1_tp, this.ctx.helper.div(ratio, 100, 4), this.ctx.tender.info.decimal.tp);
                 const checkTp = this.ctx.helper.add(data.contract_tp, data.pre_contract_tp);
                 if (tp > checkTp) return 1; // 违规
                 if (tp < checkTp) return 2; // 漏计

+ 8 - 8
app/public/js/change_information_approval.js

@@ -201,13 +201,13 @@ $(document).ready(() => {
                     validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
                     // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
                     const usedInfo = _.find(changeUsedData, { id: select.id });
-                    if (usedInfo && validText >= 0 && validText < usedInfo.used_qty) {
-                        toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
+                    if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
+                        toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
                         return;
-                    } else if (usedInfo && validText < 0 && validText > usedInfo.used_qty) {
-                        toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
+                    } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
+                        toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
                         return;
@@ -294,14 +294,14 @@ $(document).ready(() => {
                         validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
                         // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
                         const usedInfo = _.find(changeUsedData, { id: sortData[curRow].id });
-                        if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
-                            toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
+                        if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
+                            toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
                             SpreadJsObj.reLoadRowData(info.sheet, curRow);
                             changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol);
                             bPaste = false;
                             continue;
-                        } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
-                            toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
+                        } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
+                            toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
                             SpreadJsObj.reLoadRowData(info.sheet, curRow);
                             changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol);
                             bPaste = false;

+ 68 - 13
app/public/js/change_information_set.js

@@ -384,7 +384,7 @@ $(document).ready(() => {
             const sel = info.sheet.getSelections()[0];
             const col = info.sheet.zh_setting.cols[sel.col];
             const data = SpreadJsObj.getSelectObject(info.sheet);
-            if (col && col.field === 'del_list' && !_.find(changeUsedData, { cbid: data.id })) {
+            if (col && col.field === 'del_list' && data && !_.find(changeUsedData, { cbid: data.id })) {
                 changeSpreadObj.del();
             }
             changeSpreadObj.resetXmjSpread(data);
@@ -456,12 +456,12 @@ $(document).ready(() => {
                 if(col.field === 'camount') {
                     // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
                     const usedInfo = _.find(changeUsedData, { cbid: select.id });
-                    if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
-                        toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
+                    if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
+                        toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         return;
-                    } else if (usedInfo && usedInfo.used_qty < 0  && validText > usedInfo.used_qty) {
-                        toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
+                    } else if (usedInfo && usedInfo.qty < 0  && validText > usedInfo.qty) {
+                        toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         return;
                     }
@@ -509,6 +509,8 @@ $(document).ready(() => {
             }
             const data = [];
             // const rowData = [];
+            let needCopyIgnore = !$('#customCheck1').is(':checked');
+            let needColAdd = false;
             for (let iRow = 0; iRow < range.rowCount; iRow++) {
                 let bPaste = true;
                 const curRow = range.row + iRow;
@@ -518,7 +520,12 @@ $(document).ready(() => {
                 let sameCol = 0;
                 for (let iCol = 0; iCol < range.colCount; iCol++) {
                     const curCol = range.col + iCol;
-                    const colSetting = info.sheet.zh_setting.cols[curCol];
+                    let colSetting = info.sheet.zh_setting.cols[curCol];
+                    if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
+                        const newCurCol = curCol + 1;
+                        needColAdd = true;
+                        colSetting = info.sheet.zh_setting.cols[newCurCol];
+                    }
                     if (!colSetting) continue;
 
                     let validText = info.sheet.getText(curRow, curCol);
@@ -546,12 +553,12 @@ $(document).ready(() => {
                         if(colSetting.field === 'camount') {
                             // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
                             const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
-                            if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
-                                toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
+                            if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
+                                toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
                                 bPaste = false;
                                 continue;
-                            } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
-                                toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
+                            } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
+                                toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
                                 bPaste = false;
                                 continue;
                             }
@@ -566,8 +573,10 @@ $(document).ready(() => {
                         cLData.camount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
                         cLData.oamount = ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
                     }
-                    cLData[colSetting.field] = validText;
-                    sortData[curRow][colSetting.field] = validText;
+                    if (colSetting.field !== 'oa_tp' && colSetting.field !== 'ca_tp') {
+                        cLData[colSetting.field] = validText;
+                        sortData[curRow][colSetting.field] = validText;
+                    }
                     cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
                 }
                 if (bPaste) {
@@ -716,7 +725,53 @@ $(document).ready(() => {
         changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
         SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
         changeSpreadSheet.getCell(-1, 10).foreColor('#dc3545');
+        const delCommand = {
+            canUndo: false,
+            execute: function (context, options, isUndo) {
+                const Commands = GC.Spread.Sheets.Commands;
+                const sel = changeSpreadSheet.getSelections()[0];
+                const col = changeSpreadSheet.zh_setting.cols[sel.col];
+                if (col && col.field !== 'ca_tp') {
+                    isUndo = true;
+                }
+                if (isUndo) {
+                    Commands.undoTransaction(context, options);
+                    return true;
+                } else {
+                    Commands.startTransaction(context, options);
 
+                    Commands.endTransaction(context, options);
+                    return true;
+                }
+            }
+        };
+        const delCommand2 = {
+            canUndo: false,
+            execute: function (context, options, isUndo) {
+                const Commands = GC.Spread.Sheets.Commands;
+                const sel = changeSpreadSheet.getSelections()[0];
+                const col = changeSpreadSheet.zh_setting.cols[sel.col];
+                if (col && col.field !== 'del_list') {
+                    isUndo = true;
+                }
+                if (isUndo) {
+                    Commands.undoTransaction(context, options);
+                    return true;
+                } else {
+                    Commands.startTransaction(context, options);
+
+                    Commands.endTransaction(context, options);
+                    return true;
+                }
+            }
+        };
+        const commandManager = changeSpread.commandManager();
+        commandManager.register('banDel', delCommand);
+        commandManager.register('banDel2', delCommand2);
+        commandManager.register('banDel3', _.cloneDeep(delCommand2));// 不能共用banDel2
+        commandManager.setShortcutKey('banDel', 39, false, false, false, false);// 改写键盘右键,防止删除清单
+        commandManager.setShortcutKey('banDel2', 40, false, false, false, false);// 改写键盘下键,防止删除清单
+        commandManager.setShortcutKey('banDel3', 38, false, false, false, false);// 改写键盘上键,防止删除清单
         let batchInsertObj;
         $.contextMenu.types.batchInsert = function (item, opt, root) {
             const self = this;
@@ -1136,7 +1191,7 @@ $(document).ready(() => {
     $('#list-input').on('blur', function () {
         const select = parseInt($('#select-list').val());
         const value = _.trim($(this).val());
-        const valueList = _.slice(_.without(_.uniq(_.replace(value, /\t/g, ' ').split(' ')), ''), 0, 10);
+        const valueList = _.slice(_.without(_.uniq(_.replace(_.replace(value, /\'|\"/g, ''), /\t/g, ' ').split(' ')), ''), 0, 10);
         console.log(valueList);
         // 判断是否存在多个分词,以换行或空格分隔,多个则显示左侧菜单
         if (value !== '' && valueList.length > 1) {

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

@@ -200,7 +200,7 @@ const ledgerCheckUtil = {
                 if (ratio === 0) {
                     if (!data.contract_tp && !data.pre_contract_tp) return 2; // 漏计
                 } else {
-                    const tp = ZhCalc.mul(data.total_price, ZhCalc.div(ratio, 100, 4), this.ctx.tender.info.decimal.tp);
+                    const tp = ZhCalc.mul(data.final_1_tp, ZhCalc.div(ratio, 100, 4), this.ctx.tender.info.decimal.tp);
                     const checkTp = ZhCalc.add(data.contract_tp, data.pre_contract_tp);
                     if (tp > checkTp) return 1; // 违规
                     if (tp < checkTp) return 2; // 漏计

+ 12 - 40
app/public/js/stage.js

@@ -36,7 +36,7 @@ function customColDisplay () {
         { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
         { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
         { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
-        { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent', 'end_gather_1_percent'], visible: true },
+        { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent'], visible: true },
         { title: '本期批注', fields: ['postil'], visible: true },
         { title: '图册号', fields: ['drawing_code'], visible: true },
         { title: '备注', fields: ['memo'], visible: true },
@@ -267,9 +267,9 @@ $(document).ready(() => {
         markExpandSubKey: window.location.pathname.split('/')[2],
     };
     // 台账树结构计算相关设置
-    stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr', 'minus_qc_qty'];
+    stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr'];
     stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
-        'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp', 'end_1_tp'];
+        'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp'];
     stageTreeSetting.calcFun = function (node) {
         if (!node.children || node.children.length === 0) {
             node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
@@ -277,9 +277,6 @@ $(document).ready(() => {
             node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
             node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
             node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
-            node.end_minus_qc_qty = ZhCalc.add(node.pre_minus_qc_qty, node.minus_qc_qty);
-            node.end_1_qty = ZhCalc.add(node.end_minus_qc_qty, node.quantity); // 1#台账 台账+负变更
-            node.end_1_tp = ZhCalc.mul(node.unit_price, node.end_1_qty, tenderInfo.decimal.tp);
         }
         node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
         node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
@@ -287,7 +284,7 @@ $(document).ready(() => {
         node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
         node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
         node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
-        node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.end_1_tp);
+        node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.final_1_tp);
         if (!node.children || node.children.length === 0) {
             if (node.end_contract_qty) {
                 node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
@@ -297,8 +294,6 @@ $(document).ready(() => {
         }
         node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
         node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
-        node.end_gather_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_1_tp), 100, 2);
-        node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_1_tp), 100, 2);
         node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
     };
     const stageTree = createNewPathTree('stage', stageTreeSetting);
@@ -418,6 +413,7 @@ $(document).ready(() => {
             // 切换变更令,加载右侧明细数据
             this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
                 const change = SpreadJsObj.getSelectObject(info.sheet);
+                console.log(change);
                 if(change) {
                     self._loadChangeDetail(change);
                 }
@@ -658,8 +654,6 @@ $(document).ready(() => {
     };
     const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_gather_percent' || x.field === 'end_correct_percent'});
     if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_percent' : 'end_gather_percent';
-    const ratioCol1 = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_gather_1_percent' || x.field === 'end_correct_1_percent'});
-    if (ratioCol) ratioCol1.field = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_gather_1_percent';
     ledgerSpreadSetting.imageClick = function (data, hitinfo) {
         const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
         switch (col.field) {
@@ -974,11 +968,12 @@ $(document).ready(() => {
             }
         },
         loadRelaData: function () {
-            const billsSheet = spSpread.getActiveSheet();
-            SpreadJsObj.resetTopAndSelect(billsSheet);
+            const billsSheet = slSpread.getActiveSheet();
+            SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
+            const posSheet = spSpread.getActiveSheet();
+            SpreadJsObj.resetTopAndSelect(posSheet);
             stagePosSpreadObj.loadCurPosData();
             if (posSearch) posSearch.search();
-            SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
         },
         selectionChanged: function (e, info) {
             if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
@@ -2041,26 +2036,11 @@ $(document).ready(() => {
     });
 
     // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
-    postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;import_change;tag;cooperation;minus_change' }, function (result) {
+    postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;import_change;tag;cooperation' }, function (result) {
         // 加载树结构
         stageTree.loadDatas(result.ledgerData);
-        let mcIndex = {};
-        if (result.minus_change && result.minus_change.length > 0) {
-            for (const mc of result.minus_change) {
-                if (!mcIndex[mc.lid]) mcIndex[mc.lid] = stageTree.nodes.find(x => { return x.id === mc.lid; });
-                if (!mcIndex[mc.lid]) continue;
-                mcIndex[mc.lid].pre_minus_qc_qty = ZhCalc.add(mcIndex[mc.lid].pre_minus_qc_qty, mc.qty);
-            }
-        }
-        if (result.changeData && result.changeData.length > 0) {
-            for (const mc of result.changeData) {
-                if (!mc.minus || !mc.qty) continue;
-                if (!mcIndex[mc.lid]) mcIndex[mc.lid] = stageTree.nodes.find(x => { return x.id === mc.lid; });
-                if (!mcIndex[mc.lid]) continue;
-                mcIndex[mc.lid].minus_qc_qty = ZhCalc.add(mcIndex[mc.lid].minus_qc_qty, mc.qty);
-            }
-        }
-        mcIndex = null;
+        // 加载部位明细
+        stagePos.loadDatas(result.posData);
         checkShowLast(result.ledgerData.length);
         treeCalc.calculateAll(stageTree);
         // 加载解锁相关
@@ -2075,8 +2055,6 @@ $(document).ready(() => {
             t.node = stageTree.datas.find(x => {return x.id === t.lid});
         }
         billsTag.loadDatas(result.tags);
-        // 加载部位明细
-        stagePos.loadDatas(result.posData);
         stagePos.calculateAll();
         SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
         SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
@@ -3900,7 +3878,6 @@ $(document).ready(() => {
                             {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
                             {title: '数量', field: 'quantity', hAlign: 2, width: 50},
                             {title: '完成率(%)', field: 'end_gather_percent', hAlign: 2, width: 70},
-                            {title: '本期负变更', field: 'minus_qc_qty', hAlign: 2, width: 50},
                         ],
                         emptyRows: 0,
                         headRows: 1,
@@ -3939,11 +3916,6 @@ $(document).ready(() => {
                                 }
                             }
                         }, {
-                            key: 'minus_qc_qty', title: '负变更', valid: true,
-                            check: function (node) {
-                                return node.end_minus_qc_qty;
-                            }
-                        }, {
                             key: 'estimate', title: '预计变更', valid: true,
                             check: function (node) {
                                 const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];

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

@@ -155,7 +155,7 @@ $(document).ready(() => {
             }
         }
     });
-    $('a', '.side-menu').bind('click', function (e) {
+    $('a', '.content-wrap .side-menu').bind('click', function (e) {
         e.preventDefault();
         const tab = $(this), tabPanel = $(tab.attr('content'));
         const showSideTools = function (show) {

+ 2 - 2
app/service/material_list.js

@@ -463,7 +463,7 @@ module.exports = app => {
          * @param {int} id 工料id
          * @return {void}
          */
-        async dels(datas, checklist = false) {
+        async dels(datas, checklist = false, fromCheckList = false) {
             if (!this.ctx.tender || !this.ctx.material) {
                 throw '数据错误';
             }
@@ -486,7 +486,7 @@ module.exports = app => {
                 await transaction.commit();
                 // console.log(datas);
                 const gclList = await this.ctx.service.materialListGcl.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
-                return checklist ? gclList : {
+                return fromCheckList ? gclList : {
                     gclList,
                     materialListData: await this.getMaterialData(this.ctx.tender.id, this.ctx.material.id),
                 };

+ 5 - 0
app/service/stage.js

@@ -720,6 +720,11 @@ module.exports = app => {
             }
             return stages;
         }
+
+        async isLastStage(tid, sid) {
+            const lastStage = await this.ctx.service.stage.getLastestStage(tid, true);
+            return lastStage ? lastStage.id === sid : false;
+        }
     }
 
     return Stage;

+ 39 - 43
app/service/stage_bills_final.js

@@ -75,54 +75,50 @@ module.exports = app => {
             if (!transaction || !tender || !stage) {
                 throw '数据错误';
             }
-            if (stage.order > 1) {
-                const cur = await this.ctx.service.stageBills.getLastestStageData2(tender.id, stage.id);
-                const pre = await this.getFinalData(tender, stage.order - 1);
-                if ((!cur || cur.length === 0) && (!pre || pre.length === 0)) return;
-                for (const c of cur) {
-                    delete c.id;
-                    delete c.said;
-                    delete c.times;
-                    delete c.order;
-                    delete c.postil;
-                    c.sorder = stage.order;
-                    const p = this.ctx.helper._.find(pre, function (x) {
-                        return x.lid === c.lid;
-                    });
-                    if (p) {
-                        c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
-                        c.contract_tp = this.ctx.helper.add(c.contract_tp, p.contract_tp);
-                        c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
-                        c.qc_tp = this.ctx.helper.add(c.qc_tp, p.qc_tp);
-                        c.used = p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)
-                            || !this.ctx.helper.checkZero(c.contract_tp) || !this.ctx.helper.checkZero(c.qc_tp);
-                        pre.splice(pre.indexOf(p), 1);
+            const cur = await this.ctx.service.stageBills.getLastestStageData2(tender.id, stage.id);
+            const pre = await this.getFinalData(tender, stage.order - 1);
+            const minusChange = await this.ctx.service.stageChange.getStageMinusChange(stage);
+            if ((!cur || cur.length === 0) && (!pre || pre.length === 0)) return;
+            for (const c of cur) {
+                delete c.id;
+                delete c.said;
+                delete c.times;
+                delete c.order;
+                delete c.postil;
+                c.sorder = stage.order;
+                const p = this.ctx.helper._.find(pre, function (x) {
+                    return x.lid === c.lid;
+                });
+                if (p) {
+                    c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
+                    c.contract_tp = this.ctx.helper.add(c.contract_tp, p.contract_tp);
+                    c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
+                    c.qc_tp = this.ctx.helper.add(c.qc_tp, p.qc_tp);
+                    if (p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)
+                        || !this.ctx.helper.checkZero(c.contract_tp)) {
+                        c.used = true;
                     } else {
-                        c.used = !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)
-                            || !this.ctx.helper.checkZero(c.contract_tp) || !this.ctx.helper.checkZero(c.qc_tp);
+                        const mc = minusChange.find(x => { return x.lid === c.lid && x.qty < 0 });
+                        c.used = !!mc;
+                    }
+                    pre.splice(pre.indexOf(p), 1);
+                } else {
+                    if (!this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)
+                        || !this.ctx.helper.checkZero(c.contract_tp)) {
+                        c.used = true;
+                    } else {
+                        const mc = minusChange.find(x => { return x.lid === c.lid && x.qty < 0 });
+                        c.used = !!mc;
                     }
                 }
+            }
 
-                for (const p of pre) {
-                    if (p.id !== undefined) delete p.id;
-                    p.sid = stage.id;
-                    p.sorder = stage.order;
-                }
-                await transaction.insert(this.tableName, cur ? cur.concat(pre) : pre);
-            } else {
-                const sql = 'Insert Into ??(tid, sid, lid, sorder, contract_qty, contract_tp, qc_qty, qc_tp, used)' +
-                    '  SELECT b.tid, b.sid, b.lid, ? As `sorder`, b.contract_qty, b.contract_tp, b.qc_qty, b.qc_tp,' +
-                    '    IF(IFNULL(b.contract_qty, 0) <> 0 or IFNULL(b.contract_tp, 0) <> 0 or IFNULL(b.qc_qty, 0) <> 0 or IFNULL(b.qc_tp, 0) <> 0, 1, 0) As used' +
-                    '  FROM ' + this.ctx.service.stageBills.tableName + ' AS b' +
-                    '  INNER JOIN(' +
-                    '    SELECT Max(`times` * ' + timesLen + ' + `order`) As `flow`, `lid` FROM ' + this.ctx.service.stageBills.tableName +
-                    '    WHERE `sid` = ?' +
-                    '    GROUP By `lid`) As MF' +
-                    '  ON (b.times * ' + timesLen + ' + b.order) = MF.flow AND b.lid = MF.lid' +
-                    '  WHERE b.sid = ?';
-                const sqlParam = [this.tableName, stage.order, stage.id, stage.id];
-                await transaction.query(sql, sqlParam);
+            for (const p of pre) {
+                if (p.id !== undefined) delete p.id;
+                p.sid = stage.id;
+                p.sorder = stage.order;
             }
+            await transaction.insert(this.tableName, cur ? cur.concat(pre) : pre);
         }
 
         /**

+ 15 - 16
app/service/stage_change.js

@@ -156,9 +156,7 @@ module.exports = app => {
                 if (!nc || nc.qty !== oc.qty) {
                     const qty = nc ? this.round(nc.qty, precision.value) : null;
                     const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc ? nc.minus : oc.minus);
-                    if (!change.minus) {
-                        billsQty = this.ctx.helper.add(billsQty, change.qty);
-                    }
+                    billsQty = this.ctx.helper.add(billsQty, change.qty);
                     if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
                         change.id = oc.id;
                         updateChanges.push(change);
@@ -166,18 +164,14 @@ module.exports = app => {
                         newChanges.push(change);
                     }
                 } else {
-                    if (!oc.minus) {
-                        billsQty = this.ctx.helper.add(billsQty, oc.qty);
-                    }
+                    billsQty = this.ctx.helper.add(billsQty, oc.qty);
                 }
             }
             for (const c of changes) {
                 const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
                 if (!nc) {
                     const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus);
-                    if (!change.minus) {
-                        billsQty = this.ctx.helper.add(billsQty, change.qty);
-                    }
+                    billsQty = this.ctx.helper.add(billsQty, change.qty);
                     newChanges.push(change);
                 }
             }
@@ -234,7 +228,7 @@ module.exports = app => {
                 if (!nc || nc.qty !== oc.qty) {
                     const qty = nc ? this.round(nc.qty, precision.value) : null;
                     const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc ? nc.minus : oc.minus);
-                    if (!change.minus) posQty = this.ctx.helper.add(posQty, change.qty);
+                    posQty = this.ctx.helper.add(posQty, change.qty);
                     if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
                         change.id = oc.id;
                         updateChanges.push(change);
@@ -242,16 +236,14 @@ module.exports = app => {
                         newChanges.push(change);
                     }
                 } else {
-                    if (!oc.minus) posQty = this.ctx.helper.add(posQty, oc.qty);
+                    posQty = this.ctx.helper.add(posQty, oc.qty);
                 }
             }
             for (const c of changes) {
                 const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
                 if (!nc) {
                     const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus);
-                    if (!change.minus) {
-                        posQty = this.ctx.helper.add(posQty, change.qty);
-                    }
+                    posQty = this.ctx.helper.add(posQty, change.qty);
                     newChanges.push(change);
                 }
             }
@@ -399,7 +391,7 @@ module.exports = app => {
             data = helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
             const bqData = [];
             for (const d of data) {
-                if (!d.qty || d.minus) continue;
+                if (!d.qty) continue;
                 let bd = bqData.find(x => { return x.lid === d.lid && x.quality === d.quality; });
                 if (!bd) {
                     const bills = await this.db.get(this.ctx.service.ledger.departTableName(tender.id), { id: d.lid });
@@ -486,7 +478,7 @@ module.exports = app => {
         }
 
         async getStageMinusChange(stage) {
-            const data = this.getAllDataByCondition({ where: { sid: stage.id, minus: 1 } });
+            const data = await this.getAllDataByCondition({ where: { sid: stage.id, minus: 1 } });
             return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
         };
 
@@ -495,6 +487,13 @@ module.exports = app => {
             const filter = this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
             return { lid, qty: this.ctx.helper.sum(filter.map(x => { return x.qty; })) };
         };
+
+
+        async getPosMinusQty(stage, pid) {
+            const data = await this.getAllDataByCondition({ where: { sid: stage.id, pid, minus: 1 } });
+            const filter = this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
+            return { pid, qty: this.ctx.helper.sum(filter.map(x => { return x.qty; })) };
+        };
     }
 
     return StageChange;

+ 35 - 39
app/service/stage_pos_final.js

@@ -57,50 +57,46 @@ module.exports = app => {
             if (!transaction || !tender || !stage) {
                 throw '数据错误';
             }
-            if (stage.order > 1) {
-                const cur = await this.ctx.service.stagePos.getLastestStageData2(tender.id, stage.id);
-                const pre = await this.getFinalData(tender, stage.order - 1);
-                if ((!cur || cur.length === 0) && (!pre || pre.length === 0)) return;
-                for (const c of cur) {
-                    delete c.id;
-                    delete c.said;
-                    delete c.times;
-                    delete c.order;
-                    delete c.postil;
-                    c.sorder = stage.order;
-                    const p = this.ctx.helper._.find(pre, function (x) {
-                        return x.pid === c.pid;
-                    });
-                    if (p) {
-                        c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
-                        c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
-                        c.used = p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty);
-                        pre.splice(pre.indexOf(p), 1);
+            const cur = await this.ctx.service.stagePos.getLastestStageData2(tender.id, stage.id);
+            const pre = stage.order > 1 ? await this.getFinalData(tender, stage.order - 1) : [];
+            const minusChange = await this.ctx.service.stageChange.getStageMinusChange(stage);
+            if ((!cur || cur.length === 0) && (!pre || pre.length === 0)) return;
+            for (const c of cur) {
+                delete c.id;
+                delete c.said;
+                delete c.times;
+                delete c.order;
+                delete c.postil;
+                c.sorder = stage.order;
+                const p = this.ctx.helper._.find(pre, function (x) {
+                    return x.pid === c.pid;
+                });
+                if (p) {
+                    c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
+                    c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
+                    c.used = p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty);
+                    pre.splice(pre.indexOf(p), 1);
+                } else {
+                    if (!this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)) {
+                        c.used = true;
                     } else {
-                        c.used = !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty);
+                        const mc = minusChange.find(x => { return x.pid === c.pid && x.qty < 0});
+                        c.used = !!mc;
                     }
                 }
-                for (const p of pre) {
-                    if (p.id !== undefined) delete p.id;
-                    p.sid = stage.id;
-                    p.sorder = stage.order;
-                    p.used = p.used || !this.ctx.helper.checkZero(p.contract_qty) || !this.ctx.helper.checkZero(p.qc_qty);
+            }
+            for (const p of pre) {
+                if (p.id !== undefined) delete p.id;
+                p.sid = stage.id;
+                p.sorder = stage.order;
+                if (p.used || !this.ctx.helper.checkZero(p.contract_qty) || !this.ctx.helper.checkZero(p.qc_qty)) {
+                    p.used = true;
+                } else {
+                    const mc = minusChange.find(x => { return x.pid === p.pid && x.qty < 0});
+                    p.used = !!mc;
                 }
-                await transaction.insert(this.tableName, cur ? cur.concat(pre) : pre);
-            } else {
-                const sql = 'Insert Into ??(tid, sid, lid, pid, sorder, contract_qty, qc_qty, used)' +
-                            '  SELECT p.tid, p.sid, p.lid, p.pid, ? As `sorder`, p.contract_qty, p.qc_qty,' +
-                            '    IF(IFNULL(p.contract_qty, 0) <> 0 or IFNULL(p.qc_qty, 0) <> 0, 1, 0) As used' +
-                            '  FROM ' + this.ctx.service.stagePos.tableName + ' AS p' +
-                            '  INNER JOIN(' +
-                            '    SELECT Max(`times` * ' + timesLen +' + `order`) As `flow`, `pid` FROM ' + this.ctx.service.stagePos.tableName +
-                            '    WHERE `sid` = ?' +
-                            '    GROUP By `pid`) As MF' +
-                            '  ON (p.times * ' + timesLen + ' + p.order) = MF.flow AND p.pid = MF.pid' +
-                            '  WHERE p.sid = ?';
-                const sqlParam = [this.tableName, stage.order, stage.id, stage.id];
-                await transaction.query(sql, sqlParam);
             }
+            await transaction.insert(this.tableName, cur ? cur.concat(pre) : pre);
         }
 
         /**

+ 3 - 3
app/view/change/information.ejs

@@ -478,7 +478,7 @@
     let changeOrder = parseInt('<%- change.order_by %>');
     console.log(changeUsedData);
 </script>
-<script src="/public/js/change_information_set.js?202001181"></script>
+<script src="/public/js/change_information_set.js?202206211"></script>
 <script src="/public/js/change_audit.js"></script>
 <% } else if (auditStatus === 3 || auditStatus === 4 || auditStatus === 5 || auditStatus === 7 || auditStatus === 8) { %>
 <script>
@@ -486,7 +486,7 @@
     const aidList = _.map(auditList2, 'uid');
     aidList.splice(0, 1);
 </script>
-<script src="/public/js/change_information_show.js?202001181"></script>
+<script src="/public/js/change_information_show.js?202206211"></script>
 <% } else if (auditStatus === 6) { %>
 <script>
     const auditList2 = JSON.parse(unescape('<%- escape(JSON.stringify(auditList2)) %>'));
@@ -497,5 +497,5 @@
     const changeLedgerList = JSON.parse(unescape('<%- escape(JSON.stringify(changeLedgerList)) %>'));
     const changePosList = JSON.parse(unescape('<%- escape(JSON.stringify(changePosList)) %>'));
 </script>
-<script src="/public/js/change_information_approval.js?202001181"></script>
+<script src="/public/js/change_information_approval.js?202206211"></script>
 <% } %>

+ 24 - 12
app/view/dashboard/index.ejs

@@ -38,21 +38,33 @@
                             <div>
                                 <select class="form-control form-control-sm" id="select-doing-type">
                                     <option value="0">全部</option>
-                                    <option value="6">预付款</option>
-                                    <option value="5">台账审批</option>
-                                    <option value="4">台账修订</option>
-                                    <option value="2">计量审批</option>
-                                    <option value="3">变更审批</option>
-                                    <% if (ctx.session.sessionProject.page_show.openChangeProject) { %>
-                                        <option value="7">变更立项</option>
+                                    <% if (auditAdvance.length !== 0) { %>
+                                    <option value="6">预付款(<%- auditAdvance.length %>)</option>
                                     <% } %>
-                                    <% if (ctx.session.sessionProject.page_show.openChangeApply) { %>
-                                        <option value="8">变更申请</option>
+                                    <% if (auditTenders.length !== 0) { %>
+                                    <option value="5">台账审批(<%- auditTenders.length %>)</option>
                                     <% } %>
-                                    <% if (ctx.session.sessionProject.page_show.openChangePlan) { %>
-                                        <option value="9">变更方案</option>
+                                    <% if (auditRevise.length !== 0) { %>
+                                    <option value="4">台账修订(<%- auditRevise.length %>)</option>
+                                    <% } %>
+                                    <% if (auditStages.length !== 0) { %>
+                                    <option value="2">计量审批(<%- auditStages.length %>)</option>
+                                    <% } %>
+                                    <% if (auditChanges.length !== 0) { %>
+                                    <option value="3">变更审批(<%- auditChanges.length %>)</option>
+                                    <% } %>
+                                    <% if (ctx.session.sessionProject.page_show.openChangeProject && auditChangeProject.length !== 0) { %>
+                                        <option value="7">变更立项(<%- auditChangeProject.length %>)</option>
+                                    <% } %>
+                                    <% if (ctx.session.sessionProject.page_show.openChangeApply && auditChangeApply.length !== 0) { %>
+                                        <option value="8">变更申请(<%- auditChangeApply.length %>)</option>
+                                    <% } %>
+                                    <% if (ctx.session.sessionProject.page_show.openChangePlan && auditChangePlan.length !== 0) { %>
+                                        <option value="9">变更方案(<%- auditChangePlan.length %>)</option>
+                                    <% } %>
+                                    <% if (auditMaterial.length !== 0) { %>
+                                    <option value="1">材料调差(<%- auditMaterial.length %>)</option>
                                     <% } %>
-                                    <option value="1">材料调差</option>
                                 </select>
                             </div>
                         </div>

+ 2 - 2
app/view/stage/bwtz.ejs

@@ -169,7 +169,7 @@
             {title: '截止本期计量金额|合同计量', colSpan: '4|1', rowSpan: '1|1', field: 'end_contract_tp', hAlign: 2, width: 70, type: 'Number'},
             {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 70, type: 'Number'},
             {title: '|完成计量', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 70, type: 'Number'},
-            {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_1_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
+            {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
             {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
             {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
             {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
@@ -244,7 +244,7 @@
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
             {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
-            {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_1_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
+            {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 80, readOnly: true, type: 'Number'},
             {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code_merge', hAlign: 0, width: 80, formatter: '@'},
             {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil_merge', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
             {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo_merge', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},

+ 22 - 1
sql/update.sql

@@ -109,4 +109,25 @@ ALTER TABLE `zh_stage_change`
 ADD COLUMN `minus`  tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否负变更' AFTER `qty`;
 
 ALTER TABLE `zh_stage_change_final`
-ADD COLUMN `minus`  tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否负变更' AFTER `qty`;
+ADD COLUMN `minus`  tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否负变更' AFTER `qty`;
+
+CREATE TABLE `zh_stage_stash` (
+  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+  `pid` int(11) unsigned NOT NULL COMMENT '项目id',
+  `tid` int(11) unsigned NOT NULL COMMENT '标段id',
+  `sid` int(11) unsigned NOT NULL COMMENT '期id',
+  `sorder` int(11) unsigned NOT NULL COMMENT '期序号',
+  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  `uid` int(11) unsigned NOT NULL COMMENT '保存人',
+  `uname` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '保存人姓名',
+  `filepath` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'oss保存路径',
+  `valid` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '是否可用',
+  `info` varchar(1000) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '相关信息',
+  `remark` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+Update zh_stage_change sc Left Join zh_change_audit_list cal ON sc.cbid = cal.id Set sc.minus = 1 WHERE sc.minus = 0 and cal.spamount < 0;
+
+Update zh_stage_change_final sc Left Join zh_change_audit_list cal ON sc.cbid = cal.id Set sc.minus = 1 WHERE sc.minus = 0 and cal.spamount < 0;