-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·356 lines (320 loc) · 12.1 KB
/
index.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
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
body {
padding-top: 50px;
padding-bottom: 20px;
}
.no-left-important {
padding-left: 0px !important;
}
</style>
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<style>
@media print {
.editable {
background-color: white;
}
.no-print,
.no-print * {
display: none !important;
}
}
.editable {
background-color: lightyellow;
}
</style>
</head>
<body>
<div id="file_drop" class="container">
<div class="row">
<div class="col-md-4">
<h2>INVOICE</h2>
</div>
</div>
<div class="row">
<div class="col-md-4">
<h3>To:</h3>
<h4 contenteditable="true" class="editable" id="invoicee">The Customer</h4>
<div contenteditable="true" class="editable" id="invoicee_1">[email protected]</div>
<div contenteditable="true" class="editable" id="invoicee_2">800/234-1234</div>
<div contenteditable="true" class="editable" id="invoicee_3"> </div>
</div>
<div class="col-md-4">
<div class="col-md-6">
<h4>Invoice Date:</h4>
<p contenteditable="true" class="editable" id="invoice_date">m/d/y</p>
</div>
<div class="col-md-6">
<h4>Invoice Number:</h4>
<p contenteditable="true" class="editable" id="invoice_number">nn-nnnn</p>
</div>
</div>
<div class="col-md-4">
<div class="col-md-12">
<div class="pull-right">
<h3>From:</h3>
<h4 contenteditable="true" class="editable" id="invoicer">The Vendor</h4>
</div>
</div>
<div class="col-md-12">
<div class="pull-right">
<div contenteditable="true" class="editable" id="invoicer_1">[email protected]</div>
<div contenteditable="true" class="editable" id="invoicer_2">800/123-2345</div>
<div contenteditable="true" class="editable" id="invoicer_3"> </div>
</div>
</div>
</div>
</div>
<div class="row" style="height: 50px;">
</div>
<div id="line_item_header" class="row" style="border-bottom: 1px solid black; margin-bottom: 15px;">
<div class="col-md-7">
<div class="col-md-offset-2 col-md-10">
<h5>Description</h5>
</div>
</div>
<div class="col-md-5">
<div class="col-md-4">
<h5>Quantity</h5>
</div>
<div class="col-md-4">
<h5>Unit Cost</h5>
</div>
<div class="col-md-4">
<h5>Amount</h5>
</div>
</div>
</div>
<div id="line_item_list">
</div>
<div id="line_item_template" class="row line_items hidden-print">
<div class="col-md-7">
<div class="col-md-12">
<p class="item_description">Drop Timing HTML Exports Here <smaller>(anything in yellow is editable, and stuff cleans up for printing)</smaller>
</p>
</div>
</div>
<div class="col-md-5 item_group">
<div class="col-md-4">
<p class="item_quantity">X</p>
</div>
<div class="col-md-4">
<p class="item_cost">Y.yy</p>
</div>
<div class="col-md-4">
<p class="item_value">Z.zz</p>
</div>
</div>
</div>
<div class="row" style="height: 50px;">
</div>
<div class="row">
<div class="col-md-offset-7 col-md-5">
<div class="col-md-offset-7 col-md-1">
<div class="pull-right">
<h5 class="editable">Subtotal:</h5>
</div>
</div>
<div class="col-md-3">
<div class="pull-left">
<h5 id="sub_total"></h5>
</div>
</div>
<!-- <div class="item_deletor col-md-1">
<span class="hidden-print line_item_deletor glyphicon glyphicon-remove pull-right"></span>
</div> -->
</div>
</div>
<div id="additional_item_list">
</div>
<div id="additional_item_template" class="row line_items hidden-print">
<div class="col-md-offset-7 col-md-5">
<div class="col-md-8">
<div class="pull-right">
<p class="additional_tag">Add invoice level items here (ex: Tax 6%, Shipping $22, Coupon -$50, Discount -10%) </p>
</div>
</div>
<div class="col-md-4">
<div class="col-md-6 no-left-important">
<div class="pull-left">
<p class="additional_value">T.xx</p>
</div>
</div>
<div class="col-md-6">
<span class="additional_item_generator glyphicon glyphicon-plus pull-right"></span>
</div>
</div>
</div>
</div>
<div class="row" style="height: 50px;">
</div>
<div class="row">
<div class="col-md-offset-7 col-md-5">
<div class="col-md-offset-5 col-md-2">
<div class="pull-right">
<div id="update_totals" class="btn btn-default hidden-print">Update Totals</div>
</div>
</div>
<div class="col-md-1">
<div class="pull-right">
<h5 class="editable">Total:</h5>
</div>
</div>
<div class="col-md-3">
<div class="pull-left">
<h5 id="grand_total"></h5>
</div>
</div>
</div>
</div>
<div class="row" style="height: 100px;">
</div>
<div class="row">
<div class="col-md-12">
<div class="pull-left">
<h5 contenteditable="true" class="editable">Due Date: </h5>
</div>
<div class="pull-left">
<h5 contenteditable="true" class="editable" id="due_date">mm-dd-yy</h5>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://lib.arvancloud.com/ar/datejs/1.0/date.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/filedrop.min.js"></script>
<script>
var duration = /(-?\d*\.?\d+(?:e[-+]?\d+)?)\s*([a-zμ]*)/ig
function parse(str) {
var result = 0
// ignore commas
str = str.replace(/(\d),(\d)/g, '$1$2')
str.replace(duration, function (_, n, units) {
units = parse[units]
|| parse[units.toLowerCase().replace(/s$/, '')]
|| 1
result += parseFloat(n, 10) * units
})
return result
}
parse.nanosecond = parse.ns = 1 / 1e6;
parse.millisecond = parse.ms = 1;
parse.second = parse.sec = parse.s = parse.ms * 1000;
parse.minute = parse.min = parse.m = parse.s * 60;
parse.hour = parse.hr = parse.h = parse.m * 60;
parse.day = parse.d = parse.h * 24;
parse.week = parse.wk = parse.w = parse.d * 7;
parse.b = parse.month = parse.d * (365.25 / 12);
parse.year = parse.yr = parse.y = parse.d * 365.25;
</script>
<script>
// ---------------------------------------------------------------------------
function initFileDrop() {
window.fd.logging = false;
var options = { input: false };
var zone = new FileDrop('file_drop', options);
zone.event("send", function (files) {
files.each(function (file) {
file.readData(
data => {
let descrip = $(data).find('.totalTime').parent().children().empty().parent().text().trim();
let dateRange = $(data).find('.dateRange').text().trim();
let fullDescrip = `${descrip} <smaller>[${dateRange}]</smaller>`;
let totalTime = $(data).find('.totalTime').text().trim();
let decimalHours = millisToHrs(totalTime);
let ratePerHour = 50;
let itemCost = decimalHours * ratePerHour;
let lineDeletor = '<span class="hidden-print line_item_deletor glyphicon glyphicon-remove pull-right"></span>';
let $lineTemplate = $('#line_item_template').clone();
$lineTemplate.find('.item_description').attr('contenteditable', true).addClass('editable').html(fullDescrip);
$lineTemplate.find('.item_quantity').attr('contenteditable', true).addClass('editable').text(`${decimalHours} hrs`);
$lineTemplate.find('.item_cost').attr('contenteditable', true).addClass('editable').text(`${toMonetary(ratePerHour)}`);
$lineTemplate.find('.item_value').html(`${toMonetary(itemCost)} ${lineDeletor}`);
$('#line_item_list').append(`<div class="row line_items">${$lineTemplate.html()}</div>`);
},
err => {
console.log("filedrop.readdata.err", err);
},
"text"
);
});
});
};
// ---------------------------------------------------------------------------
function millisToHrs(totalTime) {
return parseFloat(parse(totalTime) / 1000 / 60 / 60).toFixed(2);
};
// ---------------------------------------------------------------------------
function toMonetary(x) {
return `$${Number(x).toFixed(2)}`;
};
// ---------------------------------------------------------------------------
function updateTotals() {
// debugger;
let subTotal = 0;
$('.item_group').each(function () {
let item_quantity = $(this).find('.item_quantity').text().replace(/[^0-9.]/g, '');
let item_cost = $(this).find('.item_cost').text().replace(/[^0-9.]/g, '');
if (isFinite(item_quantity) && isFinite(item_cost)) {
let item_value = item_quantity * item_cost;
$(this).find('.item_value').text(toMonetary(item_value));
subTotal += item_value;
}
});
$('#sub_total').text(toMonetary(subTotal));
let grandTotal = subTotal;
$('.additional_value').each(function () {
let additional_value = $(this).text();
let dollars = (/[$]/.test(additional_value));
let percent = (/[%]/.test(additional_value));
let negative = (/[-]/.test(additional_value));
let adjustment = additional_value.replace('$', '').replace('%', '');
if (isFinite(adjustment)) {
if (dollars && !percent) {
grandTotal = grandTotal + Number(adjustment);
}
if (!dollars && percent) {
grandTotal = grandTotal + Number(grandTotal * adjustment / 100);
}
}
});
$('#grand_total').text(toMonetary(grandTotal));
}
// ---------------------------------------------------------------------------
$(document).ready(() => {
initFileDrop();
let now = new Date();
$('#invoice_date').text(now.toString('M/d/yy'));
now.add(1).months();
$('#due_date').text(now.toString('M/d/yy'));
$('#line_item_list').on('click', evt => {
if ($(evt.target).hasClass('glyphicon')) {
$(evt.target).parents('.line_items').remove();
}
});
$('.additional_item_generator').on('click', evt => {
let $additionalTemplate = $('#additional_item_template').clone();
$additionalTemplate.find('.additional_tag').attr('contenteditable', true).addClass('editable').text(`Tax`);
$additionalTemplate.find('.additional_value').attr('contenteditable', true).addClass('editable').text(`6%`);
$additionalTemplate.find('.additional_item_generator').removeClass('additional_item_generator').addClass('additional_item_subtractor').removeClass('glyphicon-plus').addClass('glyphicon-minus').addClass('hidden-print');
$('#additional_item_list').append(`<div class="row line_items">${$additionalTemplate.html()}</div>`);
$('#additional_item_list').on('click', evt => {
if ($(evt.target).hasClass('glyphicon')) {
$(evt.target).parents('.line_items').remove();
}
});
});
$('#update_totals').click(updateTotals);
});
</script>
</body>
</html>