+analytics update
This commit is contained in:
@@ -27,7 +27,7 @@ const dataTableCategories = ref([]);
|
|||||||
const tableColumns = ref([]);
|
const tableColumns = ref([]);
|
||||||
const chartData = ref(null)
|
const chartData = ref(null)
|
||||||
const selectedCategory = ref()
|
const selectedCategory = ref()
|
||||||
const formatter = ref(new Intl.NumberFormat('ru-RU', {style: 'currency', currency: 'RUB', minimumFractionDigits: 0}))
|
const formatter = ref(new Intl.NumberFormat('ru-RU', {style: 'currency', currency: 'RUB', minimumFractionDigits: 0, maximumFractionDigits:0}))
|
||||||
const isChartOpen = ref(false)
|
const isChartOpen = ref(false)
|
||||||
|
|
||||||
const closeChart = () => {
|
const closeChart = () => {
|
||||||
@@ -133,6 +133,7 @@ const prepareTableData = (categories) => {
|
|||||||
tableColumns.value = [
|
tableColumns.value = [
|
||||||
{field: "category", header: "Категория"},
|
{field: "category", header: "Категория"},
|
||||||
...allDates.map((dateStr) => ({field: dateStr, header: dateStr})),
|
...allDates.map((dateStr) => ({field: dateStr, header: dateStr})),
|
||||||
|
{field: "avg", header: "Среднее"},
|
||||||
];
|
];
|
||||||
console.log(tableColumns.value[0].field);
|
console.log(tableColumns.value[0].field);
|
||||||
const sums = {}
|
const sums = {}
|
||||||
@@ -140,10 +141,11 @@ const prepareTableData = (categories) => {
|
|||||||
const rows = categories.map((category) => {
|
const rows = categories.map((category) => {
|
||||||
// Начинаем со строки, где есть поле с именем категории
|
// Начинаем со строки, где есть поле с именем категории
|
||||||
const row = {category: category.categoryIcon + " " + category.categoryName};
|
const row = {category: category.categoryIcon + " " + category.categoryName};
|
||||||
|
let categorySum = 0
|
||||||
// Для каждой даты проверяем, есть ли в monthlySums соответствующая запись
|
// Для каждой даты проверяем, есть ли в monthlySums соответствующая запись
|
||||||
allDates.forEach((dateStr) => {
|
allDates.forEach((dateStr) => {
|
||||||
const found = category.monthlySums.find((m) => m.date === dateStr);
|
const found = category.monthlySums.find((m) => m.date === dateStr);
|
||||||
|
|
||||||
if (found.difference != 0) {
|
if (found.difference != 0) {
|
||||||
if (found.difference > 0) {
|
if (found.difference > 0) {
|
||||||
row[dateStr] = found ? formatter.value.format(found.total) + "<p class='text-red-500 text-sm'> (+ " + found.difference + "%)</p>" : 0;
|
row[dateStr] = found ? formatter.value.format(found.total) + "<p class='text-red-500 text-sm'> (+ " + found.difference + "%)</p>" : 0;
|
||||||
@@ -157,7 +159,9 @@ const prepareTableData = (categories) => {
|
|||||||
sums[dateStr] = 0
|
sums[dateStr] = 0
|
||||||
}
|
}
|
||||||
sums[dateStr] += found.total
|
sums[dateStr] += found.total
|
||||||
|
categorySum += found.total
|
||||||
});
|
});
|
||||||
|
row["avg"] = formatter.value.format(categorySum/allDates.length);
|
||||||
|
|
||||||
return row;
|
return row;
|
||||||
});
|
});
|
||||||
@@ -176,7 +180,6 @@ const prepareTableData = (categories) => {
|
|||||||
color = "text-red-500"
|
color = "text-red-500"
|
||||||
} else color = "text-green-600"
|
} else color = "text-green-600"
|
||||||
sums[key] = formatter.value.format(sums[key]) + `<p class='${color}'>(` + difference.toFixed(0) + "%)</p>";
|
sums[key] = formatter.value.format(sums[key]) + `<p class='${color}'>(` + difference.toFixed(0) + "%)</p>";
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user