salix/modules/invoiceIn/back/methods/invoice-in/getSerial.js

35 lines
864 B
JavaScript
Raw Normal View History

2023-03-27 12:29:22 +00:00
module.exports = Self => {
Self.remoteMethod('getSerial', {
description: 'Return invoiceIn serial',
accessType: 'READ',
accepts: {
arg: 'issued',
type: 'date',
required: true
},
returns: {
type: 'object',
root: true
},
http: {
path: '/getSerial',
verb: 'GET'
}
});
Self.getSerial = async(issued, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const result = await Self.rawSql(`
SELECT i.serial, SUM(IF(i.isBooked, 0,1)) pending, COUNT(*) total
FROM vn.invoiceIn i
WHERE i.issued >= ?
GROUP BY i.serial`, [issued]);
return result;
};
};