2021-04-15 08:44:25 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('summary', {
|
|
|
|
description: 'The invoiceIn summary',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'id',
|
|
|
|
type: 'number',
|
|
|
|
required: true,
|
|
|
|
description: 'The invoiceIn id',
|
|
|
|
http: {source: 'path'}
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:id/summary`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-28 08:15:54 +00:00
|
|
|
Self.summary = async(id, options) => {
|
2021-09-24 06:24:34 +00:00
|
|
|
const models = Self.app.models;
|
2021-11-18 10:17:30 +00:00
|
|
|
const myOptions = {};
|
2021-06-28 08:15:54 +00:00
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2021-04-15 08:44:25 +00:00
|
|
|
const filter = {
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'company',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'code']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'supplier',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'name']
|
|
|
|
}
|
2021-04-15 09:54:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'sageWithholding',
|
|
|
|
scope: {
|
|
|
|
fields: ['withholding']
|
|
|
|
}
|
2021-06-14 07:47:04 +00:00
|
|
|
},
|
2022-02-07 11:24:08 +00:00
|
|
|
{
|
|
|
|
relation: 'invoiceInDueDay',
|
|
|
|
scope: {
|
|
|
|
fields: [
|
|
|
|
'id',
|
|
|
|
'invoiceInFk',
|
|
|
|
'dueDated',
|
|
|
|
'bankFk',
|
|
|
|
'amount',
|
|
|
|
'foreignValue'],
|
|
|
|
include: [{
|
|
|
|
relation: 'bank',
|
|
|
|
scope: {
|
|
|
|
fields: ['bank']
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
},
|
2021-06-14 07:47:04 +00:00
|
|
|
{
|
|
|
|
relation: 'invoiceInTax',
|
|
|
|
scope: {
|
2021-06-30 06:26:03 +00:00
|
|
|
fields: [
|
|
|
|
'id',
|
|
|
|
'invoiceInFk',
|
|
|
|
'taxableBase',
|
|
|
|
'expenseFk',
|
|
|
|
'taxTypeSageFk',
|
|
|
|
'transactionTypeSageFk',
|
|
|
|
'foreignValue'],
|
2021-06-14 07:47:04 +00:00
|
|
|
include: [{
|
|
|
|
relation: 'transactionTypeSage',
|
|
|
|
scope: {
|
|
|
|
fields: ['transaction']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'taxTypeSage',
|
|
|
|
scope: {
|
|
|
|
fields: ['vat']
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
2021-06-15 07:09:08 +00:00
|
|
|
},
|
2021-06-10 15:08:21 +00:00
|
|
|
{
|
|
|
|
relation: 'expenseDeductible',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'name', 'taxTypeFk']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'currency',
|
|
|
|
scope: {
|
2021-06-15 07:58:21 +00:00
|
|
|
fields: ['id', 'code']
|
2021-06-15 07:09:08 +00:00
|
|
|
|
2021-06-10 15:08:21 +00:00
|
|
|
}
|
2021-04-15 08:44:25 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2021-09-24 06:24:34 +00:00
|
|
|
let summaryObj = await models.InvoiceIn.findById(id, filter, myOptions);
|
2021-04-15 08:44:25 +00:00
|
|
|
|
2022-01-20 09:05:24 +00:00
|
|
|
summaryObj.totals = await models.InvoiceIn.getTotals(id, myOptions);
|
2021-06-25 07:30:24 +00:00
|
|
|
return summaryObj;
|
2021-04-15 08:44:25 +00:00
|
|
|
};
|
|
|
|
};
|