]> Dogcows Code - chaz/homebank2ledger/blobdiff - lib/App/HomeBank2Ledger/Formatter/Ledger.pm
fix formatting non-fraction amounts
[chaz/homebank2ledger] / lib / App / HomeBank2Ledger / Formatter / Ledger.pm
index 8f05441599b790ce4f30a2edd294f9153de08556..300a83281788f040c52f751551b77cf0bb4ea3a9 100644 (file)
@@ -234,6 +234,12 @@ sub _format_transaction {
         $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;
 
@@ -271,6 +277,12 @@ sub _format_transaction {
 
         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;
@@ -307,8 +319,12 @@ sub _format_amount {
 
     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]/;
This page took 0.016901 seconds and 4 git commands to generate.