version 1.29, 2021/05/19 17:10:53 |
version 1.33, 2021/06/04 14:47:20 |
Line 48 my $account_name = $opt_I; |
|
Line 48 my $account_name = $opt_I; |
|
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+$//; |
|
|
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 152 LINE: while (<STDIN>) { |
|
Line 153 LINE: while (<STDIN>) { |
|
} |
} |
my $copy_line = $line; |
my $copy_line = $line; |
my @fields; |
my @fields; |
if ($quote) { |
while ($copy_line =~ /./) { |
push @fields, $1 while $copy_line =~ s/$quote([^$quote]*)$quote$delim?//; |
$quote && $copy_line =~ s/^$quote(.*?)$quote(?:$delim|$)// |
} else { |
or $copy_line =~ s/^(.*?)(?:$delim|$)//; |
@fields = split /$delim/, $line; |
push @fields, $1; |
} |
} |
my $matches = 0; |
my $matches = 0; |
my ($account, $booking); |
my ($account, $booking); |
Line 169 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; |
} |
} |
} |
} |
$matches or die "unmatched CSV line: $line"; |
$matches or die "unmatched CSV line: $line"; |
my $date = $fields[$date_field] or |
my $date = $fields[$date_field]; |
die "date parse error: $line"; |
defined $date or die "undefined date: $line"; |
|
$date or die "date ($date) parse error: $line"; |
eval '$date =~ ' . $date_regex; |
eval '$date =~ ' . $date_regex; |
foreach my $i (@amount_fields) { |
foreach my $i (@amount_fields) { |
if (defined($fields[$i])) { |
if (defined($fields[$i])) { |
Line 193 LINE: while (<STDIN>) { |
|
Line 196 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"; |
} |
} |