[--version|--help|--manual] [--account-width NUM]
[--accounts|--no-accounts] [--payees|--no-payees]
[--tags|--no-tags] [--commodities|--no-commodities]
- [--opening-date DATE] [--default-account STR]
+ [--opening-date DATE]
[--rename-account STR]... [--exclude-account STR]...
=head1 DESCRIPTION
Date must be in the form "YYYY-MM-DD". Defaults to the date of the first transaction.
-=head2 --default-account STR
-
-Specify the account to use for one-sided transactions (if any). Defaults to "Expenses:No Category".
-
-A default account may be necessary because with Ledger all transactions are double-entry.
-
=head2 --rename-account STR
Specifies a mapping for renaming accounts in the output. By default C<homebank2ledger> tries to come
my $homebank = shift;
my $opts = shift || {};
+ my $default_account_income = 'Income:Unknown';
+ my $default_account_expenses = 'Expenses:Unknown';
+
my $ledger = App::HomeBank2Ledger::Ledger->new;
my $transactions = $homebank->sorted_transactions;
$item->{excluded} = 1 if $item->{ledger_name} =~ /$re/;
}
}
+ while (my ($re, $replacement) = each %{$opts->{rename_accounts}}) {
+ $default_account_income =~ s/$re/$replacement/;
+ $default_account_expenses =~ s/$re/$replacement/;
+ }
my $has_initial_balance = grep { $_->{initial} && !$_->{excluded} } @$accounts;
if ($opts->{accounts}) {
my @accounts = map { $_->{ledger_name} } grep { !$_->{excluded} } @$accounts, @$categories;
- push @accounts, $opts->{default_account};
+ push @accounts, $default_account_income, $default_account_expenses;
push @accounts, $OPENING_BALANCES_ACCOUNT if $has_initial_balance;
$ledger->add_accounts(@accounts);
my @categories = split(/\|\|/, $transaction->{split_category} || '');
for (my $i = 0; $amounts[$i]; ++$i) {
- my $amount = -$amounts[$i];
- my $category = $homebank->find_category_by_key($categories[$i]);
- my $memo = $memos[$i] || '';
- my $other_account = $category ? $category->{ledger_name} : $opts->{default_account};
+ my $amount = -$amounts[$i];
+ my $category = $homebank->find_category_by_key($categories[$i]);
+ my $memo = $memos[$i] || '';
+ my $other_account = $category ? $category->{ledger_name}
+ : $amount < 0 ? $default_account_income
+ : $default_account_expenses;
push @postings, {
account => $other_account,
}
}
else { # with or without category
- my $category = $homebank->find_category_by_key($transaction->{category});
- my $other_account = $category ? $category->{ledger_name} : $opts->{default_account};
+ my $amount = -$transaction->{amount};
+ my $category = $homebank->find_category_by_key($transaction->{category});
+ my $other_account = $category ? $category->{ledger_name}
+ : $amount < 0 ? $default_account_income
+ : $default_account_expenses;
+
push @postings, {
account => $other_account,
commodity => $commodities{$account->{currency}},
- amount => -$transaction->{amount},
+ amount => $amount,
payee => $payee->{name},
memo => $memo,
status => $status,
tags => 1,
commodities => 1,
opening_date => '',
- default_account => 'Expenses:No Category',
rename_accounts => {},
exclude_accounts => [],
);
'tags!' => \$opts{tags},
'commodities!' => \$opts{commodities},
'opening-date=s' => \$opts{opening_date},
- 'default-account=s' => \$opts{default_account},
'rename-account|r=s' => \%{$opts{rename_accounts}},
'exclude-account|x=s' => \@{$opts{exclude_accounts}},
) or pod2usage(-exitval => 1, -verbose => 99, -sections => [qw(SYNOPSIS OPTIONS)]);