diff --git a/frontend/js/chart/capital.js b/frontend/js/chart/capital.js index 9ed60de..23303ef 100644 --- a/frontend/js/chart/capital.js +++ b/frontend/js/chart/capital.js @@ -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 diff --git a/frontend/js/chart/diffCreditDebit.js b/frontend/js/chart/diffCreditDebit.js index f77784d..782367f 100644 --- a/frontend/js/chart/diffCreditDebit.js +++ b/frontend/js/chart/diffCreditDebit.js @@ -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)) { diff --git a/frontend/js/chart/distribution.js b/frontend/js/chart/distribution.js index 5873123..3a69530 100644 --- a/frontend/js/chart/distribution.js +++ b/frontend/js/chart/distribution.js @@ -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 } diff --git a/frontend/js/chart/monthThreshold.js b/frontend/js/chart/monthThreshold.js index 2121e77..cf9a68e 100644 --- a/frontend/js/chart/monthThreshold.js +++ b/frontend/js/chart/monthThreshold.js @@ -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)) { diff --git a/frontend/js/lib/dateFilter.js b/frontend/js/lib/dateFilter.js new file mode 100644 index 0000000..51f0a12 --- /dev/null +++ b/frontend/js/lib/dateFilter.js @@ -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 +} diff --git a/frontend/js/views/DashboardView.vue b/frontend/js/views/DashboardView.vue index 44d8963..66eb068 100644 --- a/frontend/js/views/DashboardView.vue +++ b/frontend/js/views/DashboardView.vue @@ -32,7 +32,7 @@
- +
@@ -51,7 +51,7 @@
Répartion des dépenses
- +
@@ -64,7 +64,7 @@
- +
@@ -74,7 +74,7 @@
Différences des crédits et des débits
- +
@@ -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()) diff --git a/frontend/js/views/TransactionsView.vue b/frontend/js/views/TransactionsView.vue index cc6e526..79ad23b 100644 --- a/frontend/js/views/TransactionsView.vue +++ b/frontend/js/views/TransactionsView.vue @@ -91,6 +91,10 @@ Sous-catégorie banque {{ info.bank_sub_category }} + + Catégorie + +