X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fhomebank2ledger;a=blobdiff_plain;f=lib%2FFile%2FHomeBank.pm;h=184cb8928193beb804cf9bc031fc768dbde2f20c;hp=c786fddcf419a607d8c07f0f3eb78280a51bd93a;hb=45cd86c510955a5de4fac808945468a1efdac3ea;hpb=b4cac7fd661b6d2a385e89399854dde984d594fe diff --git a/lib/File/HomeBank.pm b/lib/File/HomeBank.pm index c786fdd..184cb89 100644 --- a/lib/File/HomeBank.pm +++ b/lib/File/HomeBank.pm @@ -152,6 +152,18 @@ sub file { shift->{file}; } +=method file_version + + $version = $homebank->file_version; + +Get the file format version. + +=cut + +sub file_version { + shift->{homebank}{version}; +} + =method title $title = $homebank->title; @@ -226,7 +238,7 @@ sub tags { $account = $homebank->find_account_by_key($key); -Find a account with the given key. +Find an account with the given key. =cut @@ -365,7 +377,7 @@ sub find_transaction_transfer_pair { my $self = shift; my $transaction = shift; - return if $transaction->{paymode} ne 'internaltransfer'; + return if !$transaction->{dst_account}; my $transfer_key = $transaction->{transfer_key}; @@ -385,7 +397,7 @@ sub find_transaction_transfer_pair { my @candidates; for my $t (@{$self->transactions}) { - next if $t->{paymode} ne 'internaltransfer'; + next if !$t->{dst_account}; next if $t->{account} != $transaction->{dst_account}; next if $t->{dst_account} != $transaction->{account}; next if $t->{amount} != -$transaction->{amount}; @@ -400,9 +412,9 @@ sub find_transaction_transfer_pair { # sort the candidates so we can pick the nearest one by date my @ordered_candidates = - map { $_->[1] } + map { $_->[1] } sort { $a->[0] <=> $b->[0] } - map { [abs($transaction_day - _ymd_to_julian($_->{date})), $_] } @candidates; + map { [abs($transaction_day - _ymd_to_julian($_->{date})), $_] } @candidates; if (my $winner = $ordered_candidates[0]) { my $key1 = $transfer_key || '[no key]'; @@ -520,6 +532,7 @@ Parse a HomeBank file from a string. sub parse_string { my $str = shift or die _usage(q{parse_string($str)}); + my %homebank; my %properties; my @accounts; my @payees; @@ -539,7 +552,11 @@ sub parse_string { $attr{$key} = _decode_xml_entities($attr{$key}); } - if ($node eq 'properties') { + if ($node eq 'homebank') { + $attr{version} = delete $attr{v} if $attr{v}; + %homebank = %attr; + } + elsif ($node eq 'properties') { $attr{currency} = delete $attr{curr} if $attr{curr}; %properties = %attr; } @@ -575,11 +592,15 @@ 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 - $attr{paymode} = $TRANSACTION_PAYMODES{$attr{paymode} || ''} || 'unknown'; - $attr{status} = $TRANSACTION_STATUSES{delete $attr{st}} || 'unknown'; + $attr{paymode} = $TRANSACTION_PAYMODES{$attr{paymode} || ''} || 'unknown'; + $attr{status} = $TRANSACTION_STATUSES{delete $attr{st} || ''} || 'unknown'; $attr{transfer_key} = delete $attr{kxfer} if $attr{kxfer}; $attr{split_amount} = delete $attr{samt} if $attr{samt}; @@ -601,6 +622,7 @@ sub parse_string { $xml_parser->parse($str); return { + homebank => \%homebank, properties => \%properties, accounts => \@accounts, payees => \@payees,