about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2015-04-07 14:22:03 +0100
committerAlan Pearce2015-04-07 14:22:03 +0100
commit20795d700243603c1dc7c378c82189469845e961 (patch)
tree3a973ce3bb4782654b089efde094145d7c94059a
parent14efbeb7469091725791458a8282c3bc884ca28e (diff)
downloadynab-ledger-20795d700243603c1dc7c378c82189469845e961.tar.lz
ynab-ledger-20795d700243603c1dc7c378c82189469845e961.tar.zst
ynab-ledger-20795d700243603c1dc7c378c82189469845e961.zip
Fix transaction sorting
-rw-r--r--src/Command/ConvertCommand.php11
1 files changed, 6 insertions, 5 deletions
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;