Преглед изворни кода

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

Tony Kang пре 1 година
родитељ
комит
fc50c04dee
3 измењених фајлова са 47 додато и 5 уклоњено
  1. 2 1
      app/service/payment_detail.js
  2. 36 3
      app/service/report_memory.js
  3. 9 1
      app/service/stage_change_final.js

+ 2 - 1
app/service/payment_detail.js

@@ -91,7 +91,7 @@ module.exports = app => {
                     report_json: JSON.stringify(pageRst),
                     in_time: new Date(),
                 };
-                if (preDetail) newDetail.bills_decimal = preDetail.bills_decimal;
+                newDetail.bills_decimal = preDetail ? preDetail.bills_decimal : JSON.stringify(this.ctx.service.paymentSafeBills.decimal);
                 const result = await transaction.insert(this.tableName, newDetail);
                 if (result.affectedRows === 1) {
                     newDetail.id = result.insertId;
@@ -145,6 +145,7 @@ module.exports = app => {
                     in_time: new Date(),
                     type: paymentConst.modes_value_object.safe,
                 };
+                newDetail.bills_decimal = preDetail ? preDetail.bills_decimal : JSON.stringify(this.ctx.service.paymentSafeBills.decimal);
                 const result = await transaction.insert(this.tableName, newDetail);
                 if (result.affectedRows === 1) {
                     newDetail.id = result.insertId;

+ 36 - 3
app/service/report_memory.js

@@ -38,10 +38,11 @@ const billsFields = (function () {
 
     const stage = cur.concat(pre, end, final);
     const stageEnd = pre.concat(end, final);
-    const bgl = ['qc_bgl_code'];
+    const bgl = ['qc_bgl_code', 'pre_qc_bgl_code', 'end_qc_bgl_code'];
+    const endBgl = ['pre_qc_bgl_code', 'end_qc_bgl_code'];
     const leafXmj = ['leaf_xmj_id'];
 
-    return {cur, pre, end, final, final1, stageDgn, stage, stageEnd, bgl, leafXmj};
+    return {cur, pre, end, final, final1, stageDgn, stage, stageEnd, bgl, leafXmj, endBgl};
 })();
 const posFields = (function () {
     const cur = ['contract_qty', 'qc_qty', 'qc_minus_qty', 'gather_qty', 'postil'];
@@ -372,6 +373,7 @@ module.exports = app => {
 
             for (const node of billsTree.nodes) {
                 node.qc_bgl_code = '';
+                node.qc_bgl_arr = [];
                 if (node.children && node.children.length > 0) continue;
 
                 const nodeBgl = helper._.filter(bglData, {lid: node.id});
@@ -380,7 +382,37 @@ module.exports = app => {
                 const validBgl = helper._.filter(nodeBgl, function (x) {
                     return !helper.checkZero(x.qty);
                 });
-                node.qc_bgl_code = helper._.uniq(helper._.map(validBgl, 'c_code')).join(';');
+                node.qc_bgl_arr = helper._.uniq(helper._.map(validBgl, 'c_code'));
+                node.qc_bgl_code = node.qc_bgl_arr.join(';');
+            }
+        }
+
+        async _calcBillsEndBgl(billsTree) {
+            if (!this.ctx.stage) return;
+
+            const helper = this.ctx.helper;
+            const tender = this.ctx.tender;
+            const stage = this.ctx.stage;
+            const preBglData = stage.order > 1 ? await this.ctx.service.stageChangeFinal.getFinalChangeBills(tender.id, stage.order - 1) : [];
+            for (const node of billsTree.nodes) {
+                node.pre_qc_bgl_code = '';
+                node.pre_qc_bgl_arr = [];
+                if (node.children && node.children.length > 0) continue;
+                if (preBglData.length === 0) continue;
+
+                const nodePreBgl = helper._.filter(preBglData, {lid: node.id});
+                if (nodePreBgl.length === 0) continue;
+
+                helper._.pullAll(preBglData, nodePreBgl);
+                const validBgl = helper._.filter(nodePreBgl, function(x) {
+                    return !helper.checkZero(x.qty);
+                });
+                node.pre_qc_bgl_arr = helper._.uniq(helper._.map(validBgl, 'c_code'));
+                node.pre_qc_bgl_code = node.pre_qc_bgl_arr.join(';');
+            }
+            for (const node of billsTree.nodes) {
+                node.end_qc_bgl_arr = helper._.uniq(node.pre_qc_bgl_arr.concat(node.qc_bgl_arr));
+                node.end_qc_bgl_code = node.end_qc_bgl_arr.join(';');
             }
         }
 
@@ -538,6 +570,7 @@ module.exports = app => {
 
                 if (this._checkFieldsExist(fields, billsFields.bgl)) {
                     await this._calcBillsBgl(billsTree);
+                    if (this._checkFieldsExist(fields, billsFields.endBgl)) await this._calcBillsEndBgl(billsTree)
                 }
 
                 if (this._checkFieldsExist(fields, billsFields.leafXmj)) {

+ 9 - 1
app/service/stage_change_final.js

@@ -49,7 +49,7 @@ module.exports = app => {
          * @param transaction - 所属事务
          * @param {Number} tender - 标段
          * @param {Number}stage - 本期
-         * @return {Promise<void>}
+         * @return {Promise<void>}nim
          */
         async generateFinalData(transaction, tender, stage) {
             if (!transaction || !tender || !stage) {
@@ -140,6 +140,14 @@ module.exports = app => {
                 '  WHERE c.tid = ? AND c.valid' + (onlyChecked ? ' AND c.status = 3' : '');
             return await this.db.query(sql, [tid, tid]);
         }
+
+        async getFinalChangeBills(tid, stageOrder) {
+            const sql = 'SELECT scf.*, c.code As c_code' +
+                '  FROM ' + this.ctx.service.stageChangeFinal.tableName + ' scf ' +
+                '  LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON scf.cid = c.cid' +
+                '  WHERE scf.tid = ? And scf.sorder <= ?';
+            return await this.db.query(sql, [tid, stageOrder]);
+        }
     }
 
     return StageChangeFinal;