-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
220 lines (202 loc) · 8.64 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
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jautocalc@1.4.2/dist/jautocalc.js"></script>
</head>
<body style="max-width: max-content" class="mx-auto p-3">
<form id="calculator">
<div class="row mb-3">
<label class="col col-form-label" for="service">Hizmet+İşlem Bedeli: </label>
<div class="col-sm input-group">
<input class="form-control" type="number" name="service" id="service" min="0" step="0.01" value="4">
<span class="input-group-text">₺</span>
</div>
</div>
<div class="row mb-3">
<label class="col col-form-label" for="vatP">KDV: </label>
<div class="col-sm input-group">
<span class="input-group-text">%</span>
<input class="form-control" type="number" name="vatP" id="vatP" min="0" value="20">
</div>
</div>
<div class="row mb-3">
<label class="col col-form-label" for="feeP">Komisyon: </label>
<div class="col-sm input-group">
<span class="input-group-text">%</span>
<input class="form-control" type="number" name="feeP" id="feeP" min="0" step="0.5">
</div>
</div>
<div class="row mb-3">
<div class="form-group">
<label for="dropdown">Kargo firması:</label>
<select class="form-control" id="dropdown" onchange="updateValue()">
<option value="aras">Aras Kargo</option>
<option value="surat" selected>Sürat Kargo</option>
<option value="mng">MNG Kargo</option>
<option value="ptt">PTT Kargo</option>
<option value="yurtici">Yurtiçi Kargo</option>
<option value="sendeo">Sendeo</option>
<option value="tex">TEX</option>
<option value="ups">UPS</option>
<option value="borusan">Borusan</option>
<option value="ceva">CEVA</option>
<option value="horoz">Horoz Lojistik</option>
<option value="custom">ÖZEL</option>
</select>
</div>
<div class="form-group" id="desiGroup">
<label for="desi">Desi:</label>
<input class="form-control" type="number" name="desi" id="desi" min="0" value="1" onchange="updateValue()">
</div>
<div class="form-group">
<label class="col col-form-label" for="shipping">Kargo (<span id="last_changed"></span>):</label>
<div class="col-sm input-group">
<input class="form-control" type="number" name="shipping" id="shipping" min="0" readonly>
<span class="input-group-text">₺</span>
</div>
</div>
</div>
<div class="row mb-3">
<label class="col col-form-label" for="cost">Geliş: </label>
<div class="col-sm input-group">
<input class="form-control" type="number" name="cost" id="cost" min="0">
<span class="input-group-text">₺</span>
</div>
</div>
<div class="row mb-3">
<label class="col col-form-label" for="price">Satış: </label>
<div class="col-sm input-group">
<input class="form-control" type="number" name="price" id="price" min="0">
<span class="input-group-text">₺</span>
</div>
</div>
<div class="row mb-3">
<h5>KAR</h5>
<div class="col-sm input-group">
<input class="form-control" type="number" name="profit" id="profit" value=""
jAutoCalc="{price}*(1/(1+{vatP}/100)-{feeP}/100)-{cost}-{shipping}-{service}" disabled>
<span class="input-group-text">₺</span>
</div>
<div class="col-sm input-group">
<span class="input-group-text">%</span>
<input class="form-control" type="number" name="percent" id="percent" value="" jAutoCalc="{profit}/{price}*100"
disabled>
</div>
</div>
<div class="row mb-3">
<button class="btn btn-primary col-sm" type="button" onclick="addToTable()">Kaydet</button>
</div>
</form>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Komisyon</th>
<th scope="col">Satış</th>
<th scope="col">Kar (%)</th>
<th scope="col"></th>
</tr>
</thead>
<tbody id="offers">
<!--
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
<td><a class="delete" title="Kaldır" data-toggle="tooltip"><i class="material-icons"></i></a></td>
</tr>
-->
</tbody>
<script>
function autoCalcSetup() {
$('form#calculator').jAutoCalc('destroy');
$('form#calculator').jAutoCalc({
keyEventsFire: true, decimalPlaces: 2, emptyAsZero: true
});
}
// Call it once when the page loads
autoCalcSetup();
</script>
<script>
function addToTable() {
let tableBody = document.getElementById("offers");
let header = document.createElement("th");
header.setAttribute('scope', 'row');
if (tableBody.rows.length == 0) {
header.innerHTML = 1;
} else {
header.innerHTML = parseInt(tableBody.rows.item(tableBody.rows.length - 1).querySelector('th').innerHTML) + 1;
}
let row = tableBody.insertRow();
row.appendChild(header);
row.insertCell().innerHTML = document.getElementById("fee").value;
row.insertCell().innerHTML = document.getElementById("price").value;
row.insertCell().innerHTML = document.getElementById("percent").value;
row.insertCell().innerHTML = '<a class="delete" title="Kaldır" data-toggle="tooltip" onclick=removeRow(this)><i class="material-icons"></i></a>';
}
function removeRow(a) {
a.parentElement.parentElement.remove();
refreshTable();
}
function refreshTable() {
let rows = document.getElementById("offers").rows;
for (let i = 0; i < rows.length; i++) {
rows[i].querySelector('th').innerHTML = i + 1;
}
}
</script>
<script>
// Flag variable to keep track of whether data has been fetched
let isDataFetched = false;
let shippingCosts;
async function fetchShippingCosts() {
try {
const response = await fetch('https://frknltrk.github.io/trendyol_public_api/data/shipping_costs.json');
const data = await response.json();
shippingCosts = data;
isDataFetched = true;
document.getElementById("last_changed").innerText = shippingCosts['last_changed'];
} catch (error) {
console.error('Error fetching shipping costs:', error);
}
}
async function updateValue() {
// Check if data has been fetched, and fetch it if not
if (!isDataFetched) {
await fetchShippingCosts();
}
var selectedValue = document.getElementById("dropdown").value;
var shipping = document.getElementById("shipping");
var priceValue = document.getElementById("price").value;
var desiValue = document.getElementById("desi").value;
if (selectedValue === "custom") {
shipping.value = 0;
shipping.removeAttribute("readonly");
document.getElementById("desiGroup").style.display = "none";
} else {
shipping.setAttribute("readonly", true);
document.getElementById("desiGroup").style.display = "block";
// Find the matching shipping cost for the selected shipping company and desi value
var selectedShippingCost = shippingCosts[selectedValue][desiValue];
// Replace comma with dot as decimal sign & convert type to float
selectedShippingCost = parseFloat(String(selectedShippingCost).replace(',', '.'));
// Update the shipping input field with the calculated shipping cost
shipping.value = selectedShippingCost;
}
autoCalcSetup();
}
// Call the updateValue function once the page loads
updateValue();
</script>
</body>
</html>