|
|
@@ -429,6 +429,8 @@ module.exports = app => {
|
|
|
if (!(data.block instanceof Array)) throw '提交数据错误';
|
|
|
|
|
|
const result = { ledger: {}, pos: null };
|
|
|
+ const qtyDecimal = this.ctx.tender.info.decimal.qty;
|
|
|
+ const user_id = this.ctx.session.sessionUser.accountId;
|
|
|
|
|
|
const bills = await this.ctx.service.ledger.getDataById(data.lid);
|
|
|
const le = await this.ctx.service.ledgerExtra.getDataById(data.lid);
|
|
|
@@ -440,7 +442,7 @@ module.exports = app => {
|
|
|
? { id: bills.id, sgfh_qty: bills.sgfh_qty, sjcl_qty: bills.sjcl_qty, qtcl_qty: bills.qtcl_qty, quantity: bills.quantity, ex_qty1: bills.ex_qty1 }
|
|
|
: { id: bills.id, sgfh_qty: 0, sjcl_qty: 0, qtcl_qty: 0, quantity: 0, ex_qty1: 0 };
|
|
|
|
|
|
- const insertPos = [], insertDetail = [];
|
|
|
+ const insertPos = [], insertDetail = [], insertAncGcl = [], insertAncGclDetail = [];
|
|
|
for (const [i, b] of data.block.entries()) {
|
|
|
const nip = {};
|
|
|
insertPos.push(nip);
|
|
|
@@ -508,6 +510,38 @@ module.exports = app => {
|
|
|
this._calcExpr(nip, 'qtcl_qty', b.qtcl_expr, b.qtcl_qty, precision);
|
|
|
nip.quantity = this.ctx.helper.add(nip.sgfh_qty, this.ctx.helper.add(nip.sjcl_qty, nip.qtcl_qty));
|
|
|
nip.ex_qty1 = this.ctx.helper.round(b.ex_qty1, precision.value);
|
|
|
+ for (const ag of b.ancGcl) {
|
|
|
+ const nig = {
|
|
|
+ id: this.uuid.v4(), tid: this.ctx.tender.id,
|
|
|
+ add_user_id: user_id, update_user_id: user_id,
|
|
|
+ lid: nip.lid, pid: nip.id, g_order: ag.g_order,
|
|
|
+ is_aux: ag.is_aux || 0, name: ag.name || '', unit: ag.unit || '',
|
|
|
+ drawing_code: ag.drawing_code || '', memo: ag.memo || '',
|
|
|
+ quantity: ag.quantity || 0, expr: b.expr || '', calc_template: ag.calc_template || ''
|
|
|
+ };
|
|
|
+ insertAncGcl.push(nig);
|
|
|
+ if (!ag.calc_template) continue;
|
|
|
+
|
|
|
+ let sumQty = 0;
|
|
|
+ for (const cd of ag.calcDetail) {
|
|
|
+ const newDetail = {
|
|
|
+ id: this.uuid.v4(), tid: this.ctx.tender.id, lid: nip.lid, pid: nip.id, ag_id: nig.id,
|
|
|
+ create_user_id: user_id, update_user_id: user_id,
|
|
|
+ agd_order: cd.agd_order,
|
|
|
+ str1 : cd.str1 || '', str2 : cd.str1 || '', str3 : cd.str1 || '', str4 : cd.str1 || '',
|
|
|
+ num_a : cd.num_a || 0, num_b : cd.num_b || 0, num_c : cd.num_c || 0, num_d : cd.num_d || 0,
|
|
|
+ num_e : cd.num_e || 0, num_f : cd.num_f || 0, num_g : cd.num_g || 0, num_h : cd.num_h || 0,
|
|
|
+ num_i : cd.num_i || 0, num_j : cd.num_j || 0, num_k : cd.num_k || 0, num_l : cd.num_l || 0,
|
|
|
+ num_m : cd.num_m || 0, num_n : cd.num_n || 0, num_o : cd.num_o || 0, num_p : cd.num_p || 0,
|
|
|
+ num_q : cd.num_q || 0, num_r : cd.num_r || 0, num_s : cd.num_s || 0, num_t : cd.num_t || 0,
|
|
|
+ num_u : cd.num_u || 0,
|
|
|
+ qty: cd.qty || 0, expr: cd.expr || 0, spec: cd.spec || ''
|
|
|
+ };
|
|
|
+ sumQty = this.ctx.helper.add(sumQty, newDetail.qty);
|
|
|
+ insertAncGclDetail.push(newDetail);
|
|
|
+ }
|
|
|
+ nig.quantity = this.ctx.helper.round(sumQty, qtyDecimal);
|
|
|
+ }
|
|
|
|
|
|
updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, nip.sgfh_qty);
|
|
|
updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, nip.sjcl_qty);
|
|
|
@@ -527,6 +561,8 @@ module.exports = app => {
|
|
|
try {
|
|
|
await transaction.insert(this.tableName, insertPos);
|
|
|
if (insertDetail.length > 0) await transaction.insert(this.ctx.service.posCalcDetail.tableName, insertDetail);
|
|
|
+ if (insertAncGcl.length > 0) await transaction.insert(this.ctx.service.ancillaryGcl.tableName, insertAncGcl);
|
|
|
+ if (insertAncGclDetail.length > 0) await transaction.insert(this.ctx.service.ancillaryGclDetail.tableName, insertAncGclDetail);
|
|
|
await transaction.update(this.ctx.service.ledger.tableName, updateBills);
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
@@ -537,6 +573,8 @@ module.exports = app => {
|
|
|
updateBills.ledger_id = bills.ledger_id;
|
|
|
result.ledger.update = [updateBills];
|
|
|
result.posCalcDetail = { add: insertDetail };
|
|
|
+ result.ancGcl = { add: insertAncGcl };
|
|
|
+ result.ancGclDetail = { add: insertAncGclDetail };
|
|
|
return result;
|
|
|
}
|
|
|
|