diff options
-rw-r--r-- | src/Command/ConvertCommand.php | 31 |
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; } |