all repos — archive/ynab-ledger @ 5b2846ac67f99d1cc8bc5cd5bec705014196d3c7

Convert exported YNAB data to ledger-cli

Fix handling of first month’s budget

Alan Pearce
commit

5b2846ac67f99d1cc8bc5cd5bec705014196d3c7

parent

2d371fdd6b9d805e7d7b35f53c3c626fa1408740

1 file changed, 17 insertions(+), 12 deletions(-)

jump to
M src/Command/ConvertCommand.phpsrc/Command/ConvertCommand.php
@@ -251,22 +251,27 @@ function multiRead (SplFileObject $budgetFile, SplFileObject $registerFile, NumberFormatter $fmt) {
$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; + 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); + $budget->next(); + $bTxn = $budget->current(); + } while ($bTxn->date == $bDate); + } } } + } elseif ($rTxn->payee === 'Starting Balance') { + $openDate = $rTxn->date; } yield $rTxn; }