From 5b2846ac67f99d1cc8bc5cd5bec705014196d3c7 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 6 Apr 2015 11:10:32 +0100 Subject: Fix handling of first month’s budget --- src/Command/ConvertCommand.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src') 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; } -- cgit 1.4.1