salix/modules/ticket/methods/sale/getClaimableFromTicket.js

45 lines
1.2 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('getClaimableFromTicket', {
description: 'Gets the claimable sales for a client',
accessType: 'READ',
accepts: [{
arg: 'ticketFk',
type: 'Number',
required: true,
description: 'ticketFk'
}],
returns: {
type: 'string',
root: true
},
http: {
path: `/getClaimableFromTicket`,
verb: 'GET'
}
});
Self.getClaimableFromTicket = async ticketFk => {
let query = `SELECT
s.id AS saleFk,
t.id AS ticketFk,
t.landed,
s.concept,
s.itemFk,
s.quantity,
s.price,
s.discount,
t.nickname
FROM vn.ticket t
INNER JOIN vn.sale s ON s.ticketFk = t.id
LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id
WHERE (t.landed) >= TIMESTAMPADD(DAY, -7, CURDATE())
AND t.id = ? AND cb.id IS NULL
ORDER BY t.landed DESC, t.id DESC`;
let claimableSales = await Self.rawSql(query, [ticketFk]);
return claimableSales;
};
};