-
Notifications
You must be signed in to change notification settings - Fork 0
/
Document.tsx
269 lines (234 loc) · 6.95 KB
/
Document.tsx
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
'use client';
import dayjs from 'dayjs';
import type React from 'react';
import { styled } from 'styled-components';
import { GlobalStyles } from '#pkg/documents/Document.global-style';
import { formatter } from '#pkg/formatter';
const invoiceData = {
year: 2021,
nr: 1,
location: 'invoice-location',
date: dayjs(),
supplier: {
name: 'supplier-name',
street: 'supplier-street',
zipCode: 'supplier-zipcode',
city: 'supplier-city',
uid: 'supplier-uid',
iban: 'DE00 1111 0000 1111 0000 11',
bic: 'NTSBDEB1XXX',
},
recipient: {
name: 'recipient-name',
street: 'recipient-street',
zipCode: 'recipient-zipcode',
city: 'recipient-city',
uid: 'recipient-uid',
},
items: [
{
description: (
<>
<span>Full Stack Development</span>
<br />
<br />
<span>Leistungszeitraum:</span>
<br />
<span>Jänner 2021</span>
</>
),
price: 10,
amount: 120,
},
],
};
export const Document: React.FC = () => {
let nettoSum = 0;
for (const item of invoiceData.items) {
nettoSum += item.amount * item.price;
}
const ust = nettoSum * 0.2;
const bruttoSum = nettoSum + ust;
return (
<>
<GlobalStyles />
<Header>
<SupplierRegion>
<span>{invoiceData.supplier.name}</span>
<br />
<span>{invoiceData.supplier.street}</span>
<br />
<span>
{invoiceData.supplier.zipCode} {invoiceData.supplier.city}
</span>
<br />
<span>UID: {invoiceData.supplier.uid}</span>
</SupplierRegion>
</Header>
<Divider />
<RecipientRegion>
<span>{invoiceData.recipient.name}</span>
<br />
<span>{invoiceData.recipient.street}</span>
<br />
<span>
{invoiceData.recipient.zipCode} {invoiceData.recipient.city}
</span>
<br />
<span>UID: {invoiceData.recipient.uid}</span>
<br />
</RecipientRegion>
<InvoiceHeading>
<span>
Rechnung Nr. {invoiceData.year}-{`${invoiceData.nr}`.padStart(2, '0')}
</span>
<span>
{invoiceData.location}, am {dayjs().format('D. MMMM YYYY')}
</span>
</InvoiceHeading>
<InvoiceRecordsContainer>
<InvoiceRecordsTable>
<thead>
<InvoiceRecordsRow>
<InvoiceRecordsTd as="th">Pos.</InvoiceRecordsTd>
<InvoiceRecordsTd as="th">Beschreibung</InvoiceRecordsTd>
<InvoiceRecordsTd as="th">Preis</InvoiceRecordsTd>
<InvoiceRecordsTd as="th">Menge</InvoiceRecordsTd>
<InvoiceRecordsTd as="th">Betrag</InvoiceRecordsTd>
</InvoiceRecordsRow>
</thead>
<tbody>
{invoiceData.items.map((item, idx) => (
<InvoiceRecordsRow key={idx}>
<InvoiceRecordsTd>{idx + 1}</InvoiceRecordsTd>
<InvoiceRecordsTd>{item.description}</InvoiceRecordsTd>
<InvoiceRecordsTd>
{formatter.number(item.price, {
format: 'currency',
countOfDecimals: 0,
})}
</InvoiceRecordsTd>
<InvoiceRecordsTd>
{formatter.number(item.amount, { countOfDecimals: 2 })}
</InvoiceRecordsTd>
<InvoiceRecordsTd>
{formatter.number(item.price * item.amount, {
format: 'currency',
})}
</InvoiceRecordsTd>
</InvoiceRecordsRow>
))}
<InvoiceRecordsSubtotalsRow>
<InvoiceRecordsTd colSpan={2} />
<InvoiceRecordsTd colSpan={2}>Netto</InvoiceRecordsTd>
<InvoiceRecordsTd colSpan={1}>
{formatter.number(nettoSum, { format: 'currency' })}
</InvoiceRecordsTd>
</InvoiceRecordsSubtotalsRow>
<InvoiceRecordsSubtotalsRow>
<InvoiceRecordsTd colSpan={2} />
<InvoiceRecordsTd colSpan={2}>20% USt.</InvoiceRecordsTd>
<InvoiceRecordsTd colSpan={1}>
{formatter.number(ust, { format: 'currency' })}
</InvoiceRecordsTd>
</InvoiceRecordsSubtotalsRow>
<InvoiceRecordsTotalsRow>
<InvoiceRecordsTd colSpan={2} />
<InvoiceRecordsTd colSpan={2}>Endsumme inkl. USt.</InvoiceRecordsTd>
<InvoiceRecordsTd colSpan={1}>
{formatter.number(bruttoSum, { format: 'currency' })}
</InvoiceRecordsTd>
</InvoiceRecordsTotalsRow>
</tbody>
</InvoiceRecordsTable>
<PaymentDetails>
<span>IBAN: {invoiceData.supplier.iban}</span>
<br />
<span>BIC: {invoiceData.supplier.bic}</span>
<br />
<span>Zahlungsziel: 30 Tage nach Rechnungserhalt</span>
<br />
</PaymentDetails>
<GreetingSection>
<div>Mit freundlichen Grüßen,</div>
<div>{invoiceData.supplier.name}</div>
</GreetingSection>
</InvoiceRecordsContainer>
<SpacerXs />
<Divider />
<SpacerXs />
<div>Anhang: Bestätigung des Kunden</div>
</>
);
};
const Divider = styled.hr`
width: 100%;
margin-top: 8px;
margin-bottom: 8px;
`;
const SpacerXs = styled.div`
margin-top: var(--spacing-xs);
`;
const Header = styled.div`
display: flex;
justify-content: flex-end;
align-items: flex-start;
text-align: right;
`;
const SupplierRegion = styled.div`
text-align: right;
`;
const RecipientRegion = styled.div`
margin-top: var(--spacing-sm);
`;
const InvoiceHeading = styled.div`
margin-top: var(--spacing-sm);
display: flex;
justify-content: space-between;
& > *:nth-of-type(1) {
font-weight: bold;
}
`;
const InvoiceRecordsContainer = styled.div`
margin-top: var(--spacing-xs);
`;
const InvoiceRecordsTable = styled.table`
width: 100%;
`;
const InvoiceRecordsRow = styled.tr``;
const InvoiceRecordsSubtotalsRow = styled(InvoiceRecordsRow)``;
const InvoiceRecordsTotalsRow = styled(InvoiceRecordsRow)``;
const InvoiceRecordsTd = styled.td`
${InvoiceRecordsRow} > &:last-of-type {
text-align: right;
}
${InvoiceRecordsSubtotalsRow} > & {
border: 0;
}
${InvoiceRecordsSubtotalsRow} > &:nth-of-type(2),
${InvoiceRecordsSubtotalsRow} > &:nth-of-type(3) {
text-align: right;
}
${InvoiceRecordsTotalsRow} > &:nth-of-type(1) {
border: 0;
}
${InvoiceRecordsTotalsRow} > &:nth-of-type(2),
${InvoiceRecordsTotalsRow} > &:nth-of-type(3) {
border-bottom-width: 0;
border-left-width: 0;
border-right-width: 0;
border-top-width: 1px;
text-align: right;
}
`;
const PaymentDetails = styled.div`
margin-top: var(--spacing-xs);
`;
const GreetingSection = styled.div`
& > div:nth-of-type(1) {
margin-top: var(--spacing-sm);
}
& > div:nth-of-type(2) {
margin-top: var(--spacing-sm);
}
`;