From: Charles McGarvey Date: Sat, 17 Aug 2019 22:26:56 +0000 (-0600) Subject: Version 0.005 X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=7e41aec36980b1a053b9e54cfd6119a38dd819a3;p=chaz%2Fhomebank2ledger Version 0.005 --- diff --git a/Changes b/Changes index 24f288f..3a74157 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,13 @@ Revision history for App-HomeBank2Ledger. +0.005 2019-08-17 16:26:33-06:00 MST7MDT + * Add --budget option for converting HomeBank budget to Ledger. + * Support quoting commodities when needed. + * The formatter now adds posting notes when they differ from the transaction + memo and avoids printing posting payees if not different from the + transaction payee. + * Fix bug which could add duplicate ":Unknown" accounts. + 0.004 2019-06-17 23:28:10-06:00 MST7MDT * Remove --default-account option. Instead the default account(s) can be customized using the --rename-account option, like this: diff --git a/META.json b/META.json index 277ec80..15836ee 100644 --- a/META.json +++ b/META.json @@ -63,6 +63,7 @@ "XML::Entities" : "0", "XML::Parser::Lite" : "0", "parent" : "0", + "perl" : "v5.10.1", "strict" : "0", "warnings" : "0" } @@ -76,39 +77,38 @@ "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", - "Test::More" : "0", - "perl" : "5.006" + "Test::More" : "0" } } }, "provides" : { "App::HomeBank2Ledger" : { "file" : "lib/App/HomeBank2Ledger.pm", - "version" : "0.004" + "version" : "0.005" }, "App::HomeBank2Ledger::Formatter" : { "file" : "lib/App/HomeBank2Ledger/Formatter.pm", - "version" : "0.004" + "version" : "0.005" }, "App::HomeBank2Ledger::Formatter::Beancount" : { "file" : "lib/App/HomeBank2Ledger/Formatter/Beancount.pm", - "version" : "0.004" + "version" : "0.005" }, "App::HomeBank2Ledger::Formatter::Ledger" : { "file" : "lib/App/HomeBank2Ledger/Formatter/Ledger.pm", - "version" : "0.004" + "version" : "0.005" }, "App::HomeBank2Ledger::Ledger" : { "file" : "lib/App/HomeBank2Ledger/Ledger.pm", - "version" : "0.004" + "version" : "0.005" }, "App::HomeBank2Ledger::Util" : { "file" : "lib/App/HomeBank2Ledger/Util.pm", - "version" : "0.004" + "version" : "0.005" }, "File::HomeBank" : { "file" : "lib/File/HomeBank.pm", - "version" : "0.004" + "version" : "0.005" } }, "release_status" : "stable", @@ -123,7 +123,7 @@ "web" : "https://github.com/chazmcgarvey/homebank2ledger" } }, - "version" : "0.004", + "version" : "0.005", "x_authority" : "cpan:CCM", "x_generated_by_perl" : "v5.28.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.08" diff --git a/META.yml b/META.yml index 863d993..cc85c06 100644 --- a/META.yml +++ b/META.yml @@ -8,7 +8,6 @@ build_requires: IO::Handle: '0' IPC::Open3: '0' Test::More: '0' - perl: '5.006' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 @@ -28,25 +27,25 @@ no_index: provides: App::HomeBank2Ledger: file: lib/App/HomeBank2Ledger.pm - version: '0.004' + version: '0.005' App::HomeBank2Ledger::Formatter: file: lib/App/HomeBank2Ledger/Formatter.pm - version: '0.004' + version: '0.005' App::HomeBank2Ledger::Formatter::Beancount: file: lib/App/HomeBank2Ledger/Formatter/Beancount.pm - version: '0.004' + version: '0.005' App::HomeBank2Ledger::Formatter::Ledger: file: lib/App/HomeBank2Ledger/Formatter/Ledger.pm - version: '0.004' + version: '0.005' App::HomeBank2Ledger::Ledger: file: lib/App/HomeBank2Ledger/Ledger.pm - version: '0.004' + version: '0.005' App::HomeBank2Ledger::Util: file: lib/App/HomeBank2Ledger/Util.pm - version: '0.004' + version: '0.005' File::HomeBank: file: lib/File/HomeBank.pm - version: '0.004' + version: '0.005' requires: Carp: '0' Exporter: '0' @@ -59,13 +58,14 @@ requires: XML::Entities: '0' XML::Parser::Lite: '0' parent: '0' + perl: v5.10.1 strict: '0' warnings: '0' resources: bugtracker: https://github.com/chazmcgarvey/homebank2ledger/issues homepage: https://github.com/chazmcgarvey/homebank2ledger repository: https://github.com/chazmcgarvey/homebank2ledger.git -version: '0.004' +version: '0.005' x_authority: cpan:CCM x_generated_by_perl: v5.28.0 x_serialization_backend: 'YAML::Tiny version 1.73' diff --git a/Makefile.PL b/Makefile.PL index 115a98f..83b1aa4 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -2,7 +2,7 @@ use strict; use warnings; -use 5.006; +use 5.010001; use ExtUtils::MakeMaker; @@ -17,7 +17,7 @@ my %WriteMakefileArgs = ( "bin/homebank2ledger" ], "LICENSE" => "mit", - "MIN_PERL_VERSION" => "5.006", + "MIN_PERL_VERSION" => "5.010001", "NAME" => "App::HomeBank2Ledger", "PREREQ_PM" => { "Carp" => 0, @@ -41,7 +41,7 @@ my %WriteMakefileArgs = ( "IPC::Open3" => 0, "Test::More" => 0 }, - "VERSION" => "0.004", + "VERSION" => "0.005", "test" => { "TESTS" => "t/*.t" } diff --git a/README b/README index 8ee3673..2209329 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ NAME VERSION - version 0.004 + version 0.005 SYNOPSIS @@ -131,6 +131,15 @@ OPTIONS Defaults to enabled; use --no-commodities to disable. + --budget + + Enables budget transactions. + + Budget transactions are only supported by the Ledger format (for now). + This option is silently ignored otherwise. + + Defaults to enabled; use --no-budget to disable. + --opening-date DATE Specify the opening date for the "opening balances" transaction. This @@ -224,7 +233,7 @@ CAVEATS * I didn't intend to make this a releasable robust product, so it's lacking tests. - * Budgets and scheduled transactions are not (yet) converted. + * Scheduled transactions are not (yet) converted. * There are some minor formatting tweaks I will make (e.g. consolidate transaction tags and payees) diff --git a/bin/homebank2ledger b/bin/homebank2ledger index bc5b007..933243f 100644 --- a/bin/homebank2ledger +++ b/bin/homebank2ledger @@ -8,7 +8,7 @@ use strict; use App::HomeBank2Ledger; -our $VERSION = '0.004'; # VERSION +our $VERSION = '0.005'; # VERSION App::HomeBank2Ledger->main(@ARGV); @@ -24,7 +24,7 @@ homebank2ledger - A tool to convert HomeBank files to Ledger format =head1 VERSION -version 0.004 +version 0.005 =head1 SYNOPSIS @@ -160,6 +160,15 @@ Enables commodity declarations. Defaults to enabled; use C<--no-commodities> to disable. +=head2 --budget + +Enables budget transactions. + +Budget transactions are only supported by the Ledger format (for now). This option is silently +ignored otherwise. + +Defaults to enabled; use C<--no-budget> to disable. + =head2 --opening-date DATE Specify the opening date for the "opening balances" transaction. This transaction is created (if @@ -265,7 +274,7 @@ I didn't intend to make this a releasable robust product, so it's lacking tests. =item * -Budgets and scheduled transactions are not (yet) converted. +Scheduled transactions are not (yet) converted. =item * diff --git a/lib/App/HomeBank2Ledger.pm b/lib/App/HomeBank2Ledger.pm index 5a61f7d..9d6ce60 100644 --- a/lib/App/HomeBank2Ledger.pm +++ b/lib/App/HomeBank2Ledger.pm @@ -2,7 +2,7 @@ package App::HomeBank2Ledger; # ABSTRACT: A tool to convert HomeBank files to Ledger format -use warnings FATAL => 'all'; # temp fatal all +use warnings; use strict; use App::HomeBank2Ledger::Formatter; @@ -11,7 +11,7 @@ use File::HomeBank; use Getopt::Long 2.38 qw(GetOptionsFromArray); use Pod::Usage; -our $VERSION = '0.004'; # VERSION +our $VERSION = '0.005'; # VERSION my %ACCOUNT_TYPES = ( # map HomeBank account types to Ledger accounts bank => 'Assets:Bank', @@ -101,6 +101,7 @@ sub convert_homebank_to_ledger { my $transactions = $homebank->sorted_transactions; my $accounts = $homebank->accounts; my $categories = $homebank->categories; + my @budget; # determine full Ledger account names for my $account (@$accounts) { @@ -111,6 +112,15 @@ sub convert_homebank_to_ledger { my $type = $category->{flags}{income} ? 'Income' : 'Expenses'; my $full_name = $homebank->full_category_name($category->{key}); $category->{ledger_name} = "${type}:${full_name}"; + + if ($opts->{budget} && $category->{flags}{budget}) { + for my $month_num ($category->{flags}{custom} ? (1 .. 12) : 0) { + my $amount = $category->{budget_amounts}[$month_num] || 0; + next if !$amount && !$category->{flags}{forced}; + + $budget[$month_num]{$category->{ledger_name}} = $amount; + } + } } # handle renaming and marking excluded accounts @@ -132,7 +142,8 @@ sub convert_homebank_to_ledger { if ($opts->{accounts}) { my @accounts = map { $_->{ledger_name} } grep { !$_->{excluded} } @$accounts, @$categories; - push @accounts, $default_account_income, $default_account_expenses; + push @accounts, $default_account_income if !grep { $_ eq $default_account_income } @accounts; + push @accounts, $default_account_expenses if !grep { $_ eq $default_account_expenses } @accounts; push @accounts, $OPENING_BALANCES_ACCOUNT if $has_initial_balance; $ledger->add_accounts(@accounts); @@ -171,9 +182,10 @@ sub convert_homebank_to_ledger { $ledger->add_commodities($commodity) if $opts->{commodities}; } + my $first_date; if ($has_initial_balance) { # transactions are sorted, so the first transaction is the oldest - my $first_date = $opts->{opening_date} || $transactions->[0]{date}; + $first_date = $opts->{opening_date} || $transactions->[0]{date}; if ($first_date !~ /^\d{4}-\d{2}-\d{2}$/) { die "Opening date must be in the form YYYY-MM-DD.\n"; } @@ -202,6 +214,44 @@ sub convert_homebank_to_ledger { }); } + if ($opts->{budget}) { + my ($first_year) = $first_date =~ /^(\d{4})/; + + for my $month_num (0 .. 12) { + next if !$budget[$month_num]; + + my $payee = 'Monthly'; + if (0 < $month_num) { + my $year = $first_year; + $year += 1 if sprintf('%04d-%02d-99', $first_year, $month_num) lt $first_date; + my $date = sprintf('%04d-%02d', $year, $month_num); + $payee = "Every 12 months from ${date}"; + } + # my @MONTHS = qw(ALL Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); + # $payee = "Monthly this $MONTHS[$month_num]" if 0 < $month_num; + + my @postings; + + for my $account (sort keys %{$budget[$month_num]}) { + my $amount = $budget[$month_num]{$account}; + push @postings, { + account => $account, + amount => -$amount, + commodity => $commodities{$homebank->base_currency}, + } + } + push @postings, { + account => 'Assets', + }; + + $ledger->add_transactions({ + date => '~', + payee => $payee, + postings => \@postings, + }); + } + } + my %seen; TRANSACTION: @@ -223,7 +273,7 @@ sub convert_homebank_to_ledger { amount => $amount, commodity => $commodities{$account->{currency}}, payee => $payee->{name}, - memo => $memo, + note => $memo, status => $status, tags => $tags, }; @@ -252,7 +302,7 @@ sub convert_homebank_to_ledger { amount => $paired_transaction->{amount} || -$transaction->{amount}, commodity => $commodities{$dst_account->{currency}}, payee => $paired_payee->{name}, - memo => $paired_transaction->{wording} || '', + note => $paired_transaction->{wording} || '', status => $STATUS_SYMBOLS{$paired_transaction->{status} || ''} || $status, tags => _split_tags($paired_transaction->{tags}), }; @@ -275,7 +325,7 @@ sub convert_homebank_to_ledger { commodity => $commodities{$account->{currency}}, amount => $amount, payee => $payee->{name}, - memo => $memo, + note => $memo, status => $status, tags => $tags, }; @@ -293,7 +343,7 @@ sub convert_homebank_to_ledger { commodity => $commodities{$account->{currency}}, amount => $amount, payee => $payee->{name}, - memo => $memo, + note => $memo, status => $status, tags => $tags, }; @@ -347,6 +397,7 @@ sub parse_args { payees => 1, tags => 1, commodities => 1, + budget => 1, opening_date => '', rename_accounts => {}, exclude_accounts => [], @@ -364,12 +415,14 @@ sub parse_args { 'payees!' => \$opts{payees}, 'tags!' => \$opts{tags}, 'commodities!' => \$opts{commodities}, + 'budget!' => \$opts{budget}, 'opening-date=s' => \$opts{opening_date}, 'rename-account|r=s' => \%{$opts{rename_accounts}}, 'exclude-account|x=s' => \@{$opts{exclude_accounts}}, ) or pod2usage(-exitval => 1, -verbose => 99, -sections => [qw(SYNOPSIS OPTIONS)]); - $opts{input} = shift @args if !$opts{input}; + $opts{input} = shift @args if !$opts{input}; + $opts{budget} = 0 if lc($opts{format}) ne 'ledger'; return \%opts; } @@ -393,7 +446,7 @@ App::HomeBank2Ledger - A tool to convert HomeBank files to Ledger format =head1 VERSION -version 0.004 +version 0.005 =head1 SYNOPSIS diff --git a/lib/App/HomeBank2Ledger/Formatter.pm b/lib/App/HomeBank2Ledger/Formatter.pm index 94ee0ec..f529943 100644 --- a/lib/App/HomeBank2Ledger/Formatter.pm +++ b/lib/App/HomeBank2Ledger/Formatter.pm @@ -9,7 +9,7 @@ use Module::Load; use Module::Pluggable search_path => [__PACKAGE__], sub_name => 'available_formatters'; -our $VERSION = '0.004'; # VERSION +our $VERSION = '0.005'; # VERSION sub _croak { require Carp; Carp::croak(@_) } @@ -59,7 +59,7 @@ App::HomeBank2Ledger::Formatter - Abstract class for formatting a ledger =head1 VERSION -version 0.004 +version 0.005 =head1 SYNOPSIS diff --git a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm index 73fd7a2..2ec6a2c 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm @@ -2,6 +2,7 @@ package App::HomeBank2Ledger::Formatter::Beancount; # ABSTRACT: Beancount formatter +use v5.10.1; # defined-or use warnings; use strict; @@ -9,7 +10,7 @@ use App::HomeBank2Ledger::Util qw(commify rtrim); use parent 'App::HomeBank2Ledger::Formatter'; -our $VERSION = '0.004'; # VERSION +our $VERSION = '0.005'; # VERSION my %STATUS_SYMBOLS = ( cleared => '*', @@ -24,18 +25,19 @@ sub format { my $ledger = shift; my @out = ( - $self->_format_header, - $self->_format_accounts($ledger), - $self->_format_commodities($ledger), - # $self->_format_payees, - # $self->_format_tags, - $self->_format_transactions($ledger), + $self->format_header, + $self->format_accounts($ledger), + $self->format_commodities($ledger), + # $self->format_payees, + # $self->format_tags, + $self->format_transactions($ledger), ); return join($/, map { rtrim($_) } @out); } -sub _format_header { + +sub format_header { my $self = shift; my @out; @@ -43,16 +45,17 @@ sub _format_header { if (my $name = $self->name) { push @out, "; Name: $name"; } - - my $file = $self->file; - push @out, "; Converted from ${file} using homebank2ledger ${VERSION}"; + if (my $file = $self->file) { + push @out, "; File: $file"; + } push @out, ''; return @out; } -sub _format_accounts { + +sub format_accounts { my $self = shift; my $ledger = shift; @@ -70,7 +73,8 @@ sub _format_accounts { return @out; } -sub _format_commodities { + +sub format_commodities { my $self = shift; my $ledger = shift; @@ -89,7 +93,8 @@ sub _format_commodities { return @out; } -sub _format_transactions { + +sub format_transactions { my $self = shift; my $ledger = shift; @@ -150,7 +155,27 @@ sub _format_transaction { push @line, ($posting_status_symbol ? " $posting_status_symbol " : ' '); push @line, sprintf("\%-${account_width}s", $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}); + my $lot_price = $posting->{lot_price}; + my $lot_date = $posting->{lot_date}; + my $lot_ref = $posting->{lot_ref}; + if ($lot_price || $lot_date || $lot_ref) { + push @line, ' {', + join(', ', + $lot_price ? $self->_format_amount($lot_price->{amount}, $lot_price->{commodity}) : (), + $lot_date ? $lot_date : (), + $lot_ref ? $self->_format_string($lot_ref) : (), + ), + '}'; + } + 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}); + } + } push @out, join('', @line); } @@ -257,12 +282,56 @@ App::HomeBank2Ledger::Formatter::Beancount - Beancount formatter =head1 VERSION -version 0.004 +version 0.005 =head1 DESCRIPTION This is a formatter for L. +=head1 METHODS + +=head2 format_header + + @lines = $formatter->format_header; + +Get formatted header. For example, + + ; Name: My Finances + ; File: path/to/finances.xhb + +=head2 format_accounts + + @lines = $formatter->format_accounts($ledger); + +Get formatted accounts. For example, + + 2003-02-14 open Assets:Bank:Credit-Union:Savings + 2003-02-14 open Assets:Bank:Credit-Union:Checking + ... + +=head2 format_commodities + + @lines = $formatter->format_commodities($ledger); + +Get formattted commodities. For example, + + 2003-02-14 commodity USD + name: "US Dollar" + ... + +=head2 format_transactions + + @lines = $formatter->format_transactions($ledger); + +Get formatted transactions. For example, + + 2003-02-14 * "Opening Balance" + Assets:Bank:Credit-Union:Savings 458.21 USD + Assets:Bank:Credit-Union:Checking 194.17 USD + Equity:Opening-Balances + + ... + =head1 SEE ALSO L diff --git a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm index 8bb5247..4cf72cb 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm @@ -2,6 +2,7 @@ package App::HomeBank2Ledger::Formatter::Ledger; # ABSTRACT: Ledger formatter +use v5.10.1; # defined-or use warnings; use strict; @@ -9,7 +10,7 @@ use App::HomeBank2Ledger::Util qw(commify rtrim); use parent 'App::HomeBank2Ledger::Formatter'; -our $VERSION = '0.004'; # VERSION +our $VERSION = '0.005'; # VERSION my %STATUS_SYMBOLS = ( cleared => '*', @@ -23,18 +24,19 @@ sub format { my $ledger = shift; my @out = ( - $self->_format_header, - $self->_format_accounts($ledger), - $self->_format_commodities($ledger), - $self->_format_payees($ledger), - $self->_format_tags($ledger), - $self->_format_transactions($ledger), + $self->format_header, + $self->format_accounts($ledger), + $self->format_commodities($ledger), + $self->format_payees($ledger), + $self->format_tags($ledger), + $self->format_transactions($ledger), ); return join($/, map { rtrim($_) } @out); } -sub _format_header { + +sub format_header { my $self = shift; my @out; @@ -42,16 +44,17 @@ sub _format_header { if (my $name = $self->name) { push @out, "; Name: $name"; } - - my $file = $self->file; - push @out, "; Converted from ${file} using homebank2ledger ${VERSION}"; + if (my $file = $self->file) { + push @out, "; File: $file"; + } push @out, ''; return @out; } -sub _format_accounts { + +sub format_accounts { my $self = shift; my $ledger = shift; @@ -63,7 +66,8 @@ sub _format_accounts { return @out; } -sub _format_commodities { + +sub format_commodities { my $self = shift; my $ledger = shift; @@ -81,7 +85,8 @@ sub _format_commodities { return @out; } -sub _format_payees { + +sub format_payees { my $self = shift; my $ledger = shift; @@ -93,7 +98,8 @@ sub _format_payees { return @out; } -sub _format_tags { + +sub format_tags { my $self = shift; my $ledger = shift; @@ -105,7 +111,8 @@ sub _format_tags { return @out; } -sub _format_transactions { + +sub format_transactions { my $self = shift; my $ledger = shift; @@ -161,16 +168,39 @@ 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); - if (my $payee = $posting->{payee}) { - push @out, ' ; Payee: '.$self->_format_string($payee); + if (my $posting_payee = $posting->{payee}) { + $posting_payee = $self->_format_string($posting_payee); + push @out, " ; Payee: $posting_payee" if $posting_payee ne $payee; } if (my @tags = @{$posting->{tags} || []}) { - push @out, " ; :".join(':', @tags).":"; + push @out, ' ; :'.join(':', @tags).':'; } } @@ -186,6 +216,13 @@ sub _format_string { return $str; } +sub _quote_string { + my $self = shift; + my $str = shift; + $str =~ s/"/\\"/g; + return "\"$str\""; +} + sub _format_amount { my $self = shift; my $amount = shift; @@ -196,7 +233,10 @@ sub _format_amount { my $num = join($commodity->{dchar}, commify($whole, $commodity->{gchar}), $fraction); - $num = $commodity->{syprf} ? "$commodity->{symbol} $num" : "$num $commodity->{symbol}"; + my $symbol = $commodity->{symbol}; + $symbol = $self->_quote_string($symbol) if $symbol =~ /[0-9\s]/; + + $num = $commodity->{syprf} ? "$symbol $num" : "$num $symbol"; return $num; } @@ -215,12 +255,76 @@ App::HomeBank2Ledger::Formatter::Ledger - Ledger formatter =head1 VERSION -version 0.004 +version 0.005 =head1 DESCRIPTION This is a formatter for L. +=head1 METHODS + +=head2 format_header + + @lines = $formatter->format_header; + +Get formatted header. For example, + + ; Name: My Finances + ; File: path/to/finances.xhb + +=head2 format_accounts + + @lines = $formatter->format_accounts($ledger); + +Get formatted accounts. For example, + + account Assets:Bank:Credit Union:Savings + account Assets:Bank:Credit Union:Checking + ... + +=head2 format_commodities + + @lines = $formatter->format_commodities($ledger); + +Get formattted commodities. For example, + + commodity $ + note US Dollar + format $ 1,000.00 + alias USD + ... + +=head2 format_payees + + @lines = $formatter->format_payees($ledger); + +Get formatted payees. For example, + + payee 180 Tacos + ... + +=head2 format_tags + + @lines = $formatter->format_tags($ledger); + +Get formatted tags. For example, + + tag yapc + ... + +=head2 format_transactions + + @lines = $formatter->format_transactions($ledger); + +Get formatted transactions. For example, + + 2003-02-14 * Opening Balance + Assets:Bank:Credit Union:Savings $ 458.21 + Assets:Bank:Credit Union:Checking $ 194.17 + Equity:Opening Balances + + ... + =head1 SEE ALSO L diff --git a/lib/App/HomeBank2Ledger/Ledger.pm b/lib/App/HomeBank2Ledger/Ledger.pm index d61dcee..f89063f 100644 --- a/lib/App/HomeBank2Ledger/Ledger.pm +++ b/lib/App/HomeBank2Ledger/Ledger.pm @@ -5,7 +5,7 @@ package App::HomeBank2Ledger::Ledger; use warnings; use strict; -our $VERSION = '0.004'; # VERSION +our $VERSION = '0.005'; # VERSION sub new { @@ -63,7 +63,7 @@ App::HomeBank2Ledger::Ledger - Ledger data representation =head1 VERSION -version 0.004 +version 0.005 =head1 SYNOPSIS diff --git a/lib/App/HomeBank2Ledger/Util.pm b/lib/App/HomeBank2Ledger/Util.pm index 0be4dd3..c4d00e0 100644 --- a/lib/App/HomeBank2Ledger/Util.pm +++ b/lib/App/HomeBank2Ledger/Util.pm @@ -6,7 +6,7 @@ use strict; use Exporter qw(import); -our $VERSION = '0.004'; # VERSION +our $VERSION = '0.005'; # VERSION our @EXPORT_OK = qw(commify rtrim); @@ -42,7 +42,7 @@ App::HomeBank2Ledger::Util - Miscellaneous utility functions =head1 VERSION -version 0.004 +version 0.005 =head1 FUNCTIONS diff --git a/lib/File/HomeBank.pm b/lib/File/HomeBank.pm index 4f38a30..5a8da62 100644 --- a/lib/File/HomeBank.pm +++ b/lib/File/HomeBank.pm @@ -12,7 +12,7 @@ use Time::Piece; use XML::Entities; use XML::Parser::Lite; -our $VERSION = '0.004'; # VERSION +our $VERSION = '0.005'; # VERSION our @EXPORT_OK = qw(parse_string parse_file); @@ -411,6 +411,10 @@ sub parse_string { $attr{flags}{$name} = $flags & (1 << $shift) ? 1 : 0; } + for my $bnum (0 .. 12) { + $attr{budget_amounts}[$bnum] = delete $attr{"b$bnum"} if $attr{"b$bnum"}; + } + push @categories, \%attr; } elsif ($node eq 'ope') { # transaction @@ -487,7 +491,7 @@ File::HomeBank - Parse HomeBank files =head1 VERSION -version 0.004 +version 0.005 =head1 SYNOPSIS diff --git a/t/00-report-prereqs.dd b/t/00-report-prereqs.dd index 4ce9265..0f6138b 100644 --- a/t/00-report-prereqs.dd +++ b/t/00-report-prereqs.dd @@ -39,6 +39,7 @@ do { my $x = { 'XML::Entities' => '0', 'XML::Parser::Lite' => '0', 'parent' => '0', + 'perl' => 'v5.10.1', 'strict' => '0', 'warnings' => '0' } @@ -52,8 +53,7 @@ do { my $x = { 'File::Spec' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', - 'Test::More' => '0', - 'perl' => '5.006' + 'Test::More' => '0' } } };