Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BudgE",
"version": "0.0.6",
"version": "0.0.8",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions backend/src/controllers/BudgetsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class BudgetsController extends Controller {
{
id: 'abc123',
name: 'My Budget',
currency: 'USD',
accounts: [
{
id: 'def123',
Expand All @@ -45,6 +46,7 @@ export class BudgetsController extends Controller {
{
id: 'abc456',
name: 'Another Budget',
currency: 'USD',
accounts: [],
created: new Date('2011-10-05T14:48:00.000Z'),
updated: new Date('2011-10-05T14:48:00.000Z'),
Expand Down Expand Up @@ -74,6 +76,7 @@ export class BudgetsController extends Controller {
data: {
id: 'abc123',
name: 'My Budget',
currency: 'USD',
accounts: [],
created: new Date('2011-10-05T14:48:00.000Z'),
updated: new Date('2011-10-05T14:48:00.000Z'),
Expand Down Expand Up @@ -108,6 +111,7 @@ export class BudgetsController extends Controller {
data: {
id: 'abc123',
name: 'My Budget',
currency: 'USD',
accounts: [],
created: new Date('2011-10-05T14:48:00.000Z'),
updated: new Date('2011-10-05T14:48:00.000Z'),
Expand Down Expand Up @@ -149,6 +153,7 @@ export class BudgetsController extends Controller {
data: {
id: 'abc123',
name: 'My Budget',
currency: 'USD',
accounts: [],
created: new Date('2011-10-05T14:48:00.000Z'),
updated: new Date('2011-10-05T14:48:00.000Z'),
Expand Down
5 changes: 5 additions & 0 deletions backend/src/entities/Budget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export class Budget {
@Column({ type: 'varchar' })
name: string

@Column({ type: 'varchar', default: 'USD' })
currency: string

@CreateDateColumn()
created: Date

Expand Down Expand Up @@ -77,13 +80,15 @@ export class Budget {
id: this.id,
userId: this.userId,
name: this.name,
currency: this.currency,
}
}

public async toResponseModel(): Promise<BudgetModel> {
return {
id: this.id,
name: this.name,
currency: this.currency,
accounts: await Promise.all((await this.accounts).map(account => account.toResponseModel())),
created: this.created,
updated: this.updated,
Expand Down
20 changes: 20 additions & 0 deletions backend/src/migrations/1650032177205-add-budget-currency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class addBudgetCurrency1650032177205 implements MigrationInterface {
name = 'addBudgetCurrency1650032177205'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "temporary_budgets" ("id" varchar PRIMARY KEY NOT NULL, "userId" varchar NOT NULL, "name" varchar NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "updated" datetime NOT NULL DEFAULT (datetime('now')), "currency" varchar NOT NULL DEFAULT ('USD'), CONSTRAINT "FK_27e688ddf1ff3893b43065899f9" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`);
await queryRunner.query(`INSERT INTO "temporary_budgets"("id", "userId", "name", "created", "updated") SELECT "id", "userId", "name", "created", "updated" FROM "budgets"`);
await queryRunner.query(`DROP TABLE "budgets"`);
await queryRunner.query(`ALTER TABLE "temporary_budgets" RENAME TO "budgets"`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "budgets" RENAME TO "temporary_budgets"`);
await queryRunner.query(`CREATE TABLE "budgets" ("id" varchar PRIMARY KEY NOT NULL, "userId" varchar NOT NULL, "name" varchar NOT NULL, "created" datetime NOT NULL DEFAULT (datetime('now')), "updated" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_27e688ddf1ff3893b43065899f9" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`);
await queryRunner.query(`INSERT INTO "budgets"("id", "userId", "name", "created", "updated") SELECT "id", "userId", "name", "created", "updated" FROM "temporary_budgets"`);
await queryRunner.query(`DROP TABLE "temporary_budgets"`);
}

}
6 changes: 6 additions & 0 deletions backend/src/models/Budget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export interface BudgetModel {
*/
name: string

/**
* Currency setting of the budget
*/
currency: string

/**
* Budget's accounts
*/
Expand All @@ -44,6 +49,7 @@ export interface BudgetModel {
*/
export interface BudgetRequest {
name: string
currency?: string
}

export type BudgetResponse = DataResponse<BudgetModel>
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BudgE",
"version": "0.0.6",
"version": "0.0.8",
"private": true,
"dependencies": {
"@dinero.js/currencies": "^2.0.0-alpha.8",
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export default class API {
return response.data.data
}

static async updateBudget(id, name, currency) {
const response = await axios.put(`/api/budgets/${id}`, {
name,
currency,
})

return response.data.data
}

static async fetchBudgets() {
const response = await axios.get('/api/budgets')

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/AccountDetails.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react'
import Box from '@mui/material/Box'
import { useSelector, useDispatch } from 'react-redux'
import { FromAPI, intlFormat, inputToDinero } from '../utils/Currency'
import { FromAPI, Currency } from '../utils/Currency'
import { useTheme } from '@mui/styles'
import Stack from '@mui/material/Stack'
import Button from '@mui/material/Button'
Expand Down Expand Up @@ -97,7 +97,7 @@ export default function BudgetDetails({ accountId, name }) {

return vals
},
[inputToDinero(0), inputToDinero(0), 0],
[Currency.inputToDinero(0), Currency.inputToDinero(0), 0],
)

return (
Expand Down Expand Up @@ -200,12 +200,12 @@ export default function BudgetDetails({ accountId, name }) {

<TableRow>
<TableCell>Income</TableCell>
<TableCell sx={{ textAlign: 'right' }}>{intlFormat(income)}</TableCell>
<TableCell sx={{ textAlign: 'right' }}>{Currency.intlFormat(income)}</TableCell>
</TableRow>

<TableRow>
<TableCell>Activity</TableCell>
<TableCell sx={{ textAlign: 'right' }}>{intlFormat(activity)}</TableCell>
<TableCell sx={{ textAlign: 'right' }}>{Currency.intlFormat(activity)}</TableCell>
</TableRow>
</TableBody>
</Table>
Expand Down
20 changes: 10 additions & 10 deletions frontend/src/components/AccountTable/AccountTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import IconButton from '@mui/material/IconButton'
import AccessTimeIcon from '@mui/icons-material/AccessTime'
import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline'
import LockIcon from '@mui/icons-material/Lock'
import { FromAPI, intlFormat, valueToDinero, inputToDinero, getBalanceColor } from '../../utils/Currency'
import { FromAPI, Currency, getBalanceColor } from '../../utils/Currency'
import { isZero, isPositive, add } from 'dinero.js'
import Tooltip from '@mui/material/Tooltip'
import { useTheme } from '@mui/styles'
Expand Down Expand Up @@ -610,12 +610,12 @@ export default function Account(props) {
textAlign: 'right',
}}
>
{intlFormat(trx.amount)}
{Currency.intlFormat(trx.amount)}
</Typography>
)
},
Editing: props => <AccountAmountCell {...props} />,
exportTransformer: value => intlFormat(valueToDinero(value)),
exportTransformer: value => Currency.intlFormat(Currency.valueToDinero(value)),
},
{
title: 'Status',
Expand Down Expand Up @@ -826,7 +826,7 @@ export default function Account(props) {
date: newRow.date,
memo: newRow.memo,
payeeId: newRow.payeeId,
categoryId: newRow.categoryId === '0' ? null : newRow.categoryId,
categoryId: newRow.categoryId === '0' || newRow.categoryId === '' ? null : newRow.categoryId,
status: 0,
},
}),
Expand Down Expand Up @@ -855,7 +855,7 @@ export default function Account(props) {
{
...rowData,
status: rowData.status === 0 ? 1 : 0,
amount: valueToDinero(rowData.amount),
amount: Currency.valueToDinero(rowData.amount),
},
{ ...rowData },
)
Expand Down Expand Up @@ -967,7 +967,7 @@ export default function Account(props) {
getSelectedRows().map(row => ({
...row,
status: 1,
amount: valueToDinero(row.amount),
amount: Currency.valueToDinero(row.amount),
})),
)
}
Expand All @@ -978,7 +978,7 @@ export default function Account(props) {
getSelectedRows().map(row => ({
...row,
status: 0,
amount: valueToDinero(row.amount),
amount: Currency.valueToDinero(row.amount),
})),
)
}
Expand Down Expand Up @@ -1057,9 +1057,9 @@ export default function Account(props) {
}

const selectedTransactionTotal = getSelectedRows().reduce((total, row) => {
total = add(total, valueToDinero(row.amount))
total = add(total, Currency.valueToDinero(row.amount))
return total
}, inputToDinero(0))
}, Currency.inputToDinero(0))

return (
<Box
Expand Down Expand Up @@ -1214,7 +1214,7 @@ export default function Account(props) {
<Box
sx={{ fontWeight: 'bold', color: getBalanceColor(selectedTransactionTotal, theme), px: 1 }}
>
{intlFormat(selectedTransactionTotal)}
{Currency.intlFormat(selectedTransactionTotal)}
</Box>
</>
)}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/AccountTable/AccountTableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'
import TableBody from '@mui/material/TableBody'
import Box from '@mui/material/Box'
import AccountTableRow from './AccountTableRow'
import { inputToDinero, valueToDinero } from '../../utils/Currency'
import { Currency } from '../../utils/Currency'
import AutoSizer from 'react-virtualized-auto-sizer'
import { FixedSizeList as List } from 'react-window'
import { ROW_HEIGHT } from './constants'
Expand All @@ -27,18 +27,18 @@ export default function AccountTableBody({
if (newData.id === 0) {
return onTransactionAdd({
...newData,
amount: inputToDinero(newData.amount),
amount: Currency.inputToDinero(newData.amount),
})
}

onRowSave(
{
...newData,
amount: inputToDinero(newData.amount),
amount: Currency.inputToDinero(newData.amount),
},
{
...oldData,
amount: valueToDinero(oldData.amount),
amount: Currency.valueToDinero(oldData.amount),
},
)
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/AccountTable/AccountTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useSelector, useDispatch } from 'react-redux'
import TableRow from '@mui/material/TableRow'
import TableCell from '@mui/material/TableCell'
import Box from '@mui/material/Box'
import { valueToDinero } from '../../utils/Currency'
import { Currency } from '../../utils/Currency'
import { toUnit } from 'dinero.js'
import clsx from 'clsx'
import { ROW_HEIGHT } from './constants'
Expand Down Expand Up @@ -39,7 +39,7 @@ export default function AccountTableRow({
const [categoryOptions, setCategoryOptions] = useState(buildCategoryOptions(row.original))
const [rowData, setRowData] = useState({
...row.original,
amount: toUnit(valueToDinero(row.original.amount), { digits: 2 }),
amount: toUnit(Currency.valueToDinero(row.original.amount), { digits: 2 }),
})

const updateRowData = (field, val) => {
Expand Down Expand Up @@ -83,7 +83,7 @@ export default function AccountTableRow({

setRowData({
...row.original,
amount: toUnit(valueToDinero(row.original.amount), { digits: 2 }),
amount: toUnit(Currency.valueToDinero(row.original.amount), { digits: 2 }),
})
dispatch(setEditingRow(0))
onCancel(row.original.id)
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/AccountTable/BalanceCalculation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react'
import { useDispatch } from 'react-redux'
import { accountsSelectors, editAccount } from '../../redux/slices/Accounts'
import { FromAPI, getBalanceColor, intlFormat } from '../../utils/Currency'
import { FromAPI, getBalanceColor, Currency } from '../../utils/Currency'
import { usePopupState } from 'material-ui-popup-state/hooks'
import Stack from '@mui/material/Stack'
import Box from '@mui/material/Box'
Expand All @@ -28,7 +28,7 @@ export default function BalanceCalculation({ account }) {
}}
variant="subtitle1"
>
{intlFormat(account.cleared)}
{Currency.intlFormat(account.cleared)}
</Typography>
<Typography
variant="caption"
Expand Down Expand Up @@ -63,7 +63,7 @@ export default function BalanceCalculation({ account }) {
}}
variant="subtitle1"
>
{intlFormat(account.uncleared)}
{Currency.intlFormat(account.uncleared)}
</Typography>
<Typography
variant="caption"
Expand Down Expand Up @@ -98,7 +98,7 @@ export default function BalanceCalculation({ account }) {
}}
variant="subtitle1"
>
{intlFormat(account.balance)}
{Currency.intlFormat(account.balance)}
</Typography>
<Typography
variant="caption"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/AddAccountDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useDispatch, useSelector } from 'react-redux'
import MenuItem from '@mui/material/MenuItem'
import { fetchCategories } from '../redux/slices/CategoryGroups'
import { refreshBudget } from '../redux/slices/Budgets'
import { inputToDinero } from '../utils/Currency'
import { Currency } from '../utils/Currency'
import { fetchPayees } from '../redux/slices/Payees'

const accountTypes = ['Bank', 'Credit Card', 'Off Budget Account']
Expand Down Expand Up @@ -38,7 +38,7 @@ export default function AddAccountDialog(props) {
createAccount({
name,
accountType,
balance: inputToDinero(balance),
balance: Currency.inputToDinero(balance),
date: new Date(),
}),
)
Expand Down
Loading