Browse Source

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

Tony Kang 1 năm trước cách đây
mục cha
commit
33e2464d5b

+ 1 - 1
app/controller/tender_controller.js

@@ -630,7 +630,7 @@ module.exports = app => {
                 const stageAUditorsId = ctx.helper._.map(stageAuditors, 'aid');
                 const accountId = ctx.session.sessionUser.accountId;
                 if (auditorsId.indexOf(accountId) === -1 && ctx.tender.data.user_id !== accountId &&
-                    stageAUditorsId.indexOf(accountId) === -1) {
+                    stageAUditorsId.indexOf(accountId) === -1 && !ctx.session.sessionUser.is_admin) {
                     throw '您无权修改标段设置内容';
                 }
 

+ 6 - 8
app/lib/revise_price.js

@@ -348,8 +348,6 @@ class revisePriceCalc {
         const said = this.ctx.session.sessionUser.accountId;
         billsTree.calculateAll(node => {
             if (node.children && node.children.length > 0) return;
-            // const priceDiff = helper.sub(node.unit_price, node.pre_unit_price);
-            // if (!priceDiff) return;
             if (node.cur_id && (node.cur_contract_qty || node.cur_qc_qty)) {
                 const cur_contract_tp = helper.mul(node.cur_contract_qty, node.unit_price, decimal.tp);
                 const cur_qc_tp = helper.mul(node.cur_qc_qty, node.unit_price, decimal.tp);
@@ -375,6 +373,12 @@ class revisePriceCalc {
                     }
                 }
             }
+            const scDetail = stageChange.filter(x => { return x.lid === node.id; });
+            for (const scd of scDetail) {
+                result.scData.push({ id: scd.id, unit_price: node.unit_price });
+            }
+            const priceDiff = helper.sub(node.unit_price, node.pre_unit_price);
+            if (!priceDiff) return;
             if (node.pre_id && (node.pre_contract_qty || node.pre_qc_qty)) {
                 node.contract_pc_tp = helper.sub(helper.mul(node.pre_contract_qty, node.unit_price, decimal.tp), node.pre_contract_tp);
                 node.qc_pc_tp = helper.sub(helper.mul(node.pre_qc_qty, node.unit_price, decimal.tp), node.pre_qc_tp);
@@ -387,10 +391,6 @@ class revisePriceCalc {
                     positive_qc_pc_tp: node.positive_qc_pc_tp, negative_qc_pc_tp: node.negative_qc_pc_tp,
                 });
             }
-            const scDetail = stageChange.filter(x => { return x.lid === node.id; });
-            for (const scd of scDetail) {
-                result.scData.push({ id: scd.id, unit_price: node.unit_price });
-            }
         });
         if (result.ibData.length > 0) await transaction.insert(this.ctx.service.stageBills.tableName, result.ibData);
         if (result.ubData.length > 0) await transaction.updateRows(this.ctx.service.stageBills.tableName, result.ubData);
