pos.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. 'use strict';
  2. /**
  3. * 部位明细
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = app => {
  10. class Pos extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.depart = 20;
  20. this.tableName = 'pos';
  21. }
  22. async getPosData(condition, column) {
  23. if (!condition.tid) throw '查询计量单元缺少必要信息';
  24. return await this.db.select(this.departTableName(condition.tid), {
  25. where: condition,
  26. columns: column || ['id', 'tid', 'lid', 'name', 'quantity', 'position', 'drawing_code', 'sgfh_qty', 'sjcl_qty',
  27. 'qtcl_qty', 'in_time', 'porder', 'add_stage', 'sgfh_expr', 'sjcl_expr', 'qtcl_expr', 'real_qty',
  28. 'ex_memo1', 'ex_memo2', 'ex_memo3'],
  29. order: [['porder', 'ASC']],
  30. });
  31. }
  32. async getPosDataWithAddStageOrder(condition) {
  33. if (!condition.tid) throw '查询计量单元缺少必要信息';
  34. const sql = 'SELECT id, tid, lid, name, quantity, position, drawing_code,' +
  35. ' sgfh_qty, sjcl_qty, qtcl_qty, porder, add_stage, add_times, add_user, add_stage_order,' +
  36. ' sgfh_expr, sjcl_expr, qtcl_expr, real_qty, ex_memo1, ex_memo2, ex_memo3' +
  37. ' FROM ' + this.departTableName(condition.tid) + this.ctx.helper.whereSql(condition);
  38. return await this.db.query(sql);
  39. }
  40. async getPosDataByIds(tid, ids) {
  41. if (ids instanceof Array && ids.length > 0) {
  42. const sql = 'SELECT id, tid, lid, name, quantity, position, drawing_code,' +
  43. ' sgfh_qty, sjcl_qty, qtcl_qty, add_stage, add_times, add_user, sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
  44. ' ex_memo1, ex_memo2, ex_memo3' +
  45. ' FROM ' + this.departTableName(tid) +
  46. ' WHERE id in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ')';
  47. return await this.db.query(sql, []);
  48. } else {
  49. return [];
  50. }
  51. // this.initSqlBuilder();
  52. // this.sqlBuilder.setAndWhere('id', {
  53. // operate: 'in',
  54. // value: ids
  55. // });
  56. // this.sqlBuilder.columns = ['id', 'tid', 'lid', 'name', 'quantity', 'drawing_code', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty'];
  57. // const [sql, sqlParam] = this.sqlBuilder.build(this.tableName)
  58. // return await this.db.query(sql, sqlParam);
  59. }
  60. async getPosDataByUnits(tenderId, units) {
  61. const sql = 'SELECT p.id, p.lid, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty' +
  62. ' FROM ' + this.departTableName(tenderId) + ' p' +
  63. ' LEFT JOIN ' + this.ctx.service.ledger.tableName + ' b' +
  64. ' ON p.lid = b.id ' +
  65. ' WHERE p.tid = ? and b.unit IN (?)';
  66. const sqlParam = [tenderId, units];
  67. return await this.db.query(sql, sqlParam);
  68. }
  69. async _insertPosData(transaction, data, tid) {
  70. data.id = this.uuid.v4();
  71. data.tid = tid;
  72. // todo 新增期
  73. data.add_stage = 0;
  74. data.add_stage_order = 0;
  75. data.add_times = 0;
  76. data.in_time = new Date();
  77. data.add_user = this.ctx.session.sessionUser.accountId;
  78. if (data.quantity) {
  79. const bills = await this.ctx.service.ledger.getDataById(data.lid);
  80. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  81. data.quantity = this.round(data.quantity, precision.value);
  82. }
  83. if (transaction) {
  84. const addRst = await transaction.insert(this.tableName, data);
  85. } else {
  86. const addRst = await this.db.insert(this.tableName, data);
  87. }
  88. }
  89. async _completeInsertPosData(tid, data) {
  90. data.id = this.uuid.v4();
  91. data.tid = tid;
  92. // todo 新增期
  93. data.add_stage = 0;
  94. data.add_stage_order = 0;
  95. data.add_times = 0;
  96. data.in_time = new Date();
  97. data.add_user = this.ctx.session.sessionUser.accountId;
  98. }
  99. async _getUpdateBills(data) {
  100. const datas = data instanceof Array ? data : [data];
  101. const bills = await this.ctx.service.ledger.getDataById(datas[0].lid);
  102. const billsPos = await this.getAllDataByCondition({where: {tid: bills.tender_id, lid: bills.id} });
  103. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  104. const updateBills = {id: bills.id};
  105. for (const bp of billsPos) {
  106. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  107. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  108. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  109. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
  110. }
  111. for (const d of datas) {
  112. if (d.sgfh_qty) {
  113. d.sgfh_qty = this.ctx.helper.round(d.sgfh_qty, precision.value);
  114. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, d.sgfh_qty);
  115. }
  116. if (d.sjcl_qty) {
  117. d.sjcl_qty = this.ctx.helper.round(d.sjcl_qty, precision.value);
  118. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, d.sjcl_qty);
  119. }
  120. if (d.qtcl_qty) {
  121. d.qtcl_qty = this.ctx.helper.round(d.qtcl_qty, precision.value);
  122. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
  123. }
  124. d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
  125. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, d.quantity);
  126. }
  127. const info = this.ctx.tender.info;
  128. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  129. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  130. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  131. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  132. return updateBills;
  133. }
  134. async _addPosData(tid, data) {
  135. let updateBills = null;
  136. if (data instanceof Array) {
  137. for (const d of data) {
  138. this._completeInsertPosData(tid, d);
  139. }
  140. if (data[0].sgfh_qty !== undefined || data[0].sjcl_qty !== undefined || data[0].qtcl_qty !== undefined) {
  141. updateBills = await this._getUpdateBills(data);
  142. }
  143. } else {
  144. this._completeInsertPosData(tid, data);
  145. if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined) {
  146. updateBills = await this._getUpdateBills(data);
  147. }
  148. }
  149. if (updateBills) {
  150. const transaction = await this.db.beginTransaction();
  151. try {
  152. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  153. updateBills.ledger_id = bills.ledger_id;
  154. await transaction.commit();
  155. } catch (err) {
  156. await transaction.rollback();
  157. throw err;
  158. }
  159. return {
  160. ledger: { update: [updateBills] },
  161. pos: data,
  162. }
  163. } else {
  164. await this.db.insert(this.tableName, data);
  165. return { pos: data }
  166. }
  167. }
  168. async _updatePosData(tid, data) {
  169. if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined) {
  170. const op = await this.getDataById(data.id);
  171. const bills = await this.ctx.service.ledger.getDataById(op.lid);
  172. if (!bills) throw '数据错误';
  173. const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: op.lid} });
  174. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  175. if (data.sgfh_qty !== undefined) {
  176. data.sgfh_qty = this.round(data.sgfh_qty, precision.value);
  177. } else if (op) {
  178. data.sgfh_qty = op.sgfh_qty;
  179. }
  180. if (data.sjcl_qty !== undefined) {
  181. data.sjcl_qty = this.round(data.sjcl_qty, precision.value);
  182. } else if (op) {
  183. data.sjcl_qty = op.sjcl_qty;
  184. }
  185. if (data.qtcl_qty !== undefined) {
  186. data.qtcl_qty = this.round(data.qtcl_qty, precision.value);
  187. } else if (op) {
  188. data.qtcl_qty = op.qtcl_qty;
  189. }
  190. data.quantity = this.ctx.helper.sum([data.sgfh_qty, data.qtcl_qty, data.sjcl_qty]);
  191. const updateBills = {id: bills.id};
  192. for (const bp of billsPos) {
  193. const calcData = bp.id === data.id ? data : bp;
  194. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, calcData.sgfh_qty);
  195. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, calcData.sjcl_qty);
  196. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, calcData.qtcl_qty);
  197. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, calcData.quantity);
  198. }
  199. const info = this.ctx.tender.info;
  200. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  201. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  202. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  203. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  204. const transaction = await this.db.beginTransaction();
  205. try {
  206. await transaction.update(this.tableName, data);
  207. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  208. await transaction.commit();
  209. updateBills.ledger_id = bills.ledger_id;
  210. return {
  211. ledger: { update: [updateBills] },
  212. pos: data,
  213. }
  214. } catch(err) {
  215. await transaction.rollback();
  216. throw err;
  217. }
  218. } else {
  219. await this.db.update(this.tableName, data);
  220. return {pos: data};
  221. }
  222. }
  223. async _updatePosDatas(tid, data) {
  224. if (data.length === 0) return;
  225. const op = await this.getDataById(data[0].id);
  226. const bills = await this.ctx.service.ledger.getDataById(op.lid);
  227. const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: op.lid} });
  228. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  229. let needUpdateBills;
  230. for (const d of data) {
  231. if (d.sgfh_qty !== undefined || d.sjcl_qty !== undefined || d.qtcl_qty !== undefined) {
  232. if (d.sgfh_qty !== undefined) {
  233. d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
  234. } else if (op) {
  235. d.sgfh_qty = op.sgfh_qty;
  236. }
  237. if (d.sjcl_qty !== undefined) {
  238. d.sjcl_qty = this.round(d.sjcl_qty, precision.value);
  239. } else if (op) {
  240. d.sjcl_qty = op.sjcl_qty;
  241. }
  242. if (d.qtcl_qty !== undefined) {
  243. d.qtcl_qty = this.round(d.qtcl_qty, precision.value);
  244. } else if (op) {
  245. d.qtcl_qty = op.qtcl_qty;
  246. }
  247. d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
  248. needUpdateBills = true;
  249. }
  250. }
  251. const updateBills = {id: bills.id};
  252. if (needUpdateBills) {
  253. for (const bp of billsPos) {
  254. const newPos = data.find(function (x) { return x.id === bp.id });
  255. updateBills.sgfh_qty = newPos && newPos.sgfh_qty !== undefined
  256. ? this.ctx.helper.add(updateBills.sgfh_qty, newPos.sgfh_qty)
  257. : this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  258. updateBills.sjcl_qty = newPos && newPos.sjcl_qty !== undefined
  259. ? this.ctx.helper.add(updateBills.sjcl_qty, newPos.sjcl_qty)
  260. : this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  261. updateBills.qtcl_qty = newPos && newPos.qtcl_qty !== undefined
  262. ? this.ctx.helper.add(updateBills.qtcl_qty, newPos.qtcl_qty)
  263. : this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  264. updateBills.quantity = newPos && newPos.quantity !== undefined
  265. ? this.ctx.helper.add(updateBills.quantity, newPos.quantity)
  266. : this.ctx.helper.add(updateBills.quantity, bp.quantity);
  267. }
  268. const info = this.ctx.tender.info;
  269. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  270. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  271. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  272. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  273. }
  274. const transaction = await this.db.beginTransaction();
  275. try {
  276. for (const d of data) {
  277. await transaction.update(this.tableName, d);
  278. }
  279. if (needUpdateBills) await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  280. await transaction.commit();
  281. updateBills.ledger_id = bills.ledger_id;
  282. return {
  283. ledger: { update: [updateBills] },
  284. pos: data,
  285. }
  286. } catch(err) {
  287. await transaction.rollback();
  288. throw err;
  289. }
  290. }
  291. async _deletePosData(tid, data) {
  292. if (!data || data.length === 0) throw '提交数据错误';
  293. const pos = await this.getPosData({tid: tid, id: data});
  294. if (!pos || pos.length === 0) throw '删除的计量单元不存在';
  295. const bills = await this.ctx.service.ledger.getDataById(pos[0].lid);
  296. const billsPos = await this.getAllDataByCondition({ where: {tid: tid, lid: bills.id} });
  297. const updateBills = {id: bills.id, sgfh_qty: null, sjcl_qty: null, qtcl_qty: null, quantity: null};
  298. for (const bp of billsPos) {
  299. if (data.indexOf(bp.id) >= 0) continue;
  300. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  301. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  302. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  303. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
  304. }
  305. const info = this.ctx.tender.info;
  306. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  307. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  308. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  309. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  310. const transaction = await this.db.beginTransaction();
  311. try {
  312. await transaction.delete(this.tableName, {tid: tid, id: data});
  313. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  314. await transaction.commit();
  315. updateBills.ledger_id = bills.ledger_id;
  316. return { ledger: { update: [updateBills] }, pos: data };
  317. } catch(err) {
  318. await transaction.rollback();
  319. throw err;
  320. }
  321. }
  322. async _insertPosData(tid, data) {
  323. if (!data.length) return;
  324. let porder = data[0].porder, lid = data[0].lid;
  325. for (const d of data) {
  326. this._completeInsertPosData(tid, d);
  327. porder = Math.min(porder, d.porder);
  328. }
  329. const transaction = await this.db.beginTransaction();
  330. try {
  331. this.initSqlBuilder();
  332. this.sqlBuilder.setAndWhere('lid', {
  333. value: this.db.escape(lid),
  334. operate: '=',
  335. });
  336. this.sqlBuilder.setAndWhere('porder', {
  337. value: porder,
  338. operate: '>=',
  339. });
  340. this.sqlBuilder.setUpdateData('porder', {
  341. value: data.length,
  342. selfOperate: '+',
  343. });
  344. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
  345. const result = await transaction.query(sql, sqlParam);
  346. await transaction.insert(this.tableName, data);
  347. await transaction.commit();
  348. } catch (err) {
  349. await transaction.rollback();
  350. throw err;
  351. }
  352. this.initSqlBuilder();
  353. this.sqlBuilder.setAndWhere('lid', {
  354. value: this.db.escape(lid),
  355. operate: '=',
  356. });
  357. this.sqlBuilder.setAndWhere('porder', {
  358. value: porder,
  359. operate: '>=',
  360. });
  361. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
  362. const update = await this.db.query(sql, sqlParam);
  363. return { pos: update }
  364. }
  365. /**
  366. * 保存部位明细数据
  367. * @param data
  368. * @param {Number} tid - 标段id
  369. * @returns {Promise<{ledger: {}, pos: null}>}
  370. */
  371. async savePosData(data, tid) {
  372. switch (data.updateType) {
  373. case 'add':
  374. return await this._addPosData(tid, data.updateData);
  375. case 'update':
  376. if (data.updateData instanceof Array) {
  377. return await this._updatePosDatas(tid, data.updateData);
  378. } else {
  379. return await this._updatePosData(tid, data.updateData);
  380. }
  381. case 'delete':
  382. return await this._deletePosData(tid, data.updateData);
  383. case 'insert':
  384. return await this._insertPosData(tid, data.updateData);
  385. }
  386. }
  387. /**
  388. * 复制粘贴 部位明细数据
  389. * @param {Array} data - 复制粘贴的数据
  390. * @param {Number} tid - 标段id
  391. * @returns {Promise<{ledger: {}, pos: null}>}
  392. */
  393. async pastePosData(data, tid) {
  394. if (!(data instanceof Array)) {
  395. throw '提交数据错误';
  396. }
  397. const transaction = await this.db.beginTransaction();
  398. const result = { ledger: {}, pos: null };
  399. const bills = await this.ctx.service.ledger.getDataById(data[0].lid);
  400. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  401. const updateBills = {id: bills.id};
  402. const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: bills.id} });
  403. for (const bp of billsPos) {
  404. const d = data.find(function (x) {
  405. return bp.id ? x.id === bp.id : false;
  406. });
  407. if (d) continue;
  408. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  409. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  410. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  411. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
  412. }
  413. try {
  414. for (const d of data) {
  415. const op = d.id ? this._.find(billsPos, {id: d.id}) : null;
  416. if (d.sgfh_qty !== undefined) {
  417. d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
  418. } else if (op) {
  419. d.sgfh_qty = op.sgfh_qty;
  420. }
  421. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, d.sgfh_qty);
  422. if (d.sjcl_qty !== undefined) {
  423. d.sjcl_qty = this.round(d.sjcl_qty, precision.value);
  424. } else if (op) {
  425. d.sjcl_qty = op.sjcl_qty;
  426. }
  427. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, d.sjcl_qty);
  428. if (d.qtcl_qty) {
  429. d.qtcl_qty = this.round(d.qtcl_qty, precision.value);
  430. } else if (op) {
  431. d.qtcl_qty = op.qtcl_qty;
  432. }
  433. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
  434. d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
  435. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, d.quantity);
  436. if (d.id) {
  437. await transaction.update(this.tableName, d);
  438. } else {
  439. this._completeInsertPosData(tid, d);
  440. await transaction.insert(this.tableName, d);
  441. }
  442. }
  443. const info = this.ctx.tender.info;
  444. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  445. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  446. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  447. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  448. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  449. updateBills.ledger_id = bills.ledger_id;
  450. await transaction.commit();
  451. } catch (err) {
  452. await transaction.rollback();
  453. throw err;
  454. }
  455. result.pos = data;
  456. result.ledger.update = [updateBills];
  457. return result;
  458. }
  459. /**
  460. * 删除清单下部位明细数据(删除清单时调用)
  461. *
  462. * @param transaction - 事务
  463. * @param tid - 标段id
  464. * @param lid - 清单id
  465. * @returns {Promise<void>}
  466. */
  467. async deletePosData(transaction, tid, lid) {
  468. await transaction.delete(this.tableName, {tid: tid, lid: lid});
  469. }
  470. }
  471. return Pos;
  472. };