-
Notifications
You must be signed in to change notification settings - Fork 0
/
statement.ts
58 lines (49 loc) · 1.74 KB
/
statement.ts
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
// type PlayTypeT = 'comedy' | 'tragedy';
type PlaysT = {
[playID: string]: { name: string, type: string }
}
type InvoiceT = {
customer: string,
performances: {
playID: string,
audience: number
}[]
}
function statement(invoice: InvoiceT, plays: PlaysT): string {
let totalAmount = 0;
let volumeCredits = 0;
let result = `청구 내역 (고객명: ${invoice.customer})\n`;
const format = new Intl.NumberFormat("en-US", { style: 'currency', currency: 'USD', minimumFractionDigits: 2 }).format
for (let i = 0; i < invoice.performances.length; i++) {
const perf = invoice.performances[i]
const play = plays[perf.playID];
let thisAmount = 0;
switch (play.type) {
case 'tragedy':
thisAmount = 40000;
if (perf.audience > 30) {
thisAmount += 1000 * (perf.audience - 30);
}
break;
case "comedy":
thisAmount = 30000;
if (perf.audience > 20) {
thisAmount += 10000 + 500 * (perf.audience - 20);
}
thisAmount += 300 * perf.audience;
break;
default:
throw new Error('알 수 없는 장르: '+ play.type);
}
volumeCredits += Math.max(perf.audience - 30, 0);
if (play.type === 'comedy') {
volumeCredits += Math.floor(perf.audience / 5);
}
result += ` ${play.name}: ${format(thisAmount/100)} (${perf.audience}석)\n`;
totalAmount += thisAmount;
}
result += `총액: ${format(totalAmount/100)}\n`
result += `적립 포인트: ${volumeCredits}점`
return result;
}
export default statement;