Ver código fonte

1. 计算模板,自定义计算式,if计算
2. 台账分解,复制整块相关

MaiXinRong 6 horas atrás
pai
commit
c74bf7deb6

+ 61 - 16
app/base/base_bills_service.js

@@ -21,10 +21,11 @@ const billsUtils = require('../lib/bills_utils');
 
 class BaseBillsSerivce extends TreeService {
 
-    constructor (ctx, setting, relaPosName, relaAncGclName, relaExtraName, relaPosDetailName) {
+    constructor (ctx, setting, relaPosName, relaAncGclName, relaAncGclDetailName, relaExtraName, relaPosDetailName) {
         super(ctx, setting);
         this.relaPosService = relaPosName;
         this.relaAncGclService = relaAncGclName;
+        this.relaAncGclDetailService = relaAncGclDetailName;
         this.relaExtraService = relaExtraName;
         this.relaPosDetailService = relaPosDetailName;
     }
@@ -50,6 +51,13 @@ class BaseBillsSerivce extends TreeService {
         return this._ancGclName ? this.ctx.service[this._ancGclName] : undefined;
     }
 
+    set relaAncGclDetailService(ancGclDetailName) {
+        this._ancGclDetailName = ancGclDetailName;
+    }
+    get relaAncGclDetailService() {
+        return this._ancGclDetailName ? this.ctx.service[this._ancGclDetailName] : undefined;
+    }
+
     set relaExtraService(extraName) {
         this._extraName = extraName
     }
@@ -657,12 +665,13 @@ class BaseBillsSerivce extends TreeService {
             if (pd[0].ledger_pid !== pasteData[0][0].ledger_pid) throw '复制数据错误:仅可操作同层节点';
         }
         const userId = this.ctx.session.sessionUser.accountId;
+        const qtyDecimal = this.ctx.tender.info.decimal.qty;
         this.newBills = false;
         const selectData = await this.getDataByKid(tid, sid);
         if (!selectData) throw '粘贴数据错误';
         const newParentPath = selectData.full_path.replace(selectData.ledger_id, '');
 
-        const pasteBillsData = [], pastePosData = [], pasteAncGclData = [], pasteBillsExtraData = [], pastePosDetailData = [], leafBillsId = [];
+        const pasteBillsData = [], pastePosData = [], pasteAncGclData = [], pasteAncGclDetailData = [], pasteBillsExtraData = [], pastePosDetailData = [], leafBillsId = [];
         const tpDecimal = this.ctx.tender.info.decimal.tp;
         let maxId = await this._getMaxLid(this.ctx.tender.id);
         const calcTemplate = await this.ctx.service.calcTmpl.getAllTemplateDetail(this.ctx.session.sessionProject.id, 'posCalc');
@@ -794,6 +803,40 @@ class BaseBillsSerivce extends TreeService {
                         newBills.qtcl_qty = this.ctx.helper.add(newBills.qtcl_qty, newPos.qtcl_qty);
                         newBills.ex_qty1 = this.ctx.helper.add(newBills.ex_qty1, newPos.ex_qty1);
                         if (defaultData) this.ctx.helper._.assignIn(newPos, defaultData);
+
+                        for (const ag of pos.ancGcl) {
+                            const nig = {
+                                id: this.uuid.v4(), tid: this.ctx.tender.id,
+                                add_user_id: userId, update_user_id: userId,
+                                lid: newPos.lid, pid: newPos.id, g_order: ag.g_order,
+                                is_aux: ag.is_aux || 0, name: ag.name || '', unit: ag.unit || '',
+                                drawing_code: ag.drawing_code || '', memo: ag.memo || '',
+                                quantity: ag.quantity || 0, expr: ag.expr || '', calc_template: ag.calc_template || ''
+                            };
+                            pasteAncGclData.push(nig);
+                            if (!ag.calc_template) continue;
+
+                            let sumQty = 0;
+                            for (const cd of ag.calcDetail) {
+                                const newDetail = {
+                                    id: this.uuid.v4(), tid: this.ctx.tender.id, lid: newPos.lid, pid: newPos.id, ag_id: nig.id,
+                                    create_user_id: userId, update_user_id: userId,
+                                    agd_order: cd.agd_order,
+                                    str1 : cd.str1 || '', str2 : cd.str1 || '', str3 : cd.str1 || '', str4 : cd.str1 || '',
+                                    num_a : cd.num_a || 0, num_b : cd.num_b || 0, num_c : cd.num_c || 0, num_d : cd.num_d || 0,
+                                    num_e : cd.num_e || 0, num_f : cd.num_f || 0, num_g : cd.num_g || 0, num_h : cd.num_h || 0,
+                                    num_i : cd.num_i || 0, num_j : cd.num_j || 0, num_k : cd.num_k || 0, num_l : cd.num_l || 0,
+                                    num_m : cd.num_m || 0, num_n : cd.num_n || 0, num_o : cd.num_o || 0, num_p : cd.num_p || 0,
+                                    num_q : cd.num_q || 0, num_r : cd.num_r || 0, num_s : cd.num_s || 0, num_t : cd.num_t || 0,
+                                    num_u : cd.num_u || 0,
+                                    qty: cd.qty || 0, expr: cd.expr || 0, spec: cd.spec || ''
+                                };
+                                sumQty = this.ctx.helper.add(sumQty, newDetail.qty);
+                                pasteAncGclDetailData.push(newDetail);
+                            }
+                            nig.quantity = this.ctx.helper.round(sumQty, qtyDecimal);
+                        }
+
                         pastePosData.push(newPos);
                     }
                 } else {
@@ -811,19 +854,19 @@ class BaseBillsSerivce extends TreeService {
                 newBills.deal_tp = this.ctx.helper.mul(newBills.deal_qty, newBills.unit_price, tpDecimal);
                 newBills.ex_tp1 = this.ctx.helper.mul(newBills.ex_qty1, newBills.unit_price, tpDecimal);
                 if (defaultData) this.ctx.helper._.assignIn(newBills, defaultData);
-                if (d.ancGcl && d.ancGcl.length > 0) {
-                    for (const gcl of d.ancGcl) {
-                        const newAncGcl = {
-                            id: this.uuid.v4(), tid: tid, lid: newBills.id,
-                            add_user_id: userId, update_user_id: userId,
-                            name: gcl.name, unit: gcl.unit, g_order: gcl.g_order, is_aux: gcl.is_aux,
-                            quantity: gcl.quantity, expr: gcl.expr,
-                            drawing_code: gcl.drawing_code, memo: gcl.memo,
-                        };
-                        if (defaultData) this.ctx.helper._.assignIn(newAncGcl, defaultData);
-                        pasteAncGclData.push(newAncGcl);
-                    }
-                }
+                // if (d.ancGcl && d.ancGcl.length > 0) {
+                //     for (const gcl of d.ancGcl) {
+                //         const newAncGcl = {
+                //             id: this.uuid.v4(), tid: tid, lid: newBills.id,
+                //             add_user_id: userId, update_user_id: userId,
+                //             name: gcl.name, unit: gcl.unit, g_order: gcl.g_order, is_aux: gcl.is_aux,
+                //             quantity: gcl.quantity, expr: gcl.expr,
+                //             drawing_code: gcl.drawing_code, memo: gcl.memo,
+                //         };
+                //         if (defaultData) this.ctx.helper._.assignIn(newAncGcl, defaultData);
+                //         pasteAncGclData.push(newAncGcl);
+                //     }
+                // }
                 pbd.push(newBills);
             }
             for (const d of pbd) {
@@ -852,6 +895,7 @@ class BaseBillsSerivce extends TreeService {
                 await this.transaction.insert(this.relaPosService.tableName, pastePosData);
             }
             if (pasteAncGclData.length > 0 && this.relaAncGclService) await this.transaction.insert(this.relaAncGclService.tableName, pasteAncGclData);
+            if (pasteAncGclDetailData.length > 0 && this.relaAncGclDetailService) await this.transaction.insert(this.relaAncGclDetailService.tableName, pasteAncGclDetailData);
             if (pasteBillsExtraData.length > 0 && this.relaExtraService) await this.transaction.insert(this.relaExtraService.tableName, pasteBillsExtraData);
             if (pastePosDetailData.length > 0 && this.relaPosDetailService) await this.transaction.insert(this.relaPosDetailService.tableName, pastePosDetailData);
             await this.transaction.commit();
@@ -863,6 +907,7 @@ class BaseBillsSerivce extends TreeService {
         // 查询应返回的结果
         const updateData = await this.getNextsData(selectData.tender_id, selectData.ledger_pid, selectData.order + pasteData.length);
         const ancGcl = this.relaAncGclService ? { add: pasteAncGclData } : undefined;
+        const ancGclDetail = this.relaAncGclDetailSerivce ? { add: pasteAncGclDetailData } : undefined;
         const posCalcDetail = this.relaPosDetailService ? { add: pastePosDetailData } : undefined;
         if (pasteBillsExtraData.length > 0) {
             for (const be of pasteBillsExtraData) {
@@ -872,7 +917,7 @@ class BaseBillsSerivce extends TreeService {
         }
         return {
             ledger: { create: pasteBillsData, update: updateData },
-            pos: pastePosData, ancGcl, posCalcDetail,
+            pos: pastePosData, ancGcl, ancGclDetail, posCalcDetail,
         };
     }
 

+ 13 - 7
app/public/js/ledger.js

@@ -1934,18 +1934,24 @@ $(document).ready(function() {
                 for (const b of cbl) {
                     const posRange = pos.getLedgerPos(b.id);
                     if (posRange && posRange.length > 0) b.pos = posRange;
-                    if (b.calc_template) {
-                        const template = posCalcTemplate.find(x => { return x.id === b.calc_template; });
-                        b.calc_template_str = template ? template.name : '';
-                        if (b.pos) {
+
+                    if (b.pos) {
+                        for (p of b.pos) {
+                            p.ancGcl = ancGcl.getPartData(p.id) || [];
+                            for (const ag of p.ancGcl) {
+                                if (ag.calc_template) ag.calcDetail = ancGclDetail.detail.getPartData(ag.id);
+                            }
+                        }
+                        if (b.calc_template) {
+                            const template = posCalcTemplate.find(x => { return x.id === b.calc_template; });
+                            b.calc_template_str = template ? template.name : '';
                             for (const p of b.pos) {
                                 const detailRange = posCalcDetail.detail.getPartData(p.id);
                                 p.calcDetail = detailRange;
                             }
                         }
                     }
-                    const gclRange = ancGcl.getPartData(b.id);
-                    if (gclRange && gclRange.length > 0) b.ancGcl = gclRange;
+
                 }
             }
             return copyBlockList;
@@ -3425,7 +3431,7 @@ $(document).ready(function() {
                     const detailRange = posCalcDetail.detail.getPartData(p.id);
                     p.calcDetail = detailRange;
                 }
-                p.ancGcl = ancGcl.getPartData(p.id);
+                p.ancGcl = ancGcl.getPartData(p.id) || [];
                 for (const ag of p.ancGcl) {
                     if (ag.calc_template) ag.calcDetail = ancGclDetail.detail.getPartData(ag.id);
                 }

+ 1 - 0
app/public/js/shares/ct_preview.js

@@ -16,6 +16,7 @@ const calcTemplatePreview = (function(){
                 try {
                     pd[pc.field] = ZhCalc.round(ZhCalc.mathCalcExpr(calcExpr.replace(new RegExp('%', 'gm'), '/100')), pc.decimal);
                 } catch(err) {
+                    console.log(err);
                     pd[pc.field] = 0;
                 }
             }

+ 3 - 0
app/public/js/zh_calc.js

@@ -9,6 +9,9 @@
  */
 
 ;
+math.import({
+    if: function(con, a, b) { return con ? a : b; },
+});
 const zhBaseCalc = (function () {
     const zeroPrecision = 12, mulPrecision = 12, divPrecision = 12;
 

+ 3 - 0
app/service/calc_tmpl.js

@@ -14,6 +14,9 @@ const math = require('mathjs');
 math.config({
     number: 'BigNumber',
 });
+math.import({
+    if: function(con, a, b) { return con ? a : b; },
+});
 const ValidTemplateType = ['posCalc', 'cost'];
 const PosCalc = (function(){
     const EmptySpreadCache = {

+ 1 - 1
app/service/ledger.js

@@ -51,7 +51,7 @@ module.exports = app => {
                 fullPath: 'full_path',
                 keyPre: 'ledger_bills_maxLid:',
                 uuid: true,
-            }, 'pos', 'ancillaryGcl', 'ledgerExtra', 'posCalcDetail');
+            }, 'pos', 'ancillaryGcl', 'ancillaryGclDetail', 'ledgerExtra', 'posCalcDetail');
             this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'ledger';
         }

+ 1 - 1
app/service/pos.js

@@ -517,7 +517,7 @@ module.exports = app => {
                         lid: nip.lid, pid: nip.id, g_order: ag.g_order,
                         is_aux: ag.is_aux || 0, name: ag.name || '', unit: ag.unit || '',
                         drawing_code: ag.drawing_code || '', memo: ag.memo || '',
-                        quantity: ag.quantity || 0, expr: b.expr || '', calc_template: ag.calc_template || ''
+                        quantity: ag.quantity || 0, expr: ag.expr || '', calc_template: ag.calc_template || ''
                     };
                     insertAncGcl.push(nig);
                     if (!ag.calc_template) continue;