]> Dogcows Code - chaz/homebank2ledger/blobdiff - lib/File/HomeBank.pm
internal xfers no longer use a paymode
[chaz/homebank2ledger] / lib / File / HomeBank.pm
index 7d29ada68dfa09d4acc4459090b60af58ec6bfc2..184cb8928193beb804cf9bc031fc768dbde2f20c 100644 (file)
@@ -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;
                 }
@@ -605,6 +622,7 @@ sub parse_string {
     $xml_parser->parse($str);
 
     return {
+        homebank        => \%homebank,
         properties      => \%properties,
         accounts        => \@accounts,
         payees          => \@payees,
This page took 0.018459 seconds and 4 git commands to generate.