66 lines
1.5 KiB
JavaScript
66 lines
1.5 KiB
JavaScript
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() {
|
|
const minDate = new Date();
|
|
minDate.setHours(0, 0, 0, 0);
|
|
minDate.setMonth(minDate.getMonth() - 2);
|
|
|
|
const maxDate = new Date();
|
|
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() {
|
|
this.vnReport.show('supplier-campaign-metrics', this.reportParams);
|
|
}
|
|
|
|
sendEmail() {
|
|
this.vnEmail.send('supplier-campaign-metrics', this.reportParams);
|
|
}
|
|
|
|
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'
|
|
}
|
|
});
|