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

88 lines
2.3 KiB
JavaScript
Raw 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: ['type', '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();
}
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);
}
}
ngModule.vnComponent('vnTicketComponents', {
template: require('./index.html'),
controller: Controller,
bindings: {
ticket: '<'
}
});