+
+
${item.nama_menu}
+
+
+
+ ${checkout_biodata?.jenis_customer === "Karyawan RSAB Harapan Kita"
+ ? 'Harga Karyawan'
+ : 'Harga'
+ }
+ Rp ${parseInt(harga).toLocaleString('id-ID')}
-
-
-
+
+ ${item?.kalori ? `
Kalori: ${item.kalori} kal
` : ''}
-
-
-
+
+ ${item.deskripsi ? `
${item.deskripsi}
` : ''}
+
+
+
+
+
+ ${item.apakah_someday
+ ? 'Tersedia setiap hari (Senin – Minggu)'
+ : (item.tgl_tersedia ? `Tersedia pada tanggal: ${item.tgl_tersedia}` : 'Tidak ada info tanggal tersedia')
+ }
+
+
+
+ ${item.apakah_someday ? 'Sameday' : 'Menu Normal'}
-
-
- ${countDate > 1
- ? `
`
- : ''
- }
+
+
+ Petunjuk: Isi tanggal pemesanan, pilih karbohidrat, dan catatan tambahan (opsional).
+
+
+
+ ${pesananHTML}
+
+
+
+
+
+
+ Total: Rp ${itemTotal.toLocaleString('id-ID')}
+
- ${item.kalori
- ? `
Total Kalori: ${p?.resultKalori ? p?.resultKalori : item?.kalori} kal
`
- : ''}
+
+
+ `;
- `;
+ container.insertAdjacentHTML('beforeend', itemHTML);
+ pesananList.forEach((p, i) => initFlatpickrTersedia(item, i));
});
- const itemHTML = `
-
-
-
-
-
-

+ container.insertAdjacentHTML('beforeend', `
+
+
+ Total Keseluruhan: Rp ${totalKeseluruhan.toLocaleString('id-ID')}
+ `);
-
+ document.getElementById('no_order_price').textContent = 'Rp ' + totalKeseluruhan.toLocaleString('id-ID');
+ }
-
-
-
${item.nama_menu}
+ // =======================
+ // EVENT HANDLER FIELD
+ // =======================
+ function onJumlahChange(itemId, index) {
+ let cart = JSON.parse(sessionStorage.getItem('cart') || '[]');
+ const input = document.querySelector(`div[data-item-id='${itemId}'][data-index='${index}'] .jumlah-input`);
+ if (!isNaN(input.value)) {
+ cart.find(item => item.id === itemId).pesanan[index].jumlah = parseInt(input.value);
+ sessionStorage.setItem('cart', JSON.stringify(cart));
+ isiKonfirmasi();
+ }
+ }
+ function ymdLocal(date) {
+ const y = date.getFullYear();
+ const m = String(date.getMonth() + 1).padStart(2, "0");
+ const d = String(date.getDate()).padStart(2, "0");
+ return `${y}-${m}-${d}`;
+ }
-
-
- ${checkout_biodata?.jenis_customer === "Karyawan RSAB Harapan Kita"
- ? 'Harga Karyawan'
- : 'Harga'
- }
- Rp ${parseInt(harga).toLocaleString('id-ID')}
-
-
- ${item?.kalori ? `
Kalori: ${item.kalori} kal
` : ''}
+ async function onTanggalChange(itemId, index) {
+ let cart = JSON.parse(sessionStorage.getItem('cart') || '[]');
+ const input = document.querySelector(`div[data-item-id='${itemId}'][data-index='${index}'] .tanggal-input`);
+ const serverDate = await getServerTime();
+ const year = serverDate.getFullYear();
+ const month = String(serverDate.getMonth() + 1).padStart(2, '0');
+ const day = String(serverDate.getDate()).padStart(2, '0');
-
- ${item.deskripsi ? `
${item.deskripsi}
` : ''}
+ // const todayStr = ymdLocal(new Date());
+ const todayStr = `${year}-${month}-${day}`
+ const isToday = input.value === todayStr;
-
-
-
-
- ${item.apakah_someday
- ? 'Tersedia setiap hari (Senin – Minggu)'
- : (item.tgl_tersedia ? `Tersedia pada tanggal: ${item.tgl_tersedia}` : 'Tidak ada info tanggal tersedia')
- }
-
-
-
- ${item.apakah_someday ? 'Sameday' : 'Menu Normal'}
-
-
-
-
-
- Petunjuk: Isi tanggal pemesanan, pilih karbohidrat, dan catatan tambahan (opsional).
-
-
-
- ${pesananHTML}
-
-
-
-
-
-
- Total: Rp ${itemTotal.toLocaleString('id-ID')}
-
-
-
-
-
-
- `;
-
- container.insertAdjacentHTML('beforeend', itemHTML);
- pesananList.forEach((p, i) => initFlatpickrTersedia(item, i));
- });
-
- container.insertAdjacentHTML('beforeend', `
-
-
- Total Keseluruhan: Rp ${totalKeseluruhan.toLocaleString('id-ID')}
-
- `);
-
- document.getElementById('no_order_price').textContent = 'Rp ' + totalKeseluruhan.toLocaleString('id-ID');
-}
-
-// =======================
-// EVENT HANDLER FIELD
-// =======================
-function onJumlahChange(itemId, index) {
- let cart = JSON.parse(sessionStorage.getItem('cart') || '[]');
- const input = document.querySelector(`div[data-item-id='${itemId}'][data-index='${index}'] .jumlah-input`);
- if (!isNaN(input.value)) {
- cart.find(item => item.id === itemId).pesanan[index].jumlah = parseInt(input.value);
+ cart.find(item => item.id === itemId).pesanan[index].tgl = input.value;
sessionStorage.setItem('cart', JSON.stringify(cart));
- isiKonfirmasi();
- }
-}
+ const selectEl = document.querySelector(
+ `.kategori-pemesanan-input[data-item-id='${itemId}'][data-index='${index}']`
+ );
+ if (!selectEl) return;
+ const next = selectEl.value;
+ if (!isKategoriMasihDibuka(next, isToday)) {
+ cart.find(item => item.id === itemId).pesanan[index].kategoriPemesanan = null;
+ sessionStorage.setItem("cart", JSON.stringify(cart));
+ // Tampilkan alert & revert ke sebelumnya
+ const msg =
+ next === "Makan Siang"
+ ? "Pemesanan Makan Siang hanya bisa dilakukan sebelum jam 10:00."
+ : "Pemesanan Makan Sore hanya bisa dilakukan sebelum jam 13:00.";
-function onTanggalChange(itemId, index) {
- let cart = JSON.parse(sessionStorage.getItem('cart') || '[]');
- 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();
-}
-
-function onKarbohidratChange(itemId, index, el, kalori){
- const selectedOption = el.options[el.selectedIndex];
- const kaloriOption = parseInt(selectedOption.getAttribute('data-kalori')) || 0;
-
- const kaloriMenuInt = kalori || 0;
-
- const totalKalori = kaloriOption + kaloriMenuInt;
- const kaloriEl = document.getElementById(`kalori_${itemId}_${index}`);
-
- if (kaloriEl) {
- kaloriEl.textContent = totalKalori ;
- }
- let cart = JSON.parse(sessionStorage.getItem('cart') || '[]');
- const input = document.querySelector(`div[data-item-id='${itemId}'][data-index='${index}'] .karbohidrat-input`);
- cart.find(item => item.id === itemId).pesanan[index].karbohidrat_id = parseInt(input.value);
- cart.find(item => item.id === itemId).pesanan[index].resultKalori = totalKalori;
- sessionStorage.setItem('cart', JSON.stringify(cart));
-}
-
-function onKategoriChange(itemId, index, isToday) {
- let cart = JSON.parse(sessionStorage.getItem('cart') || '[]');
- const selectEl = document.querySelector(`.kategori-pemesanan-input[data-item-id='${itemId}'][data-index='${index}']`);
- const kategori = selectEl.value;
- let now = new Date();
- let jam = now.getHours();
-
- if (kategori === "Makan Siang" && isToday && jam >= 10) {
- alert("Pemesanan Makan Siang hanya bisa dilakukan sebelum jam 10:00.");
- } else if (kategori === "Makan Sore" && isToday && jam >= 13) {
- alert("Pemesanan Makan Sore hanya bisa dilakukan sebelum jam 13:00.");
+ Swal.fire({ title: "Perhatian!", text: msg, icon: "warning" }).then(() => {
+ selectEl.value = "";
+ });
+ }
+ renderCartSummary();
}
- const item = cart.find(item => item.id === itemId);
- if (item && item.pesanan && item.pesanan[index]) {
- item.pesanan[index].kategoriPemesanan = kategori;
+ function onKarbohidratChange(itemId, index, el, kalori){
+ const selectedOption = el.options[el.selectedIndex];
+ const kaloriOption = parseInt(selectedOption.getAttribute('data-kalori')) || 0;
+
+ const kaloriMenuInt = kalori || 0;
+
+ const totalKalori = kaloriOption + kaloriMenuInt;
+ const kaloriEl = document.getElementById(`kalori_${itemId}_${index}`);
+
+ if (kaloriEl) {
+ kaloriEl.textContent = totalKalori ;
+ }
+ let cart = JSON.parse(sessionStorage.getItem('cart') || '[]');
+ const input = document.querySelector(`div[data-item-id='${itemId}'][data-index='${index}'] .karbohidrat-input`);
+ cart.find(item => item.id === itemId).pesanan[index].karbohidrat_id = parseInt(input.value);
+ cart.find(item => item.id === itemId).pesanan[index].resultKalori = totalKalori;
sessionStorage.setItem('cart', JSON.stringify(cart));
- // renderCartSummary();
}
-}
+
+ function onKategoriChange(itemId, index, isToday) {
+ const selectEl = document.querySelector(
+ `.kategori-pemesanan-input[data-item-id='${itemId}'][data-index='${index}']`
+ );
+ if (!selectEl) return;
+ const next = selectEl.value;
+
+ // Validasi batas waktu
+ let cart = JSON.parse(sessionStorage.getItem("cart") || "[]");
+ const item = cart.find((it) => it.id === itemId);
+ if (!isKategoriMasihDibuka(next, isToday)) {
+
+ item.pesanan[index].kategoriPemesanan = null;
+ sessionStorage.setItem("cart", JSON.stringify(cart));
+
+ // Tampilkan alert & revert ke sebelumnya
+ const msg =
+ next === "Makan Siang"
+ ? "Pemesanan Makan Siang hanya bisa dilakukan sebelum jam 10:00."
+ : "Pemesanan Makan Sore hanya bisa dilakukan sebelum jam 13:00.";
+
+ Swal.fire({ title: "Perhatian!", text: msg, icon: "warning" }).then(() => {
+ selectEl.value = "";
+ });
+ return;
+ }else{
+ if (item && item.pesanan && item.pesanan[index]) {
+ item.pesanan[index].kategoriPemesanan = next;
+ sessionStorage.setItem("cart", JSON.stringify(cart));
+ // update nilai previous
+ selectEl.dataset.previousValue = next;
+ // rerender ringkasan
+ if (typeof renderCartSummary === "function") renderCartSummary();
+ }
+ }
+ }
+
+ function isKategoriMasihDibuka(kategori, isToday) {
+ if (!isToday) return true; // pesanan untuk hari lain bebas
+ const jam = new Date().getHours();
+ const cutoff = { "Makan Siang": 10, "Makan Sore": 15 };
+ return cutoff[kategori] ? jam < cutoff[kategori] : true;
+ }
+
// =======================
@@ -619,19 +686,19 @@ function addOrderDate(itemId, sore) {
}
}
-function removeOrderDate(itemId, index, count) {
- let cart = JSON.parse(sessionStorage.getItem('cart') || '[]');
- const item = cart.find(i => i.id === itemId);
+ function removeOrderDate(itemId, index, count) {
+ let cart = JSON.parse(sessionStorage.getItem('cart') || '[]');
+ const item = cart.find(i => i.id === itemId);
- if(count == 1){
- cart = cart.filter(i => i.id !== itemId);
- sessionStorage.setItem('cart', JSON.stringify(cart));
- }else if(item && Array.isArray(item.pesanan) && item.pesanan.length > index) {
- item.pesanan.splice(index, 1);
- sessionStorage.setItem('cart', JSON.stringify(cart));
+ if(count == 1){
+ cart = cart.filter(i => i.id !== itemId);
+ sessionStorage.setItem('cart', JSON.stringify(cart));
+ }else if(item && Array.isArray(item.pesanan) && item.pesanan.length > index) {
+ item.pesanan.splice(index, 1);
+ sessionStorage.setItem('cart', JSON.stringify(cart));
+ }
+ renderCartSummary();
}
- renderCartSummary();
-}
function removeCartItem(itemId){
@@ -641,105 +708,105 @@ function removeOrderDate(itemId, index, count) {
renderCartSummary()
}
-// validasi step one dan sebelum submit
-function validateStepOne() {
- const jenisCustomer = document.querySelector('input[name="jenis_customer"]:checked');
- const jenisKelamin = document.querySelector('input[name="jenis_kelamin"]:checked');
- const namaPemesan = document.getElementById('nama_pemesan').value.trim();
- const noWA = document.getElementById('no_whatsapp').value.trim();
- const email = document.getElementById('email').value.trim();
+ // validasi step one dan sebelum submit
+ function validateStepOne() {
+ const jenisCustomer = document.querySelector('input[name="jenis_customer"]:checked');
+ const jenisKelamin = document.querySelector('input[name="jenis_kelamin"]:checked');
+ const namaPemesan = document.getElementById('nama_pemesan').value.trim();
+ const noWA = document.getElementById('no_whatsapp').value.trim();
+ const email = document.getElementById('email').value.trim();
- if (!jenisCustomer) {
- Swal.fire({
- title: 'Perhatian!',
- text: 'Silakan pilih jenis customer.',
- icon: 'warning',
- confirmButtonText: 'Oke'
- })
- return false;
- }
-
- if (!namaPemesan) {
- Swal.fire({
- title: 'Perhatian!',
- text: 'Silakan isi nama pemesan.',
- icon: 'warning',
- confirmButtonText: 'Oke'
- })
- return false;
- }
-
- if (!jenisKelamin) {
- Swal.fire({
- title: 'Perhatian!',
- text: 'Silakan pilih jenis kelamin.',
- icon: 'warning',
- confirmButtonText: 'Oke'
- })
- return false;
- }
-
- if (!noWA) {
- Swal.fire({
- title: 'Perhatian!',
- text: 'Silakan isi nomor WhatsApp.',
- icon: 'warning',
- confirmButtonText: 'Oke'
- })
- return false;
- }
- if (!email) {
- Swal.fire({
- title: 'Perhatian!',
- text: 'Silakan isi email terlebih dahulu.',
- icon: 'warning',
- confirmButtonText: 'Oke'
- })
- return false;
- }
-
- // Validasi tambahan sesuai jenis customer
- const selected = jenisCustomer.value;
- if (selected === 'Karyawan RSAB Harapan Kita') {
- const bagian = document.getElementById('bagian_instalasi').value.trim();
- if (!bagian) {
- Swal.fire({
- title: 'Perhatian!',
- text: 'Silakan lengkapi data karyawan.',
- icon: 'warning',
- confirmButtonText: 'Oke'
- })
- return false;
- }
- } else if (selected === 'Keluarga Pasien / Penunggu Pasien') {
- const namaPasien = document.getElementById('nama_pasien').value.trim();
- const ruang = document.getElementById('ruang_perawatan').value;
- const noKamar = document.getElementById('no_kamar').value.trim();
- const kelas = document.getElementById('kelas_perawatan').value;
- if (!namaPasien || !ruang || !noKamar || !kelas) {
+ if (!jenisCustomer) {
Swal.fire({
- title: 'Perhatian!',
- text: 'Silakan lengkapi data pasien.',
- icon: 'warning',
- confirmButtonText: 'Oke'
- })
+ title: 'Perhatian!',
+ text: 'Silakan pilih jenis customer.',
+ icon: 'warning',
+ confirmButtonText: 'Oke'
+ })
return false;
}
- }else if(selected === "Masyarakat Umum"){
- const alamat = document.getElementById('alamat').value;
- if(!alamat){
- Swal.fire({
- title: 'Perhatian!',
- text: 'Silahkan lengkapi alamat.',
- icon: 'warning',
- confirmButtonText: 'Oke'
- })
- return false
- }
- }
- return true;
-}
+ if (!namaPemesan) {
+ Swal.fire({
+ title: 'Perhatian!',
+ text: 'Silakan isi nama pemesan.',
+ icon: 'warning',
+ confirmButtonText: 'Oke'
+ })
+ return false;
+ }
+
+ if (!jenisKelamin) {
+ Swal.fire({
+ title: 'Perhatian!',
+ text: 'Silakan pilih jenis kelamin.',
+ icon: 'warning',
+ confirmButtonText: 'Oke'
+ })
+ return false;
+ }
+
+ if (!noWA) {
+ Swal.fire({
+ title: 'Perhatian!',
+ text: 'Silakan isi nomor WhatsApp.',
+ icon: 'warning',
+ confirmButtonText: 'Oke'
+ })
+ return false;
+ }
+ if (!email) {
+ Swal.fire({
+ title: 'Perhatian!',
+ text: 'Silakan isi email terlebih dahulu.',
+ icon: 'warning',
+ confirmButtonText: 'Oke'
+ })
+ return false;
+ }
+
+ // Validasi tambahan sesuai jenis customer
+ const selected = jenisCustomer.value;
+ if (selected === 'Karyawan RSAB Harapan Kita') {
+ const bagian = document.getElementById('bagian_instalasi').value.trim();
+ if (!bagian) {
+ Swal.fire({
+ title: 'Perhatian!',
+ text: 'Silakan lengkapi data karyawan.',
+ icon: 'warning',
+ confirmButtonText: 'Oke'
+ })
+ return false;
+ }
+ } else if (selected === 'Keluarga Pasien / Penunggu Pasien') {
+ const namaPasien = document.getElementById('nama_pasien').value.trim();
+ const ruang = document.getElementById('ruang_perawatan').value;
+ const noKamar = document.getElementById('no_kamar').value.trim();
+ const kelas = document.getElementById('kelas_perawatan').value;
+ if (!namaPasien || !ruang || !noKamar || !kelas) {
+ Swal.fire({
+ title: 'Perhatian!',
+ text: 'Silakan lengkapi data pasien.',
+ icon: 'warning',
+ confirmButtonText: 'Oke'
+ })
+ return false;
+ }
+ }else if(selected === "Masyarakat Umum"){
+ const alamat = document.getElementById('alamat').value;
+ if(!alamat){
+ Swal.fire({
+ title: 'Perhatian!',
+ text: 'Silahkan lengkapi alamat.',
+ icon: 'warning',
+ confirmButtonText: 'Oke'
+ })
+ return false
+ }
+ }
+
+ return true;
+ }
function validateCartBeforeSubmit() {
@@ -777,7 +844,6 @@ function hitungTotalHarga(){
cart.forEach(item => {
const harga = biodata.jenis_customer === "Karyawan RSAB Harapan Kita" ? item.harga_karyawan : item.harga_public || 0
-
const itemTotal = item.pesanan?.reduce((sum, p) => sum + (p.jumlah * harga), 0);
total += itemTotal
})
@@ -880,7 +946,7 @@ function initFlatpickrTersedia(item, i) {
let minTanggal = 'today';
- // Jika item adalah someday dan waktu sekarang sudah lewat 13:00
+ // Jika item adalah someday dan waktu sekarang sudah lewat 13:00
if (item?.apakah_someday && totalMenitFlatSekarang >= 13 * 60) {
const besok = new Date(now);
besok.setDate(now.getDate() + 1);
@@ -896,7 +962,7 @@ function initFlatpickrTersedia(item, i) {
onChange: function(selectedDates, dateStr) {
onTanggalChange(item.id, i, dateStr);
}
- });
+ });
}
@@ -914,7 +980,7 @@ function decrement(itemId, index) {
input.value = current - 1;
onJumlahChange(itemId, index);
}else{
- return
+ return;
}
}
diff --git a/resources/views/guest/checkout/step/step2.blade.php b/resources/views/guest/checkout/step/step2.blade.php
index 2eec41c..97516b0 100644
--- a/resources/views/guest/checkout/step/step2.blade.php
+++ b/resources/views/guest/checkout/step/step2.blade.php
@@ -28,14 +28,14 @@
Waktu pengambilan makanan:
- - Siang: 12.00 – 13.00 WIB
- - Sore: 16.00 – 17.00 WIB
+ - Siang: 12.00 - 13.00 WIB
+ - Sore: 16.00 - 17.00 WIB
Butuh bantuan? Hubungi WhatsApp Instalasi Gizi:
08815611382
- Jam kerja: 08.00 – 15.00 WIB
+ Jam kerja: 08.00 - 15.00 WIB