Skip to content

Commit

Permalink
Merge branch 'calendar_report' of https://github.com/lelemm/actual in…
Browse files Browse the repository at this point in the history
…to calendar_report
  • Loading branch information
lelemm committed Nov 12, 2024
2 parents 9f9f468 + 171523b commit b0037de
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ export function CalendarGraph({
}: CalendarGraphProps) {
const { t } = useTranslation();
const startingDate = startOfWeek(new Date(), {
weekStartsOn: firstDayOfWeekIdx
? (parseInt(firstDayOfWeekIdx) as 0 | 1 | 2 | 3 | 4 | 5 | 6)
: 0,
weekStartsOn:
firstDayOfWeekIdx !== undefined &&
!isNaN(parseInt(firstDayOfWeekIdx)) &&
parseInt(firstDayOfWeekIdx) >= 0 &&
parseInt(firstDayOfWeekIdx) <= 6
? (parseInt(firstDayOfWeekIdx) as 0 | 1 | 2 | 3 | 4 | 5 | 6)
: 0,
});
const [fontSize, setFontSize] = useState(14);

Expand Down
49 changes: 29 additions & 20 deletions packages/desktop-client/src/components/reports/reports/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,29 +296,38 @@ function CalendarInner({ widget, parameters }: CalendarInnerProps) {
throw new Error('No widget that could be saved.');
}

await send('dashboard-update-widget', {
id: widget.id,
meta: {
...(widget.meta ?? {}),
conditions,
conditionsOp,
timeFrame: {
start,
end,
mode,
try {
await send('dashboard-update-widget', {
id: widget.id,
meta: {
...(widget.meta ?? {}),
conditions,
conditionsOp,
timeFrame: {
start,
end,
mode,
},
},
},
});
dispatch(
addNotification({
type: 'message',
message: t('Dashboard widget successfully saved.'),
}),
);
});
dispatch(
addNotification({
type: 'message',
message: t('Dashboard widget successfully saved.'),
}),
);
} catch (error) {
dispatch(
addNotification({
type: 'error',
message: t('Failed to save dashboard widget.'),
}),
);
console.error('Error saving widget:', error);
}
}

const { totalIncome, totalExpense } = useMemo(() => {
if (!data) {
if (!data || !data.calendarData) {
return { totalIncome: 0, totalExpense: 0 };
}
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,31 @@ export function calendarSpreadsheet(
.groupBy(['date'])
.select(['date', { amount: { $sum: '$amount' } }]);

const expenseData = await runQuery(
makeRootQuery().filter({
$and: { amount: { $lt: 0 } },
}),
);
let expenseData;
try {
expenseData = await runQuery(
makeRootQuery().filter({
$and: { amount: { $lt: 0 } },
}),
);
} catch (error) {
// Handle error appropriately
console.error('Failed to fetch expense data:', error);
expenseData = { data: [] };
}

const incomeData = await runQuery(
makeRootQuery().filter({
$and: { amount: { $gt: 0 } },
}),
);
let incomeData;
try {
incomeData = await runQuery(
makeRootQuery().filter({
$and: { amount: { $gt: 0 } },
}),
);
} catch (error) {
// Handle error appropriately
console.error('Failed to fetch income data:', error);
incomeData = { data: [] };
}

const getOneDatePerMonth = (start: Date, end: Date) => {
const months = [];
Expand Down

0 comments on commit b0037de

Please sign in to comment.