[BACK]Return to pta_import.pl CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / pta

Diff for /pta/pta_import.pl between version 1.28 and 1.31

version 1.28, 2020/12/11 19:28:12 version 1.31, 2021/05/19 21:52:11
Line 21  use Getopt::Std qw(getopts);
Line 21  use Getopt::Std qw(getopts);
   
 our ($opt_I);  our ($opt_I);
   
 my %banks = (  
     "bbva_usa"              => \&import_bbva_usa,  
     "capital_one_360"       => \&import_capital_one_360,  
     "capital_one_credit"    => \&import_capital_one_credit,  
     "chase_credit"          => \&import_chase_credit,  
     "etrade_ira"            => \&import_etrade_ira,  
     "optum_hsa"             => \&import_optum_hsa,  
     "sparkasse_camt"        => \&import_sparkasse_camt,  
     "wellsfargo"            => \&import_wellsfargo,  
 );  
   
 my %date_formats = (  my %date_formats = (
     'MM/DD/YYYY' => 's#(\d+)/(\d+)/(\d+)#$3$1$2#',      'MM/DD/YYYY' => 's#(\d+)/(\d+)/(\d+)#$3$1$2#',
     'MM/DD/YY'   => 's#(\d+)/(\d+)/(\d+)#20$3$1$2#',      'MM/DD/YY'   => 's#(\d+)/(\d+)/(\d+)#20$3$1$2#',
Line 54  unless ($opt_I) {
Line 43  unless ($opt_I) {
         usage;          usage;
 }  }
 my $account_name = $opt_I;  my $account_name = $opt_I;
 $banks{$account_name} or die "unknown accountname: $account_name";  
   
 # Parse the configuration file.  # Parse the configuration file.
 my $fn = "import/" . $account_name . ".txt";  my $fn = "import/" . $account_name . ".txt";
 open my $in, '<', $fn or die "$fn: $!";  open my $in, '<', $fn or die "$fn: $!";
 my ($cost_center_field, $csv_account, $date_field, $date_regex,  my ($cost_center_field, $csv_account, $date_field, $date_regex,
     $delim, $header, $quantity_field, $quote, @amount_fields,      $delim, $header, $quantity_field, $quote, $subaccount,
     @compiled, @description_fields, @ignored);      @amount_fields, @compiled, @description_fields, @ignored);
 while (<$in>) {  while (<$in>) {
         chomp;          chomp;
         s/\s+$//;          s/\s+$//;
Line 133  while (<$in>) {
Line 121  while (<$in>) {
                 next;                  next;
         }          }
         $delim or die "no DELIM line in $fn";          $delim or die "no DELIM line in $fn";
         s/^(.*)$delim\s+(\d+)\s+(\S+)// or          s/^(.*)$delim\s+(\d+)\s+(\S+)\s*(\S*)// or
             die "$fn import parse error: $line";              die "$fn import parse error: $line";
         push @compiled, {          push @compiled, {
                 re => [map { qr/$_/ } split /$delim/, $1],                  re => [map { qr/$_/ } split /$delim/, $1],
                 ac => $2,                  ac => $2,
                 id => $3,                  id => $3,
                   su => $4,
         };          };
 }  }
 close $in;  close $in;
Line 181  LINE: while (<STDIN>) {
Line 170  LINE: while (<STDIN>) {
                 if ($matches) {                  if ($matches) {
                         $account = $selector->{ac};                          $account = $selector->{ac};
                         $booking = $selector->{id};                          $booking = $selector->{id};
                           $subaccount = $selector->{su};
                         last;                          last;
                 }                  }
         }          }
Line 205  LINE: while (<STDIN>) {
Line 195  LINE: while (<STDIN>) {
         }          }
         $amount = sprintf "%.2f", $amount;          $amount = sprintf "%.2f", $amount;
         my $description = join ' ', @fields[@description_fields];          my $description = join ' ', @fields[@description_fields];
         $date && $amount && $debit && $credit && $description          defined($date) && defined($amount) && defined($debit) &&
               defined($credit) && defined($description)
             or die "import parse error: $line";              or die "import parse error: $line";
         $description =~ s/#//g;          $description =~ s/#//g;
         $description .= " [$fields[$cost_center_field]]"          $description .= " [$fields[$cost_center_field]]"
             if $cost_center_field;              if $cost_center_field;
         $description .= " quantity $fields[$quantity_field]"          $description .= " quantity $fields[$quantity_field]"
             if $quantity_field;              if $quantity_field;
           $description .= " ($subaccount)"
               if $subaccount;
   
         print "$date $booking $debit $credit $amount $description\n";          print "$date $booking $debit $credit $amount $description\n";
 }  }

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.31

CVSweb