#6321 - Negative tickets #1945

Open
jsegarra wants to merge 93 commits from 6321_negative_tickets into dev
3 changed files with 116 additions and 0 deletions
Showing only changes of commit 1a21dda00b - Show all commits

View File

@ -0,0 +1,69 @@
/* eslint-disable no-console */
module.exports = Self => {
Self.remoteMethod('itemLackDetail', {
description: 'Download a ticket delivery note document',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
description: 'The item id',
}
],
returns: [
{
arg: 'body',
type: ['object'],
root: true
}
],
http: {
path: `/itemLack/:id/detail`,
verb: 'GET'
}
});
Self.itemLackDetail = async(id, options) => {
const myOptions = {};
// const versionSQL = false;
if (typeof options == 'object')
Object.assign(myOptions, options);
const detail = await Self.rawSQL(`
SELECT
s.Id_Movimiento, st.code, t.Id_Ticket, t.Alias, t.Fecha, s.Cantidad, ag.Agencia,
ts.alertLevel alertLevel,
st.name stateName,
st.id stateId,
s.Id_Article id,
al.code alertLevelCode,
z.name,
z.hour theoreticalhour,
cn.isRookie,
sc.saleClonedFk turno,
tr.saleFk peticionCompra,
t.Fecha minTimed
FROM
Sale s
JOIN Tickets t ON t.Id_Ticket=s.Id_Ticket -- vn.ticket
LEFT JOIN zone z ON z.id = t.zoneFk -- vn.zone
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = DateValue(t.Fecha)
JOIN Clientes c ON c.Id_Cliente=t.Id_Cliente -- vn.client
LEFT JOIN clientNewBorn cn ON cn.clientFk=c.Id_Cliente
JOIN Agencias ag ON ag.Id_Agencia=t.Id_Agencia -- vn.agencyMode
JOIN ticketState tls ON ts.ticketFk=t.Id_Ticket -- vn.sale
LEFT JOIN state s ON st.id=ts.state
LEFT JOIN alertLevel al ON al.id = st.alertLevel
LEFT JOIN saleCloned sc ON sc.saleClonedFk = s.Id_Movimiento
LEFT JOIN ticketRequest tr ON tr.saleFk = s.Id_Movimiento
WHERE
AND s.Id_Article = ?
AND NOT Cantidad
AND Fecha >= util.VN_CURDATE()
AND Fecha < INTERVAL util.VN_CURDATE() + INTERVAL ? + 1 DAY
ORDER BY s.Id_Movimiento DESC+
`, [id, 2], myOptions);
return detail;
};
};

View File

@ -0,0 +1,46 @@
const models = require('vn-loopback/server/server').models;
describe('Item Lack Detail', () => {
it('should return false if id is null', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
const id = null;
const result = await models.Ticket.itemLackDetail(id, options);
expect(result).toBeFalsy();
} catch (e) {
throw e;
}
});
it('should return data if id exists', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
const id = 1167;
const result = await models.Ticket.itemLackDetail(id, options);
expect(result).toBeFalsy();
} catch (e) {
throw e;
}
});
it('should return error is if not exists', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
const id = 0;
const result = await models.Ticket.itemLackDetail(id, options);
expect(result).toBeFalsy();
} catch (e) {
throw e;
}
});
});

View File

@ -44,4 +44,5 @@ module.exports = function(Self) {
require('../methods/ticket/invoiceTickets')(Self); require('../methods/ticket/invoiceTickets')(Self);
require('../methods/ticket/docuwareDownload')(Self); require('../methods/ticket/docuwareDownload')(Self);
require('../methods/ticket/itemLack')(Self); require('../methods/ticket/itemLack')(Self);
require('../methods/ticket/itemLackDetail')(Self);
}; };