]> Dogcows Code - chaz/homebank2ledger/blobdiff - lib/App/HomeBank2Ledger/Formatter/Ledger.pm
add formatting of transactions with lot specifiers
[chaz/homebank2ledger] / lib / App / HomeBank2Ledger / Formatter / Ledger.pm
index 3a5a71379b6d6941f58c70e47793ed1e9c43c718..8f05441599b790ce4f30a2edd294f9153de08556 100644 (file)
@@ -11,6 +11,7 @@ L<App::HomeBank2Ledger::Formatter>
 
 =cut
 
+use v5.10.1;    # defined-or
 use warnings;
 use strict;
 
@@ -244,7 +245,29 @@ sub _format_transaction {
         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);
 
This page took 0.01809 seconds and 4 git commands to generate.