@@ -430,8 +430,6 @@ class revisePriceCalc {
         const said = this.ctx.session.sessionUser.accountId;
         billsTree.calculateAll(node => {
             if (node.children && node.children.length > 0) return;
-            // const priceDiff = helper.sub(node.unit_price, node.pre_unit_price);
-            // if (!priceDiff) return;
             if (node.cur_id && (node.cur_contract_qty || node.cur_qc_qty)) {
                 const cur_contract_tp = helper.mul(node.cur_contract_qty, node.unit_price, decimal.tp);
                 const cur_qc_tp = helper.mul(node.cur_qc_qty, node.unit_price, decimal.tp);

+ 183 - 34
app/public/js/change_information_add_list.js

@@ -145,7 +145,7 @@ $(document).ready(() => {
                 }
             }
             SpreadJsObj.loadSheetData(xmjSpreadSheet, SpreadJsObj.DataType.Data, xmjs);
-            checkSelectAll();
+            checkSelectAll(data);
         },
         selectionChanged: function (e, info) {
             const data = SpreadJsObj.getSelectObject(info.sheet);
@@ -202,6 +202,8 @@ $(document).ready(() => {
             if (info.sheet.zh_setting) {
                 const select = SpreadJsObj.getSelectObject(info.sheet);
                 const col = info.sheet.zh_setting.cols[info.col];
+                const gclInfo = SpreadJsObj.getSelectObject(gclSpreadSheet);
+                const gclIndex = changeListData.indexOf(gclInfo);
                 if (col.field === 'is_change') {
                     if (xmjCol.readOnly.isChangeList(select)) {
                         info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
@@ -211,24 +213,6 @@ $(document).ready(() => {
                         info.sheet.endEdit(true);
                     }
                     const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
-                    let gclIndex = -1;
-                    let gclInfo = null;
-                    if (select.deal_id) {
-                        gclInfo = _.find(changeListData, function (item) {
-                            return item.id && item.id === select.deal_id; });
-                        gclIndex =_.findIndex(changeListData, function (item) {
-                            return item.id && item.id === select.deal_id; });
-                    } else {
-                        gclInfo = _.find(changeListData, function (item) {
-                            return item.leafXmjs && _.find(item.leafXmjs, function (item2) {
-                                return item2.gcl_id === select.gcl_id && (item2.mx_id === undefined || item2.mx_id === select.mx_id) });
-                        });
-                        gclIndex = _.findIndex(changeListData, function (item) {
-                            return item.leafXmjs && _.find(item.leafXmjs, function (item2) {
-                                return item2.gcl_id === select.gcl_id && (item2.mx_id === undefined || item2.mx_id === select.mx_id) });
-                        });
-                    }
-                    console.log(gclIndex);
                     if (!gclInfo) {
                         info.sheet.setValue(info.row, info.col, 0);
                         return;
@@ -262,7 +246,7 @@ $(document).ready(() => {
                                 mx_id: '',
                             }
                             _.assign(data, newData);
-                        } else {
+                        } else if (gclInfo.leafXmjs) {
                             const xmjInfo = _.find(gclInfo.leafXmjs, function (item) {
                                 return item.gcl_id === select.gcl_id && (item.mx_id === undefined || item.mx_id === select.mx_id);
                             });
@@ -295,6 +279,7 @@ $(document).ready(() => {
                             select.is_change = 1;
                             changeListData[gclIndex].is_change = 1;
                             SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
+                            checkSelectAll(gclInfo);
                         }, function () {
                             info.sheet.setValue(info.row, info.col, 0);
                         });
@@ -316,6 +301,7 @@ $(document).ready(() => {
                             }, function (result) {
                                 changeList = result.changeList;
                                 select.is_change = 0;
+                                checkSelectAll(gclInfo);
                                 if (select.deal_id) {
                                     changeListData[gclIndex].is_change = 0;
                                     SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
@@ -372,7 +358,7 @@ $(document).ready(() => {
                 const changePos = _.find(result.changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
                 if (changeLedger || changePos) {
                     xmj.cid = 1;
-                    xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
+                    xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
                     hadcid = 1;
                 }
             }
@@ -519,22 +505,185 @@ $(document).ready(() => {
         gclSpread.refresh();
         xmjSpread.refresh();
     });
-});
-function checkSelectAll() {
-    let check = $('#code-list tr').length > 0 ? true : false;
-    const codeNum = $('#code-list tr').length;
-    let i = 0;
-    $('#code-list tr').each(function () {
-        if ($(this).css('display') !== 'none' && !$(this).find('input').is(':checked')) {
-            check = false;
-            return;
+
+    // 全选及取消
+    $('#code-select-all').click(function () {
+        // 全选checkbox
+        const data = SpreadJsObj.getSelectObject(gclSpreadSheet);
+        if ($(this).is(':checked')){
+            const addDatas = [];
+            if (data && data.id) {
+                if (_.findIndex(changeList, function (item) {
+                    return item.id && item.id === data.id;
+                }) === -1) {
+                    addDatas.push({
+                        lid: data.id,
+                        code: data.code,
+                        name: data.name || '',
+                        unit: data.unit || '',
+                        unit_price: data.unit_price,
+                        oamount: data.quantity ? parseFloat(data.quantity) : 0,
+                        oamount2: data.quantity ? parseFloat(data.quantity) : 0,
+                        bwmx: '',
+                        xmj_code: '',
+                        xmj_jldy: '',
+                        xmj_dwgc: '',
+                        xmj_fbgc: '',
+                        xmj_fxgc: '',
+                        gcl_id: '',
+                        mx_id: '',
+                    });
+                }
+            } else if (data && data.leafXmjs) {
+                for (const leaf of data.leafXmjs) {
+                    if (_.findIndex(changeList, function (item) {
+                        return item.gcl_id === leaf.gcl_id && item.mx_id === (leaf.mx_id || '');
+                    }) === -1) {
+                        addDatas.push({
+                            lid: leaf.gcl_id,
+                            code: data.code,
+                            name: data.name || '',
+                            unit: data.unit || '',
+                            unit_price: data.unit_price,
+                            oamount: leaf.quantity,
+                            oamount2: leaf.quantity,
+                            bwmx: leaf.bwmx || leaf.jldy || '',
+                            xmj_code: leaf.code || '',
+                            xmj_jldy: leaf.jldy || '',
+                            xmj_dwgc: leaf.dwgc || '',
+                            xmj_fbgc: leaf.fbgc || '',
+                            xmj_fxgc: leaf.fxgc || '',
+                            gcl_id: leaf.gcl_id,
+                            mx_id: leaf.mx_id,
+                        });
+                    }
+                }
+            }
+            console.log(addDatas);
+            if (addDatas.length > 0) {
+                // 更新至服务器
+                postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
+                    type: 'add-change-list',
+                    postData: addDatas,
+                }, function (result) {
+                    changeList = result.changeList;
+                    const gclIndex = changeListData.indexOf(data);
+                    console.log(gclIndex, data);
+                    data.is_change = 1;
+                    changeListData[gclIndex].is_change = 1;
+                    SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
+                    gclSpreadObj.resetXmjSpread(data);
+                }, function () {
+                    $('#code-select-all').prop('checked', false);
+                });
+            }
+        } else {
+            const cList = xmjSpreadSheet.zh_data;
+            const removeDatas = [];
+            let hadContinue = false;
+            for (const c of cList) {
+                const cInfo = c.deal_id ? _.find(changeList, { lid: c.deal_id }) : _.find(changeList, function (item) {
+                   return item.gcl_id === c.gcl_id && item.mx_id === c.mx_id;
+                });
+                if (_.find(changeUsedData, {cbid: cInfo.id})) {
+                    hadContinue = true;
+                    continue;
+                } else if (checkIsSettle(cInfo)) {
+                    hadContinue = true;
+                    continue;
+                }
+                removeDatas.push(cInfo);
+            }
+            console.log(removeDatas);
+            if (removeDatas.length > 0) {
+                postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
+                    type: 'del-change-list',
+                    ids: _.map(removeDatas, 'id'),
+                    postData: null
+                }, function (result) {
+                    changeList = result.changeList;
+                    if (!hadContinue) {
+                        const gclIndex = changeListData.indexOf(data);
+                        data.is_change = 0;
+                        changeListData[gclIndex].is_change = 0;
+                        SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
+                    }
+                    gclSpreadObj.resetXmjSpread(data);
+                }, function () {
+                    $('#code-select-all').prop('checked', true);
+                });
+            }
+        }
+    });
+    // 选中所有新增部位/清单
+    $('#add-all-revise').click(function() {
+        const this_cid = window.location.pathname.split('/')[4];
+        const addDatas = [];
+        const refreshIndexs = [];
+        for (const gclInfo of _.filter(changeListData, { cid: 1 })) {
+            const leafXmjs = _.filter(gclInfo.leafXmjs, { ccid: this_cid });
+            if (leafXmjs.length > 0) {
+                gclInfo.is_change = 1;
+                refreshIndexs.push(changeListData.indexOf(gclInfo));
+                for (const xmj of leafXmjs) {
+                    if (_.findIndex(changeList, function (item) {
+                        return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
+                    }) === -1) {
+                        addDatas.push({
+                            lid: xmj.gcl_id,
+                            code: gclInfo.code,
+                            name: gclInfo.name || '',
+                            unit: gclInfo.unit || '',
+                            unit_price: gclInfo.unit_price,
+                            oamount: xmj.quantity,
+                            oamount2: xmj.quantity,
+                            bwmx: xmj.bwmx || xmj.jldy || '',
+                            xmj_code: xmj.code || '',
+                            xmj_jldy: xmj.jldy || '',
+                            xmj_dwgc: xmj.dwgc || '',
+                            xmj_fbgc: xmj.fbgc || '',
+                            xmj_fxgc: xmj.fxgc || '',
+                            gcl_id: xmj.gcl_id,
+                            mx_id: xmj.mx_id || '',
+                        });
+                    }
+                }
+            }
         }
-        else if ($(this).css('display') === 'none') {
-            i++;
+        console.log(addDatas);
+        if (addDatas.length > 0) {
+            // 更新至服务器
+            postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
+                type: 'add-change-list',
+                postData: addDatas,
+            }, function (result) {
+                toastr.success('已新增当前变更令新增的所有部位/清单');
+                changeList = result.changeList;
+                refreshIndexs.forEach(function (index) {
+                    changeListData[index].is_change = 1;
+                    SpreadJsObj.reLoadRowData(gclSpreadSheet, index);
+                });
+                const data = SpreadJsObj.getSelectObject(gclSpreadSheet);
+                gclSpreadObj.resetXmjSpread(data);
+            });
+        } else {
+            toastr.warning('未存在当前变更令新增的部位/清单');
         }
     });
-    if (check && i === codeNum) {
-        check = false;
+});
+function checkSelectAll(data) {
+    let check = false;
+    if (data && data.id && data.is_change) {
+        check = true;
+    } else if(data && data.leafXmjs) {
+        check = data.leafXmjs.length > 0 ? true : false;
+        data.leafXmjs.forEach(function (item) {
+            const is_change = _.findIndex(changeList, { gcl_id: item.gcl_id, mx_id: item.mx_id || '' }) !== -1
+            if (!is_change) {
+                check = false;
+                return;
+            }
+        });
     }
     $('#code-select-all').prop('checked', check);
 }

+ 11 - 1
app/view/change/addlist.ejs

@@ -3,9 +3,11 @@
     <div class="panel-title">
         <div class="title-main  d-flex">
             <% include ./sub_mini_menu.ejs %>
+            <% if (ctx.session.sessionProject.page_show.openChangeRevise) { %>
             <div class="ml-auto">
-                <a class="btn btn-sm btn-primary mr-1" id="select-all-revise" href="javascript: void(0);">添加当前新增部位/清单</a>
+                <a class="btn btn-sm btn-primary mr-1" id="add-all-revise" href="javascript: void(0);">添加当前新增部位/清单</a>
             </div>
+            <% } %>
         </div>
     </div>
     <div class="content-wrap row pr-46">
@@ -24,6 +26,14 @@
                             <li class="nav-item">
                                 <a class="nav-link active" href="javascript:void(0)">所属项目节</a>
                             </li>
+                            <li class="nav-item">
+                                <div class="d-inline-block mt-1 ml-3 mr-1">
+                                    <div class="custom-control custom-checkbox">
+                                        <input type="checkbox" class="custom-control-input" id="code-select-all">
+                                        <label class="custom-control-label" for="code-select-all">全选</label>
+                                    </div>
+                                </div>
+                            </li>
                             <li class="nav-item" style="width: 350px;" id="xmj-search">
                             </li>
                         </ul>