salix/modules/ticket/back/methods/ticket/getVolume.js

50 lines
1.4 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('getVolume', {
description: 'Returns the volumes of a ticket',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'ticket id',
http: {source: 'path'}
}],
returns: [{
arg: 'saleVolume',
type: ['object']
},
{
arg: 'packingTypeVolume',
type: ['object']
}],
http: {
path: `/:id/getVolume`,
verb: 'GET'
}
});
Self.getVolume = async(ticketFk, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const saleVolume = await Self.rawSql(`
SELECT saleFk, volume
FROM vn.saleVolume
WHERE ticketFk = ?`, [ticketFk], myOptions);
const packingTypeVolume = await Self.rawSql(`
SELECT s.itemPackingTypeFk code,
i.description,
SUM(s.volume) volume
FROM vn.saleVolume s
LEFT JOIN vn.itemPackingType i
ON i.code = s.itemPackingTypeFk
WHERE s.ticketFk = ?
GROUP BY s.itemPackingTypeFk`, [ticketFk], myOptions);
return [saleVolume, packingTypeVolume];
};
};