version 1.13, 2020/11/18 21:32:16 |
version 1.15, 2020/11/18 23:44:46 |
|
|
"chase_credit" => \&import_chase_credit, |
"chase_credit" => \&import_chase_credit, |
"optum_hsa" => \&import_optum_hsa, |
"optum_hsa" => \&import_optum_hsa, |
"sparkasse_camt" => \&import_sparkasse_camt, |
"sparkasse_camt" => \&import_sparkasse_camt, |
|
"wellsfargo" => \&import_wellsfargo, |
); |
); |
|
|
# === SUBROUTINES ===================================================== |
# === SUBROUTINES ===================================================== |
Line 82 sub import_sparkasse_camt ($$$) { |
|
Line 83 sub import_sparkasse_camt ($$$) { |
|
(join ' ', $fields[11], $fields[4]); |
(join ' ', $fields[11], $fields[4]); |
} |
} |
|
|
|
sub import_wellsfargo ($$$) { |
|
my ($account, $csv_account, $line) = @_; |
|
$line =~ |
|
m#^"(\d+)/(\d+)/(\d+)","(-?\d+\.\d+)","\*","","(.*?)"$# or |
|
die "parse error: $line" ; |
|
my ($month, $day, $year, $amount, $description) = |
|
($1, $2, $3, $4, $5); |
|
return "$year$month$day", |
|
get_accounts_by_amount_sign($amount, $account, $csv_account), |
|
$description; |
|
} |
|
|
sub get_accounts_by_amount_sign ($$$) { |
sub get_accounts_by_amount_sign ($$$) { |
my ($amount, $account, $csv_account) = @_; |
my ($amount, $account, $csv_account) = @_; |
my ($debit, $credit); |
my ($debit, $credit); |
|
|
|
|
# === MAIN PROGRAM ===================================================== |
# === MAIN PROGRAM ===================================================== |
|
|
my ($csv_account, $fn, $in, $account_name, $delim, @compiled); |
|
|
|
# Parse command line arguments. |
|
getopts 'I:' or usage; |
getopts 'I:' or usage; |
if ($opt_I) { |
unless ($opt_I) { |
$account_name = $opt_I; |
warn "The option -I is required."; |
$banks{$account_name} or die "unknown accountname: $account_name"; |
|
$fn = "import_" . $account_name . ".txt"; |
|
open $in, $fn or die "$fn: $!"; |
|
} else { |
|
usage; |
usage; |
} |
} |
|
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"; |
|
open my $in, '<', $fn or die "$fn: $!"; |
|
my ($csv_account, $delim, $header, @compiled); |
while (<$in>) { |
while (<$in>) { |
chomp; |
chomp; |
next if /^(?:#|$)/; |
next if /^(?:#|$)/; |
|
|
$delim = $1; |
$delim = $1; |
next; |
next; |
} |
} |
|
if (/^HEADER\s+(.*)$/) { |
|
$header and die "duplicate HEADER line: $1"; |
|
$header = $1; |
|
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+)// or |
die "$fn import parse error: $line"; |
die "$fn import parse error: $line"; |
|
|
$csv_account or die "no ACCOUNT line in $fn"; |
$csv_account or die "no ACCOUNT line in $fn"; |
|
|
# Parse the CSV file from the bank. |
# Parse the CSV file from the bank. |
chomp(my $header = <>); |
|
while (<>) { |
while (<>) { |
chomp; |
chomp; |
next if (/^$/); |
next if (/^$/); |
my $line = $_; |
my $line = $_; |
|
if ($header) { |
|
$line eq $header |
|
or die "expected HEADER $header\nbut got $line"; |
|
undef $header; |
|
next; |
|
} |
my @fields = split /$delim/, $line; |
my @fields = split /$delim/, $line; |
my $matches = 0; |
my $matches = 0; |
my ($account, $booking); |
my ($account, $booking); |