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

42 lines
1.2 KiB
JavaScript

module.exports = function(Self) {
Self.remoteMethodCtx('canBeInvoiced', {
description: 'Change property isEqualizated in all client addresses',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'string',
required: true,
description: 'Client id',
http: {source: 'path'}
}
],
returns: {
arg: 'data',
type: 'boolean',
root: true
},
http: {
path: `/:id/canBeInvoiced`,
verb: 'get'
}
});
Self.canBeInvoiced = async id => {
let ticket = await Self.app.models.Ticket.findById(id, {fields: ['id', 'refFk', 'shipped']});
let ticketTotal = await Self.app.models.Ticket.getTotal(id);
let query = `SELECT vn.hasSomeNegativeBase(?) AS hasSomeNegativeBase`;
let [result] = await Self.rawSql(query, [id]);
let hasSomeNegativeBase = result.hasSomeNegativeBase;
let today = new Date();
let shipped = new Date(ticket.shipped);
if (ticket.refFk || ticketTotal == 0 || shipped.getTime() > today.getTime() || hasSomeNegativeBase)
return false;
return true;
};
};