2020-12-16 07:05:41 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Section from 'salix/components/section';
|
|
|
|
|
|
|
|
class Controller extends Section {
|
|
|
|
constructor($element, $, vnReport, vnEmail) {
|
|
|
|
super($element, $);
|
|
|
|
this.vnReport = vnReport;
|
|
|
|
this.vnEmail = vnEmail;
|
|
|
|
|
|
|
|
this.setDefaultFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
setDefaultFilter() {
|
2023-01-16 14:18:24 +00:00
|
|
|
const minDate = Date.vnNew();
|
2020-12-16 07:05:41 +00:00
|
|
|
minDate.setHours(0, 0, 0, 0);
|
|
|
|
minDate.setMonth(minDate.getMonth() - 2);
|
|
|
|
|
2023-01-16 14:18:24 +00:00
|
|
|
const maxDate = Date.vnNew();
|
2020-12-16 07:05:41 +00:00
|
|
|
maxDate.setHours(23, 59, 59, 59);
|
|
|
|
|
|
|
|
this.filterParams = {
|
|
|
|
from: minDate,
|
|
|
|
to: maxDate
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get reportParams() {
|
|
|
|
const userParams = this.$.model.userParams;
|
|
|
|
return Object.assign({
|
|
|
|
authorization: this.vnToken.token,
|
|
|
|
recipientId: this.supplier.id
|
|
|
|
}, userParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
showReport() {
|
2022-09-26 11:33:27 +00:00
|
|
|
const path = `Suppliers/${this.supplier.id}/campaign-metrics-pdf`;
|
|
|
|
this.vnReport.show(path, this.reportParams);
|
2020-12-16 07:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sendEmail() {
|
2021-04-30 11:50:41 +00:00
|
|
|
const params = {
|
|
|
|
filter: {
|
|
|
|
where: {
|
|
|
|
supplierFk: this.$params.id,
|
|
|
|
email: {neq: null}
|
|
|
|
},
|
|
|
|
limit: 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.$http.get('SupplierContacts', params).then(({data}) => {
|
|
|
|
if (data.length) {
|
|
|
|
const contact = data[0];
|
|
|
|
const params = Object.assign({
|
|
|
|
recipient: contact.email
|
|
|
|
}, this.reportParams);
|
2022-09-26 11:33:27 +00:00
|
|
|
|
|
|
|
const path = `Suppliers/${this.supplier.id}/campaign-metrics-email`;
|
|
|
|
this.vnEmail.send(path, params);
|
2021-04-30 11:50:41 +00:00
|
|
|
} else {
|
|
|
|
const message = this.$t(`This supplier doesn't have a contact with an email address`);
|
|
|
|
this.vnApp.showError(message);
|
|
|
|
}
|
|
|
|
});
|
2020-12-16 07:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getTotal(entry) {
|
|
|
|
if (entry.buys) {
|
|
|
|
let total = 0;
|
|
|
|
for (let buy of entry.buys)
|
|
|
|
total += buy.total;
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail'];
|
|
|
|
|
|
|
|
ngModule.vnComponent('vnSupplierConsumption', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
supplier: '<'
|
|
|
|
},
|
|
|
|
require: {
|
|
|
|
card: '^vnSupplierCard'
|
|
|
|
}
|
|
|
|
});
|