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

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

laiguoran пре 2 година
родитељ
комит
513d6edf83

+ 3 - 3
app/lib/revise_price.js

@@ -66,7 +66,7 @@ class revisePriceCalc {
             node.positive_qc_pc_tp = helper.mul(priceDiff, node.pre_positive_qc_qty, decimal.tp);
             node.negative_qc_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,
+                tid: newStage.tid, sid: newStage.id, sorder: newStage.order, lid: node.id, org_price: node.pre_unit_price, unit_price: node.unit_price,
                 contract_pc_tp: node.contract_pc_tp, qc_pc_tp: node.qc_pc_tp, pc_tp: node.pc_tp,
                 positive_qc_pc_tp: node.positive_qc_pc_tp, negative_qc_pc_tp: node.negative_qc_pc_tp,
             });
@@ -137,7 +137,7 @@ class revisePriceCalc {
                 node.positive_qc_pc_tp = helper.mul(priceDiff, node.pre_positive_qc_qty, decimal.tp);
                 node.negative_qc_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,
+                    tid: stage.tid, sid: stage.id, sorder: stage.order, lid: node.id, org_price: node.pre_unit_price, unit_price: node.unit_price,
                     contract_pc_tp: node.contract_pc_tp, qc_pc_tp: node.qc_pc_tp, pc_tp: node.pc_tp,
                     positive_qc_pc_tp: node.positive_qc_pc_tp, negative_qc_pc_tp: node.negative_qc_pc_tp,
                 });
