From c8eb7cd9bfa92d06510c0d9797d4cfd0f181e5d2 Mon Sep 17 00:00:00 2001 From: ewandor Date: Mon, 17 Feb 2025 21:00:19 +0100 Subject: [PATCH] Adding first draft of ledger component --- gui/app/src/App.tsx | 2 + gui/app/src/pages/accounts/ledger.tsx | 70 +++++++++++++++++++++++++++ gui/app/src/pages/accounts/list.tsx | 7 ++- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 gui/app/src/pages/accounts/ledger.tsx diff --git a/gui/app/src/App.tsx b/gui/app/src/App.tsx index f9ddabf..1e3ddd2 100644 --- a/gui/app/src/App.tsx +++ b/gui/app/src/App.tsx @@ -28,6 +28,7 @@ import { AccountList, AccountCreate, AccountEdit } from "./pages/accounts"; import { CategoryList, CategoryCreate, CategoryEdit } from "./pages/categories"; import { PayeeCreate, PayeeEdit, PayeeList } from "./pages/payees"; import { TransactionCreate, TransactionEdit, TransactionList } from "./pages/transactions"; +import {AccountLedger} from "./pages/accounts/ledger"; /** * mock auth credentials to simulate authentication @@ -135,6 +136,7 @@ const App: React.FC = () => { } /> } /> } /> + } /> } /> diff --git a/gui/app/src/pages/accounts/ledger.tsx b/gui/app/src/pages/accounts/ledger.tsx new file mode 100644 index 0000000..b17d17e --- /dev/null +++ b/gui/app/src/pages/accounts/ledger.tsx @@ -0,0 +1,70 @@ +import React from "react"; + +import Table from '@mui/material/Table'; +import TableBody from '@mui/material/TableBody'; +import TableCell from '@mui/material/TableCell'; +import TableContainer from '@mui/material/TableContainer'; +import TableHead from '@mui/material/TableHead'; +import TableRow from '@mui/material/TableRow'; +import Paper from '@mui/material/Paper'; + + +import { useParams } from "react-router"; +import {useList, useOne} from "@refinedev/core"; + + + +export const AccountLedger: React.FC = () => { + const { id } = useParams() + + const { data, isLoading, isError } = useOne({ + resource: `ledgers`, + id: id + }); + if (isLoading) { + return
Loading
+ } + return ( + + + + + + Date + Deposit + Payment + Balance + + + + {data?.data.map((row: any) => { + const is_expense: boolean = row.account_split.amount < 0 + const destination_accounts = [] + for (const split of row.transaction.splits) { + if ((is_expense && split.amount >= 0) || (!is_expense && split.amount < 0)) { + destination_accounts.push(split) + } + } + let is_split = false; + if (destination_accounts) { + if (destination_accounts.length > 1) { + is_split = true; + } + } + return( + + + {row.transaction.transaction_date} + { is_expense ? "" : row.account_split.amount } + { is_expense ? row.account_split.amount : "" } + { row.balance } + ) + })} + +
+
+ ); +} \ No newline at end of file diff --git a/gui/app/src/pages/accounts/list.tsx b/gui/app/src/pages/accounts/list.tsx index fe7051b..b882449 100644 --- a/gui/app/src/pages/accounts/list.tsx +++ b/gui/app/src/pages/accounts/list.tsx @@ -1,7 +1,8 @@ import React from "react"; -import { ButtonGroup } from "@mui/material"; +import { Button, ButtonGroup } from "@mui/material"; import { DataGrid, type GridColDef } from "@mui/x-data-grid"; +import RequestQuoteIcon from '@mui/icons-material/RequestQuote'; import { DeleteButton, EditButton, List, useDataGrid} from "@refinedev/mui"; @@ -15,7 +16,7 @@ export const AccountList: React.FC = () => { { field: "id", headerName: "ID" }, { field: "name", headerName: "Name", flex: 1 }, { field: "path", headerName: "path", flex: 1 }, - { field: "type", headerName: "Type", flex: 0.3 }, + { field: "type", headerName: "Type", flex: 1 }, { field: "actions", headerName: "Actions", @@ -23,6 +24,7 @@ export const AccountList: React.FC = () => { renderCell: function render({ row }) { return ( + @@ -30,6 +32,7 @@ export const AccountList: React.FC = () => { }, align: "center", headerAlign: "center", + flex: 1, }, ], [],