hotfix #6408 #2578
|
@ -26,6 +26,7 @@ module.exports = Self => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
let newStateOrder;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -40,11 +41,16 @@ module.exports = Self => {
|
||||||
throw new UserError('State cannot be blank');
|
throw new UserError('State cannot be blank');
|
||||||
|
|
||||||
if (params.stateFk) {
|
if (params.stateFk) {
|
||||||
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
|
const {code, order} = await models.State.findById(
|
||||||
|
params.stateFk,
|
||||||
|
{fields: ['code', 'order']},
|
||||||
|
myOptions);
|
||||||
params.code = code;
|
params.code = code;
|
||||||
|
newStateOrder = order;
|
||||||
} else {
|
} else {
|
||||||
const {id} = await models.State.findOne({where: {code: params.code}}, myOptions);
|
const {id, order} = await models.State.findOne({where: {code: params.code}}, myOptions);
|
||||||
params.stateFk = id;
|
params.stateFk = id;
|
||||||
|
newStateOrder = order;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.userFk) {
|
if (!params.userFk) {
|
||||||
|
@ -75,7 +81,9 @@ module.exports = Self => {
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const salesPersonFk = ticket.client().salesPersonFk;
|
const salesPersonFk = ticket.client().salesPersonFk;
|
||||||
if (salesPersonFk) {
|
const stateChecked = await models.State.findOne({fields: ['order'], where: {code: 'CHECKED'}});
|
||||||
|
|
||||||
|
if (salesPersonFk && newStateOrder >= stateChecked.order) {
|
||||||
const sales = await Self.rawSql(`
|
const sales = await Self.rawSql(`
|
||||||
SELECT DISTINCT s.id,
|
SELECT DISTINCT s.id,
|
||||||
s.itemFk,
|
s.itemFk,
|
||||||
|
@ -83,17 +91,9 @@ module.exports = Self => {
|
||||||
s.originalQuantity AS oldQuantity,
|
s.originalQuantity AS oldQuantity,
|
||||||
s.quantity AS newQuantity
|
s.quantity AS newQuantity
|
||||||
FROM vn.sale s
|
FROM vn.sale s
|
||||||
JOIN vn.saleTracking st ON st.saleFk = s.id
|
|
||||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
|
||||||
JOIN vn.client c ON c.id = t.clientFk
|
|
||||||
JOIN vn.ticketState ts ON ts.ticketFk = t.id
|
|
||||||
JOIN vn.state s2 ON s2.id = ts.stateFk
|
|
||||||
WHERE s.ticketFk = ?
|
WHERE s.ticketFk = ?
|
||||||
AND st.isChecked
|
|
||||||
AND s.originalQuantity IS NOT NULL
|
AND s.originalQuantity IS NOT NULL
|
||||||
AND s.originalQuantity <> s.quantity
|
AND s.originalQuantity <> s.quantity
|
||||||
AND s2.\`order\` < (SELECT \`order\` FROM vn.state WHERE code = 'CHECKED')
|
|
||||||
ORDER BY st.created DESC
|
|
||||||
`, [params.ticketFk], myOptions);
|
`, [params.ticketFk], myOptions);
|
||||||
|
|
||||||
let changes = '';
|
let changes = '';
|
||||||
|
|
Loading…
Reference in New Issue