development #6
@ -338,11 +338,7 @@ function renderCartSummary() {
|
||||
|
||||
<!-- Tanggal -->
|
||||
<div class="col-12 col-md-2">
|
||||
<input type="text"
|
||||
class="form-control form-control-sm tanggal-input"
|
||||
id="${item?.apakah_someday ? `tgl_someday-${item.id}-${i}`: `tanggal-${item.id}-${i}`}"
|
||||
readonly
|
||||
placeholder="Pilih Tanggal">
|
||||
<input type="text" class="form-control form-control-sm tanggal-input" id="tanggal-${item.id}-${i}" readonly placeholder="Pilih Tanggal">
|
||||
</div>
|
||||
|
||||
<!-- Karbohidrat -->
|
||||
@ -398,7 +394,8 @@ function renderCartSummary() {
|
||||
<!-- Jumlah -->
|
||||
<div class="col-6 col-md-2">
|
||||
<div class="d-flex align-items-center justify-content-between">
|
||||
<button class="btn btn-sm btn-outline-success" onclick="decrement(${item.id}, ${i})">
|
||||
|
||||
<button class="btn btn-sm btn-outline-success" onclick="decrement(${item.id}, ${i})" ${p.jumlah > 1 ? '' : 'disabled'}>
|
||||
<i class="fa fa-minus"></i>
|
||||
</button>
|
||||
<input type="text" class="form-control form-control-sm text-center mx-2 jumlah-input"
|
||||
@ -473,10 +470,7 @@ function renderCartSummary() {
|
||||
`;
|
||||
|
||||
container.insertAdjacentHTML('beforeend', itemHTML);
|
||||
pesananList.forEach((p, i) => {
|
||||
initFlatpickrTersedia(item, i);
|
||||
});
|
||||
|
||||
pesananList.forEach((p, i) => initFlatpickrTersedia(item, i));
|
||||
});
|
||||
|
||||
container.insertAdjacentHTML('beforeend', `
|
||||
@ -507,7 +501,7 @@ function onTanggalChange(itemId, index) {
|
||||
const input = document.querySelector(`div[data-item-id='${itemId}'][data-index='${index}'] .tanggal-input`);
|
||||
cart.find(item => item.id === itemId).pesanan[index].tgl = input.value;
|
||||
sessionStorage.setItem('cart', JSON.stringify(cart));
|
||||
// renderCartSummary();
|
||||
renderCartSummary();
|
||||
}
|
||||
|
||||
function onKarbohidratChange(itemId, index, el, kalori){
|
||||
@ -537,20 +531,11 @@ function onKategoriChange(itemId, index, isToday) {
|
||||
let jam = now.getHours();
|
||||
|
||||
if (kategori === "Makan Siang" && isToday && jam >= 10) {
|
||||
batasLewat = true;
|
||||
alert("Pemesanan Makan Siang hanya bisa dilakukan sebelum jam 10:00.");
|
||||
} else if (kategori === "Makan Sore" && isToday && jam >= 15) {
|
||||
batasLewat = true;
|
||||
} else if (kategori === "Makan Sore" && isToday && jam >= 13) {
|
||||
alert("Pemesanan Makan Sore hanya bisa dilakukan sebelum jam 13:00.");
|
||||
}
|
||||
|
||||
if (batasLewat) {
|
||||
// Kembalikan ke value sebelumnya
|
||||
const previous = selectEl.dataset.previousValue || '';
|
||||
selectEl.value = previous;
|
||||
return;
|
||||
}
|
||||
|
||||
const item = cart.find(item => item.id === itemId);
|
||||
if (item && item.pesanan && item.pesanan[index]) {
|
||||
item.pesanan[index].kategoriPemesanan = kategori;
|
||||
@ -708,6 +693,7 @@ function validateCartBeforeSubmit() {
|
||||
cart.forEach((item, index) => {
|
||||
const pesananList = item.pesanan || [];
|
||||
pesananList.forEach((pesanan, i) => {
|
||||
console.log(!pesanan.karbohidrat_id, !item?.apakah_someday);
|
||||
|
||||
if (!pesanan.tgl) {
|
||||
isValid = false;
|
||||
@ -745,45 +731,23 @@ function hitungTotalHarga(){
|
||||
}
|
||||
|
||||
|
||||
function copyNoRek() {
|
||||
const text = document.getElementById('noRekText').innerText;
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Disalin!',
|
||||
text: 'Nomor rekening berhasil disalin: ' + text,
|
||||
showConfirmButton: false,
|
||||
timer: 1500
|
||||
});
|
||||
}).catch(err => {
|
||||
console.error('Gagal menyalin: ', err);
|
||||
Swal.fire({
|
||||
icon: 'warning',
|
||||
text: 'Gagal menyalin teks: ' + text,
|
||||
showConfirmButton: false,
|
||||
timer: 2000
|
||||
});
|
||||
});
|
||||
}
|
||||
function copyNoRek() {
|
||||
const text = document.getElementById('noRekText').innerText;
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
alert("Nomor rekening berhasil disalin: " + text);
|
||||
}).catch(err => {
|
||||
console.error('Gagal menyalin: ', err);
|
||||
alert("Gagal menyalin teks.");
|
||||
});
|
||||
}
|
||||
|
||||
function copyNoOrder() {
|
||||
const text = document.getElementById('no_order_display').innerText;
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Disalin!',
|
||||
text: 'Nomor order berhasil disalin: ' + text,
|
||||
showConfirmButton: false,
|
||||
timer: 1500
|
||||
});
|
||||
alert("Nomor order berhasil disalin: " + text);
|
||||
}).catch(err => {
|
||||
console.error('Gagal menyalin: ', err);
|
||||
Swal.fire({
|
||||
icon: 'warning',
|
||||
text: 'Gagal menyalin teks: ' + text,
|
||||
showConfirmButton: false,
|
||||
timer: 2000
|
||||
});
|
||||
alert("Gagal menyalin teks.");
|
||||
});
|
||||
}
|
||||
|
||||
@ -846,26 +810,16 @@ function initFlatpickrTersedia(item, i) {
|
||||
}
|
||||
|
||||
|
||||
const id = item?.apakah_someday
|
||||
? `#tgl_someday-${item.id}-${i}`
|
||||
: `#tanggal-${item.id}-${i}`;
|
||||
flatpickr(`#tanggal-${item.id}-${i}`, {
|
||||
dateFormat: "Y-m-d",
|
||||
...(item?.apakah_someday ? {minDate: minTanggal} : {enable:availableDates}),
|
||||
defaultDate: item.pesanan[i]?.tgl || null,
|
||||
disableMobile: true,
|
||||
onChange: function(selectedDates, dateStr) {
|
||||
onTanggalChange(item.id, i, dateStr);
|
||||
}
|
||||
});
|
||||
|
||||
const config = item?.apakah_someday
|
||||
? {
|
||||
disableMobile: true,
|
||||
minDate: minTanggal,
|
||||
onChange: (selectedDates, dateStr) =>
|
||||
onTanggalChange(item.id, i, dateStr)
|
||||
}
|
||||
: {
|
||||
dateFormat: "Y-m-d",
|
||||
enable: availableDates,
|
||||
defaultDate: item.pesanan[i]?.tgl || null,
|
||||
onChange: (selectedDates, dateStr) =>
|
||||
onTanggalChange(item.id, i, dateStr)
|
||||
};
|
||||
|
||||
flatpickr(id, config);
|
||||
}
|
||||
|
||||
function increment(itemId, index) {
|
||||
@ -877,6 +831,7 @@ function increment(itemId, index) {
|
||||
function decrement(itemId, index) {
|
||||
const input = document.getElementById(`jumlah-${itemId}-${index}`);
|
||||
let current = parseInt(input.value || "0");
|
||||
console.log(current);
|
||||
|
||||
if (current > 1) {
|
||||
input.value = current - 1;
|
||||
@ -952,6 +907,7 @@ document.getElementById('submitNote').addEventListener('click', function(e){
|
||||
const noted = $("#note_order").val()
|
||||
const cart = JSON.parse(sessionStorage.getItem('cart') || '[]');
|
||||
const item =cart.find(item => item.id === id)
|
||||
console.log(id, index, item);
|
||||
|
||||
if(item && item.pesanan && item.pesanan[index]){
|
||||
item.pesanan[index].catatan = noted
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user