-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
501 lines (429 loc) · 15.3 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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>
<style>
body {
font-family: Helvetica;
}
.containerparent {
margin: 2em;
display: flex;
justify-content: space-between;
flex-direction: column;
}
.left, .right {
display: flex;
flex-direction: column;
align-items: center;
}
.right > * > *:not(label) {
display: block;
}
@media only screen and (min-width: 860px)
{
.containerparent {
flex-direction: row;
}
.left {
width: 30%;
}
.right {
width: 60%;
}
}
h1 {
text-align: center;
}
h2 {
font-size: 2rem;
color: #333;
margin-top: 20px;
margin-bottom: 1rem;
}
form {
margin-top: 20px;
}
label {
font-size: 1.2rem;
color: #333;
}
input[type="number"], select {
padding: .5rem;
border-radius: .5rem;
border: none;
box-shadow: rgba(0,0,0,.1) 0px 4px 12px;
margin-bottom: .5rem;
}
button[type="button"] {
background-color: #333;
color: #fff;
padding: .5rem .8rem;
border-radius: .5rem;
border: none;
}
p {
font-size: 1.2rem;
color: #333;
margin-bottom: .5rem;
}
#totalcost {
font-size: 1.5rem;
font-weight: bold;
}
#profit {
font-size: 1.5rem;
font-weight: bold;
color: green;
}
.error {
display: block;
}
#results {
display:block;
}
#results.error {
display:none;
}
.breakeven_switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
box-shadow: rgba(0,0,0,.1) 0px 4px 12px;
margin-bottom: 0.5rem;
}
.breakeven_switch input[type="checkbox"] {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input[type="checkbox"]:checked + .slider {
background-color: #2196F3;
}
input[type="checkbox"]:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input[type="checkbox"]:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
</head>
<body>
<h1>Prinfity profit calculator</h1>
<div class="containerparent">
<div class="left">
<h2>Help and information</h2>
<p>These details should give an overview of the selling platform or final cost and profit. <br>
All the data needed can be found in your product details and choose a product variant for which you want to calculate the costs and profit. This tool has been made to approximate
cost. I am not responsible for any errors. In my usage the error was smaller than 1%, but depending on currencies and specific details it can yield a bigger error.</p>
</div>
<div class="right">
<form>
<label for="plat_select">Selling Platform</label><br>
<select class="select" id="plat_select" name="plat_select" onchange="throttledCheck()">
<option value="">Select an option</option>
<option value="Cheapest">Cheapest</option>
<option value="Etsy">Etsy</option>
<option value="BigCartel">Big Cartel</option>
<option value="Shopify">Shopify</option>
<option value="WooCommerce">WooCommerce</option>
<option value="Squarespace">Squarespace</option>
<!--<option value="3">Other?</option>-->
</select>
<label for="plat_select_from">Print on demand or directly</label><br>
<select class="select" id="plat_select_from" name="plat_select_from" onchange="throttledCheck()">
<option value="Printify">Printify</option>
<option value="Direct">Directly from selling platform</option>
</select>
<div id="BC_parent" style="display:none;">
<label for="BigCartel_select">BigCartel payment type</label><br>
<select class="select" id="BigCartel_select" name="BigCartel_select" onchange="throttledCheck()">
<option value="">Select an option</option>
<option value="Stripe">Stripe</option>
<option value="Paypal">Paypal</option>
</select>
</div>
<label for="prod_cost">Production cost (Provider)</label><br> <!-- 9.01 eur -->
<input type="number" id="prod_cost" name="prod_cost" oninput="throttledCheck()" min="0"><br>
<label for="ship_cost">Shipping cost (Provider)</label><br> <!-- 5.10 eur -->
<input type="number" id="ship_cost" name="ship_cost" oninput="throttledCheck()" min="0"><br>
<label for="retailprice">Retail price (Provider: EXCLUDING SHIPPING)</label><br> <!-- -->
<input type="number" id="retailprice" name="retailprice" oninput="throttledCheck()" min="0"><br>
<label for="VATamount">VAT percentage (0-100%)</label><br> <!-- -->
<input type="number" id="VATamount" name="VATamount" oninput="throttledCheck()" min="0" onkeydown="if (event.keyCode === 13) { throttledCheck(); return false; }"><br>
<!--<label for="num3">Printify retail price</label><br>
<input type="number" id="num3" name="num3"><br><br>-->
<!--<label for="nSales">Amount of sales (expected) over listing months</label><br>
<input type="number" id="nSales" name="nSales"><br><br>-->
<label for="prod_cost">Calculate break-even point</label><br> <!-- 9.01 eur -->
<label class="breakeven_switch">
<input type="checkbox" id="breakeven_checkbox" oninput="throttledCheck()">
<span class="slider round"></span>
</label>
<button type="button" onclick="throttledCheck()">Calculate</button>
<label id="error" class="error"></label>
</form>
<div>
<p id="printifyresult"></p> <!-- 17.07 eur -->
<div id="results">
<p id="platresult"></p> <!-- 3.13 eur -->
<!--<p id="cheapestOption"></p> -->
<p id="totalcost"></p> <!-- 20.22 eur -->
<p id="noprofit"></p>
<p id="profit"></p> <!-- 1.43 eur -->
</div>
</div>
</div>
</div>
<script>
// Get the current URL
var currentUrl = window.location.href;
// Create a URLSearchParams object from the URL
var urlParams = new URLSearchParams(currentUrl);
// Get the values of 'plat' and 'plat_from' parameters
var platUrl = urlParams.get('plat');
var platFromUrl = urlParams.get('plat_from');
var select = document.getElementById("plat_select");
var select_from = document.getElementById("plat_select_from");
select.value = platUrl;
select_from.value = platFromUrl;
// select.dispatchEvent(new Event('change'));
function getInput(id) {
return parseFloat(document.getElementById(id).value);
}
function calculate(plat="", plat_from="") {
let profit, totalcost, prodplusship;
var VAT_rate = getInput("VATamount") / 100;
var provider_production_costs = getInput("prod_cost");
var provider_shipping = getInput("ship_cost");
if (plat_from == "Printify"){
var printify_VAT = (provider_production_costs + provider_shipping)*VAT_rate;
printify_result = provider_shipping + provider_production_costs + printify_VAT;
prodplusship = printify_result;
} else if (plat_from == "Direct"){
prodplusship = provider_shipping + provider_production_costs;
}
document.getElementById("printifyresult").innerHTML = "Total costs (Printify) " + prodplusship.toFixed(2);
var retailprice_excl_shipping = parseFloat(document.getElementById("retailprice").value);
if(plat == "")
{
errorFeedback('platform');
}
var stepsize;
var finalaccuracy = 0.004; // As long as sub 1 cent, not noticable in any calculation or visual display
var firsttime = true;
var iter = 0;
var maxIter = 1000;
var noprofitEl = document.getElementById("noprofit");
var breakeven_toggle = document.getElementById("breakeven_checkbox");
if (breakeven_toggle.checked) {
//maxIter = 1000
} else {
maxIter = 1;
noprofitEl.innerHTML = "";
}
while ((profit == null || Math.abs(profit) > finalaccuracy) && iter < maxIter) {
iter ++;
// Set retailprice_excl_shipping manually and run this code to check if profit goes to 0.
var retailprice_incl_shipping = retailprice_excl_shipping+provider_shipping;
var plat_cost = 0;
lowest_plat_price = null;
cheapest_plat = "";
let isCheapest = plat === 'Cheapest';
if (plat == "Etsy" || isCheapest) // Etsy
{
var listing_cost = 0.2; // one time
var trans_cost = 0.065*retailprice_excl_shipping;
var process_cost = 0.04*retailprice_excl_shipping+0.30;
var Etsy_VAT = trans_cost*VAT_rate + process_cost * VAT_rate;
// 0.01*retailprice_excl_shipping + 0.01 * provider_shipping + process_cost * VAT_rate;
var plat_cost = process_cost + trans_cost + Etsy_VAT;
console.log("Etsy cost: "+ retailprice_excl_shipping+ " " + trans_cost+" " + process_cost +" "+ Etsy_VAT);
cheapCheck("Etsy",plat_cost);
}
if (plat == "BigCartel" || isCheapest) // Big Cartel // ONLY payment fees, so calculate them here
{
var select_BC = document.getElementById("BigCartel_select");
var BC_payment = select_BC.value;
BC_VAT = VAT_rate*retailprice_incl_shipping;
if(BC_payment == 'Stripe' || isCheapest)
{
plat_cost = 0.015*(retailprice_incl_shipping+BC_VAT) + .25; //1,5% + € 0,25
cheapCheck("BigCartel stripe",plat_cost);
}
if (BC_payment == 'Paypal' || isCheapest)
{
plat_cost = 0.044*(retailprice_incl_shipping+BC_VAT); // 4.4% + any currency fees
cheapCheck("BigCartel paypal",plat_cost);
}
if (BC_payment == "" && !isCheapest)
{
errorFeedback('platform');
}
}
if (plat == "Shopify" || isCheapest) {
// Shopify fees
var monthly_fee = 29; // Basic Shopify plan
var trans_fee = 0.02 + 0.032 * retailprice_incl_shipping; // 2% + 3.2% of transaction
var shopify_cost = monthly_fee + trans_fee;
cheapCheck("Shopify", shopify_cost);
}
if (plat == "WooCommerce" || isCheapest) {
// WooCommerce fees
var trans_fee = 0.035 * retailprice_incl_shipping + 0.50;
var woo_cost = trans_fee;
cheapCheck("WooCommerce", woo_cost);
}
if (plat == "Squarespace" || isCheapest) {
// Squarespace fees
var monthly_fee = 12; // Basic Commerce plan
var trans_fee = 0.03 * retailprice_incl_shipping;
var square_cost = monthly_fee + trans_fee;
cheapCheck("Squarespace", square_cost);
}
totalcost = plat != "Cheapest" ? prodplusship + plat_cost : prodplusship + lowest_plat_price;
profit = retailprice_excl_shipping - totalcost; // 1.43 eur
if(firsttime)
{
document.getElementById("totalcost").innerHTML = "Total cost " + totalcost.toFixed(2);
document.getElementById("profit").innerHTML = "Total profit " + profit.toFixed(2);
if (plat == "Cheapest")
{
document.getElementById("platresult").innerHTML = "Cheapest platform available: " + cheapest_plat + " at a price of: " + lowest_plat_price.toFixed(2);
} else
{
document.getElementById("platresult").innerHTML = "Selling platform: Total cost " + plat_cost.toFixed(2);
}
firsttime = false;
stepsize = 0.01;
} else if(Math.abs(profit) > finalaccuracy)
{
stepsize = Math.abs(profit) / 10;
// console.log("stepsize,profit: "+stepsize+","+profit)
/*if(stepsize > Math.abs(profit))
{
stepsize /= 10;
} else */
if (profit < -stepsize) {
retailprice_excl_shipping += stepsize;
} else if (profit > stepsize) {
retailprice_excl_shipping -= stepsize;
}
} else if (Math.abs(profit) <= finalaccuracy) // noprofit price in range/found
{
noprofitEl.innerHTML = "The break-even retail price (exl. shipping) price is: " + retailprice_excl_shipping.toFixed(2);
}
}
}
var cheapest_plat;
var lowest_plat_price;
function cheapCheck(plat, price)
{
if(!lowest_plat_price)
{
lowest_plat_price = price;
return;
}
if(price < lowest_plat_price)
{
lowest_plat_price = price;
cheapest_plat = plat;
}
}
const errorEl = document.getElementById('error');
const resultsEl = document.getElementById('results')
function errorFeedback(type = '')
{
if(type == 'platform')
{
errorEl.textContent = 'Not valid platform and details selected';
resultsEl.classList.add("error");
return;
}
if (type == 'input')
{
errorEl.textContent = 'Please enter a valid number (above 0) for all fields';
resultsEl.classList.add("error");
return;
}
if (type == 'no_prod_cost')
{
errorEl.textContent = 'No production cost filled in, only platform data will be shown until the production field is filled in.';
//resultsEl.classList.add("error");
return;
}
// Clear error
errorEl.textContent = '';
resultsEl.classList.remove("error");
}
const throttledCheck = _.throttle(checkInputs, 200);
function checkInputs() {
var inputs = document.querySelectorAll('input[type=number]');
var filledIn = true;
var plat = select.value;
var plat_from = select_from.value;
var BC_parent = document.getElementById("BC_parent");
BC_parent.style.display = "none";
if (plat == "BigCartel") // Big Cartel // ONLY payment fees, so calculate them here
{
// Show BC select
BC_parent.style.display = "block";
}
errorFeedback(); // Clear errors of previous inputs
inputs.forEach(function(input) {
if (input.value === '') {
filledIn = false;
}
if(input.value < 0 || parseInt(input.value) === 0) {
filledIn = false;
input.value = Math.abs(input.value);
}
if(input.id == "prod_cost" && !filledIn)
{
errorFeedback('no_prod_cost');
filledIn = true;
return;
}
});
if (filledIn) {
calculate(plat,plat_from);
} else
{
errorFeedback('input');
}
}
</script>
</body>
</html>