Browse Source

金额增加补差值

ellisran 1 year ago
parent
commit
fdcee145f4
4 changed files with 39 additions and 2 deletions
  1. 2 1
      app/service/stage.js
  2. 32 0
      app/service/stage_bills_pc.js
  3. 1 1
      app/view/setting/sub_menu.ejs
  4. 4 0
      sql/update.sql

+ 2 - 1
app/service/stage.js

@@ -822,7 +822,8 @@ module.exports = app => {
                     case 'bab':
                     case 'jiub':
                         const sumGcl = await this.ctx.service.stageBills.getSumTotalPriceGclByMaterial(stage_list, cb.filter);
-                        cb.value = this.ctx.helper.add(sumGcl.contract_tp, sumGcl.qc_tp);
+                        const sumPc = await this.ctx.service.stageBillsPc.getSumTotalPriceGclByMaterial(stage_list, cb.filter);
+                        cb.value = this.ctx.helper.sum([sumGcl.contract_tp, sumGcl.qc_tp, sumPc.pc_tp]);
                         break;
                     case 'bqyf':
                         cb.value = this.ctx.helper.roundNum(this._.sumBy(stage_list, 'yf_tp'), 2);

+ 32 - 0
app/service/stage_bills_pc.js

@@ -30,6 +30,16 @@ module.exports = app => {
             return result;
         }
 
+        async getSumTotalPriceFilter(stage, operate, filter) {
+            const sql = 'SELECT Sum(`contract_pc_tp`) As `contract_pc_tp`, Sum(`qc_pc_tp`) As `qc_pc_tp`, Sum(`pc_tp`) As `pc_tp`, Sum(`positive_qc_pc_tp`) As `positive_qc_pc_tp`, Sum(`negative_qc_pc_tp`) As `negative_qc_pc_tp`' +
+                '  FROM ' + this.tableName + ' As Bills' +
+                '  INNER JOIN ' + this.ctx.service.ledger.departTableName(stage.tid) + ' As Ledger ON Bills.lid = Ledger.id' +
+                '  WHERE Bills.sid = ? And Ledger.b_code ' + operate + ' ?';
+            const sqlParam = [stage.id, filter];
+            const result = await this.db.queryOne(sql, sqlParam);
+            return result;
+        }
+
         async getSumTotalPriceByMaterial(stage_list) {
             let contract_pc_tp = 0;
             let qc_pc_tp = 0;
@@ -45,6 +55,28 @@ module.exports = app => {
             return { contract_pc_tp, qc_pc_tp, pc_tp };
         }
 
+        async getSumTotalPriceGclByMaterial(stage_list, regText) {
+            let contract_pc_tp = 0;
+            let qc_pc_tp = 0;
+            let pc_tp = 0;
+            for (const stage of stage_list) {
+                const result = await this.getSumTotalPriceGcl(stage, regText);
+                if (result) {
+                    contract_pc_tp = this.ctx.helper.add(contract_pc_tp, result.contract_pc_tp);
+                    qc_pc_tp = this.ctx.helper.add(qc_pc_tp, result.qc_pc_tp);
+                    pc_tp = this.ctx.helper.add(pc_tp, result.pc_tp);
+                }
+            }
+            return { contract_pc_tp, qc_pc_tp, pc_tp };
+        }
+
+        async getSumTotalPriceGcl(stage, regText) {
+            if (regText) {
+                return await this.getSumTotalPriceFilter(stage, 'REGEXP', regText);
+            }
+            return await this.getSumTotalPriceFilter(stage, '<>', this.db.escape(''));
+        }
+
         async getEndStageData(stage) {
             const sql = 'SELECT lid, SUM(contract_pc_tp) AS end_contract_pc_tp, SUM(qc_pc_tp) AS end_qc_pc_tp,' +
                 '    SUM(pc_tp) AS end_pc_tp, Sum(`positive_qc_pc_tp`) As `positive_qc_pc_tp`, Sum(`negative_qc_pc_tp`) As `negative_qc_pc_tp`,' +

+ 1 - 1
app/view/setting/sub_menu.ejs

@@ -1,6 +1,6 @@
 <div class="panel-sidebar">
     <div class="sidebar-title">
-        项目信息
+        项目设置
     </div>
     <div class="scrollbar-auto">
         <div class="nav-box">

+ 4 - 0
sql/update.sql

@@ -35,3 +35,7 @@ CREATE TABLE `zh_budget_zb` (
 
 ALTER TABLE `zh_material_list_notjoin`
 ADD COLUMN `type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '1为本期不参与调差,2为数量变更不参与调差' AFTER `mx_id`;
+
+
+ALTER TABLE `zh_stage_bills_pc`
+MODIFY COLUMN `lid` varchar(36) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '项目节id' AFTER `sorder`;