|
@@ -33,7 +33,7 @@ module.exports = app => {
|
|
|
* @param {Number} sid - 期id
|
|
|
* @param {Number} lid - 台账节点id
|
|
|
* @param {Number} pid - 部位明细id
|
|
|
- * @returns {Promise<*>}
|
|
|
+ * @return {Promise<*>}
|
|
|
*/
|
|
|
async getLastestStageData(tid, sid, lid, pid) {
|
|
|
const sql = 'SELECT c.*,' +
|
|
@@ -62,7 +62,7 @@ module.exports = app => {
|
|
|
* @param {Number} order - 第几人
|
|
|
* @param {Number} lid - 台账节点id
|
|
|
* @param {Number} pid - 部位明细id
|
|
|
- * @returns {Promise<*>}
|
|
|
+ * @return {Promise<*>}
|
|
|
*/
|
|
|
async getAuditorStageData(tid, sid, times, order, lid, pid) {
|
|
|
const sql = 'SELECT c.*,' +
|
|
@@ -71,7 +71,7 @@ module.exports = app => {
|
|
|
' INNER JOIN ( ' +
|
|
|
' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
|
|
|
' WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?)) And lid = ? And pid = ?' +
|
|
|
- ' GROUP By `lid`, `pid`' +
|
|
|
+ ' GROUP By `lid`, `pid`, cid, cbid' +
|
|
|
' ) As m ' +
|
|
|
' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
|
|
|
' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
|
|
@@ -90,11 +90,11 @@ module.exports = app => {
|
|
|
' INNER JOIN ( ' +
|
|
|
' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
|
|
|
' WHERE tid = ? And sid = ?' +
|
|
|
- ' GROUP By `lid`, `pid`' +
|
|
|
+ ' GROUP By `lid`, `pid`, cid, cbid' +
|
|
|
' ) As m ' +
|
|
|
' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
|
|
|
' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
|
|
|
- ' ON c.cid = oc.cid'+
|
|
|
+ ' ON c.cid = oc.cid' +
|
|
|
' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
|
|
|
' ON c.cbid = ocb.id' +
|
|
|
' WHERE not ISNULL(ocb.id)';
|
|
@@ -109,11 +109,11 @@ module.exports = app => {
|
|
|
' INNER JOIN ( ' +
|
|
|
' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
|
|
|
' WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?))' +
|
|
|
- ' GROUP By `lid`, `pid`' +
|
|
|
+ ' GROUP By `lid`, `pid`, cid, cbid' +
|
|
|
' ) As m ' +
|
|
|
' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
|
|
|
' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
|
|
|
- ' ON c.cid = oc.cid'+
|
|
|
+ ' ON c.cid = oc.cid' +
|
|
|
' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
|
|
|
' ON c.cbid = ocb.id' +
|
|
|
' WHERE not ISNULL(ocb.id)';
|
|
@@ -126,7 +126,7 @@ module.exports = app => {
|
|
|
*
|
|
|
* @param {Object} bills - 台账节点数据
|
|
|
* @param {Array} changes - 调用的变更令
|
|
|
- * @returns {Promise<void>}
|
|
|
+ * @return {Promise<void>}
|
|
|
*/
|
|
|
async billsChange(bills, changes) {
|
|
|
const self = this;
|
|
@@ -136,12 +136,12 @@ module.exports = app => {
|
|
|
sid: self.ctx.stage.id,
|
|
|
lid: bills.id,
|
|
|
pid: -1,
|
|
|
- cid: cid,
|
|
|
- cbid: cbid,
|
|
|
+ cid,
|
|
|
+ cbid,
|
|
|
stimes: times,
|
|
|
sorder: order,
|
|
|
- qty: qty
|
|
|
- }
|
|
|
+ qty,
|
|
|
+ };
|
|
|
}
|
|
|
const ledgerBills = await this.ctx.service.ledger.getDataById(bills.id);
|
|
|
if (!ledgerBills || ledgerBills.tender_id !== this.ctx.tender.id) {
|
|
@@ -151,10 +151,11 @@ module.exports = app => {
|
|
|
// 获取原变更令
|
|
|
const oldChanges = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, bills.id, -1);
|
|
|
// 获取更新数据
|
|
|
- const updateChanges = [], newChanges = [];
|
|
|
+ const updateChanges = [],
|
|
|
+ newChanges = [];
|
|
|
let billsQty = 0;
|
|
|
for (const oc of oldChanges) {
|
|
|
- const nc = this._.find(changes, {cid: oc.cid, cbid: oc.cbid});
|
|
|
+ const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
|
|
|
if (!nc || nc.qty !== oc.qty) {
|
|
|
const qty = nc ? this.round(nc.qty, precision.value) : null;
|
|
|
const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty);
|
|
@@ -170,7 +171,7 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
for (const c of changes) {
|
|
|
- const nc = this._.find(oldChanges, {cid: c.cid, cbid: c.cbid});
|
|
|
+ const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
|
|
|
if (!nc) {
|
|
|
const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value));
|
|
|
billsQty = this.ctx.helper.add(billsQty, change.qty);
|
|
@@ -194,7 +195,7 @@ module.exports = app => {
|
|
|
throw err;
|
|
|
}
|
|
|
const result = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, [bills.id]);
|
|
|
- return { bills: {curStageData: result} };
|
|
|
+ return { bills: { curStageData: result } };
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -202,7 +203,7 @@ module.exports = app => {
|
|
|
*
|
|
|
* @param {Object} pos - 部位明细数据
|
|
|
* @param {Array} changes - 调用的变更令
|
|
|
- * @returns {Promise<{}>}
|
|
|
+ * @return {Promise<{}>}
|
|
|
*/
|
|
|
async posChange(pos, changes) {
|
|
|
const self = this;
|
|
@@ -212,12 +213,12 @@ module.exports = app => {
|
|
|
sid: self.ctx.stage.id,
|
|
|
lid: pos.lid,
|
|
|
pid: pos.id,
|
|
|
- cid: cid,
|
|
|
- cbid: cbid,
|
|
|
+ cid,
|
|
|
+ cbid,
|
|
|
stimes: times,
|
|
|
sorder: order,
|
|
|
- qty: qty
|
|
|
- }
|
|
|
+ qty,
|
|
|
+ };
|
|
|
}
|
|
|
const ledgerBills = await this.ctx.service.ledger.getDataById(pos.lid);
|
|
|
if (!ledgerBills || ledgerBills.tender_id !== this.ctx.tender.id) {
|
|
@@ -226,10 +227,11 @@ module.exports = app => {
|
|
|
const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, ledgerBills.unit);
|
|
|
// 获取原变更令
|
|
|
const oldChanges = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, pos.lid, pos.id);
|
|
|
- const updateChanges = [], newChanges = [];
|
|
|
+ const updateChanges = [],
|
|
|
+ newChanges = [];
|
|
|
let posQty = 0;
|
|
|
for (const oc of oldChanges) {
|
|
|
- const nc = this._.find(changes, {cid: oc.cid, cbid: oc.cbid});
|
|
|
+ const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
|
|
|
if (!nc || nc.qty !== oc.qty) {
|
|
|
const qty = nc ? this.round(nc.qty, precision.value) : null;
|
|
|
const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty);
|
|
@@ -245,7 +247,7 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
for (const c of changes) {
|
|
|
- const nc = this._.find(oldChanges, {cid: c.cid, cbid: c.cbid});
|
|
|
+ const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
|
|
|
if (!nc) {
|
|
|
const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value));
|
|
|
posQty = this.ctx.helper.add(posQty, change.qty);
|
|
@@ -272,9 +274,9 @@ module.exports = app => {
|
|
|
try {
|
|
|
const data = { bills: {}, pos: {} };
|
|
|
data.bills.curStageData = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, [pos.lid]);
|
|
|
- data.pos.curStageData = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: pos.id});
|
|
|
+ data.pos.curStageData = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, { pid: pos.id });
|
|
|
return data;
|
|
|
- } catch(err) {
|
|
|
+ } catch (err) {
|
|
|
throw '获取数据错误,请刷新页面';
|
|
|
}
|
|
|
}
|
|
@@ -283,7 +285,7 @@ module.exports = app => {
|
|
|
* 获取 变更令 - 变更清单 使用情况
|
|
|
* @param {Number} sid - 查询期id
|
|
|
* @param {uuid} cid - 变更令id
|
|
|
- * @returns {Promise<void>}
|
|
|
+ * @return {Promise<void>}
|
|
|
*/
|
|
|
async getUsedData(tid, cid) {
|
|
|
const lastStage = await this.ctx.service.stage.getLastestStage(tid, true);
|
|
@@ -298,7 +300,7 @@ module.exports = app => {
|
|
|
filter = '';
|
|
|
} else if (lastStage.status === audit.stage.status.checkNo) {
|
|
|
filter = this.db.format(' And (s.`order` < ? || (s.`order` = ? And sChange.`stimes` <= ?))',
|
|
|
- [lastStage.order, lastStage.order, lastStage.times])
|
|
|
+ [lastStage.order, lastStage.order, lastStage.times]);
|
|
|
} else {
|
|
|
const curAuditor = await this.ctx.service.stageAudit.getCurAuditor(lastStage.id, lastStage.times);
|
|
|
filter = this.db.format(' And (s.`order` < ? || (s.`order` = ? And sChange.`stimes` <= ? And sChange.`sorder` <= ?))',
|
|
@@ -347,7 +349,7 @@ module.exports = app => {
|
|
|
* 获取 变更令 - 变更清单 当期使用情况
|
|
|
* @param {Number} sid - 查询期id
|
|
|
* @param {uuid} cid - 变更令id
|
|
|
- * @returns {Promise<*>}
|
|
|
+ * @return {Promise<*>}
|
|
|
*/
|
|
|
async getStageUsedData(sid, cid) {
|
|
|
const sql = 'SELECT c.*, ' +
|
|
@@ -371,7 +373,7 @@ module.exports = app => {
|
|
|
/**
|
|
|
* 获取 本期 使用的变更令
|
|
|
* @param sid
|
|
|
- * @returns {Promise<void>}
|
|
|
+ * @return {Promise<void>}
|
|
|
*/
|
|
|
async getStageUsedChangeId(sid) {
|
|
|
const sql = 'SELECT c.`cid`, sum(qty) As qty FROM ' + this.tableName + ' As c' +
|
|
@@ -387,49 +389,12 @@ module.exports = app => {
|
|
|
return this._.map(this._.filter(result, 'qty'), 'cid');
|
|
|
}
|
|
|
|
|
|
- async getReportLastestAllStageData(tid, sid) {
|
|
|
- const sql = 'SELECT c.*,' +
|
|
|
- ' oc.p_code As c_code, oc.name As c_name, oc.new_code As c_new_code, oc.new_name As c_new_name, ' +
|
|
|
- ' oc.content As c_content, oc.basis As c_basis, oc.cin_time As c_cin_time, ' +
|
|
|
- ' ocb.code As b_code, ocb.name As b_name, ocb.unit As b_unit, ocb.unit_price As b_unit_price, ' +
|
|
|
- ' FROM ' + this.tableName + ' As c ' +
|
|
|
- ' INNER JOIN ( ' +
|
|
|
- ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
|
|
|
- ' WHERE tid = ? And sid = ?' +
|
|
|
- ' GROUP By `lid`, `pid`' +
|
|
|
- ' ) As m ' +
|
|
|
- ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
|
|
|
- ' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
|
|
|
- ' ON c.cid = oc.cid'+
|
|
|
- ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
|
|
|
- ' ON c.cbid = ocb.id' +
|
|
|
- ' WHERE not ISNULL(ocb.id)';
|
|
|
- const sqlParam = [tid, sid];
|
|
|
- return await this.db.query(sql, sqlParam);
|
|
|
- }
|
|
|
-
|
|
|
- async getReportAuditorAllStageData(tid, sid, times, order) {
|
|
|
- const sql = 'SELECT c.*, ' +
|
|
|
- ' oc.p_code As c_code, oc.name As c_name, oc.new_code As c_new_code, oc.new_name As c_new_name, ' +
|
|
|
- ' oc.content As c_content, oc.basis As c_basis, oc.cin_time As c_cin_time, ' +
|
|
|
- ' ocb.code As b_code, ocb.name As b_name, ocb.unit As b_unit, ocb.unit_price As b_unit_price, ' +
|
|
|
- ' FROM ' + this.tableName + ' As c ' +
|
|
|
- ' INNER JOIN ( ' +
|
|
|
- ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
|
|
|
- ' WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?))' +
|
|
|
- ' GROUP By `lid`, `pid`' +
|
|
|
- ' ) As m ' +
|
|
|
- ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
|
|
|
- ' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
|
|
|
- ' ON c.cid = oc.cid'+
|
|
|
- ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
|
|
|
- ' ON c.cbid = ocb.id' +
|
|
|
- ' WHERE not ISNULL(ocb.id)';
|
|
|
- const sqlParam = [tid, sid, times, times, order];
|
|
|
- return await this.db.query(sql, sqlParam);
|
|
|
+ async getFinalStageData(tid, sid) {
|
|
|
+ const data = await this.getAllDataByCondition({ where: { tid, sid } });
|
|
|
+ return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cid', 'cbid']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return StageChange;
|
|
|
|
|
|
-};
|
|
|
+};
|