-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpaypaltoxero
executable file
·105 lines (99 loc) · 2.41 KB
/
paypaltoxero
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
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env ruby
require "csv"
require "benchmark"
require "set"
require_relative "chunked_writer"
wanted_statuses = [
"Completed",
"Cleared",
"Refunded",
"Partially Refunded",
"Reversed",
]
output_headers = [
"Date",
"Amount",
"Payee",
"Description",
"Account Code",
"Tax Type",
"Reference",
"Status",
]
input = CSV.new(ARGF, headers: true, return_headers: true)
input.header_convert{ |field|
field.strip
}
count = 0
out = ChunkedWriter.new("xero.csv", write_headers: true, headers: output_headers)
input.each do |row|
next unless wanted_statuses.include?(row["Status"])
gross = Float(row["Gross"])
fee = Float(row["Fee"])
type = row["Type"]
status = row["Status"]
details = "#{row['Name']} <#{row['From Email Address']}>"
desc = "#{type} (#{details})"
if type == "Recurring Payment Received" && status == "Completed"
out << {
"Date" => row["Date"],
"Amount" => gross,
"Payee" => "PayPal Subscriber",
"Description" => desc,
"Account Code" => "400",
"Tax Type" => "Tax on Sales",
"Reference" => row["Transaction ID"],
"Status" => status,
}
count += 1
out << {
"Date" => row["Date"],
"Amount" => fee,
"Payee" => "PayPal",
"Description" => "PayPal Transaction Fee",
"Account Code" => "TXNFEE",
"Tax Type" => "Tax Exempt",
"Reference" => row["Transaction ID"],
"Status" => status,
}
count += 1
elsif type == "Shopping Cart Payment Received" &&
status == "Completed" &&
gross < 100.0
out << {
"Date" => row["Date"],
"Amount" => gross,
"Payee" => "PayPal Buyer",
"Description" => desc,
"Account Code" => "400",
"Tax Type" => "Tax on Sales",
"Reference" => row["Transaction ID"],
"Status" => status,
}
count += 1
out << {
"Date" => row["Date"],
"Amount" => fee,
"Payee" => "PayPal",
"Description" => "PayPal Transaction Fee",
"Account Code" => "TXNFEE",
"Tax Type" => "Tax Exempt",
"Reference" => row["Transaction ID"],
"Status" => status,
}
count += 1
else
out << {
"Date" => row["Date"],
"Amount" => gross,
"Payee" => row["Name"],
"Description" => desc,
"Account Code" => "",
"Tax Type" => "",
"Reference" => row["Transaction ID"],
"Status" => status,
}
count += 1
end
end
out.close