=cut
+use v5.10.1; # defined-or
use warnings;
use strict;
$memo && " ; $memo",
);
+ my $metadata = $transaction->{metadata} || {};
+ for my $key (sort keys %$metadata) {
+ my $value = $self->_format_string($metadata->{$key});
+ push @out, " ; ${key}: ${value}";
+ }
+
for my $posting (@postings) {
my @line;
push @line, ($posting_status_symbol ? " $posting_status_symbol " : ' ');
push @line, sprintf("\%-${account_width}s", $posting->{account});
push @line, ' ';
- push @line, $self->_format_amount($posting->{amount}, $posting->{commodity}) if defined $posting->{amount};
+ if (defined $posting->{amount}) {
+ push @line, $self->_format_amount($posting->{amount}, $posting->{commodity});
+ if (my $price = $posting->{lot_price}) {
+ my $is_fixed = $posting->{lot_fixed};
+ my $fixed_symbol = $is_fixed ? '=' : '';
+ push @line, " {${fixed_symbol}",
+ $self->_format_amount($price->{amount}, $price->{commodity}),
+ '}';
+ }
+ if (my $lot_date = $posting->{lot_date}) {
+ push @line, " [$posting->{lot_date}]";
+ }
+ if (my $cost = $posting->{total_cost} // $posting->{cost}) {
+ my $is_total = defined $posting->{total_cost};
+ my $cost_symbol = $is_total ? '@@' : '@';
+ push @line, ' ', $cost_symbol, ' ',
+ $self->_format_amount($cost->{amount}, $cost->{commodity});
+ }
+ }
+ if (my $note = $posting->{note}) {
+ $note = $self->_format_string($note);
+ push @line, " ; $note" if $note ne $memo;
+ }
push @out, join('', @line);
+ my $metadata = $posting->{metadata} || {};
+ for my $key (sort keys %$metadata) {
+ my $value = $self->_format_string($metadata->{$key});
+ push @out, " ; ${key}: ${value}";
+ }
+
if (my $posting_payee = $posting->{payee}) {
$posting_payee = $self->_format_string($posting_payee);
push @out, " ; Payee: $posting_payee" if $posting_payee ne $payee;
my $format = "\% .$commodity->{frac}f";
my ($whole, $fraction) = split(/\./, sprintf($format, $amount));
+ $fraction ||= 0;
- my $num = join($commodity->{dchar}, commify($whole, $commodity->{gchar}), $fraction);
+ my $num = commify($whole, $commodity->{gchar});
+ if ($commodity->{frac}) {
+ $num .= $commodity->{dchar} . $fraction;
+ }
my $symbol = $commodity->{symbol};
$symbol = $self->_quote_string($symbol) if $symbol =~ /[0-9\s]/;