|
@@ -28,7 +28,7 @@ module.exports = app => {
|
|
|
return await this.db.select(this.departTableName(condition.tid), {
|
|
|
where: condition,
|
|
|
columns: column || ['id', 'tid', 'lid', 'name', 'quantity', 'position', 'drawing_code', 'sgfh_qty', 'sjcl_qty',
|
|
|
- 'qtcl_qty', 'in_time', 'porder', 'add_stage', 'add_stage_order', 'sgfh_expr', 'sjcl_expr', 'qtcl_expr', 'real_qty',
|
|
|
+ 'qtcl_qty', 'in_time', 'porder', 'add_stage', 'add_stage_order', 'sgfh_expr', 'sjcl_expr', 'qtcl_expr', 'real_qty', 'ex_qty1',
|
|
|
'ex_memo1', 'ex_memo2', 'ex_memo3'],
|
|
|
order: [['porder', 'ASC']],
|
|
|
});
|
|
@@ -38,7 +38,7 @@ module.exports = app => {
|
|
|
if (!condition.tid) throw '查询计量单元缺少必要信息';
|
|
|
const sql = 'SELECT id, tid, lid, name, quantity, position, drawing_code,' +
|
|
|
' sgfh_qty, sjcl_qty, qtcl_qty, porder, add_stage, add_times, add_user, add_stage_order,' +
|
|
|
- ' sgfh_expr, sjcl_expr, qtcl_expr, real_qty, ex_memo1, ex_memo2, ex_memo3' +
|
|
|
+ ' sgfh_expr, sjcl_expr, qtcl_expr, real_qty, ex_qty1, ex_memo1, ex_memo2, ex_memo3' +
|
|
|
' FROM ' + this.departTableName(condition.tid) + this.ctx.helper.whereSql(condition);
|
|
|
return await this.db.query(sql);
|
|
|
}
|
|
@@ -46,7 +46,7 @@ module.exports = app => {
|
|
|
async getPosDataByIds(tid, ids) {
|
|
|
if (ids instanceof Array && ids.length > 0) {
|
|
|
const sql = 'SELECT id, tid, lid, name, quantity, position, drawing_code,' +
|
|
|
- ' sgfh_qty, sjcl_qty, qtcl_qty, add_stage, add_times, add_user, sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
|
|
|
+ ' sgfh_qty, sjcl_qty, qtcl_qty, add_stage, add_times, add_user, sgfh_expr, sjcl_expr, qtcl_expr, real_qty, ex_qty1' +
|
|
|
' ex_memo1, ex_memo2, ex_memo3' +
|
|
|
' FROM ' + this.departTableName(tid) +
|
|
|
' WHERE id in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ')';
|
|
@@ -117,6 +117,7 @@ module.exports = app => {
|
|
|
updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
|
|
|
updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
|
|
|
updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
|
|
|
+ updateBills.ex_qty1 = this.ctx.helper.add(updateBills.ex_qty1, bp.ex_qty1);
|
|
|
}
|
|
|
for (const d of datas) {
|
|
|
if (d.sgfh_qty) {
|
|
@@ -133,12 +134,17 @@ module.exports = app => {
|
|
|
}
|
|
|
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.ex_qty1) {
|
|
|
+ d.ex_qty1 = this.ctx.helper.round(d.ex_qty1, precision.value);
|
|
|
+ updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
|
|
|
+ }
|
|
|
}
|
|
|
const info = this.ctx.tender.info;
|
|
|
updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
|
|
|
+ updateBills.ex_tp1 = this.ctx.helper.mul(updateBills.ex_qty1, bills.unit_price, info.decimal.tp);
|
|
|
return updateBills;
|
|
|
}
|
|
|
|
|
@@ -148,12 +154,12 @@ module.exports = app => {
|
|
|
for (const d of data) {
|
|
|
this._completeInsertPosData(tid, d);
|
|
|
}
|
|
|
- if (data[0].sgfh_qty !== undefined || data[0].sjcl_qty !== undefined || data[0].qtcl_qty !== undefined) {
|
|
|
+ if (data[0].sgfh_qty !== undefined || data[0].sjcl_qty !== undefined || data[0].qtcl_qty !== undefined || data[0].ex_qty1 !== undefined) {
|
|
|
updateBills = await this._getUpdateBills(data);
|
|
|
}
|
|
|
} else {
|
|
|
this._completeInsertPosData(tid, data);
|
|
|
- if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined) {
|
|
|
+ if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined || data.ex_qty1 !== undefined) {
|
|
|
updateBills = await this._getUpdateBills(data);
|
|
|
}
|
|
|
}
|
|
@@ -178,7 +184,7 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
async _updatePosData(tid, data) {
|
|
|
- if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined) {
|
|
|
+ if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined || data.ex_qty1 !== undefined) {
|
|
|
const op = await this.getDataById(data.id);
|
|
|
const bills = await this.ctx.service.ledger.getDataById(op.lid);
|
|
|
if (!bills) throw '数据错误';
|
|
@@ -201,6 +207,11 @@ module.exports = app => {
|
|
|
data.qtcl_qty = op.qtcl_qty;
|
|
|
}
|
|
|
data.quantity = this.ctx.helper.sum([data.sgfh_qty, data.qtcl_qty, data.sjcl_qty]);
|
|
|
+ if (data.ex_qty1 !== undefined) {
|
|
|
+ data.ex_qty1 = this.round(data.ex_qty1, precision.value);
|
|
|
+ } else if (op) {
|
|
|
+ data.ex_qty1 = op.ex_qty1;
|
|
|
+ }
|
|
|
|
|
|
const updateBills = {id: bills.id};
|
|
|
for (const bp of billsPos) {
|
|
@@ -209,12 +220,14 @@ module.exports = app => {
|
|
|
updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, calcData.sjcl_qty);
|
|
|
updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, calcData.qtcl_qty);
|
|
|
updateBills.quantity = this.ctx.helper.add(updateBills.quantity, calcData.quantity);
|
|
|
+ updateBills.ex_qty1 = this.ctx.helper.add(updateBills.ex_qty1, calcData.ex_qty1);
|
|
|
}
|
|
|
const info = this.ctx.tender.info;
|
|
|
updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
|
|
|
+ updateBills.ex_tp1 = this.ctx.helper.mul(updateBills.ex_qty1, bills.unit_price, info.decimal.tp);
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
@@ -244,7 +257,7 @@ module.exports = app => {
|
|
|
const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
|
|
|
let needUpdateBills;
|
|
|
for (const d of data) {
|
|
|
- if (d.sgfh_qty !== undefined || d.sjcl_qty !== undefined || d.qtcl_qty !== undefined) {
|
|
|
+ if (d.sgfh_qty !== undefined || d.sjcl_qty !== undefined || d.qtcl_qty !== undefined || d.ex_qty1 !== undefined) {
|
|
|
if (d.sgfh_qty !== undefined) {
|
|
|
d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
|
|
|
} else if (op) {
|
|
@@ -261,6 +274,11 @@ module.exports = app => {
|
|
|
d.qtcl_qty = op.qtcl_qty;
|
|
|
}
|
|
|
d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
|
|
|
+ if (d.ex_qty1 !== undefined) {
|
|
|
+ d.ex_qty1 = this.round(d.ex_qty1, precision.value);
|
|
|
+ } else if (op) {
|
|
|
+ d.ex_qty1 = op.ex_qty1;
|
|
|
+ }
|
|
|
needUpdateBills = true;
|
|
|
}
|
|
|
}
|
|
@@ -280,12 +298,16 @@ module.exports = app => {
|
|
|
updateBills.quantity = newPos && newPos.quantity !== undefined
|
|
|
? this.ctx.helper.add(updateBills.quantity, newPos.quantity)
|
|
|
: this.ctx.helper.add(updateBills.quantity, bp.quantity);
|
|
|
+ updateBills.ex_qty1 = newPos && newPos.ex_qty1 !== undefined
|
|
|
+ ? this.ctx.helper.add(updateBills.ex_qty1, newPos.ex_qty1)
|
|
|
+ : this.ctx.helper.add(updateBills.ex_qty1, bp.ex_qty1);
|
|
|
}
|
|
|
const info = this.ctx.tender.info;
|
|
|
updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
|
|
|
+ updateBills.ex_tp1 = this.ctx.helper.mul(updateBills.ex_qty1, bills.unit_price, info.decimal.tp);
|
|
|
}
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
@@ -314,19 +336,21 @@ module.exports = app => {
|
|
|
|
|
|
const bills = await this.ctx.service.ledger.getDataById(pos[0].lid);
|
|
|
const billsPos = await this.getAllDataByCondition({ where: {tid: tid, lid: bills.id} });
|
|
|
- const updateBills = {id: bills.id, sgfh_qty: null, sjcl_qty: null, qtcl_qty: null, quantity: null};
|
|
|
+ const updateBills = {id: bills.id, sgfh_qty: 0, sjcl_qty: 0, qtcl_qty: 0, quantity: 0, ex_qty1: 0};
|
|
|
for (const bp of billsPos) {
|
|
|
if (data.indexOf(bp.id) >= 0) continue;
|
|
|
updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
|
|
|
updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
|
|
|
updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
|
|
|
updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
|
|
|
+ updateBills.ex_qty1 = this.ctx.helper.add(updateBills.ex_qty1, bp.ex_qty1);
|
|
|
}
|
|
|
const info = this.ctx.tender.info;
|
|
|
updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
|
|
|
+ updateBills.ex_tp1 = this.ctx.helper.mul(updateBills.ex_qty1, bills.unit_price, info.decimal.tp);
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
@@ -438,6 +462,7 @@ module.exports = app => {
|
|
|
updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
|
|
|
updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
|
|
|
updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
|
|
|
+ updateBills.ex_qty1 = this.ctx.helper.add(updateBills.ex_qty1, bp.ex_qty1);
|
|
|
}
|
|
|
|
|
|
try {
|
|
@@ -464,6 +489,12 @@ module.exports = app => {
|
|
|
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.ex_qty1) {
|
|
|
+ d.ex_qty1 = this.round(d.ex_qty1, precision.value);
|
|
|
+ } else if (op) {
|
|
|
+ d.ex_qty1 = op.ex_qty1;
|
|
|
+ }
|
|
|
+ updateBills.ex_qty1 = this.ctx.helper.add(updateBills.ex_qty1, d.ex_qty1);
|
|
|
|
|
|
if (d.id) {
|
|
|
await transaction.update(this.tableName, d);
|
|
@@ -478,6 +509,7 @@ module.exports = app => {
|
|
|
updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
|
|
|
+ updateBills.ex_tp1 = this.ctx.helper.mul(updateBills.ex_qty1, bills.unit_price, info.decimal.tp);
|
|
|
await transaction.update(this.ctx.service.ledger.tableName, updateBills);
|
|
|
updateBills.ledger_id = bills.ledger_id;
|
|
|
await transaction.commit();
|