|
@@ -578,6 +578,100 @@ module.exports = app => {
|
|
|
result.ancGclDetail = { add: insertAncGclDetail };
|
|
result.ancGclDetail = { add: insertAncGclDetail };
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
+ async _addPosDataWithDetail(tid, data) {
|
|
|
|
|
+ if (!(data.pos instanceof Array)) throw '提交数据错误';
|
|
|
|
|
+
|
|
|
|
|
+ const result = { ledger: {}, pos: null };
|
|
|
|
|
+ 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);
|
|
|
|
|
+ const calcTemplate = le && le.calc_template ? await this.ctx.service.calcTmpl.getTemplate(le.calc_template) : null;
|
|
|
|
|
+ const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
|
|
|
|
|
+ const existPos = await this.ctx.service.pos.getAllDataByCondition({ where : { lid: bills.id }, orders: [['porder', 'DESC']]});
|
|
|
|
|
+ const maxOrder = existPos.length > 0 ? existPos[0].porder : 0;
|
|
|
|
|
+ const updateBills = existPos.length > 0
|
|
|
|
|
+ ? { 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 = [];
|
|
|
|
|
+ for (const [i, b] of data.pos.entries()) {
|
|
|
|
|
+ const nip = {};
|
|
|
|
|
+ insertPos.push(nip);
|
|
|
|
|
+ this._completeInsertPosData(tid, nip);
|
|
|
|
|
+ nip.lid = b.lid;
|
|
|
|
|
+ nip.name = b.name || '';
|
|
|
|
|
+ nip.porder = maxOrder + i + 1;
|
|
|
|
|
+
|
|
|
|
|
+ let sumQty = 0;
|
|
|
|
|
+ for (const [icd, cd] of b.calcDetail.entries()) {
|
|
|
|
|
+ const newDetail = {
|
|
|
|
|
+ id: this.uuid.v4(), tid: tid, lid: bills.id, pid: nip.id,
|
|
|
|
|
+ create_user_id: user_id, update_user_id: user_id,
|
|
|
|
|
+ pcd_order: icd+1,
|
|
|
|
|
+ };
|
|
|
|
|
+ if (data.calc_template === le.calc_template) {
|
|
|
|
|
+ newDetail.str1 = cd.str1 || '';
|
|
|
|
|
+ newDetail.str2 = cd.str2 || '';
|
|
|
|
|
+ newDetail.str3 = cd.str3 || '';
|
|
|
|
|
+ newDetail.str4 = cd.str4 || '';
|
|
|
|
|
+ newDetail.num_a = cd.num_a || 0;
|
|
|
|
|
+ newDetail.num_b = cd.num_b || 0;
|
|
|
|
|
+ newDetail.num_c = cd.num_c || 0;
|
|
|
|
|
+ newDetail.num_d = cd.num_d || 0;
|
|
|
|
|
+ newDetail.num_e = cd.num_e || 0;
|
|
|
|
|
+ newDetail.num_f = cd.num_f || 0;
|
|
|
|
|
+ newDetail.num_g = cd.num_g || 0;
|
|
|
|
|
+ newDetail.num_h = cd.num_h || 0;
|
|
|
|
|
+ newDetail.num_i = cd.num_i || 0;
|
|
|
|
|
+ newDetail.num_j = cd.num_j || 0;
|
|
|
|
|
+ newDetail.num_k = cd.num_k || 0;
|
|
|
|
|
+ newDetail.num_l = cd.num_l || 0;
|
|
|
|
|
+ newDetail.num_m = cd.num_m || 0;
|
|
|
|
|
+ newDetail.num_n = cd.num_n || 0;
|
|
|
|
|
+ newDetail.num_o = cd.num_o || 0;
|
|
|
|
|
+ newDetail.num_p = cd.num_p || 0;
|
|
|
|
|
+ newDetail.num_q = cd.num_q || 0;
|
|
|
|
|
+ newDetail.num_r = cd.num_r || 0;
|
|
|
|
|
+ newDetail.num_s = cd.num_s || 0;
|
|
|
|
|
+ newDetail.num_t = cd.num_t || 0;
|
|
|
|
|
+ newDetail.num_u = cd.num_u || 0;
|
|
|
|
|
+ newDetail.qty = cd.qty || 0;
|
|
|
|
|
+ newDetail.expr = cd.expr || '';
|
|
|
|
|
+ newDetail.spec = cd.spec || '';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.ctx.service.posCalcDetail._loadDataAndCalc(newDetail, cd, {}, calcTemplate);
|
|
|
|
|
+ }
|
|
|
|
|
+ sumQty = this.ctx.helper.add(sumQty, newDetail.qty);
|
|
|
|
|
+ insertDetail.push(newDetail);
|
|
|
|
|
+ }
|
|
|
|
|
+ this._calcExpr(nip, 'sgfh_qty', '', sumQty, precision);
|
|
|
|
|
+
|
|
|
|
|
+ nip.quantity = this.ctx.helper.add(nip.sgfh_qty, this.ctx.helper.add(nip.sjcl_qty, nip.qtcl_qty));
|
|
|
|
|
+ updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, nip.sgfh_qty);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const info = this.ctx.tender.info;
|
|
|
|
|
+ updateBills.quantity = this.ctx.helper.add(updateBills.sgfh_qty, this.ctx.helper.add(updateBills.sjcl_qty, updateBills.qtcl_qty));
|
|
|
|
|
+ updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
|
|
|
|
|
+ updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
|
|
|
|
|
+
|
|
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
|
|
+ try {
|
|
|
|
|
+ await transaction.insert(this.tableName, insertPos);
|
|
|
|
|
+ if (insertDetail.length > 0) await transaction.insert(this.ctx.service.posCalcDetail.tableName, insertDetail);
|
|
|
|
|
+ await transaction.update(this.ctx.service.ledger.tableName, updateBills);
|
|
|
|
|
+ await transaction.commit();
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ await transaction.rollback();
|
|
|
|
|
+ throw err;
|
|
|
|
|
+ }
|
|
|
|
|
+ result.pos = insertPos;
|
|
|
|
|
+ updateBills.ledger_id = bills.ledger_id;
|
|
|
|
|
+ result.ledger.update = [updateBills];
|
|
|
|
|
+ result.posCalcDetail = { add: insertDetail };
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 保存部位明细数据
|
|
* 保存部位明细数据
|
|
@@ -601,6 +695,8 @@ module.exports = app => {
|
|
|
return await this._insertPosData(tid, data.updateData);
|
|
return await this._insertPosData(tid, data.updateData);
|
|
|
case 'paste-block':
|
|
case 'paste-block':
|
|
|
return await this.pasteBlockData(tid, data.updateData);
|
|
return await this.pasteBlockData(tid, data.updateData);
|
|
|
|
|
+ case 'add-with-detail':
|
|
|
|
|
+ return await this._addPosDataWithDetail(tid, data.updateData);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|