Skip to content
Snippets Groups Projects
Unverified Commit 12f91f7d authored by wdpk's avatar wdpk Committed by GitHub
Browse files

update split transaction handling for csv export (#2973)


* Split transaction handling for csv export (#2973)

* refactor, zero-amt parents and add split_amount

change how child/parents are counted to remove dependence on `sort_order` being negative. for export, give parent transactions a 0 in the `amount` column, but add a new column with their `split_amount` for other programs to possibly import

---------

Co-authored-by: default avatarZeus\Herb <herb@win.dows>
Co-authored-by: default avatarDJ Mountney <david.mountney@twkie.net>
parent f75d0f80
No related branches found
No related tags found
No related merge requests found
...@@ -66,6 +66,8 @@ export async function exportQueryToCSV(query) { ...@@ -66,6 +66,8 @@ export async function exportQueryToCSV(query) {
{ Payee: 'payee.name' }, { Payee: 'payee.name' },
{ ParentId: 'parent_id' }, { ParentId: 'parent_id' },
{ IsParent: 'is_parent' }, { IsParent: 'is_parent' },
{ IsChild: 'is_child' },
{ SortOrder: 'sort_order' },
{ Notes: 'notes' }, { Notes: 'notes' },
{ Category: 'category.name' }, { Category: 'category.name' },
{ Amount: 'amount' }, { Amount: 'amount' },
...@@ -75,25 +77,46 @@ export async function exportQueryToCSV(query) { ...@@ -75,25 +77,46 @@ export async function exportQueryToCSV(query) {
.options({ splits: 'all' }), .options({ splits: 'all' }),
); );
const parentsPayees = new Map(); // initialize a map to allow splits to have correct number of split from
const parentsChildCount: Map<number, number> = new Map();
const childSplitOrder: Map<number, number> = new Map();
// find children, their order, and total # siblings
for (const trans of transactions) { for (const trans of transactions) {
if (trans.IsParent) { if (trans.IsChild) {
parentsPayees.set(trans.Id, trans.Payee); let childNumber = parentsChildCount.get(trans.ParentId) || 0;
childNumber++;
childSplitOrder.set(trans.Id, childNumber);
parentsChildCount.set(trans.ParentId, childNumber);
} }
} }
// filter out any parent transactions // map final properties for export and grab the child count for splits from their parent transaction
const noParents = transactions.filter(t => !t.IsParent); const transactionsForExport = transactions.map(trans => {
// map final properties for export and grab the payee for splits from their parent transaction
const transactionsForExport = noParents.map(trans => {
return { return {
Account: trans.Account, Account: trans.Account,
Date: trans.Date, Date: trans.Date,
Payee: trans.ParentId ? parentsPayees.get(trans.ParentId) : trans.Payee, Payee: trans.Payee,
Notes: trans.Notes, Notes: trans.IsParent
? '(SPLIT INTO ' +
parentsChildCount.get(trans.Id) +
') ' +
(trans.Notes || '')
: trans.IsChild
? '(SPLIT ' +
childSplitOrder.get(trans.Id) +
' OF ' +
parentsChildCount.get(trans.ParentId) +
') ' +
(trans.Notes || '')
: trans.Notes,
Category: trans.Category, Category: trans.Category,
Amount: trans.Amount == null ? 0 : integerToAmount(trans.Amount), Amount: trans.IsParent
? 0
: trans.Amount == null
? 0
: integerToAmount(trans.Amount),
Split_Amount: trans.IsParent ? integerToAmount(trans.Amount) : 0,
Cleared: Cleared:
trans.Reconciled === true trans.Reconciled === true
? 'Reconciled' ? 'Reconciled'
......
---
category: Bugfix
authors: [wdpk]
---
Fix exporting split transactions to CSV by including top-line transactions and noting the split.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment