-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoquote.js
329 lines (284 loc) · 9.5 KB
/
autoquote.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
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
// TO CHANGE PRICES: Be sure to update both pricesheet.html, autoquote.html AND autoquote.js
let numOfCharacters = 0;
let framingCosts = {
"Headshot": 35,
"Bust": 40,
"Halfbody": 45,
"Thighup": 50,
"Fullbody": 55,
}
let addonsCosts = {
backgrounds: {
"None": 0,
"Abstract": 6,
"Simple Scene": 15,
},
props: 8, // per character (first 3 are free)
shading: 10, // per character
noColor: 8, // per character (subtract this value, don't add)
}
let total = 0;
let overview = {
framingOptions: {
mostExpensive: "",
discounted: []
},
addons: {
background: "",
props: 0,
shading: false,
noColor: false
},
details: ""
};
// for fomatting
let currency = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
});
// autoquote form submission
document.getElementById("autoquote_form").addEventListener("submit", function(e) {
e.preventDefault(); // keep browser from reloading on submit
var formData = new FormData(e.target);
// reset overview vals
overview.framingOptions.mostExpensive = "";
overview.framingOptions.discounted = [];
overview.addons.background = "";
overview.addons.props = 0;
overview.addons.shading = false;
overview.addons.noColor = false;
overview.details = "";
total = 0;
// hide form, show results
document.getElementById("results").style.display = "grid";
document.getElementById("autoquote_form").style.display = "none";
// find most expensive framing cost
let highestFramingCost = 0;
let highestFramingOption = "";
for (let i = 0; i <= numOfCharacters; ++i) {
let framingOption = formData.get(`framing_${i}`);
if (highestFramingCost < framingCosts[framingOption]) {
highestFramingCost = framingCosts[framingOption];
highestFramingOption = framingOption;
}
}
overview.framingOptions.mostExpensive = `${highestFramingOption}`;
// add that to total as is,
// apply 35% discount for all other framing options selected
total += highestFramingCost;
let skippedHighest = false;
for (let i = 0; i <= numOfCharacters; ++i) {
let framingOption = formData.get(`framing_${i}`);
if (highestFramingCost != framingCosts[framingOption] || skippedHighest) {
total += framingCosts[framingOption] * 0.65; // discount
overview.framingOptions.discounted.push(framingOption);
} else {
skippedHighest = true;
}
}
// addons
// backgrounds
let background = formData.get("background");
total += addonsCosts.backgrounds[background];
overview.addons.background = background;
// props
let props = formData.get("props");
if (props > 3) {
total += addonsCosts.props * (props - 3);
}
overview.addons.props = props;
// shading
if (formData.get("shading") == "on") {
total += addonsCosts.shading * (numOfCharacters + 1);
overview.addons.shading = true;
}
// no color
if (formData.get("no color") == "on") {
total -= addonsCosts.noColor * (numOfCharacters + 1);
overview.addons.noColor = true;
}
let details = formData.get("details");
if (details != "") {
overview.details = details;
} else {
overview.details = "[Empty]";
}
// create HTML
let largeDelimeter = " - ";
let smallDelimeter = " ";
let item = "";
let cost = "";
let math = "";
let overviewDOM = document.getElementById("overview");
let detailsDOM = document.getElementById("details");
// clear out existing HTML
overviewDOM.replaceChildren();
detailsDOM.replaceChildren();
let appendEntry = function(item, cost, math) {
let newPar = document.createElement("p");
newPar.innerHTML += item + largeDelimeter + cost;
if (math != null) {
newPar.innerHTML += smallDelimeter + math;
}
overviewDOM.append(newPar);
}
// highest framing option
item = `${overview.framingOptions.mostExpensive}`;
cost = `$${framingCosts[overview.framingOptions.mostExpensive]}`;
appendEntry(item, cost, null);
// discounted framing options
for (let i = 0; i < overview.framingOptions.discounted.length; ++i) {
item = `${overview.framingOptions.discounted[i]}`;
cost = `$${framingCosts[overview.framingOptions.discounted[i]] * 0.65}`;
math = `(65% of $${framingCosts[overview.framingOptions.discounted[i]]})`;
appendEntry(item, cost, math);
}
if (overview.addons.shading) {
item = "Shading";
cost = `$${addonsCosts.shading * (numOfCharacters + 1)}`;
math = `($${addonsCosts.shading} per character)`;
appendEntry(item, cost, math);
}
if (overview.addons.noColor) {
item = "No Color";
cost = `-$${addonsCosts.noColor * (numOfCharacters + 1)}`;
math = `(-$${addonsCosts.noColor} per character)`;
appendEntry(item, cost, math);
}
if (overview.addons.background != "None") {
let background = overview.addons.background;
let backgroundDOM = document.createElement("p");
if (background == "Abstract") {
item = "Abstract Background";
} else if (background == "Simple Scene") {
item = "Simple Scene";
} else if (background == "Complex Scene") {
item = "Complex Scene";
}
cost = `$${addonsCosts.backgrounds[background]}`;
appendEntry(item, cost, null);
}
if (overview.addons.props > 0) {
item = `${overview.addons.props} Props`;
if (overview.addons.props > 3) {
cost = `$${addonsCosts.props * (overview.addons.props - 3)}`;
} else {
cost = "$0";
}
math = `($${addonsCosts.props} each, first 3 are free)`;
appendEntry(item, cost, math);
}
let boldPrompt = document.createElement("strong");
boldPrompt.innerHTML = "Extra Details: ";
detailsDOM.appendChild(boldPrompt);
detailsDOM.innerHTML += overview.details;
document.getElementById("total_value").innerHTML = `${currency.format(total)}`;
});
function hideResults() {
document.getElementById("results").style.display = "none";
document.getElementById("autoquote_form").style.display = "grid";
}
function copyResults() {
let largeDelimeter = " - ";
let smallDelimeter = " ";
let result = "FURTHINGS QUOTE OVERVIEW\n";
let appendEntry = function(item, cost, math) {
if (math != undefined) {
result += item + largeDelimeter + cost + smallDelimeter + math;
} else {
result += item + largeDelimeter + cost;
}
result += '\n';
}
let item = "";
let cost = "";
let math = "";
// highest framing option
item = `${overview.framingOptions.mostExpensive}`;
cost = `$${framingCosts[overview.framingOptions.mostExpensive]}`;
appendEntry(item, cost, null);
// discounted framing options
for (let i = 0; i < overview.framingOptions.discounted.length; ++i) {
item = `${overview.framingOptions.discounted[i]}`;
cost = `$${framingCosts[overview.framingOptions.discounted[i]] * 0.65}`;
math = `(65% of $${framingCosts[overview.framingOptions.discounted[i]]})`;
appendEntry(item, cost, math);
}
if (overview.addons.shading) {
item = "Shading";
cost = `$${addonsCosts.shading * (numOfCharacters + 1)}`;
math = `($${addonsCosts.shading} per character)`;
appendEntry(item, cost, math);
}
if (overview.addons.noColor) {
item = "No Color";
cost = `-$${addonsCosts.noColor * (numOfCharacters + 1)}`;
math = `(-$${addonsCosts.noColor} per character)`;
appendEntry(item, cost, math);
}
if (overview.addons.background != "None") {
let background = overview.addons.background;
let backgroundDOM = document.createElement("p");
if (background == "Abstract") {
item = "Abstract Background";
} else if (background == "Simple Scene") {
item = "Simple Scene";
} else if (background == "Complex Scene") {
item = "Complex Scene";
}
cost = `$${addonsCosts.backgrounds[background]}`;
appendEntry(item, cost, null);
}
if (overview.addons.props > 0) {
item = `${overview.addons.props} Props`;
if (overview.addons.props > 3) {
cost = `$${addonsCosts.props * (overview.addons.props - 3)}`;
} else {
cost = "$0";
}
math = `($${addonsCosts.props} each, first 3 are free)`;
appendEntry(item, cost, math);
}
result += `TOTAL - ${currency.format(total)}\n`;
if (overview.details != "[Empty]") {
result += "Prompt - " + overview.details;
}
navigator.clipboard.writeText(result);
}
function createFramingOption(value) {
let option = document.createElement("option");
option.setAttribute("value", value);
option.innerHTML = value;
return option;
}
function addCharacter() {
numOfCharacters += 1;
// select
let select = document.createElement("select");
select.setAttribute("name", `framing_${numOfCharacters}`);
// options
//let closeup = createFramingOption("Closeup");
const headshot = createFramingOption("Headshot");
const bust = createFramingOption("Bust");
const halfbody = createFramingOption("Halfbody");
const thighup = createFramingOption("Thighup");
const fullbody = createFramingOption("Fullbody");
//let scenic = createFramingOption("Scenic");
const all_options = [headshot, bust, halfbody, thighup, fullbody];
// add all options to select
for (const option of all_options) {
select.appendChild(option);
}
// add a new row for every 3 characters
let rowNumber = Math.floor(numOfCharacters / 3);
if (numOfCharacters % 3 == 0) {
let form = document.getElementById("autoquote_form");
let row = document.createElement("div");
row.setAttribute("class", "row");
row.appendChild(select);
form.children[rowNumber - 1].after(row);
} else {
let framingRow = document.getElementById("autoquote_form").children[rowNumber];
framingRow.appendChild(select);
}
}