|
@@ -21,6 +21,8 @@ SafeBillsFields.readQueryFields = [...SafeBillsFields.treeFields, ...SafeBillsFi
|
|
SafeBillsFields.compareQueryFields = [...SafeBillsFields.treeFields, ...SafeBillsFields.textFields, 'unit_price', 'cur_his', 'cur_qty', 'cur_tp'];
|
|
SafeBillsFields.compareQueryFields = [...SafeBillsFields.treeFields, ...SafeBillsFields.textFields, 'unit_price', 'cur_his', 'cur_qty', 'cur_tp'];
|
|
SafeBillsFields.preQueryFields = [...SafeBillsFields.treeFields, ...SafeBillsFields.textFields, 'tender_id', 'unit_price', 'end_qty', 'end_tp', 'add_user_id', 'add_time', 'update_user_id', 'update_time'];
|
|
SafeBillsFields.preQueryFields = [...SafeBillsFields.treeFields, ...SafeBillsFields.textFields, 'tender_id', 'unit_price', 'end_qty', 'end_tp', 'add_user_id', 'add_time', 'update_user_id', 'update_time'];
|
|
|
|
|
|
|
|
+const auditConst = require('../const/audit').stage;
|
|
|
|
+
|
|
module.exports = app => {
|
|
module.exports = app => {
|
|
|
|
|
|
class PaymentSafeBills extends app.BaseTreeService {
|
|
class PaymentSafeBills extends app.BaseTreeService {
|
|
@@ -284,7 +286,7 @@ module.exports = app => {
|
|
if (!targetData) throw '粘贴数据错误';
|
|
if (!targetData) throw '粘贴数据错误';
|
|
|
|
|
|
const newParentPath = targetData.full_path.replace(targetData.ledger_id, '');
|
|
const newParentPath = targetData.full_path.replace(targetData.ledger_id, '');
|
|
- const tpDecimal = this.decimal;
|
|
|
|
|
|
+ const tpDecimal = this.ctx.detail && this.ctx.detail.decimal ? this.ctx.detail.decimal : this.decimal;
|
|
|
|
|
|
const pasteBillsData = [], leafBillsId = [];
|
|
const pasteBillsData = [], leafBillsId = [];
|
|
let maxId = await this._getMaxLid(this.ctx.paymentTender.id);
|
|
let maxId = await this._getMaxLid(this.ctx.paymentTender.id);
|
|
@@ -463,7 +465,7 @@ module.exports = app => {
|
|
|
|
|
|
async updateCalc(detail, data) {
|
|
async updateCalc(detail, data) {
|
|
const helper = this.ctx.helper;
|
|
const helper = this.ctx.helper;
|
|
- const decimal = this.decimal;
|
|
|
|
|
|
+ const decimal = this.ctx.detail && this.ctx.detail.decimal ? this.ctx.detail.decimal : this.decimal;
|
|
// 简单验证数据
|
|
// 简单验证数据
|
|
if (!detail) throw '安全生产费不存在';
|
|
if (!detail) throw '安全生产费不存在';
|
|
if (!data) throw '提交数据错误';
|
|
if (!data) throw '提交数据错误';
|
|
@@ -511,6 +513,41 @@ module.exports = app => {
|
|
}
|
|
}
|
|
if (updateData.length > 0) await transaction.updateRows(this.tableName, updateData);
|
|
if (updateData.length > 0) await transaction.updateRows(this.tableName, updateData);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async setDecimal(decimal) {
|
|
|
|
+ if (!this.ctx.detail) throw '读取数据错误';
|
|
|
|
+ if (this.ctx.detail.order !== this.ctx.detail.highOrder) throw '往期不可修改小数位数';
|
|
|
|
+ if (this.ctx.detail.status !== auditConst.status.uncheck && this.ctx.detail.status !== auditConst.status.checkNo) throw '仅原报可修改小数位数';
|
|
|
|
+ const orgDecimal = this.ctx.detail.decimal ? this.ctx.detail.decimal : this.decimal;
|
|
|
|
+
|
|
|
|
+ const calcQty = decimal.qty < orgDecimal.qty;
|
|
|
|
+ const calcUp = decimal.up < orgDecimal.up;
|
|
|
|
+ const calcTp = decimal.tp < orgDecimal.tp;
|
|
|
|
+ this.ctx.detail.decimal = { up: decimal.up, tp: decimal.tp, qty: decimal.qty };
|
|
|
|
+
|
|
|
|
+ const updateData = [];
|
|
|
|
+ if (calcQty || calcUp || calcTp) {
|
|
|
|
+ const calcData = await this.getAllDataByCondition({ where: {detail_id: this.ctx.detail.id, tree_is_leaf: 1 } });
|
|
|
|
+ for (const cd of calcData) {
|
|
|
|
+ const nd = { id: cd.id, tree_id: cd.tree_id };
|
|
|
|
+ nd.unit_price = calcUp ? this.ctx.helper.round(cd.unit_price, decimal.up) : cd.unit_price;
|
|
|
|
+ nd.cur_qty = calcQty ? this.ctx.helper.round(cd.cur_qty, decimal.qty) : cd.cur_qty;
|
|
|
|
+ nd.cur_tp = this.ctx.helper.mul(nd.unit_price, nd.cur_qty, decimal.tp);
|
|
|
|
+ nd.end_qty = this.ctx.helper.add(nd.pre_qty, nd.cur_qty);
|
|
|
|
+ nd.end_tp = this.ctx.helper.add(nd.pre_tp, nd.cur_tp);
|
|
|
|
+ updateData.push(nd);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ const conn = await this.db.beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ await conn.update(this.ctx.service.paymentDetail.tableName, { id: this.ctx.detail.id, decimal: JSON.stringify(this.ctx.detail.decimal)});
|
|
|
|
+ if (updateData.length > 0) await conn.update(this.tableName, updateData);
|
|
|
|
+ await conn.commit();
|
|
|
|
+ } catch(err) {
|
|
|
|
+ await conn.rollback();
|
|
|
|
+ }
|
|
|
|
+ return { calc: calcQty || calcUp || calcTp, update: updateData };
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
return PaymentSafeBills;
|
|
return PaymentSafeBills;
|