Skip to content

Commit

Permalink
Dashboard Page: Add YTD Option
Browse files Browse the repository at this point in the history
Adding the ability to select YTD (Year to Date) slicer on the Dashboard page.
  • Loading branch information
01111010t authored and 18alantom committed Jul 17, 2023
1 parent 090f309 commit 3299be7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pages/Dashboard/BaseDashboardChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default defineComponent({
data() {
return {
period: 'This Year' as PeriodKey,
periodOptions: ['This Year', 'This Quarter', 'This Month'] as PeriodKey[],
periodOptions: ['This Year', 'YTD', 'This Quarter', 'This Month'] as PeriodKey[],
};
},
watch: {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Dashboard/Cashflow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default defineComponent({
data: () => ({
data: [] as { inflow: number; outflow: number; yearmonth: string }[],
periodList: [],
periodOptions: ['This Year', 'This Quarter'],
periodOptions: ['This Year', 'YTD', 'This Quarter'],
hasData: false,
}),
computed: {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PeriodSelector
class="px-3"
:value="period"
:options="['This Year', 'This Quarter', 'This Month']"
:options="['This Year', 'YTD', 'This Quarter', 'This Month']"
@change="(value) => (period = value)"
/>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Dashboard/PeriodSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default defineComponent({
value: { type: String as PropType<PeriodKey>, default: 'This Year' },
options: {
type: Array as PropType<PeriodKey[]>,
default: () => ['This Year', 'This Quarter', 'This Month'],
default: () => ['This Year', 'YTD', 'This Quarter', 'This Month'],
},
},
emits: ['change'],
Expand All @@ -65,6 +65,7 @@ export default defineComponent({
this.periodSelectorMap = {
'': t`Set Period`,
'This Year': t`This Year`,
'YTD': t`YTD`,
'This Quarter': t`This Quarter`,
'This Month': t`This Month`,
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Dashboard/ProfitAndLoss.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default defineComponent({
data: () => ({
data: [] as { yearmonth: string; balance: number }[],
hasData: false,
periodOptions: ['This Year', 'This Quarter'],
periodOptions: ['This Year', 'YTD', 'This Quarter'],
}),
computed: {
chartData() {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export function getDatesAndPeriodList(period: PeriodKey): {

if (period === 'This Year') {
fromDate = toDate.minus({ months: 12 });
} else if (period === 'YTD') {
fromDate = DateTime.now().startOf('Year');
} else if (period === 'This Quarter') {
fromDate = toDate.minus({ months: 3 });
} else if (period === 'This Month') {
Expand All @@ -39,6 +41,10 @@ export function getDatesAndPeriodList(period: PeriodKey): {
while (true) {
const nextDate = periodList.at(0)!.minus({ months: 1 });
if (nextDate.toMillis() < fromDate.toMillis()) {
if (period === 'YTD'){
periodList.unshift(nextDate);
break;
}
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export type DropdownItem = {

export type UIGroupedFields = Map<string, Map<string, Field[]>>;
export type ExportFormat = 'csv' | 'json';
export type PeriodKey = 'This Year' | 'This Quarter' | 'This Month';
export type PeriodKey = 'This Year'| 'YTD' | 'This Quarter' | 'This Month';

export type PrintValues = {
print: Record<string, unknown>;
Expand Down

0 comments on commit 3299be7

Please sign in to comment.