-
Notifications
You must be signed in to change notification settings - Fork 1
/
gnupal.pl
94 lines (75 loc) · 2.67 KB
/
gnupal.pl
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl -w
#
# Copyright (c) 2011 Koen Martens <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
use strict;
use Text::CSV_XS;
use Date::Parse;
my $netacc='Assets:Current Assets:Paypal';
my $grossacc='Paypal-import';
my $feeacc='Expenses:Fees:Paypal';
my $csv=Text::CSV_XS->new({binary=>1});
sub fieldidx {
my $name=shift;
my @fieldnames = qw( date time tz name type status currency bruto fee net from_email to_email ref from address title id shipping insurance vat opt1_name opt1_value opt2_name opt2_value site buyerid object_url enddate escrowid invoicedata refid invoice adjusted receipt balance adr1 adr2 city state zip country telno );
my ($idx) = grep { $fieldnames[$_] eq $name } 0..$#fieldnames;
return $idx;
}
print "!Account\n";
print "N$grossacc\n";
print "TBank\n";
print "^\n";
print "!Type:Bank\n";
<>;
while(<>) {
if($csv->parse($_)) {
my @fields=$csv->fields();
die('Unparseable date '.$fields[fieldidx('date')]) unless($fields[fieldidx('date')]=~/^([0-9]{2})-([0-9]{2})-([0-9]{4})$/);
print "D$2/$1/$3\n";
my $gross=$fields[fieldidx('bruto')];
$gross=~s/\./,/g;
$gross=~s/\,([0-9]{2})$/.$1/g;
$gross=~s/,//g;
my $fee=$fields[fieldidx('fee')];
$fee=~s/\./,/g;
$fee=~s/\,([0-9]{2})$/.$1/g;
$fee=~s/,//g;
my $net=$fields[fieldidx('net')];
$net=~s/\./,/g;
$net=~s/\,([0-9]{2})$/.$1/g;
$net=~s/,//g;
my $desc=$fields[fieldidx('title')].' '.$fields[fieldidx('invoicedata')].' '.$fields[fieldidx('invoice')].' from '.$fields[fieldidx('from_email')].' to '.$fields[fieldidx('to_email')];
$desc=~s/^\s//g;
$desc=~s/\s$//g;
$desc=~s/\s+/ /g;
print "N".$fields[fieldidx('ref')]."\n";
print "U".(0-$gross)."\n";
print "T".(0-$gross)."\n";
print "P$desc\n";
print "C*\n";
print "L$grossacc\n";
print "S$netacc\n";
print "EImported paypal payment\n";
print '$'.(0-$net)."\n";
print "S$feeacc\n";
print "EPaypal fee\n";
print '$'.$fee."\n";
print "^\n";
} else {
die('unable to parse line: '.$_);
}
}
close(PAL);