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

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-08-30 07:19:09 +00:00
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, options) => {
const myOptions = {};
2018-08-30 07:19:09 +00:00
if (typeof options == 'object')
Object.assign(myOptions, options);
2018-08-30 07:19:09 +00:00
2022-06-09 11:33:01 +00:00
const date = new Date();
date.setHours(0, 0, 0, 0);
const 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
2022-06-09 11:33:01 +00:00
WHERE (t.landed) >= TIMESTAMPADD(DAY, -7, ?)
AND t.id = ? AND cb.id IS NULL
ORDER BY t.landed DESC, t.id DESC`;
2022-06-09 11:33:01 +00:00
const claimableSales = await Self.rawSql(query, [ticketFk, date], myOptions);
2018-08-30 07:19:09 +00:00
return claimableSales;
};
};