2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 14:50:56 +00:00

Dashboard Page: Add YTD Option

Adding the ability to select YTD (Year to Date) slicer on the Dashboard page.
This commit is contained in:
01111010t 2023-07-10 18:23:14 -04:00 committed by Alan
parent 090f309a80
commit 3299be7e36
7 changed files with 13 additions and 6 deletions

View File

@ -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: {

View File

@ -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: {

View File

@ -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>

View File

@ -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'],
@ -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`,
};

View File

@ -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() {

View File

@ -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') {
@ -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;
}

View File

@ -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>;