about summary refs log tree commit diff stats
path: root/src/Command/ConvertCommand.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Command/ConvertCommand.php')
-rw-r--r--src/Command/ConvertCommand.php31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/Command/ConvertCommand.php b/src/Command/ConvertCommand.php
index 21f0a03..2d87015 100644
--- a/src/Command/ConvertCommand.php
+++ b/src/Command/ConvertCommand.php
@@ -251,22 +251,27 @@ function multiRead (SplFileObject $budgetFile, SplFileObject $registerFile, Numb
     $budget = readBudget($budgetFile);
     $register = readRegister($registerFile, $fmt);
     $budget->rewind();
+    $openDate;
     foreach ($register as $rTxn) {
-        if ($rTxn->payee !== 'Starting Balance' &&
-            $rTxn->category[1] !== 'Available this month') {
-            if ($budget->valid()) {
-                $bTxn = $budget->current();
-                $bDate = $bTxn->date;
-                if ($bTxn->date < $rTxn->date) {
-                    do {
-                        $bTxn->date = $rTxn->date;
-                        yield $bTxn;
-
-                        $budget->next();
-                        $bTxn = $budget->current();
-                    } while ($bTxn->date == $bDate);
+        if ($openDate !== null) {
+            if ($rTxn->payee !== 'Starting Balance' &&
+                $rTxn->category[1] !== 'Available this month') {
+                if ($budget->valid()) {
+                    $bTxn = $budget->current();
+                    $bDate = $bTxn->date;
+                    if ($bTxn->date < $rTxn->date) {
+                        do {
+                            $bTxn->date = $openDate;
+                            yield $bTxn;
+
+                            $budget->next();
+                            $bTxn = $budget->current();
+                        } while ($bTxn->date == $bDate);
+                    }
                 }
             }
+        } elseif ($rTxn->payee === 'Starting Balance') {
+            $openDate = $rTxn->date;
         }
         yield $rTxn;
     }