salix/modules/item/back/methods/item/getBalance.js

42 lines
1.2 KiB
JavaScript

module.exports = Self => {
Self.remoteMethodCtx('getBalance', {
description: 'Returns the ',
accessType: 'READ',
accepts: [{
arg: 'filter',
type: 'Object',
required: true,
description: 'Filter defining where and paginated data',
http: {source: 'query'}
}],
returns: {
type: ['Object'],
root: true
},
http: {
path: `/getBalance`,
verb: 'GET'
},
noLimit: true
});
Self.getBalance = async(ctx, filter, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);
const where = filter.where;
const query = 'CALL vn.item_getBalance(?, ?, ?)';
if (where?.date) {
where.date = new Date(where.date);
where.date.setHours(0, 0, 0, 0);
}
const [diary] = await Self.rawSql(query, [where.itemFk, where.warehouseFk, where.date], myOptions);
for (const entry of diary)
if (entry.clientType === 'loses') entry.highlighted = true;
return diary;
};
};