Prechádzať zdrojové kódy

计量单元,清单,区分正负变更统计

MaiXinRong 2 rokov pred
rodič
commit
57a3bf8f0a

+ 29 - 10
app/lib/revise_price.js

@@ -46,7 +46,7 @@ class revisePriceCalc {
         // 加载树结构
         const bills = await this.ctx.service.ledger.getData(newStage.tid);
         this.ctx.helper.assignRelaData(bills, [
-            { data: preBillsData, fields: ['id', 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'unit_price'], prefix: 'pre_', relaId: 'lid' },
+            { data: preBillsData, fields: ['id', 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'unit_price', 'positive_qc_qty', 'negative_qc_qty'], prefix: 'pre_', relaId: 'lid' },
         ]);
         const billsTree = new Ledger.billsTree(this.ctx, { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
         billsTree.loadDatas(bills);
@@ -63,6 +63,8 @@ class revisePriceCalc {
             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);
             node.pc_tp = helper.add(node.contract_pc_tp, node.qc_pc_tp);
+            node.positive_pc_tp = helper.mul(priceDiff, node.pre_positive_qc_qty, decimal.tp);
+            node.negative_pc_tp = helper.mul(priceDiff, node.pre_negative_qc_qty, decimal.tp);
             result.ibData.push({
                 tid: newStage.tid, sid: newStage.id, sorder: newStage.order, lid: node.id, org_price: node.pre_unit_price,
                 contract_pc_tp: node.contract_pc_tp, qc_pc_tp: node.qc_pc_tp, pc_tp: node.pc_tp,
@@ -70,13 +72,16 @@ class revisePriceCalc {
         });
         if (result.ibData.length > 0) await transaction.insert(this.ctx.service.stageBillsPc.tableName, result.ibData);
 
-        let contract_pc_tp = 0, qc_pc_tp = 0, pc_tp = 0;
+        let contract_pc_tp = 0, qc_pc_tp = 0, pc_tp = 0, positive_pc_tp = 0, negative_pc_tp = 0;
         for (const ibc of result.ibData) {
             contract_pc_tp = helper.add(contract_pc_tp, ibc.contract_pc_tp);
             qc_pc_tp = helper.add(qc_pc_tp, ibc.qc_pc_tp);
             pc_tp = helper.add(pc_tp, ibc.pc_tp);
+            positive_pc_tp = helper.add(positive_pc_tp, ibc.positive_pc_tp);
+            negative_pc_tp = helper.add(negative_pc_tp, ibc.negative_pc_tp);
         }
-        await transaction.update(this.ctx.service.stage.tableName, { id: newStage.id, contract_pc_tp, qc_pc_tp, pc_tp, check_calc: true, cache_time_l: new Date() });
+        await transaction.update(this.ctx.service.stage.tableName,
+            { id: newStage.id, contract_pc_tp, qc_pc_tp, pc_tp, positive_pc_tp, negative_pc_tp, check_calc: true, cache_time_l: new Date() });
     }
 
     /**
@@ -102,7 +107,6 @@ class revisePriceCalc {
         const billsTree = new Ledger.billsTree(this.ctx, { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: [] });
         billsTree.loadDatas(bills);
 
-
         // 计算 insertBills billsPriceChange reCalcBillsCur/reCalcBillsPrice
         const result = { ibData: [], bpcData: [] };
         const helper = this.ctx.helper;
@@ -127,6 +131,8 @@ class revisePriceCalc {
                 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);
                 node.pc_tp = helper.add(node.contract_pc_tp, node.qc_pc_tp);
+                node.positive_pc_tp = helper.mul(priceDiff, node.pre_positive_qc_qty, decimal.tp);
+                node.negative_pc_tp = helper.mul(priceDiff, node.pre_negative_qc_qty, decimal.tp);
                 result.bpcData.push({
                     tid: stage.tid, sid: stage.id, sorder: stage.order, lid: node.id, org_price: node.pre_unit_price,
                     contract_pc_tp: node.contract_pc_tp, qc_pc_tp: node.qc_pc_tp, pc_tp: node.pc_tp,
@@ -137,13 +143,16 @@ class revisePriceCalc {
         await transaction.delete(this.ctx.service.stageBillsPc.tableName, { sid: stage.id });
         if (result.bpcData.length > 0) await transaction.insert(this.ctx.service.stageBillsPc.tableName, result.bpcData);
 
-        let contract_pc_tp = 0, qc_pc_tp = 0, pc_tp = 0;
+        let contract_pc_tp = 0, qc_pc_tp = 0, pc_tp = 0, positive_pc_tp = 0, negative_pc_tp = 0;
         for (const bpc of result.bpcData) {
             contract_pc_tp = helper.add(contract_pc_tp, bpc.contract_pc_tp);
             qc_pc_tp = helper.add(qc_pc_tp, bpc.qc_pc_tp);
             pc_tp = helper.add(pc_tp, bpc.pc_tp);
+            positive_pc_tp = helper.add(positive_pc_tp, bpc.positive_pc_tp);
+            negative_pc_tp = helper.add(negative_pc_tp, bpc.negative_pc_tp);
         }
-        await transaction.update(this.ctx.service.stage.tableName, { id: stage.id, contract_pc_tp, qc_pc_tp, pc_tp, check_calc: true, cache_time_l: new Date() });
+        await transaction.update(this.ctx.service.stage.tableName,
+            { id: stage.id, contract_pc_tp, qc_pc_tp, pc_tp, positive_pc_tp, negative_pc_tp, check_calc: true, cache_time_l: new Date() });
     }
 
     /**
@@ -154,7 +163,7 @@ class revisePriceCalc {
     async calcChange(change, transaction) {
         const changeBills = await this.ctx.service.changeAuditList.getAllDataByCondition({ where: { cid: change.cid } });
         const updateBills = [];
-        let total_price = 0;
+        let total_price = 0, positive_tp = 0, negative_tp = 0;
         for (const b of changeBills) {
             const p = this.findPrice(b.code, b.name, b.unit, b.unit_price);
             if (p) {
@@ -163,11 +172,16 @@ class revisePriceCalc {
             } else {
                 total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(b.unit_price, b.spamount, change.tp_decimal));
             }
+            if (b.spamount >= 0) {
+                positive_tp = this.ctx.helper.add(positive_tp, total_price);
+            } else {
+                negative_tp = this.ctx.helper.add(negative_tp, total_price);
+            }
         }
         if (updateBills.length > 0) {
             const conn = transaction || this.ctx.sub_db;
             await conn.updateRows(this.ctx.service.changeAuditList.tableName, updateBills);
-            await conn.update(this.ctx.service.change.tableName, { total_price }, { where: { cid: change.cid } });
+            await conn.update(this.ctx.service.change.tableName, { total_price, positive_tp, negative_tp }, { where: { cid: change.cid } });
         }
     }
     /**
@@ -209,6 +223,8 @@ class revisePriceCalc {
             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);
             node.pc_tp = helper.add(node.contract_pc_tp, node.qc_pc_tp);
+            node.positive_pc_tp = helper.mul(priceDiff, node.pre_positive_qc_qty, decimal.tp);
+            node.negative_pc_tp = helper.mul(priceDiff, node.pre_negative_qc_qty, decimal.tp);
             if (node.cur_id) {
                 node.cur_contract_tp = helper.mul(node.cur_contract_qty, node.unit_price, decimal.tp);
                 node.cur_qc_tp = helper.mul(node.cur_qc_qty, node.unit_price, decimal.tp);
@@ -238,13 +254,16 @@ class revisePriceCalc {
         await transaction.delete(this.ctx.service.stageBillsPc.tableName, { sid: stage.id });
         if (result.bpcData.length > 0) await transaction.insert(this.ctx.service.stageBillsPc.tableName, result.bpcData);
 
-        let contract_pc_tp = 0, qc_pc_tp = 0, pc_tp = 0;
+        let contract_pc_tp = 0, qc_pc_tp = 0, pc_tp = 0, positive_pc_tp = 0, negative_pc_tp = 0;
         for (const bpc of result.bpcData) {
             contract_pc_tp = helper.add(contract_pc_tp, bpc.contract_pc_tp);
             qc_pc_tp = helper.add(qc_pc_tp, bpc.qc_pc_tp);
             pc_tp = helper.add(pc_tp, bpc.pc_tp);
+            positive_pc_tp = helper.add(positive_pc_tp, bpc.positive_pc_tp);
+            negative_pc_tp = helper.add(negative_pc_tp, bpc.negative_pc_tp);
         }
-        await transaction.update(this.ctx.service.stage.tableName, { id: stage.id, contract_pc_tp, qc_pc_tp, pc_tp, check_calc: true, cache_time_l: new Date() });
+        await transaction.update(this.ctx.service.stage.tableName,
+            { id: stage.id, contract_pc_tp, qc_pc_tp, pc_tp, positive_pc_tp, negative_pc_tp, check_calc: true, cache_time_l: new Date() });
     }
     /**
      * 计算修订台账

+ 6 - 0
app/service/stage_bills.js

@@ -183,6 +183,8 @@ module.exports = app => {
                 d.qc_qty = orgData.qc_qty;
                 d.qc_tp = orgData.qc_tp;
                 d.qc_minus_qty = orgData.qc_minus_qty;
+                d.positive_qc_qty = orgData.positive_qc_qty;
+                d.negative_qc_qty = orgData.negative_qc_qty;
                 d.postil = orgData.postil;
             }
             const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, ledgerData.unit);
@@ -197,6 +199,8 @@ module.exports = app => {
                 d.qc_tp = this.ctx.helper.mul(d.qc_qty, ledgerData.unit_price, info.decimal.tp);
             }
             d.qc_minus_qty = insertData.qc_minus_qty ? this.round(insertData.qc_minus_qty, precision.value) : 0;
+            d.positive_qc_qty = insertData.positive_qc_qty ? this.round(insertData.positive_qc_qty, precision.value) : 0;
+            d.negative_qc_qty = insertData.negative_qc_qty ? this.round(insertData.negative_qc_qty, precision.value) : 0;
             if (insertData.postil) {
                 d.postil = insertData.postil;
             }
@@ -277,6 +281,8 @@ module.exports = app => {
             const posGather = await this.ctx.service.stagePos.getPosGather(tid, sid, lid, transaction);
             if (!posGather) { return; }
             posGather.qc_minus_qty = posGather.qc_minus_qty || 0;
+            posGather.positive_qc_qty = posGather.positive_qc_qty || 0;
+            posGather.negative_qc_qty = posGather.negative_qc_qty || 0;
 
             const precision = this.ctx.helper.findPrecision(info.precision, ledgerBills.unit);
             // 计算

+ 2 - 0
app/service/stage_bills_final.js

@@ -96,6 +96,8 @@ module.exports = app => {
                     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.qc_minus_qty = this.ctx.helper.add(c.qc_minus_qty, p.qc_minus_qty);
+                    c.positive_qc_qty = this.ctx.helper.add(c.positive_qc_qty, p.positive_qc_qty);
+                    c.negative_qc_qty = this.ctx.helper.add(c.negative_qc_qty, p.negative_qc_qty);
                     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_minus_qty);
                     pre.splice(pre.indexOf(p), 1);

+ 36 - 4
app/service/stage_change.js

@@ -295,13 +295,18 @@ module.exports = app => {
             // 获取更新数据
             const updateChanges = [],
                 newChanges = [];
-            let billsQty = 0;
+            let billsQty = 0, billsPositiveQty = 0, billsNegativeQty = 0;
             for (const oc of oldChanges) {
                 const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
                 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, noValue);
                     billsQty = this.ctx.helper.add(billsQty, change.qty);
+                    if (change.minus) {
+                        billsNegativeQty = this.ctx.helper.add(billsNegativeQty, change.qty);
+                    } else {
+                        billsPositiveQty = this.ctx.helper.add(billsPositiveQty, change.qty);
+                    }
                     if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
                         change.id = oc.id;
                         updateChanges.push(change);
@@ -310,6 +315,11 @@ module.exports = app => {
                     }
                 } else {
                     billsQty = this.ctx.helper.add(billsQty, oc.qty);
+                    if (oc.minus) {
+                        billsNegativeQty = this.ctx.helper.add(billsNegativeQty, oc.qty);
+                    } else {
+                        billsPositiveQty = this.ctx.helper.add(billsPositiveQty, oc.qty);
+                    }
                 }
             }
             for (const c of changes) {
@@ -317,6 +327,11 @@ module.exports = app => {
                 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, noValue);
                     billsQty = this.ctx.helper.add(billsQty, change.qty);
+                    if (change.minus) {
+                        billsNegativeQty = this.ctx.helper.add(billsNegativeQty, change.qty);
+                    } else {
+                        billsPositiveQty = this.ctx.helper.add(billsPositiveQty, change.qty);
+                    }
                     newChanges.push(change);
                 }
             }
@@ -326,7 +341,9 @@ module.exports = app => {
                 if (newChanges.length > 0) await transaction.insert(this.tableName, newChanges);
                 if (updateChanges.length > 0) await transaction.updateRows(this.tableName, updateChange);
                 const stageBills = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, bills.id);
-                const sbUpdate = noValue ? {qc_minus_qty: billsQty} : {qc_qty: billsQty};
+                const sbUpdate = noValue
+                    ? { qc_minus_qty: billsQty }
+                    : { qc_qty: billsQty, positive_qc_qty: billsPositiveQty, negative_qc_qty: billsNegativeQty };
                 await this.ctx.service.stageBills.updateStageBillsQty(transaction, ledgerBills, stageBills, sbUpdate);
                 await transaction.commit();
             } catch (err) {
@@ -364,13 +381,18 @@ module.exports = app => {
             const oldChanges = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, pos.lid, pos.id, noValue);
             const updateChanges = [],
                 newChanges = [];
-            let posQty = 0;
+            let posQty = 0, posPositiveQty = 0, posNegativeQty = 0;
             for (const oc of oldChanges) {
                 const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
                 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, noValue);
                     posQty = this.ctx.helper.add(posQty, change.qty);
+                    if (change.minus) {
+                        posNegativeQty = this.ctx.helper.add(posNegativeQty, change.qty);
+                    } else {
+                        posPositiveQty = this.ctx.helper.add(posPositiveQty, change.qty);
+                    }
                     if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
                         change.id = oc.id;
                         updateChanges.push(change);
@@ -379,6 +401,11 @@ module.exports = app => {
                     }
                 } else {
                     posQty = this.ctx.helper.add(posQty, oc.qty);
+                    if (oc.minus) {
+                        posNegativeQty = this.ctx.helper.add(posNegativeQty, oc.qty);
+                    } else {
+                        posPositiveQty = this.ctx.helper.add(posPositiveQty, oc.qty);
+                    }
                 }
             }
             for (const c of changes) {
@@ -386,6 +413,11 @@ module.exports = app => {
                 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, noValue);
                     posQty = this.ctx.helper.add(posQty, change.qty);
+                    if (change.minus) {
+                        posNegativeQty = this.ctx.helper.add(posNegativeQty, change.qty);
+                    } else {
+                        posPositiveQty = this.ctx.helper.add(posPositiveQty, change.qty);
+                    }
                     newChanges.push(change);
                 }
             }
@@ -394,7 +426,7 @@ module.exports = app => {
             try {
                 if (newChanges.length > 0) await transaction.insert(this.tableName, newChanges);
                 if (updateChanges.length > 0) await transaction.updateRows(this.tableName, updateChanges);
-                await this.ctx.service.stagePos.updateChangeQuantity(transaction, pos, posQty, noValue);
+                await this.ctx.service.stagePos.updateChangeQuantity(transaction, pos, posQty, noValue, posPositiveQty, posNegativeQty);
                 await transaction.commit();
             } catch (err) {
                 await transaction.rollback();

+ 14 - 7
app/service/stage_pos.js

@@ -23,7 +23,7 @@ module.exports = app => {
             super(ctx);
             this.depart = 20;
             this.tableName = 'stage_pos';
-            this.qtyFields = ['contract_qty', 'qc_qty', 'qc_minus_qty']
+            this.qtyFields = ['contract_qty', 'qc_qty', 'qc_minus_qty', 'positive_qc_qty', 'negative_qc_qty']
         }
 
         _getPosFilterSql(where, asTable = '') {
@@ -108,7 +108,7 @@ module.exports = app => {
         }
         async getLastestStageData2(tid, sid, where) {
             const filterSql = this._getPosFilterSql(where);
-            const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, qc_minus_qty, postil, `times`, `order`, `contract_expr`' +
+            const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, qc_minus_qty, positive_qc_qty, negative_qc_qty, postil, `times`, `order`, `contract_expr`' +
                 '  FROM ' + this.departTableName(tid) +
                 '  WHERE tid = ? And sid = ? ' + filterSql;
             const sqlParam = [tid, sid];
@@ -117,7 +117,7 @@ module.exports = app => {
         }
         async getAuditorStageData2(tid, sid, times, order, where) {
             const filterSql = this._getPosFilterSql(where);
-            const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, qc_minus_qty, postil, `times`, `order`, `contract_expr`' +
+            const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, qc_minus_qty, positive_qc_qty, negative_qc_qty, postil, `times`, `order`, `contract_expr`' +
                 '  FROM ' + this.departTableName(tid) +
                 '  WHERE tid = ? And sid = ? And (`times` < ? OR (`times` = ? AND `order` <= ?)) ' + filterSql;
             const sqlParam = [tid, sid, times, times, order];
@@ -311,6 +311,8 @@ module.exports = app => {
                             sp.postil = d.postil === undefined && osp ? osp.postil : d.postil;
                         }
                         sp.qc_minus_qty = osp ? osp.qc_minus_qty : 0;
+                        sp.positive_qc_qty = osp ? osp.positive_qc_qty : 0;
+                        sp.negative_qc_qty = osp ? osp.negative_qc_qty : 0;
                         insertPosStage.push(sp);
                     }
                 }
@@ -546,7 +548,7 @@ module.exports = app => {
             }
         }
 
-        async updateChangeQuantity(transaction, pos, qty, noValue) {
+        async updateChangeQuantity(transaction, pos, qty, noValue, positiveQty, negativeQty) {
             let orgPos = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: pos.id});
             if (orgPos.length > 1) {
                 throw '数据错误';
@@ -554,7 +556,10 @@ module.exports = app => {
                 orgPos = orgPos[0];
             }
             if (orgPos && orgPos.times === this.ctx.stage.curTimes && orgPos.order === this.ctx.stage.curOrder) {
-                await transaction.update(this.tableName, noValue ? { id: orgPos.id, qc_minus_qty: qty || 0 } : {id: orgPos.id, qc_qty: qty});
+                await transaction.update(this.tableName, noValue
+                    ? { id: orgPos.id, qc_minus_qty: qty || 0 }
+                    : { id: orgPos.id, qc_qty: qty, positive_qc_qty: positiveQty, negative_qc_qty: negativeQty }
+                );
             } else {
                 await transaction.insert(this.tableName, {
                     tid: this.ctx.tender.id,
@@ -567,6 +572,8 @@ module.exports = app => {
                     contract_qty: orgPos ? orgPos.contract_qty : 0,
                     qc_qty: !noValue ? qty : (orgPos ? orgPos.qc_qty : 0),
                     qc_minus_qty: noValue ? qty : (orgPos ? orgPos.qc_minus_qty : 0),
+                    positive_qc_qty: !noValue ? positiveQty : (orgPos ? orgPos.positive_qc_qty : 0),
+                    negative_qc_qty: !noValue ? negativeQty : (orgPos ? orgPos.negative_qc_qty : 0),
                 });
             }
             await this.ctx.service.stageBills.calc(this.ctx.tender.id, this.ctx.stage.id, pos.lid, transaction);
@@ -581,8 +588,8 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getPosGather(tid, sid, lid, transaction) {
-            const calcQtySql = 'SELECT SUM(`contract_qty`) As `contract_qty`, SUM(`qc_qty`) As `qc_qty`, SUM(`qc_minus_qty`) AS `qc_minus_qty` FROM (' +
-                '  SELECT `contract_qty`, `qc_qty`, `qc_minus_qty` FROM ' + this.ctx.service.stagePos.tableName + ' As Pos ' +
+            const calcQtySql = 'SELECT SUM(`contract_qty`) As `contract_qty`, SUM(`qc_qty`) As `qc_qty`, SUM(`qc_minus_qty`) AS `qc_minus_qty`, SUM(`positive_qc_qty`) As `positive_qc_qty`, SUM(`negative_qc_qty`) As `negative_qc_qty` FROM (' +
+                '  SELECT `contract_qty`, `qc_qty`, `qc_minus_qty`, `positive_qc_qty`, `negative_qc_qty` FROM ' + this.ctx.service.stagePos.tableName + ' As Pos ' +
                 '    INNER JOIN (' +
                 '      SELECT MAX(`times` * ' + timesLen + ' + `order`) As `flow`, `pid` ' +
                 '        FROM ' + this.ctx.service.stagePos.tableName +

+ 2 - 0
app/service/stage_pos_final.js

@@ -74,6 +74,8 @@ module.exports = app => {
                     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.qc_minus_qty = this.ctx.helper.add(c.qc_minus_qty, p.qc_minus_qty);
+                    c.positive_qc_qty = this.ctx.helper.add(c.positive_qc_qty, p.positive_qc_qty);
+                    c.negative_qc_qty = this.ctx.helper.add(c.negative_qc_qty, p.negative_qc_qty);
                     c.used = p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty) || !this.ctx.helper.checkZero(c.qc_minus_qty);
                     pre.splice(pre.indexOf(p), 1);
                 } else {

+ 187 - 1
sql/update.sql

@@ -250,8 +250,194 @@ ALTER TABLE `zh_change`
 ADD COLUMN `positive_tp`  decimal(24,8) NOT NULL DEFAULT 0 COMMENT '正变更金额' AFTER `order_by`,
 ADD COLUMN `negative_tp`  decimal(24,8) NOT NULL DEFAULT 0 COMMENT '负变更金额' AFTER `positive_tp`;
 
+ALTER TABLE `zh_stage_bills_0`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_1`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_2`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_3`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_4`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_5`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_6`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_7`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_8`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_9`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+
+ALTER TABLE `zh_stage_bills_final_0`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_final_1`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_final_2`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_final_3`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_final_4`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_final_5`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_final_6`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_final_7`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_final_8`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_bills_final_9`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+
+ALTER TABLE `zh_stage_pos_0`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_1`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_2`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_3`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_4`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_5`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_6`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_7`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_8`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_9`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_10`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_11`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_12`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_13`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_14`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_15`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_16`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_17`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_18`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_19`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+
+ALTER TABLE `zh_stage_pos_final_0`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_1`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_2`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_3`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_4`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_5`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_6`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_7`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_8`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_9`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_10`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_11`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_12`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_13`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_14`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_15`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_16`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_17`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_18`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+ALTER TABLE `zh_stage_pos_final_19`
+ADD COLUMN `positive_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `qc_minus_qty`,
+ADD COLUMN `negative_qc_qty`  decimal(24,8) NOT NULL DEFAULT 0 AFTER `positive_qc_qty`;
+
 ALTER TABLE `zh_stage`
 ADD COLUMN `positive_qc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '本期-正-变更金额' AFTER `his_id`,
 ADD COLUMN `pre_positive_qc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '截止上期-正-变更金额' AFTER `positive_qc_tp`,
+ADD COLUMN `positive_qc_pc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '本期-正-变更金额' AFTER `pre_positive_qc_tp`,
 ADD COLUMN `negative_qc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '本期-负-变更金额' AFTER `pre_positive_qc_tp`,
-ADD COLUMN `pre_negative_qc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '截止上期-负-变更金额' AFTER `negative_qc_tp`;
+ADD COLUMN `pre_negative_qc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '截止上期-负-变更金额' AFTER `negative_qc_tp`,
+ADD COLUMN `negative_qc_pc_tp`  decimal(24,8) NULL DEFAULT 0 COMMENT '本期-负-变更金额' AFTER `pre_negative_qc_tp`;