-
Notifications
You must be signed in to change notification settings - Fork 0
/
citi_stmt_to_csv-simple
executable file
·58 lines (52 loc) · 2.32 KB
/
citi_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
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
# run on output of `pdftotext -simple Citi_CreditCardStatement.pdf Citi_CreditCardStatement.p2t`
# 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 $rdesc = '\w.*\w';
my $rdamtcapt = '([\d,]*\.\d{2})';
my $rtxn = qr"\s+($rdt)\s+($rdesc)\s+(\-?)\$$rdamtcapt\b";
my $retxn = "^(?:$rdt)?$rtxn";
for my $ifnm ( sort @ARGV ) { # sort so that write_all_csv content will be sorted (assumes stmt filenames are validly date-sortable)
my $lp_Payments = sub { # my $self = shift; $self->parse_new_txn( $retxn, 'credit' ); no way to cross-check credits in Citi stmts (because Citi stmts provide no total for credits)
};
my ($cardholder); # multiline parse support
my $lp_CardholderSummary = sub { my $self = shift;
# print "chs: $_\n" if $opts->{v};
if( !defined($cardholder) ) {
if( m"^($rdesc)\s+Card ending in\s+\d{4}" ) {
$cardholder = $1;
print "cardholder = $cardholder\n" if $opts->{v};
}
}
elsif( m"^New Charges\s+\$$rdamtcapt" ) {
my $cardtotal = CCStmtP2tToCsv::tocents( $1 ); # for cross-checking
print "cardholder = $cardholder; cardtotal = $cardtotal\n" if $opts->{v};
$self->set_total( $cardholder, $cardtotal );
my $ch_capt = $cardholder; # required!
$self->add_section_hdr( $cardholder, sub { my $self = shift; $self->parse_new_txn( $retxn, 'charge', $ch_capt ); } );
$cardholder = undef; # we're done with this $cardholder
}
};
my $lp_ignore = sub {;};
my $lp_BillPeriod = sub { my $self = shift;
if( m"^\s*Billing\s+Period:\s+\d{2}/\d{2}/(\d{2})\-(\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( shift,
{
$init_key => $lp_BillPeriod,
'CARDHOLDER\s+SUMMARY' => $lp_CardholderSummary,
'Payments,\s+Credits\s+and\s+Adjustments' => $lp_Payments,
'Fees\s+Charged' => $lp_ignore,
}, $init_key, [ qw( charge ) ], $opts
);
}
CCStmtP2tToCsv::write_all_csv() if @ARGV > 1;