git ssb

0+

cel / ledger-scripts



Tree: f1521af2d73e96acaa4e96dfc60dbfc50373845a

Files: f1521af2d73e96acaa4e96dfc60dbfc50373845a / mint2ledger

4673 bytesRaw
1#!/usr/bin/env perl
2
3use strict;
4
5$| = 1;
6
7# Customize your accounts
8
9my %accounts = (
10 'Simple Account' => 'Assets:Checking:Simple',
11 'PayPal Account' => 'Assets:Broker:Paypal',
12 'Shares' => 'Assets:Savings:Genesee Co-Op',
13 'Cash' => 'Assets:Cash',
14
15 'Income' => 'Income',
16 'Interest Income' => 'Income:Interest',
17 'Gift Received' => 'Income:Gift',
18 'Transfer for Cash Spending' => 'Assets:Cash',
19 'Returned Purchase' => 'Expenses:Shopping',
20
21 'Public Transportation' => 'Expenses:Transportation',
22 'Gas & Fuel' => 'Expenses:Transportation:Gasoline',
23 'Service & Parts' => 'Expenses:Transportation:Auto Repair',
24 'Electronics & Software' => 'Expenses:Shopping:Electronics',
25 'Restaurants' => 'Expenses:Food:Restaurant',
26 'Groceries' => 'Expenses:Food:Groceries',
27 'Food & Dining' => 'Expenses:Food',
28
29 'Federal Tax' => 'Expenses:Tax:Federal',
30 'State Tax' => 'Expenses:Tax:State',
31 'Arts' => 'Expenses:Theatre',
32 'Tuition' => 'Expenses:Education:Tuition',
33 'Tests' => 'Expenses:Education:Tests',
34
35);
36my $account_unknown = "Assets:Unknown";
37
38# Name accounts based on payee name
39my %payee_accounts = (
40 'ATM Cash Deposit' => 'Assets:Cash',
41 'ATM Withdrawal' => 'Assets:Cash',
42 'Hold' => 'Broker:Hold',
43 'Hold Release' => 'Broker:Hold',
44 'Www Dealextreme Com' => 'Expenses:Shopping:Electronics',
45 'Paymentto Bountysource' => 'Expenses:Donations:Software',
46);
47
48sub print_entry {
49 my $entry = shift;
50 return unless $entry;
51 print "\n";
52 printf "; %s\n", $entry->{notes} if ($entry->{notes});
53 printf "; :%s:\n", $entry->{labels} if ($entry->{labels});
54 printf "%s %s\n", $entry->{date}, $entry->{payee};
55 printf "\t%-36s \$%s\n", $entry->{to_account}, $entry->{amount};
56 printf "\t%s\n", $entry->{from_account};
57}
58
59my @buffer = ();
60my $buffer_i = 0;
61my $buffer_len = 10;
62
63while (<>) {
64 my ($null, $date, $description, $original_description, $amount, $transaction_type, $category, $account_name, $labels, $notes) = split(/^"|","|"$/, $_);
65
66 next if ($amount eq 'Amount');
67
68 my $payee = $description;
69 my ($month, $day, $year) = $date =~ /(.*)\/(.*)\/(.*)/;
70 $date = $year . '/' . $month . '/' . $day;
71 my $my_account = $accounts{$account_name} // $account_unknown;
72 my $their_account;
73
74 if (my $account = $payee_accounts{$payee}) {
75 $their_account = $account;
76 }
77
78 elsif ($transaction_type eq 'debit') {
79 $their_account = $accounts{$category} // 'Expenses:' . $category;
80 } else {
81 $their_account = $accounts{$category} // 'Income:' . $category;
82 }
83
84 # Combine matching transfer entries
85 if ($their_account eq 'Expenses:Transfer') {
86 if (my ($corresponding_obj) = grep {
87 $_->{from_account} eq 'Income:Transfer'
88 and $_->{amount} eq $amount
89 } @buffer) {
90 $corresponding_obj->{from_account} = $my_account;
91 next;
92 }
93 }
94 elsif ($their_account eq 'Income:Transfer' or $payee eq 'Keep Change Acct' or $payee =~ /Trnsfr/ or $their_account == 'Income') {
95 if (my ($corresponding_obj) = grep {
96 ($_->{to_account} eq 'Expenses:Transfer' or
97 $_->{payee} =~ /Tra?nsfe?r/)
98 and $_->{amount} eq $amount
99 } @buffer) {
100 $corresponding_obj->{to_account} = $my_account;
101 next;
102 }
103 }
104
105 # Custom adjustments
106
107 elsif ($payee =~ /trailways/i) {
108 $payee = 'Adirondack Trailways';
109 $their_account = 'Expenses:Transportation:Bus';
110 }
111
112 elsif ($labels =~ /genealogy/i or $notes =~ /genealogy/i) {
113 $labels = '';
114 $notes = '';
115 $their_account = 'Expenses:Genealogy:Records';
116 }
117
118 elsif (($payee eq 'iTunes' and $notes =~ /Pro/) or
119 $payee =~ /itunes app|app store/i) {
120 $their_account = 'Expenses:Software';
121 }
122
123 my ($to_account, $from_account);
124 if ($transaction_type eq 'debit') {
125 $to_account = $their_account;
126 $from_account = $my_account;
127 } else {
128 $to_account = $my_account;
129 $from_account = $their_account;
130 }
131
132 # Add the entry to the buffer
133 my $obj = {
134 date => $date,
135 payee => $payee,
136 amount => $amount,
137 to_account => $to_account,
138 from_account => $from_account,
139 notes => $notes,
140 labels => $labels,
141 };
142 if (my $prev_obj = $buffer[$buffer_i]) {
143 print_entry $prev_obj;
144 }
145 $buffer[$buffer_i] = $obj;
146 $buffer_i++;
147 $buffer_i %= $buffer_len;
148}
149
150# print the rest of the buffer
151for my $i ($buffer_i .. $buffer_i+$buffer_len-1) {
152 print_entry $buffer[$i % $buffer_len];
153}
154
155

Built with git-ssb-web