Selaa lähdekoodia

台账修订,复制粘贴计量单元,父项不计算

MaiXinRong 5 vuotta sitten
vanhempi
commit
14c6db12e7
3 muutettua tiedostoa jossa 36 lisäystä ja 16 poistoa
  1. 1 1
      app/public/js/shares/export_excel.js
  2. 29 13
      app/service/revise_pos.js
  3. 6 2
      app/service/stage_jgcl.js

+ 1 - 1
app/public/js/shares/export_excel.js

@@ -120,7 +120,7 @@ const XLSXObj = (function () {
         };
         const blob = xlsxUtils.format2Blob(xlsxData);
         saveAs(blob, file);
-    }
+    };
 
     return {exportXlsxSheet}
 });

+ 29 - 13
app/service/revise_pos.js

@@ -282,34 +282,48 @@ module.exports = app => {
             if (!(data instanceof Array)) throw '提交数据错误';
 
             const transaction = await this.db.beginTransaction();
-            const result = { ledger: {}, pos: null }, updateLid = [];
+            const result = { ledger: {}, pos: null };
             const orgPos = await this.getPosData({tid: tid, id: this._.map(data, 'id')});
-            let bills = null, precision = null;
+
+            const bills = await this.ctx.service.reviseBills.getDataById(data[0].lid);
+            const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
+            const updateBills = {id: bills.id};
+            const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: bills.id} });
+            for (const bp of billsPos) {
+                const d = data.find(function (x) {
+                    return bp.id ? x.id === bp.id : false;
+                });
+                if (d) 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);
+            }
+
             try {
                 for (const d of data) {
                     const op = d.id ? this._.find(orgPos, {id: d.id}) : null;
                     if (d.sgfh_qty || d.sjcl_qty || d.qtcl_qty) {
-                        if (!bills || bills.id !== d.lid) {
-                            bills = await this.ctx.service.reviseBills.getDataById(d.lid);
-                            precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
-                            updateLid.push(d.lid);
-                        }
                         if (d.sgfh_qty !== undefined) {
                             d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
                         } else if (op) {
                             d.sgfh_qty = op.sgfh_qty;
                         }
+                        updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, d.sgfh_qty);
                         if (d.sjcl_qty !== undefined) {
                             d.sjcl_qty = this.round(d.sjcl_qty, precision.value);
                         } else if (op) {
                             d.sjcl_qty = op.sjcl_qty;
                         }
+                        updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, d.sjcl_qty);
                         if (d.qtcl_qty) {
                             d.qtcl_qty = this.round(d.qtcl_qty, precision.value);
                         } else if (op) {
                             d.qtcl_qty = op.qtcl_qty;
                         }
+                        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.id) {
                         await transaction.update(this.tableName, d);
@@ -317,18 +331,20 @@ module.exports = app => {
                         this._insertPosData(transaction, d, tid, rid);
                     }
                 }
-                for (const lid of updateLid) {
-                    await this.ctx.service.reviseBills.calc(tid, lid, transaction);
-                }
+                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);
+                await transaction.update(this.ctx.service.reviseBills.tableName, updateBills);
+                updateBills.ledger_id = bills.ledger_id;
                 await transaction.commit();
             } catch (err) {
                 await transaction.rollback();
                 throw err;
             }
             result.pos = data;
-            if (updateLid.length > 0) {
-                result.ledger.update = await this.ctx.service.reviseBills.getDataById(updateLid);
-            }
+            result.ledger.update = [updateBills];
             return result;
         }
     }

+ 6 - 2
app/service/stage_jgcl.js

@@ -47,7 +47,9 @@ module.exports = app => {
         }
 
         async getPreStageData(sorder) {
-            const sql = 'SELECT c.uuid, Sum(c.arrive_qty) as arrive_qty, Sum(c.arrive_tp) as arrive_tp, Sum(c.deduct_qty) as deduct_qty, Sum(c.deduct_tp) as deduct_tp From ' + this.tableName + ' c' +
+            const sql = 'SELECT c.uuid, Sum(c.arrive_qty) as arrive_qty, Sum(c.arrive_tp) as arrive_tp,' +
+                '    Sum(c.deduct_qty) as deduct_qty, Sum(c.deduct_tp) as deduct_tp' +
+                '  From ' + this.tableName + ' c' +
                 '  LEFT JOIN ' + this.ctx.service.stage.tableName + ' s ON s.id = c.sid' +
                 '  WHERE s.`order` < ? And s.`tid` = ?' +
                 '  GROUP By uuid';
@@ -57,7 +59,9 @@ module.exports = app => {
         }
 
         async getEndStageData(sorder) {
-            const sql = 'SELECT c.uuid, Sum(c.arrive_qty) as arrive_qty, Sum(c.arrive_tp) as arrive_tp, Sum(c.deduct_qty) as deduct_qty, Sum(c.deduct_tp) as deduct_tp From ' + this.tableName + ' c' +
+            const sql = 'SELECT c.uuid, Sum(c.arrive_qty) as arrive_qty, Sum(c.arrive_tp) as arrive_tp,' +
+                '    Sum(c.deduct_qty) as deduct_qty, Sum(c.deduct_tp) as deduct_tp' +
+                '  From ' + this.tableName + ' c' +
                 '  LEFT JOIN ' + this.ctx.service.stage.tableName + ' s ON s.id = c.sid' +
                 '  WHERE s.`order` <= ? And s.`tid` = ?' +
                 '  GROUP By uuid';