feat: refs #6321 remove origin
This commit is contained in:
parent
dc6f93c241
commit
75b4202a7b
|
@ -4,5 +4,4 @@ INSERT IGNORE INTO salix.ACL (model,property,accessType,permission,principalType
|
||||||
('Ticket','itemLackDetail','READ','ALLOW','ROLE','employee'),
|
('Ticket','itemLackDetail','READ','ALLOW','ROLE','employee'),
|
||||||
('Ticket','itemLackOrigin','WRITE','ALLOW','ROLE','employee'),
|
('Ticket','itemLackOrigin','WRITE','ALLOW','ROLE','employee'),
|
||||||
('Ticket','split','WRITE','ALLOW','ROLE','employee'),
|
('Ticket','split','WRITE','ALLOW','ROLE','employee'),
|
||||||
('Ticket','negativeOrigin','READ','ALLOW','ROLE','employee'),
|
|
||||||
('Sale','replaceItem','WRITE','ALLOW','ROLE','employee');
|
('Sale','replaceItem','WRITE','ALLOW','ROLE','employee');
|
||||||
|
|
|
@ -1,104 +0,0 @@
|
||||||
const {ParameterizedSQL} = require('loopback-connector');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethod('itemLackDetail', {
|
|
||||||
description: 'Retrieve detail from ticket',
|
|
||||||
accessType: 'READ',
|
|
||||||
accepts: [
|
|
||||||
{
|
|
||||||
arg: 'itemFk',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The item id',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'warehouseFk',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The warehouse id',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'filter',
|
|
||||||
type: 'object',
|
|
||||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
|
||||||
http: {source: 'query'}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
returns: [
|
|
||||||
{
|
|
||||||
arg: 'body',
|
|
||||||
type: ['object'],
|
|
||||||
root: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
http: {
|
|
||||||
path: `/itemLack/:itemFk`,
|
|
||||||
verb: 'GET',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.itemLackDetail = async(itemFk, warehouseFk, filter, options) => {
|
|
||||||
const conn = Self.dataSource.connector;
|
|
||||||
|
|
||||||
const myOptions = {};
|
|
||||||
if (typeof options == 'object') Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
const stmt = new ParameterizedSQL(
|
|
||||||
`
|
|
||||||
SELECT
|
|
||||||
s.id saleFk,
|
|
||||||
st.code,
|
|
||||||
t.id ticketFk,
|
|
||||||
t.nickname,
|
|
||||||
t.shipped,
|
|
||||||
t.hour,
|
|
||||||
s.quantity,
|
|
||||||
ag.name agName,
|
|
||||||
ts.alertLevel alertLevel,
|
|
||||||
st.name stateName,
|
|
||||||
st.id stateId,
|
|
||||||
s.itemFk itemFk,
|
|
||||||
s.price price,
|
|
||||||
al.code alertLevelCode,
|
|
||||||
z.id zoneFk,
|
|
||||||
z.name zoneName,
|
|
||||||
z.hour theoreticalhour,
|
|
||||||
cn.isRookie,
|
|
||||||
IF(sc.saleClonedFk, 1, 0 ) as turno,
|
|
||||||
IF(tr.saleFk , 1, 0 ) as peticionCompra,
|
|
||||||
t.hour minTimed,
|
|
||||||
c.id customerId,
|
|
||||||
c.name customerName,
|
|
||||||
ot.code observationTypeCode
|
|
||||||
FROM
|
|
||||||
vn.sale s
|
|
||||||
JOIN vn.ticket t ON t.id=s.ticketFk
|
|
||||||
LEFT JOIN vn.zone z ON z.id = t.zoneFk
|
|
||||||
LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk
|
|
||||||
JOIN vn.client c ON c.id=t.clientFk
|
|
||||||
LEFT JOIN bs.clientNewBorn cn ON cn.clientFk=c.id
|
|
||||||
JOIN vn.agencyMode agm ON agm.id=t.agencyModeFk
|
|
||||||
JOIN vn.agency ag ON ag.id=agm.id
|
|
||||||
JOIN vn.ticketState ts ON ts.ticketFk=t.id
|
|
||||||
LEFT JOIN vn.state st ON st.id=ts.state
|
|
||||||
LEFT JOIN vn.alertLevel al ON al.id = st.alertLevel
|
|
||||||
LEFT JOIN vn.saleCloned sc ON sc.saleClonedFk = s.id
|
|
||||||
LEFT JOIN vn.ticketRequest tr ON tr.saleFk = s.id
|
|
||||||
LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id
|
|
||||||
LEFT JOIN vn.observationType ot ON ot.id = tob.observationTypeFk
|
|
||||||
WHERE
|
|
||||||
s.itemFk = ?
|
|
||||||
AND t.landed >= util.VN_CURDATE()
|
|
||||||
AND t.landed < util.VN_CURDATE() + INTERVAL ? + 1 DAY
|
|
||||||
`,
|
|
||||||
[itemFk, 2]);
|
|
||||||
|
|
||||||
if (filter.where.stateFk) {
|
|
||||||
stmt.merge({
|
|
||||||
sql: `AND ts.alertLevel=?`, params: [filter.where.stateFk]});
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
// stmt.merge(conn.makeWhere(filter.where));
|
|
||||||
const sql = ParameterizedSQL.join([stmt], ';');
|
|
||||||
const result = await conn.executeStmt(sql, myOptions);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,40 +0,0 @@
|
||||||
const {ParameterizedSQL} = require('loopback-connector');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethod('itemLackOrigin', {
|
|
||||||
description: 'Insert ticket negative into negativeOrigin',
|
|
||||||
accessType: 'WRITE',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'ctx',
|
|
||||||
type: 'Object',
|
|
||||||
http: {source: 'context'}
|
|
||||||
}, {arg: 'tickets', type: 'array', http: {source: 'body'}}],
|
|
||||||
returns:
|
|
||||||
{
|
|
||||||
type: 'boolean',
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
path: `/itemLackOrigin`,
|
|
||||||
verb: 'POST'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.itemLackOrigin = async(ctx, data, options) => {
|
|
||||||
const myOptions = {};
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
if (!myOptions.transaction) {
|
|
||||||
tx = await Self.beginTransaction({});
|
|
||||||
myOptions.transaction = tx;
|
|
||||||
}
|
|
||||||
const conn = Self.dataSource.connector;
|
|
||||||
const stmts = data.map(({itemFk, negativeType, lack}) =>
|
|
||||||
`INSERT INTO vn.negativeOrigin (itemFk, type, quantity)
|
|
||||||
VALUES (${itemFk}, "${negativeType}", ${lack})
|
|
||||||
ON DUPLICATE KEY UPDATE quantity = quantity + VALUES(quantity)`) ?? [];
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
|
||||||
const result = await conn.executeStmt(sql, myOptions);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,32 +0,0 @@
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethod('negativeOrigin', {
|
|
||||||
description: 'Get tickets from negativeOrigin',
|
|
||||||
accessType: 'READ',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'ctx',
|
|
||||||
type: 'Object',
|
|
||||||
http: {source: 'context'}
|
|
||||||
}],
|
|
||||||
returns: {
|
|
||||||
type: 'object',
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
path: `/negativeOrigin`,
|
|
||||||
verb: 'GET'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.negativeOrigin = async(ctx, data, options) => {
|
|
||||||
const myOptions = {};
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
if (!myOptions.transaction) {
|
|
||||||
tx = await Self.beginTransaction({});
|
|
||||||
myOptions.transaction = tx;
|
|
||||||
}
|
|
||||||
const negativesOrigin = await Self.app.models.NegativeOrigin.find();
|
|
||||||
return negativesOrigin;
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,51 +0,0 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
|
||||||
|
|
||||||
describe('NegativeOrigin', () => {
|
|
||||||
it('should return OK', async() => {
|
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
|
||||||
const ctx = {req: {accessToken: {userId: 9}}};
|
|
||||||
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const data = [
|
|
||||||
{itemFk: 1, negativeType: 'FALTAS', lack: 1},
|
|
||||||
{itemFk: 1, negativeType: 'FALTAS', lack: 2}
|
|
||||||
];
|
|
||||||
try {
|
|
||||||
await models.Ticket.itemLackOrigin(ctx, data, options);
|
|
||||||
const query = 'SELECT * FROM vn.negativeOrigin';
|
|
||||||
|
|
||||||
const negativeOrigin = await models.Application.rawSql(query, null, options);
|
|
||||||
|
|
||||||
expect(negativeOrigin.length).toEqual(1);
|
|
||||||
expect(negativeOrigin[0].quantity).toEqual(3);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add 2 lines', async() => {
|
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
|
||||||
const ctx = {req: {accessToken: {userId: 9}}};
|
|
||||||
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const data = [
|
|
||||||
{itemFk: 2, negativeType: 'FALTAS', lack: 1},
|
|
||||||
{itemFk: 3, negativeType: 'FALTAS', lack: 2}
|
|
||||||
];
|
|
||||||
try {
|
|
||||||
await models.Ticket.itemLackOrigin(ctx, data, options);
|
|
||||||
const query = 'SELECT * FROM vn.negativeOrigin';
|
|
||||||
|
|
||||||
const negativeOrigin = await models.Application.rawSql(query, null, options);
|
|
||||||
|
|
||||||
expect(negativeOrigin.length).toEqual(2);
|
|
||||||
expect(negativeOrigin[0].quantity).toEqual(1);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -35,9 +35,6 @@
|
||||||
"PackingSiteConfig": {
|
"PackingSiteConfig": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
"NegativeOrigin": {
|
|
||||||
"dataSource": "vn"
|
|
||||||
},
|
|
||||||
"ExpeditionMistake": {
|
"ExpeditionMistake": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"name": "NegativeOrigin",
|
|
||||||
"base": "VnModel",
|
|
||||||
"options": {
|
|
||||||
"mysql": {
|
|
||||||
"table": "negativeOrigin"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"id": true,
|
|
||||||
"type": "number",
|
|
||||||
"description": "Identifier"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"relations": {
|
|
||||||
"item": {
|
|
||||||
"type": "belongsTo",
|
|
||||||
"model": "Item",
|
|
||||||
"foreignKey": "itemFk"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -48,7 +48,5 @@ module.exports = function(Self) {
|
||||||
require('../methods/ticket/setWeight')(Self);
|
require('../methods/ticket/setWeight')(Self);
|
||||||
require('../methods/ticket/itemLack')(Self);
|
require('../methods/ticket/itemLack')(Self);
|
||||||
require('../methods/ticket/itemLackDetail')(Self);
|
require('../methods/ticket/itemLackDetail')(Self);
|
||||||
require('../methods/ticket/itemLackOrigin')(Self);
|
|
||||||
require('../methods/ticket/negativeOrigin')(Self);
|
|
||||||
require('../methods/ticket/split')(Self);
|
require('../methods/ticket/split')(Self);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue