salix/client/ticket/src/component/index.js

120 lines
3.3 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
import './style.scss';
class Controller {
constructor($scope, $stateParams) {
this.$stateParams = $stateParams;
this.$scope = $scope;
this.filter = {
order: 'concept ASC',
include: [{
relation: 'item',
scope: {
include: {
relation: 'tags',
scope: {
fields: ['tagFk', 'value'],
include: {
relation: 'tag',
scope: {
fields: ['name']
}
},
limit: 6
}
},
fields: ['itemFk', 'name']
}
},
{
relation: 'components',
scope: {
fields: ['componentFk', 'value'],
include: {
relation: 'componentRate',
scope: {
fields: ['componentTypeRate', 'name'],
include: {
relation: 'componentType',
scope: {
fields: ['type']
}
}
}
}
}
}]
};
}
total() {
let sales = this.$scope.model.data;
let sum = 0;
if (!sales) return;
for (let sale of sales)
for (let component of sale.components)
sum += sale.quantity * component.value;
return sum;
}
base() {
let sales = this.$scope.model.data;
let sum = 0;
if (!sales) return;
for (let sale of sales)
for (let component of sale.components)
if (component.componentRate.name == 'valor de compra')
sum += sale.quantity * component.value;
return sum;
}
profitMargin() {
let sales = this.$scope.model.data;
let sum = 0;
if (!sales) return;
for (let sale of sales)
for (let component of sale.components)
if (component.componentRate.name != 'valor de compra')
sum += sale.quantity * component.value;
return sum;
}
2018-05-29 12:33:29 +00:00
showDescriptor(event, itemFk) {
2018-09-04 09:49:00 +00:00
this.quicklinks = {
btnThree: {
icon: 'icon-transaction',
state: `item.card.diary({
id: ${itemFk},
q: '{"warehouseFk": ${this.ticket.warehouseFk}}'
})`,
tooltip: 'Item diary'
}
};
2018-05-29 12:33:29 +00:00
this.$scope.descriptor.itemFk = itemFk;
this.$scope.descriptor.parent = event.target;
this.$scope.descriptor.show();
}
onDescriptorLoad() {
this.$scope.popover.relocate();
}
}
Controller.$inject = ['$scope', '$stateParams'];
ngModule.component('vnTicketComponents', {
template: require('./index.html'),
controller: Controller,
bindings: {
ticket: '<'
}
});