all repos — archive/ynab-ledger @ 20795d700243603c1dc7c378c82189469845e961

Convert exported YNAB data to ledger-cli

Fix transaction sorting

Alan Pearce
commit

20795d700243603c1dc7c378c82189469845e961

parent

14efbeb7469091725791458a8282c3bc884ca28e

1 file changed, 6 insertions(+), 5 deletions(-)

jump to
M src/Command/ConvertCommand.phpsrc/Command/ConvertCommand.php
@@ -244,14 +244,15 @@ $txn->line = $i;
$txns[] = $txn; } - // Sort by date, group splits, promote income and fall back on line in file + // Sort by date, promote transfers, group splits, promote income and fall back on line in file usort($txns, function ($a, $b) use ($convertDate) { return strcmp($a->date->format('U'), $b->date->format('U')) - ?: ((in_array('Split', [substr($a->memo, 1, 5), substr($b->memo, 1, 5)]) ? - strcmp($a->memo, $b->memo) : false) - ?: ($b->out > 0.01 // Include empty starting balance transactions - ? 0 : $a->line - $b->line)); + ?: ($a->out < 0.01 ? -1 + : (strpos($b->payee, 'Transfer : ') !== false ? 1 + : ((in_array('Split', [substr($a->memo, 1, 5), substr($b->memo, 1, 5)]) ? + strcmp($a->memo, $b->memo) + : $a->line - $b->line)))); } ); foreach ($txns as $txn) yield $txn;