Parcourir la source

计算1相关

MaiXinRong il y a 3 mois
Parent
commit
f2a370aa2f
3 fichiers modifiés avec 35 ajouts et 9 suppressions
  1. 1 1
      app/public/js/revise.js
  2. 3 3
      app/service/pos.js
  3. 31 5
      app/service/revise_pos.js

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

@@ -165,7 +165,7 @@ $(document).ready(() => {
         level: 'level',
         rootId: -1,
         keys: ['id', 'tender_id', 'ledger_id'],
-        calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price', 'deal_tp'],
+        calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price', 'deal_tp', 'ex_tp1'],
         autoExpand: 3,
         markExpandKey: 'revise-bills-expand',
         markExpandSubKey: window.location.pathname.split('/')[2],

+ 3 - 3
app/service/pos.js

@@ -111,7 +111,7 @@ module.exports = app => {
             const bills = await this.ctx.service.ledger.getDataById(datas[0].lid);
             const billsPos = await this.getAllDataByCondition({where: {tid: bills.tender_id, lid: bills.id} });
             const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
-            const updateBills = {id: bills.id};
+            const updateBills = {id: bills.id, ledger_id: bills.ledger_id};
             for (const bp of billsPos) {
                 updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
                 updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
@@ -136,7 +136,7 @@ module.exports = app => {
                 updateBills.quantity = this.ctx.helper.add(updateBills.quantity, d.quantity);
                 if (d.ex_qty1) {
                     d.ex_qty1 = this.ctx.helper.round(d.ex_qty1, precision.value);
-                    updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
+                    updateBills.ex_qty1 = this.ctx.helper.add(updateBills.ex_qty1, d.ex_qty1);
                 }
             }
             const info = this.ctx.tender.info;
@@ -166,8 +166,8 @@ module.exports = app => {
             if (updateBills) {
                 const transaction = await this.db.beginTransaction();
                 try {
+                    await transaction.insert(this.tableName, data);
                     await transaction.update(this.ctx.service.ledger.tableName, updateBills);
-                    updateBills.ledger_id = bills.ledger_id;
                     await transaction.commit();
                 } catch (err) {
                     await transaction.rollback();

+ 31 - 5
app/service/revise_pos.js

@@ -25,7 +25,7 @@ module.exports = app => {
 
         async getPosData(condition) {
             const sql = 'SELECT id, tid, lid, name, quantity, position, drawing_code, sgfh_qty, ' +
-                '    sjcl_qty, qtcl_qty, porder, add_stage, add_times, add_user, add_stage_order,' +
+                '    sjcl_qty, qtcl_qty, ex_qty1, porder, add_stage, add_times, add_user, add_stage_order,' +
                 '    sgfh_expr, sjcl_expr, qtcl_expr, ex_memo1, ex_memo2, ex_memo3 ' +
                 '  FROM ' + this.tableName + this.ctx.helper.whereSql(condition) +
                 '  ORDER By porder ASC';
@@ -51,7 +51,7 @@ module.exports = app => {
         }
 
         async getPosDataByUnits(tenderId, units) {
-            const sql = 'SELECT p.id, p.lid, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty' +
+            const sql = 'SELECT p.id, p.lid, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty, p.ex_qty1,' +
                 '  FROM ' + this.tableName + ' p' +
                 '  LEFT JOIN ' + this.ctx.service.reviseBills.tableName + ' b' +
                 '  ON p.lid = b.id ' +
@@ -184,6 +184,11 @@ module.exports = app => {
                     data.qtcl_qty = op.qtcl_qty;
                 }
                 data.quantity = this.ctx.helper.sum([data.sgfh_qty, data.qtcl_qty, data.sjcl_qty]);
+                if (data.ex_qty1 !== undefined) {
+                    data.ex_qty1 = this.round(data.ex_qty1, precision.value);
+                } else if (op) {
+                    data.ex_qty1 = op.ex_qty1;
+                }
 
                 const updateBills = {id: bills.id};
                 for (const bp of billsPos) {
@@ -192,12 +197,14 @@ module.exports = app => {
                     updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, calcData.sjcl_qty);
                     updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, calcData.qtcl_qty);
                     updateBills.quantity = this.ctx.helper.add(updateBills.quantity, calcData.quantity);
+                    updateBills.ex_qty1 = this.ctx.helper.add(updateBills.ex_qty1, calcData.ex_qty1);
                 }
                 const info = this.ctx.tender.info;
                 updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
                 updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
                 updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
                 updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
+                updateBills.ex_tp1 = this.ctx.helper.mul(updateBills.ex_qty1, bills.unit_price, info.decimal.tp);
 
                 const transaction = await this.db.beginTransaction();
                 try {
@@ -228,7 +235,7 @@ module.exports = app => {
             const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
             let needUpdateBills;
             for (const d of data) {
-                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.ex_qty1 !== undefined) {
                     if (d.sgfh_qty !== undefined) {
                         d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
                     } else if (op) {
@@ -245,6 +252,11 @@ module.exports = app => {
                         d.qtcl_qty = op.qtcl_qty;
                     }
                     d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
+                    if (d.ex_qty1 !== undefined) {
+                        d.ex_qty1 = this.round(d.ex_qty1, precision.value);
+                    } else if (op) {
+                        d.ex_qty1 = op.ex_qty1;
+                    }
                     needUpdateBills = true;
                 }
             }
@@ -264,12 +276,16 @@ module.exports = app => {
                     updateBills.quantity = newPos && newPos.quantity !== undefined
                         ? this.ctx.helper.add(updateBills.quantity, newPos.quantity)
                         : this.ctx.helper.add(updateBills.quantity, bp.quantity);
+                    updateBills.ex_qty1 = newPos && newPos.ex_qty1 !== undefined
+                        ? this.ctx.helper.add(updateBills.ex_qty1, newPos.ex_qty1)
+                        : this.ctx.helper.add(updateBills.ex_qty1, bp.ex_qty1);
                 }
                 const info = this.ctx.tender.info;
                 updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
                 updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
                 updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
                 updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
+                updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.ex_qty1, bills.unit_price, info.decimal.tp);
             }
 
             const transaction = await this.db.beginTransaction();
@@ -298,19 +314,21 @@ module.exports = app => {
             const pos = await this.getPosData({tid: tid, id: data});
             const bills = await this.ctx.service.reviseBills.getDataById(pos[0].lid);
             const billsPos = await this.getAllDataByCondition({ where: {tid: tid, lid: bills.id} });
-            const updateBills = {id: bills.id, sgfh_qty: null, sjcl_qty: null, qtcl_qty: null, quantity: null};
+            const updateBills = {id: bills.id, sgfh_qty: 0, sjcl_qty: 0, qtcl_qty: 0, quantity: 0, ex_qty1: 0};
             for (const bp of billsPos) {
                 if (data.indexOf(bp.id) >= 0) continue;
                 updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
                 updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
                 updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
                 updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
+                updateBills.ex_qty1 = this.ctx.helper.add(updateBills.ex_qty1, bp.ex_qty1);
             }
             const info = this.ctx.tender.info;
             updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
             updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
             updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
             updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
+            updateBills.ex_tp1 = this.ctx.helper.mul(updateBills.ex_qty1, bills.unit_price, info.decimal.tp);
 
             const transaction = await this.db.beginTransaction();
             try {
@@ -355,12 +373,13 @@ module.exports = app => {
                 updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
                 updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
                 updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
+                updateBills.ex_qty1 = this.ctx.helper.add(updateBills.ex_qty1, bp.ex_qty1);
             }
 
             try {
                 for (const d of data) {
                     const op = d.id ? this._.find(orgPos, {id: d.id}) : null;
-                    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.ex_qty1 !== undefined) {
                         if (d.sgfh_qty !== undefined) {
                             d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
                         } else if (op) {
@@ -381,6 +400,12 @@ module.exports = app => {
                         updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
                         d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
                         updateBills.quantity = this.ctx.helper.add(updateBills.quantity, d.quantity);
+                        if (d.ex_qty1 !== undefined) {
+                            d.ex_qty1 = this.round(d.ex_qty1, precision.value);
+                        } else if (op) {
+                            d.ex_qty1 = op.ex_qty1;
+                        }
+                        updateBills.ex_qty1 = this.ctx.helper.add(updateBills.ex_qty1, d.ex_qty1);
                         needUpdateBills = true;
                     }
                     if (d.id) {
@@ -395,6 +420,7 @@ module.exports = app => {
                     updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
                     updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
                     updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
+                    updateBills.ex_tp1 = this.ctx.helper.mul(updateBills.ex_qty1, bills.unit_price, info.decimal.tp);
                     await transaction.update(this.ctx.service.reviseBills.tableName, updateBills);
                     updateBills.ledger_id = bills.ledger_id;
                 }