X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fhomebank2ledger;a=blobdiff_plain;f=lib%2FApp%2FHomeBank2Ledger.pm;h=0aa1562a3833c52984e1fcf5d23d2c3b6075cd02;hp=8b29dee923bf25ace43fa4bd9250e5b156dcf004;hb=HEAD;hpb=1290bb7c0ee4c8fa6f962712b43207a0323b18a1 diff --git a/lib/App/HomeBank2Ledger.pm b/lib/App/HomeBank2Ledger.pm index 8b29dee..0aa1562 100644 --- a/lib/App/HomeBank2Ledger.pm +++ b/lib/App/HomeBank2Ledger.pm @@ -291,24 +291,27 @@ sub convert_homebank_to_ledger { my $account = $homebank->find_account_by_key($transaction->{account}); my $amount = $transaction->{amount}; my $status = $STATUS_SYMBOLS{$transaction->{status} || ''} || ''; - my $paymode = $transaction->{paymode} || ''; # internaltransfer my $memo = $transaction->{wording} || ''; my $payee = $homebank->find_payee_by_key($transaction->{payee}); my $tags = _split_tags($transaction->{tags}); + my $date = $transaction->{date}; + my $code = $transaction->{paymode} =~ /^(?:check|epayment)$/ ? $transaction->{info} + : undef; my @postings; push @postings, { + date => $date, account => $account->{ledger_name}, amount => $amount, commodity => $commodities{$account->{currency}}, payee => $payee->{name}, - memo => $memo, + note => $memo, status => $status, tags => $tags, }; - if ($paymode eq 'internaltransfer') { + if ($transaction->{dst_account}) { # is an internal transfer my $paired_transaction = $homebank->find_transaction_transfer_pair($transaction); my $dst_account = $homebank->find_account_by_key($transaction->{dst_account}); @@ -325,14 +328,16 @@ sub convert_homebank_to_ledger { $seen{$transaction->{transfer_key}}++ if $transaction->{transfer_key}; $seen{$paired_transaction->{transfer_key}}++ if $paired_transaction->{transfer_key}; + my $paired_date = $paired_transaction && $paired_transaction->{date}; my $paired_payee = $homebank->find_payee_by_key($paired_transaction->{payee}); push @postings, { + date => $paired_date, account => $dst_account->{ledger_name}, amount => $paired_transaction->{amount} || -$transaction->{amount}, commodity => $commodities{$dst_account->{currency}}, payee => $paired_payee->{name}, - memo => $paired_transaction->{wording} || '', + note => $paired_transaction->{wording} || '', status => $STATUS_SYMBOLS{$paired_transaction->{status} || ''} || $status, tags => _split_tags($paired_transaction->{tags}), }; @@ -355,13 +360,13 @@ sub convert_homebank_to_ledger { commodity => $commodities{$account->{currency}}, amount => $amount, payee => $payee->{name}, - memo => $memo, + note => $memo, status => $status, tags => $tags, }; } } - else { # with or without category + else { # normal transaction with or without category my $amount = -$transaction->{amount}; my $category = $homebank->find_category_by_key($transaction->{category}); my $other_account = $category ? $category->{ledger_name} @@ -373,7 +378,7 @@ sub convert_homebank_to_ledger { commodity => $commodities{$account->{currency}}, amount => $amount, payee => $payee->{name}, - memo => $memo, + note => $memo, status => $status, tags => $tags, }; @@ -387,8 +392,9 @@ sub convert_homebank_to_ledger { } $ledger->add_transactions({ - date => $transaction->{date}, + date => $date, payee => $payee->{name}, + code => $code, memo => $memo, postings => \@postings, });