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

Annotation of pta/pta_import.pl, Revision 1.2

1.1       schwarze    1: #!/usr/bin/perl
                      2:
                      3: # Copyright (c) 2020 Freda Bundchen
                      4:
                      5: # Permission to use, copy, modify, and distribute this software for any
                      6: # purpose with or without fee is hereby granted, provided that the above
                      7: # copyright notice and this permission notice appear in all copies.
                      8: #
                      9: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:
                     17: use warnings;
                     18: use strict;
                     19: use autodie;
                     20:
                     21: # Please change the account numbers below to match the
                     22: # desired accounts in your accounts.txt.
                     23:
                     24: my %accounts = (
                     25:     CHASE_CREDIT_CARD => '1234',
                     26:     CHASE_PAYMENT_ACCOUNT => '5678',
                     27:     AUTO => '1111',
                     28:     BILLS => '2222',
                     29:     FEES => '3333',
                     30:     FOOD => '4444',
                     31:     GAS => '5555',
                     32:     GIFTS => '6666',
                     33:     GROCERIES => '7777',
                     34:     HEALTH => '8888',
                     35:     HOME => '9999',
                     36:     PERSONAL => '9998',
                     37:     PRO => '9997',
                     38:     SHOP => '9996'
                     39: );
                     40:
                     41: # This is the end of the user-configurable section.
                     42:
                     43: # === SUBROUTINES  =====================================================
                     44:
                     45: sub import_chase_credit_card() {
                     46:        my %categories = (
                     47:            'Automotive' => 'AUTO',
                     48:            'Bills & Utilities' => 'BILLS',
                     49:            'Fees & Adjustments' => 'FEES',
                     50:            'Food & Drink' => 'FOOD',
                     51:            'Gas' => 'GAS',
                     52:            'Gifts & Donations' => 'GIFTS',
                     53:            'Groceries' => 'GROCERIES',
                     54:            'Health & Wellness' => 'HEALTH',
                     55:            'Home' => 'HOME',
                     56:            'Personal' => 'PERSONAL',
                     57:            'Professional Services' => 'PRO',
                     58:            'Shopping' => 'SHOP'
                     59:        );
1.2     ! schwarze   60:        while (<>) {
1.1       schwarze   61:                chomp;
                     62:                my ($trans_date, $post_date, $description, $category,
                     63:                    $type, $amount) = split /,/;
                     64:
                     65:                $trans_date =~ s#(\d+)/(\d+)/(\d+)#$3$1$2#;
                     66:                $post_date =~ s#(\d+)/(\d+)/(\d+)#$3$1$2#;
                     67:                $description =~ s/#//g;
                     68:                my $booking = $categories{$category} ||
                     69:                    'CHASE_PAYMENT_ACCOUNT';
                     70:                my $contra = $accounts{$booking};
                     71:                my ($debit, $credit);
                     72:                if ($amount <= 0) {
                     73:                        $amount = substr $amount, 1;
                     74:                        $credit = $accounts{CHASE_CREDIT_CARD};
                     75:                        $debit = $contra;
                     76:                } else {
                     77:                        $debit = $accounts{CHASE_CREDIT_CARD};
                     78:                        $credit = $contra;
                     79:                }
                     80:                print "$post_date $booking $debit $credit $amount " .
                     81:                    "$description\n";
                     82:        }
                     83: }
                     84:
                     85: # === MAIN PROGRAM =====================================================
                     86:
                     87: my $chase_credit_card_header = "Transaction Date,Post Date," .
                     88:     "Description,Category,Type,Amount";
                     89: my $firstLine;
                     90:
1.2     ! schwarze   91: chomp($firstLine = <>);
1.1       schwarze   92: if ($firstLine eq $chase_credit_card_header) {
                     93:        import_chase_credit_card;
                     94: } else {
                     95:        print "Undefined bank header\n";
                     96: }

CVSweb