Skip to content

Commit

Permalink
5. Transactions page
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Oct 10, 2024
1 parent 90c7871 commit 9299d6b
Show file tree
Hide file tree
Showing 9 changed files with 711 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ const FinancialAccounts = (): ReactElement => {
/>
) : panelOpen === Panel.Filters ? (
<DynamicFilterPanel
filters={[] as FilterPanelGroupFragment[]}
filters={filterGroups as FilterPanelGroupFragment[]}
defaultExpandedFilterGroups={
new Set(['Transaction Date', 'Category'])
}
savedFilters={[]}
selectedFilters={activeFilters as FilterInput}
onClose={() => setPanelOpen(null)}
Expand Down
6 changes: 6 additions & 0 deletions pages/api/Schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import { ExpectedMonthlyTotalReportResolvers } from './reports/expectedMonthlyTo
import FinancialAccountsTypeDefs from './reports/financialAccounts/financialAccounts.graphql';
import FinancialAccountSummaryTypeDefs from './reports/financialAccounts/financialAccounts/financialAccounts.graphql';
import { FinancialAccountSummaryResolvers } from './reports/financialAccounts/financialAccounts/resolvers';
import FinancialAccountEntriesTypeDefs from './reports/financialAccounts/financialEntries/financialEntries.graphql';
import { financialAccountEntriesResolvers } from './reports/financialAccounts/financialEntries/resolvers';
import { FinancialAccountsResolvers } from './reports/financialAccounts/resolvers';
import FourteenMonthReportTypeDefs from './reports/fourteenMonth/fourteenMonth.graphql';
import { FourteenMonthReportResolvers } from './reports/fourteenMonth/resolvers';
Expand Down Expand Up @@ -133,6 +135,10 @@ const schema = buildSubgraphSchema([
typeDefs: FinancialAccountSummaryTypeDefs,
resolvers: FinancialAccountSummaryResolvers,
},
{
typeDefs: FinancialAccountEntriesTypeDefs,
resolvers: financialAccountEntriesResolvers,
},
...integrationSchema,
...organizationSchema,
...preferencesSchema,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
FinancialAccountEntry,
FinancialAccountMetaData,
} from 'src/graphql/types.generated';
import { fetchAllData } from 'src/lib/deserializeJsonApi';
import { snakeToCamel } from 'src/lib/snakeToCamel';
import { FinancialAccountEntriesResponse } from '../../../../graphql-rest.page.generated';

export interface FinancialAccountEntriesRest {
id: string;
attributes: {
amount: string;
code: string;
currency: string;
description: string;
entry_date: string;
type: string;
};
relationships: {
category: { data: IdType[] };
};
}

export interface FinancialAccountMetaRest {
id: string;
pagination: {
page: string;
per_page: number;
total_count: number;
total_pages: number;
};
sort: string;
filter: string;
credits: string;
debits: string;
difference: string;
currency: string;
closing_balance: string;
opening_balance: string;
}

interface IdType {
id: string;
type: string;
}

export const financialAccountEntriesHandler = ({
data,
included,
meta,
}: {
data: FinancialAccountEntriesRest[];
included: unknown[];
meta: FinancialAccountMetaRest;
}): FinancialAccountEntriesResponse => {
const entries = data.map((item) => {
return fetchAllData(item, included);
}) as FinancialAccountEntry[];

// Remove pagination as it's not needed since we get all transactions
const metaData = {} as FinancialAccountMetaData;
Object.keys(meta).forEach((key) => {
if (key === 'pagination') {
return;
}
metaData[snakeToCamel(key)] = meta[key];
});

return {
entries,
metaData,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
extend type Query {
financialAccountEntries(
input: FinancialAccountEntriesInput!
): FinancialAccountEntriesResponse!
}

input FinancialAccountEntriesInput {
accountListId: ID!
financialAccountId: ID!
dateRange: String!
categoryId: ID
wildcardSearch: String
}

type FinancialAccountEntriesResponse {
entries: [FinancialAccountEntry!]!
metaData: FinancialAccountMetaData!
}

type FinancialAccountEntry {
id: ID!
amount: String!
currency: String!
code: String!
description: String!
entryDate: ISO8601Date!
type: String!
category: FinancialAccountCategory!
}

type FinancialAccountMetaData {
sort: String
filter: String
credits: String
debits: String
difference: String
currency: String
closingBalance: String
openingBalance: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Resolvers } from '../../../../graphql-rest.page.generated';

export const financialAccountEntriesResolvers: Resolvers = {
Query: {
financialAccountEntries: (
_source,
{
input: {
accountListId,
financialAccountId,
dateRange,
categoryId,
wildcardSearch,
},
},
{ dataSources },
) => {
return dataSources.mpdxRestApi.financialAccountEntries(
accountListId,
financialAccountId,
dateRange,
categoryId,
wildcardSearch,
);
},
},
};
25 changes: 25 additions & 0 deletions pages/api/graphql-rest.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ import {
setActiveFinancialAccount,
} from './Schema/reports/financialAccounts/datahandler';
import { financialAccountSummaryHandler } from './Schema/reports/financialAccounts/financialAccounts/datahandler';
import { financialAccountEntriesHandler } from './Schema/reports/financialAccounts/financialEntries/datahandler';
import {
FourteenMonthReportResponse,
mapFourteenMonthReport,
Expand Down Expand Up @@ -779,6 +780,30 @@ class MpdxRestApi extends RESTDataSource {

return financialAccountSummaryHandler(data);
}

async financialAccountEntries(
accountListId: string,
financialAccountId: string,
dateRange: string,
categoryId?: string | null,
wildcardSearch?: string | null,
) {
const fields =
'fields[financial_account_entry_categories]=name,code&fields[financial_account_entry_credits]=amount,code,currency,description,entry_date,category,type' +
'&fields[financial_account_entry_debits]=amount,code,currency,description,entry_date,category,type';

let filters = `filter[entryDate]=${dateRange}&filter[financialAccountId]=${financialAccountId}`;
if (categoryId) {
filters += `&filter[categoryId]=${categoryId}`;
}
if (wildcardSearch) {
filters += `&filter[wildcardSearch]=${wildcardSearch}`;
}
const data = await this.get(
`account_lists/${accountListId}/entries?${fields}&${filters}&include=category&per_page=10000&sort=entry_date`,
);

return financialAccountEntriesHandler(data);
}

async getEntryHistories(
Expand Down
Loading

0 comments on commit 9299d6b

Please sign in to comment.