From 20795d700243603c1dc7c378c82189469845e961 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Tue, 7 Apr 2015 14:22:03 +0100 Subject: Fix transaction sorting --- src/Command/ConvertCommand.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/Command') diff --git a/src/Command/ConvertCommand.php b/src/Command/ConvertCommand.php index 306e9b4..c365a15 100644 --- a/src/Command/ConvertCommand.php +++ b/src/Command/ConvertCommand.php @@ -244,14 +244,15 @@ function readRegister (SplFileObject $registerFile, NumberFormatter $fmt) { $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; -- cgit 1.4.1