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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
Self.getClaimableFromTicket = async(ticketFk, options) => {
|
|
|
|
const myOptions = {};
|
2018-08-30 07:19:09 +00:00
|
|
|
|
2021-09-29 06:27:18 +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);
|
2021-09-29 06:27:18 +00:00
|
|
|
const query = `
|
2023-01-16 14:18:24 +00:00
|
|
|
SELECT
|
|
|
|
s.id AS saleFk,
|
|
|
|
t.id AS ticketFk,
|
2021-09-29 06:27:18 +00:00
|
|
|
t.landed,
|
2023-01-16 14:18:24 +00:00
|
|
|
s.concept,
|
|
|
|
s.itemFk,
|
|
|
|
s.quantity,
|
|
|
|
s.price,
|
|
|
|
s.discount,
|
2021-09-29 06:27:18 +00:00
|
|
|
t.nickname
|
2023-01-16 14:18:24 +00:00
|
|
|
FROM vn.ticket t
|
2021-09-29 06:27:18 +00:00
|
|
|
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, ?)
|
2021-09-29 06:27:18 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|