-
Notifications
You must be signed in to change notification settings - Fork 0
/
i7.html
184 lines (174 loc) · 5.73 KB
/
i7.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON to Invoice</title>
<style>
/* Basic Styling for the Invoice */
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f4f4f4;
}
.invoice-container {
max-width: 800px;
margin: auto;
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.invoice-header {
text-align: center;
margin-bottom: 20px;
}
.invoice-header h1 {
margin: 0;
}
.client-info, .invoice-details {
margin-bottom: 20px;
}
.invoice-details table, .items-table {
width: 100%;
border-collapse: collapse;
}
.invoice-details th, .invoice-details td,
.items-table th, .items-table td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
.invoice-details th, .items-table th {
background-color: #f2f2f2;
}
.total {
text-align: right;
margin-top: 20px;
font-size: 1.2em;
}
.notes {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="invoice-container" id="invoice">
<!-- Invoice Header -->
<div class="invoice-header">
<h1 id="invoiceTitle"></h1>
</div>
<!-- Invoice Details -->
<div class="invoice-details">
<table>
<tbody>
<tr>
<th>Invoice Number:</th>
<td id="invoiceNumber"></td>
</tr>
<tr>
<th>Date:</th>
<td id="invoiceDate"></td>
</tr>
<tr>
<th>Due Date:</th>
<td id="invoiceDueDate"></td>
</tr>
</tbody>
</table>
</div>
<!-- Client Information -->
<div class="client-info">
<h2>Bill To:</h2>
<p id="clientName"></p>
<p id="clientAddress"></p>
</div>
<!-- Items Table -->
<div class="items">
<table class="items-table">
<thead>
<tr>
<th>Description</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Total</th>
</tr>
</thead>
<tbody id="itemsBody">
<!-- Dynamic Invoice Items Will Be Injected Here -->
</tbody>
</table>
</div>
<!-- Grand Total -->
<div class="total" id="grandTotal">
Grand Total: $0.00
</div>
<!-- Notes -->
<div class="notes">
<h3>Notes:</h3>
<p id="invoiceNotes"></p>
</div>
</div>
<script>
const invoiceData = {
"title": "Invoice From Office Supplies",
"invoiceNumber": "INV-1001",
"date": "2023-10-01",
"dueDate": "2023-10-15",
"client": {
"name": "Jane Doe",
"address": "1234 Elm Street, Springfield, USA"
},
"items": [
{
"description": "Web Design Services",
"quantity": 10,
"unitPrice": 50
},
{
"description": "Hosting (1 year)",
"quantity": 1,
"unitPrice": 100
},
{
"description": "Domain Name (1 year)",
"quantity": 1,
"unitPrice": 10
},
{
"description": "Service X",
"quantity": 1,
"unitPrice": 100
},
],
"notes": "Thank you for your business!"
};
function populateCommonItems(){
document.getElementById('invoiceTitle').innerText = invoiceData.title;
document.getElementById('invoiceNumber').innerText = invoiceData.invoiceNumber;
document.getElementById('invoiceDate').textContent = invoiceData.date;
document.getElementById('invoiceDueDate').textContent = invoiceData.dueDate;
document.getElementById('clientName').textContent = invoiceData.client.name;
document.getElementById('clientAddress').textContent = invoiceData.client.address;
document.getElementById('invoiceNotes').textContent = invoiceData.notes;
}
function populateItems(){
const itemsBody = document.getElementById('itemsBody');
let grandTotal = 0;
invoiceData.items.forEach(item=>{
console.log(item);
const row = document.createElement('tr');
row.innerHTML = `<td>${item.description}</td>
<td>${item.quantity}</td>
<td>${item.unitPrice}</td>
<td>${item.quantity * item.unitPrice}</td>`;
itemsBody.appendChild(row);
grandTotal += item.quantity * item.unitPrice
document.getElementById('grandTotal').innerHTML = `Grand Total: $${grandTotal}`;
})
}
populateCommonItems();
populateItems();
</script>
</body>
</html>