@@ -255,7 +255,7 @@ class revisePriceCalc {
             }
             if (node.pre_id) {
                 result.bpcData.push({
-                    tid: stage.tid, sid: stage.id, sorder: stage.order, lid: node.id, org_price: node.pre_unit_price,
+                    tid: stage.tid, sid: stage.id, sorder: stage.order, lid: node.id, org_price: node.pre_unit_price, unit_price: node.unit_price,
                     contract_pc_tp: node.contract_pc_tp, qc_pc_tp: node.qc_pc_tp, pc_tp: node.pc_tp,
                     positive_qc_pc_tp: node.positive_qc_pc_tp, negative_qc_pc_tp: node.negative_qc_pc_tp,
                 });

+ 1 - 1
app/public/js/stage.js

@@ -1785,7 +1785,7 @@ $(document).ready(() => {
             if (info.sheet.zh_setting) {
                 const sortData = info.sheet.zh_data;
                 const range = info.cellRange;
-                const validField = ['contract_qty', 'qc_qty', 'qc_minus_qty', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3'];
+                const validField = ['contract_qty', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3'];
                 if (!checkTzMeasureType()) {
                     validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
                 }

+ 9 - 9
app/service/ledger_history.js

@@ -71,25 +71,25 @@ module.exports = app => {
          * @return {Promise<void>} - 新增备份id
          * @private
          */
-        async backupStageLedgerHistory(stage) {
-            const sbCount = await this.ctx.service.ledger.count({ tender_id: this.ctx.stage.tid });
-            const spCount = await this.ctx.service.pos.count({ tid: this.ctx.stage.tid });
-            const ledgerHis = await this.ctx.service.ledgerHistory.getLatestHistory(this.ctx.tender.id);
+        async checkBackupLedgerHistory(tid, sid = 0, rid = '') {
+            const sbCount = await this.ctx.service.ledger.count({ tender_id: tid });
+            const spCount = await this.ctx.service.pos.count({ tid: tid });
+            const ledgerHis = await this.ctx.service.ledgerHistory.getLatestHistory(tid);
             if (sbCount === ledgerHis.bills_count && spCount === ledgerHis.pos_count) return ledgerHis.id;
 
             const now = new Date();
             const timestamp = (now).getTime();
 
-            const billsHis = `${this.ctx.session.sessionProject.id}/${stage.tid}/ledger/bills${timestamp}-s.json`;
-            const bills = await this.ctx.service.ledger.getData(stage.tid);
+            const billsHis = `${this.ctx.session.sessionProject.id}/${tid}/ledger/bills${timestamp}-s.json`;
+            const bills = await this.ctx.service.ledger.getData(tid);
             await this.ctx.hisOss.put(this.ctx.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
 
-            const posHis = `${this.ctx.session.sessionProject.id}/${stage.tid}/ledger/pos${timestamp}-s.json`;
-            const pos = await this.ctx.service.pos.getPosData({ tid: stage.tid });
+            const posHis = `${this.ctx.session.sessionProject.id}/${tid}/ledger/pos${timestamp}-s.json`;
+            const pos = await this.ctx.service.pos.getPosData({ tid: tid });
             await this.ctx.hisOss.put(this.ctx.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
 
             const result = await this.db.insert(this.tableName, {
-                pid: this.ctx.session.sessionProject.id, tid: stage.tid, sid: stage.id,
+                pid: this.ctx.session.sessionProject.id, tid, sid, rid,
                 in_time: now,
                 bills_file: billsHis, pos_file: posHis,
                 bills_count: bills.length, pos_count: pos.length,

+ 3 - 3
app/service/ledger_revise.js

@@ -176,11 +176,11 @@ module.exports = app => {
                 throw '数据错误';
             }
             const maxOrder = await this.getNewOrder(tid);
-            const latest = await this.ctx.service.ledgerHistory.getLatestHistory(tid);
-            if (!latest) throw '台账历史数据有误';
+            const preHisId = await this.ctx.service.ledgerHistory.checkBackupLedgerHistory(tid);
+            if (!preHisId) throw '台账历史数据有误';
             const data = {
                 id: this.uuid.v4(), tid: tid, uid: uid,
-                corder: maxOrder + 1, in_time: new Date(), status: audit.status.uncheck, pre_his_id: latest.id,
+                corder: maxOrder + 1, in_time: new Date(), status: audit.status.uncheck, pre_his_id: preHisId,
             };
             const transaction = await this.db.beginTransaction();
             try {

+ 1 - 1
app/service/stage_audit.js

@@ -479,7 +479,7 @@ module.exports = app => {
                     await this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
                 } else {
                     await this.ctx.service.tenderTag.saveTenderTag(this.ctx.tender.id, {stage_time: new Date()}, transaction);
-                    const his_id = await this.ctx.service.ledgerHistory.backupStageLedgerHistory(this.ctx.stage);
+                    const his_id = await this.ctx.service.ledgerHistory.checkBackupLedgerHistory(this.ctx.stage.tid, this.ctx.stage.id);
 
                     // 本期结束
                     // 生成截止本期数据 final数据

+ 8 - 4
app/service/stage_bills_final.js

@@ -90,7 +90,7 @@ module.exports = app => {
                     return x.lid === c.lid;
                 });
                 if (p) {
-                    c.unit_price = p.org_price;
+                    c.unit_price = p.unit_price;
                     c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
                     c.contract_tp = this.ctx.helper.add(c.contract_tp, p.contract_tp);
                     c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
@@ -109,12 +109,12 @@ module.exports = app => {
                 }
                 const cp = curPc.find(x => { return x.lid === c.lid; });
                 if (cp) {
-                    c.unit_price = cp.org_price;
+                    c.unit_price = cp.unit_price;
                     c.contract_tp = this.ctx.helper.add(c.contract_tp, cp.contract_pc_tp);
                     c.qc_tp = this.ctx.helper.add(c.qc_tp, cp.qc_pc_tp);
                     curPc.splice(curPc.indexOf(cp), 1);
                 }
-                if (!c.org_price) {
+                if (!c.unit_price) {
                     const bills = await this.ctx.service.ledger.getDataById(c.lid);
                     c.unit_price = bills ? bills.unit_price || 0 : 0;
                 }
@@ -126,11 +126,15 @@ module.exports = app => {
                 p.sorder = stage.order;
                 const cp = curPc.find(x => { return x.lid === p.lid; });
                 if (cp) {
-                    p.unit_price = cp.org_price;
+                    p.unit_price = cp.unit_price;
                     p.contract_tp = this.ctx.helper.add(p.contract_tp, cp.contract_pc_tp);
                     p.qc_tp = this.ctx.helper.add(p.qc_tp, cp.qc_pc_tp);
                     curPc.splice(curPc.indexOf(cp), 1);
                 }
+                if (!p.unit_price) {
+                    const bills = await this.ctx.service.ledger.getDataById(c.lid);
+                    p.unit_price = bills ? bills.unit_price || 0 : 0;
+                }
             }
             await transaction.delete(this.tableName, { tid: tender.id, sid: stage.id });
             await transaction.insert(this.tableName, cur ? cur.concat(pre) : pre);

+ 1 - 1
app/service/stage_change.js

@@ -415,7 +415,7 @@ module.exports = app => {
                 const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
                 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);
-                    change.unit_price;
+                    change.unit_price = ledgerBills.unit_price;
                     posQty = this.ctx.helper.add(posQty, change.qty);
                     if (change.minus) {
                         posNegativeQty = this.ctx.helper.add(posNegativeQty, change.qty);

+ 7 - 8
app/service/stage_pos.js

@@ -150,15 +150,13 @@ module.exports = app => {
             let bills , precision;
             const  result = {pos: [], ledger: []};
             const datas = data instanceof Array ? data : [data], calcStageBills = [];
+
             if (datas[0].sgfh_qty !== undefined || datas[0].sjcl_qty !== undefined || datas[0].qtcl_qty !== undefined
                 || datas[0].contract_qty !== undefined || datas[0].qc_qty !== undefined || datas[0].real_qty !== undefined) {
                 bills = await this.ctx.service.ledger.getDataById(datas[0].lid);
                 precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
                 result.ledger.push(bills.id);
             }
-            if (datas[0].contract_qty !== undefined || datas[0].qc_qty !== undefined || datas[0].postil !== undefined) {
-                result.stageUpdate = true;
-            }
 
             const insertPos = [], insertPosStage = [];
             for (const d of datas) {
@@ -168,7 +166,8 @@ module.exports = app => {
                     add_times: this.ctx.stage.curTimes,
                     add_user: this.ctx.session.sessionUser.accountId,
                 };
-                if (d.sgfh_qty !== undefined || d.sjcl_qty !== undefined || d.qtcl_qty !== undefined) {
+                if (d.sgfh_qty !== undefined || d.sjcl_qty !== undefined || d.qtcl_qty !== undefined ||
+                    d.sgfh_expr !== undefined || d.sjcl_expr !== undefined || d.qtcl_expr !== undefined) {
                     if (d.sgfh_qty!== undefined) p.sgfh_qty = this.round(d.sgfh_qty, precision.value);
                     if (d.sjcl_qty!== undefined) p.sjcl_qty = this.round(d.sjcl_qty, precision.value);
                     if (d.qtcl_qty!== undefined) p.qtcl_qty = this.round(d.qtcl_qty, precision.value);
@@ -181,7 +180,8 @@ module.exports = app => {
                 insertPos.push(p);
                 result.pos.push(p.id);
 
-                if (d.contract_qty!== undefined || d.qc_qty!== undefined || d.postil!== undefined) {
+                if (d.contract_qty!== undefined || d.qc_qty!== undefined || d.postil!== undefined || data.contract_expr !== undefined) {
+                    result.stageUpdate = true;
                     const ps = {
                         pid: p.id,
                         lid: d.lid,
@@ -192,11 +192,10 @@ module.exports = app => {
                         order: this.ctx.stage.curOrder,
                     };
                     if (d.contract_qty !== undefined) ps.contract_qty = this.round(d.contract_qty, precision.value);
-                    if (d.contract_expr !== undefined) p.contract_expr = d.contract_expr;
-                    if (d.qc_qty!== undefined) ps.qc_qty = this.round(d.qc_qty, precision.value);
+                    if (d.contract_expr !== undefined) ps.contract_expr = d.contract_expr;
                     if (d.postil!== undefined) ps.postil = d.postil;
                     insertPosStage.push(ps);
-                    if ((d.contract_qty || d.qc_qty) && calcStageBills.indexOf(ps.lid) === -1) {
+                    if (d.contract_qty && calcStageBills.indexOf(ps.lid) === -1) {
                         calcStageBills.push(ps.lid);
                     }
                 }

+ 5 - 5
sql/update.sql

@@ -86,12 +86,16 @@ CREATE TABLE `zh_stage_bills_pc` (
   `tid` int(11) unsigned NOT NULL COMMENT '标段id',
   `sid` int(11) NOT NULL,
   `lid` varchar(36) COLLATE utf8_unicode_ci NOT NULL COMMENT '项目节id',
+  `org_price` decimal(24,8) NOT NULL DEFAULT 0 COMMENT '原单价',
+  `unit_price` decimal(24,8) NOT NULL DEFAULT 0 COMMENT '本期单价',
   `contract_pc_tp` decimal(24,8) NOT NULL DEFAULT 0 COMMENT '本期补差(合同)',
   `qc_pc_tp` decimal(24,8) NOT NULL DEFAULT 0 COMMENT '本期补差(变更)',
   `pc_tp` decimal(24,8) NOT NULL DEFAULT 0 COMMENT '本期补差',
+  `positive_qc_pc_tp` decimal(24,8) NOT NULL DEFAULT 0 COMMENT '本期补差(正变更)',
+  `negative_qc_pc_tp` decimal(24,8) NOT NULL DEFAULT 0 COMMENT '本期补差(负变更)',
   PRIMARY KEY (`id`),
   KEY `idx_sid` (`sid`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='期-项目节-补差数据';
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='期-补差数据';
 
 ALTER TABLE `zh_stage_bills_final_0`
 ADD COLUMN `unit_price`  decimal(24,8) UNSIGNED NOT NULL DEFAULT 0 COMMENT '本期单价' AFTER `contract_expr`,
@@ -474,10 +478,6 @@ 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_bills_pc`
-ADD COLUMN `positive_qc_pc_tp`  decimal(24,8) NOT NULL DEFAULT 0 COMMENT '本期补差(正变更)' AFTER `pc_tp`,
-ADD COLUMN `negative_qc_pc_tp`  decimal(24,8) NOT NULL DEFAULT 0 COMMENT '本期补差(负变更)' AFTER `positive_qc_pc_tp`;
-
 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`,