-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchase_stmt_to_csv-simple
executable file
·47 lines (41 loc) · 2.14 KB
/
chase_stmt_to_csv-simple
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
# run on output of `pdftotext -simple Chase_CreditCardStatement.pdf Chase_CreditCardStatement.p2t-simple`
# see %~dp0/CCStmtP2tToCsv.pm for details
use strict;
use warnings;
use FindBin;
use lib $FindBin::Bin;
use CCStmtP2tToCsv;
my $opts = CCStmtP2tToCsv::getopts();
my $rdt = '\d{2}/\d{2}';
my $rpmdamtcapt = CCStmtP2tToCsv::rpmdamtcapt();
my $rtxn = qr"\s+($rdt)\s+(?:&\s)?(\w.*\w)$rpmdamtcapt";
my $retxn = "^(?:$rdt)?$rtxn";
my($plus,$minus) = qw( credit charge );
for my $ifnm ( sort @ARGV ) { # sort so that write_all_csv content will be sorted (assumes stmt filenames are validly date-sortable)
my $lp_ignore = sub {;};
my $lp_AcctSummary = sub { my $self = shift; # print "lp_AcctSummary $_\n";
s/(\w)`(\w)/$1$2/; # VERY strange translation issue
if( m"^\s*Payment,\s+Credits$rpmdamtcapt" ) { $self->set_total( [$plus ], $1 ); }
elsif( m"^\s*Purchases$rpmdamtcapt" ) { $self->set_total( [$minus], $1 ); }
# elsif( m"^\s*Account Number:\s+\d{4} \d{4} \d{4} (\d{4})\b" ) { print "acctnum $1\n"; my $acctnum = $1; } # now obtained from ./AccountId.pl, but may be cross-checked in the future...
elsif( m"^\s*Opening/Closing Date\s+\d{2}/\d{2}/(\d{2})\s+\-\s+(\d{2})/(\d{2})/(\d{2})" ) { print "yrMin/yrMax raw $1/$4\n";
$self->set_stmtOpenCloseDates();
}
};
my $init_key = '(start_of_file)';
CCStmtP2tToCsv::process_stmt_p2t( $ifnm, {
$init_key => $lp_ignore,
'ACCOUNT SUMMARY' => $lp_AcctSummary,
'PAYMENTS AND OTHER CREDITS' => sub { my $self = shift; $self->parse_new_txn( $retxn, [$plus ] ); },
'PURCHASE' => sub { my $self = shift; $self->parse_new_txn( $retxn, [$minus] ); },
'PURCHASES AND REDEMPTIONS' => $lp_ignore,
'INTEREST CHARGES' => $lp_ignore,
'CASH ADVANCES' => $lp_ignore,
'BALANCE TRANSFERS' => $lp_ignore,
'FEES CHARGED' => $lp_ignore,
'RETURNS AND OTHER CREDITS' => $lp_ignore,
}, $init_key, [$minus], $opts
);
}
CCStmtP2tToCsv::write_all_csv() if @ARGV > 1;