diff --git a/src/pages/Customer/Card/CustomerConsumption.vue b/src/pages/Customer/Card/CustomerConsumption.vue index 35f366e47e0..640e37ed35a 100644 --- a/src/pages/Customer/Card/CustomerConsumption.vue +++ b/src/pages/Customer/Card/CustomerConsumption.vue @@ -2,7 +2,7 @@ import { ref, computed, onBeforeMount } from 'vue'; import axios from 'axios'; import { useI18n } from 'vue-i18n'; -import { toDate } from 'src/filters/index'; +import { dateRange, toDate } from 'src/filters/index'; import { useRoute } from 'vue-router'; import VnTable from 'components/VnTable/VnTable.vue'; @@ -104,18 +104,12 @@ function getParams() { }; } const userParams = computed(() => { - const minDate = Date.vnNew(); - minDate.setHours(0, 0, 0, 0); - minDate.setMonth(minDate.getMonth() - 2); - - const maxDate = Date.vnNew(); - maxDate.setHours(23, 59, 59, 59); - - return { - campaign: campaignList.value[0]?.id, - from: minDate, - to: maxDate, + const campaign = campaignList.value[0]?.id; + const userParams = { + campaign, + ...updateDateParams(campaign, { from: Date.vnNew(), to: Date.vnNew() }), }; + return userParams; }); const openReportPdf = () => { openReport(`Clients/${route.params.id}/campaign-metrics-pdf`, getParams()); @@ -134,6 +128,23 @@ const sendCampaignMetricsEmail = ({ address }) => { ...getParams(), }); }; + +const updateDateParams = (value, params) => { + if (!value) { + params.from = null; + params.to = null; + return; + } + const campaign = campaignList.value.find((c) => c.id === value); + if (!campaign) return; + + const { dated, previousDays, scopeDays } = campaign; + const _date = new Date(dated); + const [from, to] = dateRange(_date); + params.from = new Date(from.setDate(from.getDate() - previousDays)).toISOString(); + params.to = new Date(to.setDate(to.getDate() + scopeDays)).toISOString(); + return params; +};