Skip to content

Commit

Permalink
Merge branch 'master' into mobile-scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Sep 4, 2024
2 parents 96a955e + bc04a8c commit 75c6675
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React, { useState } from 'react';
import { Trans } from 'react-i18next';

import * as queries from 'loot-core/src/client/queries';
import { type Query } from 'loot-core/src/shared/query';
import { currencyToInteger } from 'loot-core/src/shared/util';
import { type AccountEntity } from 'loot-core/types/models';

import { SvgCheckCircle1 } from '../../icons/v2';
import { styles, theme } from '../../style';
Expand All @@ -14,20 +16,32 @@ import { View } from '../common/View';
import { useFormat } from '../spreadsheet/useFormat';
import { useSheetValue } from '../spreadsheet/useSheetValue';

type ReconcilingMessageProps = {
balanceQuery: { name: `balance-query-${string}`; query: Query };
targetBalance: number;
onDone: () => void;
onCreateTransaction: (targetDiff: number) => void;
};

export function ReconcilingMessage({
balanceQuery,
targetBalance,
onDone,
onCreateTransaction,
}) {
const cleared = useSheetValue({
name: balanceQuery.name + '-cleared',
}: ReconcilingMessageProps) {
const cleared = useSheetValue<'balance', `balance-query-${string}-cleared`>({
name: (balanceQuery.name + '-cleared') as `balance-query-${string}-cleared`,
value: 0,
query: balanceQuery.query.filter({ cleared: true }),
});
const format = useFormat();
const targetDiff = targetBalance - cleared;

const clearedBalance = format(cleared, 'financial');
const bankBalance = format(targetBalance, 'financial');
const difference =
(targetDiff > 0 ? '+' : '') + format(targetDiff, 'financial');

return (
<View
style={{
Expand Down Expand Up @@ -66,23 +80,10 @@ export function ReconcilingMessage({
<View style={{ color: theme.tableText }}>
<Text style={{ fontStyle: 'italic', textAlign: 'center' }}>
<Trans>
Your cleared balance{' '}
<strong>
{{ clearedBalance: format(cleared, 'financial') }}
</strong>{' '}
needs{' '}
<strong>
{{
difference:
(targetDiff > 0 ? '+' : '') +
format(targetDiff, 'financial'),
}}
</strong>{' '}
to match
Your cleared balance <strong>{clearedBalance}</strong> needs{' '}
<strong>{difference}</strong> to match
<br /> your bank&apos;s balance of{' '}
<Text style={{ fontWeight: 700 }}>
{{ bankBalance: format(targetBalance, 'financial') }}
</Text>
<Text style={{ fontWeight: 700 }}>{bankBalance}</Text>
</Trans>
</Text>
</View>
Expand All @@ -104,15 +105,25 @@ export function ReconcilingMessage({
);
}

export function ReconcileMenu({ account, onReconcile, onClose }) {
type ReconcileMenuProps = {
account: AccountEntity;
onReconcile: (amount: number | null) => void;
onClose: () => void;
};

export function ReconcileMenu({
account,
onReconcile,
onClose,
}: ReconcileMenuProps) {
const balanceQuery = queries.accountBalance(account);
const clearedBalance = useSheetValue({
name: balanceQuery.name + '-cleared',
const clearedBalance = useSheetValue<'account', `balance-${string}-cleared`>({
name: (balanceQuery.name + '-cleared') as `balance-${string}-cleared`,
value: null,
query: balanceQuery.query.filter({ cleared: true }),
});
const format = useFormat();
const [inputValue, setInputValue] = useState(null);
const [inputValue, setInputValue] = useState<string | null>(null);
const [inputFocused, setInputFocused] = useState(false);

function onSubmit() {
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/common/Modal2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const Modal = ({
defaultOpen={true}
onOpenChange={isOpen => !isOpen && handleOnClose?.()}
style={{
backgroundColor: 'rgba(0, 0, 0, 0.5)',
backgroundColor: 'rgba(0, 0, 0, 0.2)',
position: 'fixed',
inset: 0,
zIndex: 3000,
Expand Down
9 changes: 9 additions & 0 deletions packages/desktop-client/src/components/spreadsheet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type Spreadsheets = {

// Account fields
balance: number;
[key: `balance-${string}-cleared`]: number | null;
'accounts-balance': number;
'budgeted-accounts-balance': number;
'offbudget-accounts-balance': number;
Expand Down Expand Up @@ -62,6 +63,14 @@ export type Spreadsheets = {
goal: number;
'long-goal': number;
};
[`balance`]: {
// Common fields
'uncategorized-amount': number;
'uncategorized-balance': number;

// Balance fields
[key: `balance-query-${string}-cleared`]: number;
};
};

export type SheetNames = keyof Spreadsheets & string;
Expand Down
43 changes: 14 additions & 29 deletions packages/loot-core/src/client/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,73 +115,61 @@ export function makeTransactionSearchQuery(
});
}

export function accountBalance(
acct: AccountEntity,
): Binding<'account', 'balance'> {
export function accountBalance(acct: AccountEntity) {
return {
name: accountParametrizedField('balance')(acct.id),
query: q('transactions')
.filter({ account: acct.id })
.options({ splits: 'none' })
.calculate({ $sum: '$amount' }),
};
} satisfies Binding<'account', 'balance'>;
}

export function accountBalanceCleared(
acct: AccountEntity,
): Binding<'account', 'balanceCleared'> {
export function accountBalanceCleared(acct: AccountEntity) {
return {
name: accountParametrizedField('balanceCleared')(acct.id),
query: q('transactions')
.filter({ account: acct.id, cleared: true })
.options({ splits: 'none' })
.calculate({ $sum: '$amount' }),
};
} satisfies Binding<'account', 'balanceCleared'>;
}

export function accountBalanceUncleared(
acct: AccountEntity,
): Binding<'account', 'balanceUncleared'> {
export function accountBalanceUncleared(acct: AccountEntity) {
return {
name: accountParametrizedField('balanceUncleared')(acct.id),
query: q('transactions')
.filter({ account: acct.id, cleared: false })
.options({ splits: 'none' })
.calculate({ $sum: '$amount' }),
};
} satisfies Binding<'account', 'balanceUncleared'>;
}

export function allAccountBalance(): Binding<'account', 'accounts-balance'> {
export function allAccountBalance() {
return {
query: q('transactions')
.filter({ 'account.closed': false })
.calculate({ $sum: '$amount' }),
name: 'accounts-balance',
};
} satisfies Binding<'account', 'accounts-balance'>;
}

export function budgetedAccountBalance(): Binding<
'account',
'budgeted-accounts-balance'
> {
export function budgetedAccountBalance() {
return {
name: `budgeted-accounts-balance`,
query: q('transactions')
.filter({ 'account.offbudget': false, 'account.closed': false })
.calculate({ $sum: '$amount' }),
};
} satisfies Binding<'account', 'budgeted-accounts-balance'>;
}

export function offbudgetAccountBalance(): Binding<
'account',
'offbudget-accounts-balance'
> {
export function offbudgetAccountBalance() {
return {
name: `offbudget-accounts-balance`,
query: q('transactions')
.filter({ 'account.offbudget': true, 'account.closed': false })
.calculate({ $sum: '$amount' }),
};
} satisfies Binding<'account', 'offbudget-accounts-balance'>;
}

export function categoryBalance(category: CategoryEntity, month: string) {
Expand Down Expand Up @@ -249,14 +237,11 @@ export function uncategorizedBalance() {
};
}

export function uncategorizedCount<SheetName extends SheetNames>(): Binding<
SheetName,
'uncategorized-amount'
> {
export function uncategorizedCount<SheetName extends SheetNames>() {
return {
name: 'uncategorized-amount',
query: uncategorizedQuery.calculate({ $count: '$id' }),
};
} satisfies Binding<SheetName, 'uncategorized-amount'>;
}

export const rolloverBudget = {
Expand Down
1 change: 0 additions & 1 deletion packages/loot-core/src/server/accounts/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function parseRecurDate(desc) {

return {
type: 'recur',
// @ts-expect-error fix me
schedule: new RSchedule({
rrules: rules,
data: {
Expand Down
22 changes: 9 additions & 13 deletions packages/loot-core/src/server/schedules/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,21 +374,17 @@ async function getUpcomingDates({ config, count }) {
const rules = recurConfigToRSchedule(config);

try {
// @ts-expect-error fix me
const schedule = new RSchedule({ rrules: rules });

return (
schedule
// @ts-expect-error fix me
.occurrences({ start: d.startOfDay(new Date()), take: count })
.toArray()
.map(date =>
config.skipWeekend
? getDateWithSkippedWeekend(date.date, config.weekendSolveMode)
: date.date,
)
.map(date => dayFromDate(date))
);
return schedule
.occurrences({ start: d.startOfDay(new Date()), take: count })
.toArray()
.map(date =>
config.skipWeekend
? getDateWithSkippedWeekend(date.date, config.weekendSolveMode)
: date.date,
)
.map(date => dayFromDate(date));
} catch (err) {
captureBreadcrumb(config);
throw err;
Expand Down
12 changes: 4 additions & 8 deletions packages/loot-core/src/server/schedules/find-schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ import { Schedule as RSchedule } from '../util/rschedule';
import { SchedulesHandlers } from './types/handlers';

function takeDates(config) {
// @ts-expect-error fix me
const schedule = new RSchedule({ rrules: recurConfigToRSchedule(config) });
return (
schedule
// @ts-expect-error fix me
.occurrences({ take: 3 })
.toArray()
.map(d => d.date)
);
return schedule
.occurrences({ take: 3 })
.toArray()
.map(d => d.date);
}

async function getTransactions(date, account) {
Expand Down
1 change: 0 additions & 1 deletion packages/loot-core/src/server/util/rschedule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '@rschedule/standard-date-adapter/setup';
import '@rschedule/json-tools/Schedule';

export * from '@rschedule/standard-date-adapter';
export * from '@rschedule/core';
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3355.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MatissJanis]
---

TypeScript: migrate Reconcile file.
6 changes: 6 additions & 0 deletions upcoming-release-notes/3361.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [UnderKoen]
---

TypeScript: RSchedule types fixed

0 comments on commit 75c6675

Please sign in to comment.