2018-09-05 11:47:15 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('getSummary', {
|
|
|
|
description: 'Updates the item taxes',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'id',
|
|
|
|
type: 'number',
|
|
|
|
required: true,
|
|
|
|
description: 'The item id',
|
|
|
|
http: {source: 'path'}
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:id/getSummary`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.getSummary = async id => {
|
|
|
|
let promises = [];
|
|
|
|
let summary = {};
|
|
|
|
|
|
|
|
// Claim
|
|
|
|
|
|
|
|
let filter = {
|
|
|
|
where: {id: id},
|
|
|
|
include: [
|
|
|
|
{relation: 'worker', scope: {fields: ['name', 'firstName']}},
|
|
|
|
{relation: 'claimState', scope: {fields: ['id', 'description']}},
|
|
|
|
{
|
|
|
|
relation: 'client',
|
|
|
|
scope: {
|
|
|
|
fields: ['salesPersonFk', 'name'],
|
|
|
|
include: {
|
|
|
|
relation: 'salesPerson',
|
|
|
|
fields: ['firstName', 'name']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
promises.push(Self.app.models.Claim.find(filter));
|
|
|
|
|
|
|
|
// Claim detail
|
|
|
|
filter = {
|
|
|
|
where: {claimFk: id},
|
|
|
|
include: [
|
|
|
|
{relation: 'sale',
|
|
|
|
scope: {
|
2018-11-21 12:29:46 +00:00
|
|
|
fields: ['concept', 'ticketFk', 'price', 'quantity', 'discount', 'itemFk'],
|
2018-09-05 11:47:15 +00:00
|
|
|
include: {
|
|
|
|
relation: 'ticket'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
promises.push(Self.app.models.ClaimBeginning.find(filter));
|
|
|
|
|
|
|
|
// Claim developments
|
|
|
|
filter = {
|
|
|
|
where: {claimFk: id},
|
|
|
|
include: [
|
|
|
|
{relation: 'claimResponsible'},
|
|
|
|
{relation: 'worker'},
|
|
|
|
{relation: 'claimDestination'},
|
|
|
|
{relation: 'claimReason'},
|
|
|
|
{relation: 'claimResult'},
|
|
|
|
{relation: 'claimRedelivery'}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
promises.push(Self.app.models.ClaimDevelopment.find(filter));
|
|
|
|
|
|
|
|
// Claim action
|
|
|
|
filter = {
|
|
|
|
where: {claimFk: id},
|
|
|
|
include: [
|
|
|
|
{relation: 'sale',
|
|
|
|
scope: {
|
|
|
|
fields: ['concept', 'price', 'quantity', 'discount', 'ticketFk', 'itemFk'],
|
|
|
|
include: [
|
|
|
|
{relation: 'ticket'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{relation: 'claimBeggining'}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
promises.push(Self.app.models.ClaimEnd.find(filter));
|
|
|
|
|
|
|
|
let res = await Promise.all(promises);
|
|
|
|
|
|
|
|
[summary.claim] = res[0];
|
|
|
|
summary.salesClaimed = res[1];
|
|
|
|
summary.developments = res[2];
|
|
|
|
summary.actions = res[3];
|
|
|
|
|
|
|
|
return summary;
|
|
|
|
};
|
|
|
|
};
|