|
@@ -355,7 +355,6 @@ module.exports = app => {
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
const result = { ledger: {}, pos: null };
|
|
|
- const orgPos = await this.getPosData({tid: tid, id: this._.map(data, 'id')});
|
|
|
|
|
|
const bills = await this.ctx.service.ledger.getDataById(data[0].lid);
|
|
|
const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
|
|
@@ -374,29 +373,29 @@ module.exports = app => {
|
|
|
|
|
|
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 (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);
|
|
|
+ const op = d.id ? this._.find(billsPos, {id: d.id}) : null;
|
|
|
+
|
|
|
+ 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);
|
|
|
} else {
|