-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatement.js
More file actions
54 lines (47 loc) · 1.72 KB
/
statement.js
File metadata and controls
54 lines (47 loc) · 1.72 KB
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
'use strict';
var xeroHelper = require('./xeroHelper');
function makeStatement(contact, bank_trans, accounts) {
console.log("creating statement", contact);
const contact_trans = xeroHelper.groupByContact(bank_trans);
const trans = contact_trans[contact.ContactID];
if (!trans || trans.length == 0) {
console.log("failed to create statement due to lack of transactions")
return;
}
let result = "Statement of receipt from " + contact.Name;
if (contact.EmailAddress) {
result += ' (' + contact.EmailAddress + ')';
}
result += "\n\n";
result += 'Transaction Detail\n\n';
trans.sort(xeroHelper.transactionByDate).forEach(function(tran) {
tran.LineItems.forEach(function(li) {
let description = li.Tracking.map(t => {
return t.Name + ": " + t.Option;
}).join(' - ');
if (li.Description) {
if (description.length > 0) {
description + ' - ';
}
description += li.Description;
}
result += tran.DateString.split('T')[0] + ' - ' +
'$' + parseFloat(li.LineAmount).toFixed(2) + ' - ' +
accounts[li.AccountCode].Name;
if (description) {
result += ' - ' + description
}
result += '\n';
});
});
result += '\n\nSummary By Account\n\n'
const summary = xeroHelper.groupByTypeAndAccount(trans);
for (const accountCode in summary.receive) {
const sum = parseFloat(summary.receive[accountCode].sum).toFixed(2);
result += accounts[accountCode].Name + ": " + sum + '\n';
}
return result;
}
module.exports = {
makeStatement
}