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
2023-01-16 14:18:24 +00:00
const date = Date.vnNew();
2022-06-09 11:33:01 +00:00
date.setHours(0, 0, 0, 0);
const query = `
2023-01-16 14:18:24 +00:00
SELECT
s.id AS saleFk,
t.id AS ticketFk,
t.landed,
2023-01-16 14:18:24 +00:00
s.concept,
s.itemFk,
s.quantity,
s.price,
s.discount,
t.nickname
2023-01-16 14:18:24 +00:00
FROM vn.ticket t
INNER JOIN vn.sale s ON s.ticketFk = t.id
LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id
2023-01-16 14:18:24 +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 12:39:51 +00:00
const claimableSales = await Self.rawSql(query, [date, ticketFk], myOptions);
2018-08-30 07:19:09 +00:00
return claimableSales;
};
};