35 lines
864 B
JavaScript
35 lines
864 B
JavaScript
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;
|
|
};
|
|
};
|