fix date filter on dashboard

This commit is contained in:
Simon Vieille 2024-10-06 12:34:28 +02:00
commit 0b5bff2ba2
7 changed files with 70 additions and 18 deletions

View file

@ -1,3 +1,5 @@
import { isInRange } from '../lib/dateFilter'
const getDate = (value, precision) => {
const d = new Date(value)
@ -38,7 +40,7 @@ const toSortDate = (value) => {
return `${items[1]}${items[0]}`
}
const compute = (transactions, precision) => {
const compute = (transactions, precision, dateFrom, dateTo) => {
const indexes = {}
const values = {}
const labels = []
@ -60,7 +62,10 @@ const compute = (transactions, precision) => {
if (begin) {
indexes[date] = labels.length
values[date] = lastDate !== null ? values[lastDate] : 0
labels.push(date)
if (isInRange(transaction.date, dateFrom, dateTo)) {
labels.push(date)
}
}
lastDate = date

View file

@ -1,3 +1,5 @@
import { isInRange } from '../lib/dateFilter'
const getDate = (value) => {
const d = new Date(value)
@ -17,7 +19,7 @@ const toSortDate = (value) => {
return `${items[1]}${items[0]}`
}
const compute = (transactions) => {
const compute = (transactions, dateFrom, dateTo) => {
const indexes = {}
const values = {}
const labels = []
@ -38,6 +40,10 @@ const compute = (transactions) => {
}
transactions.forEach((transaction) => {
if (!isInRange(transaction.date, dateFrom, dateTo)) {
return
}
let date = getDate(transaction.date)
if (!indexes.hasOwnProperty(date)) {

View file

@ -1,3 +1,5 @@
import { isInRange } from '../lib/dateFilter'
const getDate = (value) => {
const d = new Date(value)
@ -11,7 +13,7 @@ const getDate = (value) => {
return `${month}/${year}`
}
const computeBar = (transactions, stacked) => {
const computeBar = (transactions, stacked, dateFrom, dateTo) => {
const indexes = {}
const labels = []
const bars = {}
@ -23,6 +25,10 @@ const computeBar = (transactions, stacked) => {
}
transactions.forEach((transaction) => {
if (!isInRange(transaction.date, dateFrom, dateTo)) {
return
}
if (transaction.credit > 0) {
return
}
@ -54,6 +60,10 @@ const computeBar = (transactions, stacked) => {
}
transactions.forEach((transaction) => {
if (!isInRange(transaction.date, dateFrom, dateTo)) {
return
}
if (transaction.credit > 0) {
return
}
@ -86,7 +96,7 @@ const computeBar = (transactions, stacked) => {
}
}
const computeDoughnut = (transactions) => {
const computeDoughnut = (transactions, dateFrom, dateTo) => {
const indexes = {}
const labels = []
const data = []
@ -98,6 +108,10 @@ const computeDoughnut = (transactions) => {
}
transactions.forEach((transaction) => {
if (!isInRange(transaction.date, dateFrom, dateTo)) {
return
}
if (transaction.credit > 0) {
return
}

View file

@ -1,3 +1,5 @@
import { isInRange } from '../lib/dateFilter'
const getDate = (value) => {
const d = new Date(value)
@ -11,7 +13,7 @@ const getDate = (value) => {
return `${month}/${year}`
}
const compute = (transactions, cats) => {
const compute = (transactions, cats, dateFrom, dateTo) => {
let categories = {}
let datas = {}
@ -26,6 +28,10 @@ const compute = (transactions, cats) => {
return
}
if (!isInRange(value.date, dateFrom, dateTo)) {
return
}
const date = getDate(value.date)
if (!datas.hasOwnProperty(date)) {

View file

@ -0,0 +1,17 @@
const isInRange = (date, dateFrom, dateTo) => {
const d = new Date(date)
if (dateFrom && new Date(dateFrom) > d) {
return false
}
if (dateTo && new Date(dateTo) < d) {
return false
}
return true
}
export {
isInRange
}

View file

@ -32,7 +32,7 @@
<BFormSelect id="capitalPrecision" v-model="capitalPrecision" :options="precisions()"></BFormSelect>
</div>
<div>
<Line :ref="chart" :data="capitalLine(data, capitalPrecision)" :options="fixedOptions()" :style="chartStyle(380)" />
<Line :ref="chart" :data="capitalLine(data, capitalPrecision, dateFrom, dateTo)" :options="fixedOptions()" :style="chartStyle(380)" />
</div>
</div>
</div>
@ -51,7 +51,7 @@
<div class="stats">
<h5 class="mb-2">Répartion des dépenses</h5>
<div>
<Doughnut :ref="chart" :data="distributionDoughnut(data)" :options="fixedOptions()" :style="chartStyle(380)" />
<Doughnut :ref="chart" :data="distributionDoughnut(data, dateFrom, dateTo)" :options="fixedOptions()" :style="chartStyle(380)" />
</div>
</div>
</div>
@ -64,7 +64,7 @@
</BFormCheckbox>
</div>
<div>
<Bar :ref="chart" :data="distributionBar(data, distributionBarStacked)" :options="stackOptions()" :style="chartStyle(380)" />
<Bar :ref="chart" :data="distributionBar(data, distributionBarStacked, dateFrom, dateTo)" :options="stackOptions()" :style="chartStyle(380)" />
</div>
</div>
</div>
@ -74,7 +74,7 @@
<div class="stats">
<h5 class="mb-2">Différences des crédits et des débits</h5>
<div>
<Bar :ref="chart" :data="diffCreditDebitBar(data)" :options="fixedOptions()" :style="chartStyle(380)" />
<Bar :ref="chart" :data="diffCreditDebitBar(data, dateFrom, dateTo)" :options="fixedOptions()" :style="chartStyle(380)" />
</div>
</div>
</div>
@ -220,7 +220,7 @@ const monthThresholdsData = () => {
return _monthThresholdsData.value
}
_monthThresholdsData.value = monthThresholds(data.value, categories.value)
_monthThresholdsData.value = monthThresholds(data.value, categories.value, dateFrom.value, dateTo.value)
return _monthThresholdsData.value
}
@ -267,13 +267,13 @@ const refresh = () => {
query['bank_account_id__eq'] = account.value
}
if (dateFrom.value) {
query['date__gt'] = dateFrom.value
}
if (dateTo.value) {
query['date__lt'] = dateTo.value
}
// if (dateFrom.value) {
// query['date__gt'] = dateFrom.value
// }
//
// if (dateTo.value) {
// query['date__lt'] = dateTo.value
// }
fetch(`/api/transaction?${new URLSearchParams(query)}`)
.then((response) => response.json())

View file

@ -91,6 +91,10 @@
<BTh>Sous-catégorie banque</BTh>
<BTd>{{ info.bank_sub_category }}</BTd>
</BTr>
<BTr>
<BTh>Catégorie</BTh>
<BTd v-html="renderCategory(info.category)"></BTd>
</BTr>
</BTableSimple>
<template v-slot:footer>