Przeglądaj źródła

Task #3106 计量单元,查找定位,新增预计变更查找模式

MaiXinRong 5 lat temu
rodzic
commit
4545a1ec1a

+ 1 - 1
app/lib/bills_pos_convert.js

@@ -39,7 +39,7 @@ class BillsPosConvert {
             id: 'id', ledgerId: 'lid',
             updateFields: ['contract_qty', 'qc_qty'],
         });
-        this.bpcChange = []
+        this.bpcChange = [];
         // reusltData
         this.resultTreeSetting = {
             id: 'ledger_id',

+ 18 - 52
app/public/js/shares/cs_tools.js

@@ -281,8 +281,11 @@ const showSideTools = function (show) {
         if (setting.searchOver || setting.searchEmpty) {
             filter.push('<select class="form-control form-control-sm" id="search-filter">');
             filter.push('<option value="">台账</option>');
-            if (setting.searchOver) filter.push('<option value="over">超计</option>');
-            if (setting.searchEmpty) filter.push('<option value="less">漏计</option>');
+            if (setting.customSearch) {
+                for (const cs of setting.customSearch) {
+                    if (cs.valid) filter.push('<option value="' + cs.key + '">' + cs.title + '</option>');
+                }
+            }
             filter.push('</select>');
             // filter.push('<div class="input-group-prepend">');
             // filter.push('<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">台帐</button>');
@@ -316,10 +319,8 @@ const showSideTools = function (show) {
         let searchResult = [];
         const search = function () {
             const filter = $('#search-filter').val();
-            if (filter === 'over') {
-                searchOver();
-            } else if (filter === 'less') {
-                searchLess();
+            if (filter) {
+                searchCustom(filter);
             } else {
                 searchBills();
             }
@@ -339,20 +340,18 @@ const showSideTools = function (show) {
             }
             SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
         };
-        const calculateCompletePercent = function (searchResult) {
-            if (!searchResult) return;
-            for (const sr of searchResult) {
-                const base = ZhCalc.add(sr.total_price, sr.end_qc_tp);
-                sr.complete_percent = base !== 0 ? ZhCalc.mul(ZhCalc.div(sr.end_gather_tp, base), 100, 2) : 0;
-            }
+        const getCheckFun = function (key) {
+            const cs = setting.customSearch.find(function (x) {return x.key === key});
+            return cs ? cs.check : null;
         };
-        const searchOver = function () {
+        const searchCustom = function (key) {
             const keyword = $('#searchKeyword', obj).val();
+            const checkFun = getCheckFun(key);
             searchResult = [];
             const sortData = SpreadJsObj.getSortData(searchSheet);
             for (const node of sortData) {
                 if (node.children && node.children.length > 0) continue;
-                if (setting.checkOver && setting.checkOver(node)) {
+                if (checkFun && checkFun(node)) {
                     if (!keyword ||
                         (node.code && node.code.indexOf(keyword) > -1) ||
                         (node.b_code && node.b_code.indexOf(keyword) > -1) ||
@@ -366,45 +365,12 @@ const showSideTools = function (show) {
             calculateCompletePercent(searchResult);
             SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
         };
-        const searchEmpty = function () {
-            const keyword = $('#searchKeyword', obj).val();
-            searchResult = [];
-            const sortData = SpreadJsObj.getSortData(searchSheet);
-            for (const node of sortData) {
-                if (node.children && node.children.length > 0) continue;
-                if (setting.checkEmpty && setting.checkEmpty(node)) {
-                    if (!keyword ||
-                        (node.code && node.code.indexOf(keyword) > -1) ||
-                        (node.b_code && node.b_code.indexOf(keyword) > -1) ||
-                        (node.name && node.name.indexOf(keyword) > -1)) {
-                        const data = JSON.parse(JSON.stringify(node));
-                        data.visible = true;
-                        searchResult.push(data);
-                    }
-                }
-            }
-            calculateCompletePercent(searchResult);
-            SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
-        };
-        const searchLess = function () {
-            const keyword = $('#searchKeyword', obj).val();
-            searchResult = [];
-            const sortData = SpreadJsObj.getSortData(searchSheet);
-            for (const node of sortData) {
-                if (node.children && node.children.length > 0) continue;
-                if (setting.checkLess && setting.checkLess(node)) {
-                    if (!keyword ||
-                        (node.code && node.code.indexOf(keyword) > -1) ||
-                        (node.b_code && node.b_code.indexOf(keyword) > -1) ||
-                        (node.name && node.name.indexOf(keyword) > -1)) {
-                        const data = JSON.parse(JSON.stringify(node));
-                        data.visible = true;
-                        searchResult.push(data);
-                    }
-                }
+        const calculateCompletePercent = function (searchResult) {
+            if (!searchResult) return;
+            for (const sr of searchResult) {
+                const base = ZhCalc.add(sr.total_price, sr.end_qc_tp);
+                sr.complete_percent = base !== 0 ? ZhCalc.mul(ZhCalc.div(sr.end_gather_tp, base), 100, 2) : 0;
             }
-            calculateCompletePercent(searchResult);
-            SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
         };
 
         $('input', obj).bind('keydown', function (e) {

+ 47 - 25
app/public/js/stage.js

@@ -2890,33 +2890,55 @@ $(document).ready(() => {
                     afterLocated: function () {
                         stagePosSpreadObj.loadCurPosData();
                     },
-                    checkLess: function (node) {
-                        if (node.quantity) {
-                            return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
-                        } else if (node.total_price) {
-                            return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
-                        }
-                    },
-                    checkOver: function (node) {
-                        const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
-                        if (posRange.length > 0) {
-                            for (const p of posRange) {
-                                if (p.end_contract_qty > p.quantity) return true;
+                    customSearch: [
+                        {
+                            key: 'less', title: '漏计', valid: true,
+                            check: function (node) {
+                                if (node.quantity) {
+                                    return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
+                                } else if (node.total_price) {
+                                    return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
+                                }
+                            }
+                        }, {
+                            key: 'over', title: '超计', valid: true,
+                            check: function (node) {
+                                const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
+                                if (posRange.length > 0) {
+                                    for (const p of posRange) {
+                                        if (p.end_contract_qty > p.quantity) return true;
+                                    }
+                                    return false;
+                                } else if (node.end_gather_qty) {
+                                    return !node.quantity || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.quantity, node.end_qc_qty));
+                                } else if (node.end_gather_tp) {
+                                    return !node.total_price || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.total_price, node.end_qc_tp));
+                                }
+                            }
+                        }, {
+                            key: 'empty', title: '漏计', valid: false,
+                            check: function (node) {
+                                if (node.quantity) {
+                                    return !node.end_gather_qty || checkZero(node.end_gather_qty);
+                                } else if (node.total_price) {
+                                    return !node.end_gather_tp || checkZero(node.end_gather_tp);
+                                }
+                            }
+                        }, {
+                            key: 'estimate', title: '预计变更', valid: true,
+                            check: function (node) {
+                                const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
+                                if (posRange.length > 0) {
+                                    for (const p of posRange) {
+                                        if (!checkZero(p.estimate_qty)) return true;
+                                    }
+                                    return false;
+                                } else {
+                                    return false;
+                                }
                             }
-                            return false;
-                        } else if (node.end_gather_qty) {
-                            return !node.quantity || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.quantity, node.end_qc_qty));
-                        } else if (node.end_gather_tp) {
-                            return !node.total_price || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.total_price, node.end_qc_tp));
-                        }
-                    },
-                    checkEmpty: function (node) {
-                        if (node.quantity) {
-                            return !node.end_gather_qty || checkZero(node.end_gather_qty);
-                        } else if (node.total_price) {
-                            return !node.end_gather_tp || checkZero(node.end_gather_tp);
                         }
-                    },
+                    ],
                 });
                 searchLedger.spread.refresh();
             }