salix/modules/ticket/front/component/index.js

99 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

import ngModule from '../module';
2020-03-18 07:35:59 +00:00
import Section from 'salix/components/section';
import './style.scss';
2020-03-18 07:35:59 +00:00
class Controller extends Section {
constructor($element, $) {
super($element, $);
this.filter = {
order: 'concept ASC',
include: [{
relation: 'item',
}, {
relation: 'components',
scope: {
fields: ['componentFk', 'value'],
include: {
relation: 'component',
scope: {
fields: ['typeFk', 'name'],
include: {
relation: 'componentType',
scope: {
fields: ['name', 'isBase']
}
}
}
}
}
}]
};
}
get ticket() {
return this._ticket;
}
set ticket(value) {
this._ticket = value;
if (!value) return;
2020-09-09 13:49:59 +00:00
this.getTheoricalCost();
2020-07-21 09:11:09 +00:00
this.getComponentsSum();
2020-12-03 09:26:49 +00:00
if (this.ticket.zone && this.ticket.zone.isVolumetric)
2020-10-29 10:09:58 +00:00
this.getTicketVolume();
}
base() {
2020-03-18 07:35:59 +00:00
let sales = this.$.model.data;
let sum = 0;
if (!sales) return;
2018-11-06 09:49:38 +00:00
for (let sale of sales) {
for (let saleComponent of sale.components) {
if (saleComponent.component.componentType.isBase)
sum += sale.quantity * saleComponent.value;
2018-11-06 09:49:38 +00:00
}
}
return sum;
}
getTotal() {
2020-09-09 13:49:59 +00:00
const sales = this.$.model.data;
let total = 0;
if (!sales) return;
for (let sale of sales) {
for (let saleComponent of sale.components)
total += sale.quantity * saleComponent.value;
}
return total;
}
2020-09-09 13:49:59 +00:00
getTheoricalCost() {
this.$http.get(`Tickets/${this.ticket.id}/freightCost`)
.then(res => this.theoricalCost = res.data);
2020-07-21 09:11:09 +00:00
}
2020-07-21 09:11:09 +00:00
getComponentsSum() {
this.$http.get(`Tickets/${this.ticket.id}/getComponentsSum`)
.then(res => this.componentsList = res.data);
}
2020-10-29 10:09:58 +00:00
getTicketVolume() {
if (!this.ticket) return;
this.$http.get(`Tickets/${this.ticket.id}/getVolume`)
.then(res => {
if (res.data.length)
this.ticketVolume = res.data[0].volume;
});
2020-10-29 10:09:58 +00:00
}
}
ngModule.vnComponent('vnTicketComponents', {
template: require('./index.html'),
controller: Controller,
bindings: {
ticket: '<'
}
});