create method getComponentSum

This commit is contained in:
Bernat Exposito Domenech 2020-07-21 11:11:09 +02:00
parent f7100f11ee
commit b972353bb4
4 changed files with 40 additions and 3 deletions

View File

@ -0,0 +1,32 @@
module.exports = Self => {
Self.remoteMethod('getComponentsSum', {
description: 'Returns the list of component and their sum from a ticket',
accessType: 'READ',
accepts: {
arg: 'id',
type: 'number',
required: true,
description: 'ticket id',
http: {source: 'path'}
},
returns: {
type: 'Number',
root: true
},
http: {
path: `/:id/getComponentsSum`,
verb: 'GET'
}
});
Self.getComponentsSum = async id => {
const models = Self.app.models;
let sales = await models.Sale.find({where: {ticketFk: id}});
let salesComponents;
for (let sale of sales) {
salesComponents = await models.SaleComponent.find({saleFk: sale.id});
console.log('salesComponents', salesComponents);
}
return true;
};
};

View File

@ -31,6 +31,7 @@ module.exports = Self => {
require('../methods/ticket/sendSms')(Self);
require('../methods/ticket/isLocked')(Self);
require('../methods/ticket/freightPorts')(Self);
require('../methods/ticket/getComponentsSum')(Self);
Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) return;

View File

@ -62,7 +62,7 @@
</vn-card>
</vn-data-viewer>
<vn-side-menu side="right">
<div class="vn-pa-md">
<div class="totalBox" style="text-align: left;">
<h6 style="text-align: center;" translate>Total</h6>
<div> <vn-label translate>Base to commission</vn-label> {{$ctrl.base() | currency: 'EUR':3}} </div>
@ -78,7 +78,7 @@
<h6 style="text-align: center;" translate>Theorical ports</h6>
<div> <vn-label translate>Price</vn-label> {{$ctrl.theoricalPorts | currency: 'EUR': 2}} </div>
</div>
</div>
</vn-side-menu>
<vn-item-descriptor-popover

View File

@ -38,6 +38,7 @@ class Controller extends Section {
if (!value) return;
this.getTheoricalPorts();
this.getComponentsSum();
}
base() {
@ -68,8 +69,11 @@ class Controller extends Section {
getTheoricalPorts() {
this.$http.get(`Tickets/${this.ticket.id}/freightPorts`)
.then(res => this.theoricalPorts = res.data);
}
console.log('this.THasdasdasdeoricalPorts', this.theoricalPorts);
getComponentsSum() {
this.$http.get(`Tickets/${this.ticket.id}/getComponentsSum`)
.then(res => this.componentsList = res.data);
}
}