App-HomeBank2Ledger

 view release on metacpan or  search on metacpan

lib/App/HomeBank2Ledger/Formatter/Beancount.pm  view on Meta::CPAN

package App::HomeBank2Ledger::Formatter::Beancount;
# ABSTRACT: Beancount formatter


use v5.10.1;    # defined-or
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.010'; # VERSION

my %STATUS_SYMBOLS = (
    cleared => '*',
    pending => '!',
);
my $UNKNOWN_DATE = '0001-01-01';

lib/App/HomeBank2Ledger/Formatter/Beancount.pm  view on Meta::CPAN

        $memo             && ' '.$self->_format_string($memo),
    );

    if (my %tags = map { $_ => 1 } map { @{$_->{tags} || []} } @postings) {
        my @tags = map { "#$_" } keys %tags;
        $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;

        my $posting_status_symbol = '';
        if (!$status_symbol) {
            $posting_status_symbol = $STATUS_SYMBOLS{$posting->{status} || ''} || '';

lib/App/HomeBank2Ledger/Formatter/Beancount.pm  view on Meta::CPAN

                my $cost_symbol = $is_total ? '@@' : '@';
                push @line, ' ', $cost_symbol, ' ',
                            $self->_format_amount($cost->{amount}, $cost->{commodity});
            }
        }

        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, '';

    return @out;
}

lib/File/HomeBank.pm  view on Meta::CPAN

    @transactions = $homebank->find_transactions_by_transfer_key($key);

Find all transactions that share the same transfer key.

=head2 find_transaction_transfer_pair

    $other_transaction = $homebank->find_transaction_transfer_pair($transaction);

Given a transaction hashref, return its corresponding transaction if it is an internal transfer. If
the transaction is an internal transaction with a destination account but is orphaned (has no
matching transfer key), this also looks for another orphaned transaction in the destination account
that it can call its partner.

Returns undef or empty if no corresponding transaction is found.

=head2 sorted_transactions

    $transations = $homebank->sorted_transactions;

Get an arrayref of transactions sorted by date (oldest first).



( run in 0.451 second using v1.01-cache-2.11-cpan-64827b87656 )