Spaces:
Running
Running
Upload 2 files
Browse files- javascript/main.js +2 -2
- javascript/search.js +85 -125
javascript/main.js
CHANGED
@@ -205,11 +205,11 @@ function formatTransactionDate(key) {
|
|
205 |
|
206 |
async function loadTransactions() {
|
207 |
const userData = await getUserData();
|
208 |
-
const transactions = userData.transactions
|
209 |
|
210 |
if (!transactions || Object.keys(transactions).length === 0) {
|
211 |
document.getElementById("transaction-details").innerHTML =
|
212 |
-
"<p>Anda belum melakukan transaksi apapun. Silahkan beli produk terlebih dahulu.</p>";
|
213 |
alert("Anda belum melakukan transaksi apapun. Silahkan beli produk terlebih dahulu.", false)
|
214 |
return;
|
215 |
}
|
|
|
205 |
|
206 |
async function loadTransactions() {
|
207 |
const userData = await getUserData();
|
208 |
+
const transactions = userData.transactions || {};
|
209 |
|
210 |
if (!transactions || Object.keys(transactions).length === 0) {
|
211 |
document.getElementById("transaction-details").innerHTML =
|
212 |
+
"<p>Anda belum melakukan transaksi apapun. Silahkan beli produk terlebih dahulu.</p>";
|
213 |
alert("Anda belum melakukan transaksi apapun. Silahkan beli produk terlebih dahulu.", false)
|
214 |
return;
|
215 |
}
|
javascript/search.js
CHANGED
@@ -109,131 +109,91 @@ document.addEventListener("DOMContentLoaded", async function () {
|
|
109 |
resultList.appendChild(hrElement);
|
110 |
}
|
111 |
|
112 |
-
if (transactionQuery) {
|
113 |
-
const userData = await getUserData();
|
114 |
-
const transactions = userData.transactions
|
115 |
-
|
116 |
-
if (
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
resultList.appendChild(messageElem);
|
121 |
-
alert(messageElem.textContent, false);
|
122 |
}
|
123 |
-
|
124 |
-
const
|
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 |
-
cardBody.innerHTML = `
|
201 |
-
<div class="payment-icon-bg">
|
202 |
-
<i class="bi ${paymentIcon}" style="font-size: 2.5rem;"></i>
|
203 |
-
<span class="m-2">Metode: ${
|
204 |
-
transaction.payment_method
|
205 |
-
? transaction.payment_method
|
206 |
-
: "N/A"
|
207 |
-
}</span>
|
208 |
-
</div>
|
209 |
-
<div class="content">
|
210 |
-
<div class="d-flex justify-content-between align-items-center">
|
211 |
-
<div class="transaction-total fw-bold">
|
212 |
-
Total: ${formatRupiah(total)}
|
213 |
-
</div>
|
214 |
-
</div>
|
215 |
-
<div class="d-flex justify-content-between align-items-center mt-auto">
|
216 |
-
<div class="transaction-date">
|
217 |
-
Tanggal: ${td[0]} <br> Waktu: ${td[1]}
|
218 |
-
</div>
|
219 |
-
</div>
|
220 |
-
</div>
|
221 |
-
`;
|
222 |
-
|
223 |
-
card.appendChild(cardBody);
|
224 |
-
col.appendChild(card);
|
225 |
-
resultList.appendChild(col);
|
226 |
-
col.addEventListener("click", () => {
|
227 |
-
window.location.href = `transaction.html?date=${transactionKey}`;
|
228 |
-
});
|
229 |
-
}
|
230 |
-
);
|
231 |
-
} else {
|
232 |
-
const messageElem = document.createElement("p");
|
233 |
-
messageElem.textContent = "Transaksi tidak ditemukan.";
|
234 |
-
messageElem.className = "text-center";
|
235 |
-
alert(messageElem.textContent, false);
|
236 |
-
resultList.appendChild(messageElem);
|
237 |
-
}
|
238 |
}
|
239 |
});
|
|
|
109 |
resultList.appendChild(hrElement);
|
110 |
}
|
111 |
|
112 |
+
if (transactionQuery) {
|
113 |
+
const userData = await getUserData();
|
114 |
+
const transactions = userData.transactions || {};
|
115 |
+
|
116 |
+
if (Object.keys(transactions).length === 0) {
|
117 |
+
document.getElementById("transaction-details").innerHTML =
|
118 |
+
"<p>Anda belum melakukan transaksi apapun. Silahkan beli produk terlebih dahulu.</p>";
|
119 |
+
return;
|
|
|
|
|
120 |
}
|
121 |
+
|
122 |
+
const transactionList = document.getElementById("transaction-list");
|
123 |
+
|
124 |
+
if (!transactionList) return;
|
125 |
+
transactionList.innerHTML = "";
|
126 |
+
|
127 |
+
const entries = Object.entries(transactions).sort((a, b) => {
|
128 |
+
const parseDateFromKey = (key) => {
|
129 |
+
const [year, month, day, hour, minute, second, ms] = key.split("_");
|
130 |
+
return new Date(year, month - 1, day, hour, minute, second, ms);
|
131 |
+
};
|
132 |
+
return parseDateFromKey(b[0]) - parseDateFromKey(a[0]);
|
133 |
+
});
|
134 |
+
|
135 |
+
entries.forEach(([transactionKey, transaction]) => {
|
136 |
+
let total = 0;
|
137 |
+
|
138 |
+
if (Array.isArray(transaction.products)) {
|
139 |
+
transaction.products.forEach((product) => {
|
140 |
+
total += product.price * product.total;
|
141 |
+
});
|
142 |
+
}
|
143 |
+
|
144 |
+
const td = formatTransactionDate(transactionKey);
|
145 |
+
|
146 |
+
let paymentIcon = "";
|
147 |
+
switch (transaction.payment_method) {
|
148 |
+
case "bank":
|
149 |
+
paymentIcon = "bi-building";
|
150 |
+
break;
|
151 |
+
case "qr":
|
152 |
+
paymentIcon = "bi-qr-code";
|
153 |
+
break;
|
154 |
+
case "card":
|
155 |
+
paymentIcon = "bi-credit-card";
|
156 |
+
break;
|
157 |
+
default:
|
158 |
+
paymentIcon = "bi-currency-dollar";
|
159 |
+
}
|
160 |
+
|
161 |
+
const col = document.createElement("div");
|
162 |
+
col.className = "transactions-body col-lg-4 col-md-6 col-sm-12 mt-4";
|
163 |
+
|
164 |
+
const card = document.createElement("div");
|
165 |
+
card.className = "card h-100";
|
166 |
+
|
167 |
+
const cardBody = document.createElement("div");
|
168 |
+
cardBody.className = "card-body d-flex flex-column";
|
169 |
+
cardBody.style.position = "relative";
|
170 |
+
|
171 |
+
cardBody.innerHTML = `
|
172 |
+
<div class="payment-icon-bg">
|
173 |
+
<i class="bi ${paymentIcon}" style="font-size: 2.5rem;"></i>
|
174 |
+
<span class="m-2">Metode: ${transaction.payment_method || "N/A"}</span>
|
175 |
+
</div>
|
176 |
+
<div class="content">
|
177 |
+
<div class="d-flex justify-content-between align-items-center">
|
178 |
+
<div class="transaction-total fw-bold">
|
179 |
+
Total: ${formatRupiah(total)}
|
180 |
+
</div>
|
181 |
+
</div>
|
182 |
+
<div class="d-flex justify-content-between align-items-center mt-auto">
|
183 |
+
<div class="transaction-date">
|
184 |
+
Tanggal: ${td[0]} <br> Waktu: ${td[1]}
|
185 |
+
</div>
|
186 |
+
</div>
|
187 |
+
</div>
|
188 |
+
`;
|
189 |
+
|
190 |
+
card.appendChild(cardBody);
|
191 |
+
col.appendChild(card);
|
192 |
+
transactionList.appendChild(col);
|
193 |
+
|
194 |
+
col.addEventListener("click", () => {
|
195 |
+
window.location.href = `transaction.html?date=${transactionKey}`;
|
196 |
+
});
|
197 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
}
|
199 |
});
|