X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FApp%2FHomeBank2Ledger%2FFormatter%2FBeancount.pm;h=85810b03b231e59b40fe654a3407c4a9d50ddf46;hb=b980f9a0c4ed7902a2c57657d5971c13333f13ca;hp=2ec6a2c89437bc4b40b39909cce98356ecc12906;hpb=7e41aec36980b1a053b9e54cfd6119a38dd819a3;p=chaz%2Fhomebank2ledger diff --git a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm index 2ec6a2c..85810b0 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm @@ -7,10 +7,11 @@ use warnings; use strict; use App::HomeBank2Ledger::Util qw(commify rtrim); +use Scalar::Util qw(looks_like_number); use parent 'App::HomeBank2Ledger::Formatter'; -our $VERSION = '0.005'; # VERSION +our $VERSION = '0.007'; # VERSION my %STATUS_SYMBOLS = ( cleared => '*', @@ -142,6 +143,13 @@ sub _format_transaction { $out[-1] .= ' '.join(' ', @tags); } + my $metadata = $transaction->{metadata} || {}; + for my $key (sort keys %$metadata) { + my $value = looks_like_number($metadata->{$key}) ? $metadata->{$key} + : $self->_format_string($metadata->{$key}); + push @out, " ; ${key}: ${value}"; + } + for my $posting (@postings) { my @line; @@ -178,6 +186,13 @@ sub _format_transaction { } push @out, join('', @line); + + my $metadata = $posting->{metadata} || {}; + for my $key (sort keys %$metadata) { + my $value = looks_like_number($metadata->{$key}) ? $metadata->{$key} + : $self->_format_string($metadata->{$key}); + push @out, " ; ${key}: ${value}"; + } } push @out, ''; @@ -208,9 +223,13 @@ sub _format_amount { my $format = "\% .$commodity->{frac}f"; my ($whole, $fraction) = split(/\./, sprintf($format, $amount)); + $fraction ||= 0; # beancount doesn't support different notations - my $num = join('.', commify($whole), $fraction); + my $num = commify($whole); + if ($commodity->{frac}) { + $num .= ".$fraction"; + } $num = "$num $commodity->{iso}"; @@ -282,7 +301,7 @@ App::HomeBank2Ledger::Formatter::Beancount - Beancount formatter =head1 VERSION -version 0.005 +version 0.007 =head1 DESCRIPTION