salix/modules/client/front/consumption/index.js

76 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-06-10 11:35:41 +00:00
import ngModule from '../module';
import Section from 'salix/components/section';
class Controller extends Section {
2020-06-15 07:07:13 +00:00
constructor($element, $, vnReport, vnEmail) {
2020-06-10 11:35:41 +00:00
super($element, $);
2020-06-15 07:07:13 +00:00
this.vnReport = vnReport;
this.vnEmail = vnEmail;
2020-06-12 07:18:19 +00:00
this.filter = {
where: {
isPackaging: false
}
};
2020-11-06 07:21:25 +00:00
this.setDefaultFilter();
}
setDefaultFilter() {
2023-01-16 14:18:24 +00:00
const minDate = Date.vnNew();
2020-06-12 07:18:19 +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-06-12 07:18:19 +00:00
maxDate.setHours(23, 59, 59, 59);
this.filterParams = {
from: minDate,
to: maxDate
};
}
get reportParams() {
const userParams = this.$.model.userParams;
return Object.assign({
2021-01-14 12:41:50 +00:00
recipient: this.client.email,
2020-06-12 07:18:19 +00:00
recipientId: this.client.id
}, userParams);
2020-06-10 11:35:41 +00:00
}
showTicketDescriptor(event, sale) {
if (!sale.isTicket) return;
this.$.ticketDescriptor.show(event.target, sale.origin);
}
2020-06-12 07:18:19 +00:00
showReport() {
2022-09-22 06:48:29 +00:00
const path = `Clients/${this.client.id}/campaign-metrics-pdf`;
this.vnReport.show(path, this.reportParams);
2020-06-12 07:18:19 +00:00
}
sendEmail() {
2022-09-22 06:48:29 +00:00
const path = `Clients/${this.client.id}/campaign-metrics-email`;
this.vnEmail.send(path, this.reportParams);
2020-06-12 07:18:19 +00:00
}
changeGrouped(value) {
const model = this.$.model;
model.addFilter({}, {grouped: value});
}
2020-06-10 11:35:41 +00:00
}
2020-06-15 07:07:13 +00:00
Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail'];
2020-06-10 11:35:41 +00:00
ngModule.vnComponent('vnClientConsumption', {
2020-06-10 11:35:41 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
client: '<'
2020-06-12 07:18:19 +00:00
},
require: {
card: '^vnClientCard'
2020-06-10 11:35:41 +00:00
}
});