-
Notifications
You must be signed in to change notification settings - Fork 0
/
sampleCsv.js
79 lines (69 loc) · 4.94 KB
/
sampleCsv.js
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
'use strict';
function generateSampleCsv() {
const transactions = [];
function addTransaction({timestamp, payee, accountNumber, transactionType, paymentReference, amount, amountForeign, currencyCode, exchangeRate}) {
transactions.push([timestamp, payee, accountNumber, transactionType, paymentReference, amount, amountForeign, currencyCode, exchangeRate]);
}
function createMonthlyTimestamps(startDate, endDate, dayOfMonth) {
const timestamps = [];
const startMonth = (startDate.getFullYear() * 12) + startDate.getMonth();
const endMonth = (endDate.getFullYear() * 12) + endDate.getMonth();
for (let month = startMonth; month < endMonth; month++) {
timestamps.push((new Date(Math.floor(month / 12), month % 12, dayOfMonth)).getTime());
}
return timestamps;
}
function generateSalaryTransactions({payee, accountNumber, amountPerMonth, dayOfMonth, startDate, endDate}) {
const timestamps = createMonthlyTimestamps(startDate, endDate, dayOfMonth);
for (const timestamp of timestamps) {
addTransaction({timestamp, payee, accountNumber, amount: amountPerMonth, transactionType: 'Income', paymentReference: 'Salary'});
}
}
generateSalaryTransactions({payee: 'Umbrella Corporation', accountNumber: 'DE12748674125896341188', amountPerMonth: 1256.3, dayOfMonth: 3, startDate: new Date(2014, 3, 1), endDate: new Date(2016, 9, 24)});
generateSalaryTransactions({payee: 'Monsters, Inc.', accountNumber: 'DE88746655446668134577', amountPerMonth: 1801.7, dayOfMonth: 15, startDate: new Date(2017, 1, 5), endDate: new Date(2020, 1, 5)});
function generateRentTransactions({payee, accountNumber, amountPerMonth, dayOfMonth, startDate, endDate}) {
const timestamps = createMonthlyTimestamps(startDate, endDate, dayOfMonth);
for (const timestamp of timestamps) {
addTransaction({timestamp, payee, accountNumber, amount: amountPerMonth, transactionType: 'Outgoing Transfer', paymentReference: 'Rent'});
}
}
generateRentTransactions({payee: 'Mr. Ditkovich', accountNumber: 'DE00599460000000000001', amountPerMonth: -647, dayOfMonth: 20, startDate: new Date(2014, 2, 18), endDate: new Date(2020, 1, 5)});
function generateSpotifyTransactions({startDate, endDate, dayOfMonth}) {
const timestamps = createMonthlyTimestamps(startDate, endDate, dayOfMonth);
for (const timestamp of timestamps) {
addTransaction({timestamp, payee: 'Spotify', transactionType: 'MasterCard Payment', amount: -9.99});
}
}
generateSpotifyTransactions({startDate: new Date(2014, 4, 6), endDate: new Date(2020, 1, 5), dayOfMonth: 15});
function generateNetflixTransactions({startDate, endDate, dayOfMonth}) {
const timestamps = createMonthlyTimestamps(startDate, endDate, dayOfMonth);
for (const timestamp of timestamps) {
addTransaction({timestamp, payee: 'NETFLIX.COM', transactionType: 'MasterCard Payment', amount: -10.99});
}
}
generateNetflixTransactions({startDate: new Date(2015, 6, 20), endDate: new Date(2020, 1, 5), dayOfMonth: 15});
// Plane tickets
addTransaction({timestamp: new Date(2015, 8, 3).getTime(), payee: 'Mordor Airlines', accountNumber: 'DE20011219555555555555', amount: -1124.87, transactionType: 'MasterCard Payment'});
addTransaction({timestamp: new Date(2019, 3, 24).getTime(), payee: 'Ghibli Airlines', accountNumber: 'DE66846442456871354989', amount: -1412.94, transactionType: 'MasterCard Payment'});
addTransaction({timestamp: new Date(2017, 2, 16).getTime(), payee: 'EASYJET000 ETX1HN7', accountNumber: 'DE58743168544997811364', amount: -86.1, transactionType: 'MasterCard Payment'});
// ATM withdrawals
const atmWithdrawalsStart = new Date(2014, 2, 2).getTime();
const atmWithdrawalsEnd = new Date(2020, 5, 1).getTime();
const atmWithdrawalsDuration = atmWithdrawalsEnd - atmWithdrawalsStart;
for (let i=0; i<200; i++) {
addTransaction({timestamp: atmWithdrawalsStart + (atmWithdrawalsDuration * Math.random()), payee: 'Berliner Sparkasse', amount: -20 - (10 * Math.floor(Math.random() * 9)), transactionType: 'MasterCard Payment'});
}
// Transfers from other accounts
addTransaction({timestamp: new Date(2014, 1, 2).getTime(), payee: 'Transferwise Ltd', paymentReference: 'Initial transfer from other account', accountNumber: 'DE26098900742314159459', amount: 2500});
addTransaction({timestamp: new Date(2015, 6, 17).getTime(), payee: 'Transferwise Ltd', paymentReference: 'Term deposit matured', amount: 2500, transactionType: 'MasterCard Payment'});
transactions.sort((transactionA, transactionB) => transactionA[0] - transactionB[0]);
transactions.forEach(transaction => {
const date = new Date(transaction[0]);
transaction[0] = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
});
return [
'"Date","Payee","Account number","Transaction type","Payment reference","Amount (EUR)","Amount (Foreign Currency)","Type Foreign Currency","Exchange Rate"',
...transactions.map(transaction => transaction.map(value => `"${value ? value : ''}"`).join(',')),
''
].join('\n');
}