-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatement.js
66 lines (54 loc) Β· 1.88 KB
/
statement.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
import createStatementData from "./createStatementData.js";
import invoices from "./invoices.json" assert { type: "json" };
import plays from "./plays.json" assert { type: "json" };
/**
* p25 μμ
*/
function statement(invoice, plays) {
return renderPlainText(createStatementData(invoice, plays));
}
function renderPlainText(data) {
let result = `μ²κ΅¬ λ΄μ (κ³ κ°λͺ
: ${data.customer})\n`;
for (let perf of data.performances) {
// μ²κ΅¬ λ΄μμ μΆλ ₯νλ€.
result += ` ${perf.play.name}: ${usd(perf.amount)} (${perf.audience}μ)\n`;
}
result += `μ΄μ‘: ${usd(data.totalAmount)}\n`;
result += `μ 립 ν¬μΈνΈ: ${data.totalVolumeCredits}μ \n`;
return result;
}
function htmlStatement(invoice, plays) {
return renderHtml(createStatementData(invoice, plays));
}
function renderHtml(data) {
let result = `<h1>μ²κ΅¬ λ΄μ (κ³ κ°λͺ
: ${data.customer})</h1>\n`;
result += "<table>\n";
result += " <tr><th>μ°κ·Ή</th><th>μ’μ μ</th><th>κΈμ‘</th></tr>\n";
for (let perf of data.performances) {
result += ` <tr><td>${perf.play.name}</td><td>${perf.audience}</td>`;
result += `<td>${usd(perf.amount)}</td></tr>\n`;
}
result += "</table>\n";
result += `<p>μ΄μ‘: <em>${usd(data.totalAmount)}</em></p>\n`;
result += `<p>μ 립 ν¬μΈνΈ: <em>${data.totalVolumeCredits}</em>μ </p>\n`;
return result;
}
function usd(aNumber) {
return new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
minimumFractionDigits: 2,
}).format(aNumber / 100);
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
console.log("\n================================\n");
invoices.forEach((invoice) => {
console.log(statement(invoice, plays));
console.log("================================\n");
});
invoices.forEach((invoice) => {
console.log(htmlStatement(invoice, plays));
console.log("================================\n");
});