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