tambah waktu 20 menit saat melakukan checkout + validasi waktu makan
This commit is contained in:
parent
accb93dac2
commit
f0df828334
@ -33,7 +33,12 @@ async function submitOrderToServer(){
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('message '+error);
|
||||
alert('Terdapat kesalahan coba lagi nanti!')
|
||||
Swal.fire({
|
||||
title: 'Gagal!',
|
||||
text: 'Terdapat kesalahan coba lagi nanti!',
|
||||
icon: 'error',
|
||||
confirmButtonText: 'Tutup!'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,8 +135,12 @@ async function submitOrderToServer(){
|
||||
}
|
||||
} catch (err) {
|
||||
clearSession()
|
||||
console.error(err);
|
||||
alert("Terjadi kesalahan saat mengirim data.");
|
||||
Swal.fire({
|
||||
title: 'Gagal!',
|
||||
text: "Terjadi kesalahan saat mengirim data.",
|
||||
icon: 'error',
|
||||
confirmButtonText: 'Tutup!'
|
||||
})
|
||||
}finally{
|
||||
buttonSubmit.prop('disabled', false).html('Selesaikan Pesanan');
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
time_order = sessionStorage.getItem('time_order')
|
||||
orderDate = new Date(time_order);
|
||||
deadline = new Date(orderDate.getTime() + 10 * 60 * 1000)
|
||||
deadline = new Date(orderDate.getTime() + 20 * 60 * 1000)
|
||||
updateCountdown()
|
||||
currentStep++;
|
||||
showStep(currentStep)
|
||||
@ -152,7 +152,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const selisihMs = now.getTime() - orderTime.getTime();
|
||||
const selisihMenit = selisihMs / 1000 / 60;
|
||||
|
||||
if (selisihMenit > 10) {
|
||||
if (selisihMenit > 20) {
|
||||
// Bersihkan session
|
||||
sessionStorage.removeItem('cart');
|
||||
sessionStorage.removeItem('checkout_biodata');
|
||||
@ -177,7 +177,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
function updateCountdown(){
|
||||
const now = new Date();
|
||||
orderDate = new Date(time_order);
|
||||
deadline = new Date(orderDate.getTime() + 10 * 60 * 1000)
|
||||
deadline = new Date(orderDate.getTime() + 20 * 60 * 1000)
|
||||
const distance = deadline - now
|
||||
|
||||
if(distance <= 0){
|
||||
@ -266,7 +266,7 @@ function toggleCustomerFields() {
|
||||
$('input[name="jenis_customer"]').on('change', toggleCustomerFields);
|
||||
toggleCustomerFields();
|
||||
|
||||
if (typeof checkout_biodata === 'object') {
|
||||
if (typeof checkout_biodata === 'object') {
|
||||
if (checkout_biodata.jenis_customer) {
|
||||
$(`input[name="jenis_customer"][value="${checkout_biodata.jenis_customer}"]`).prop('checked', true);
|
||||
}
|
||||
@ -288,9 +288,10 @@ if (typeof checkout_biodata === 'object') {
|
||||
$('#no_ekstensien').val(checkout_biodata.no_ekstensien);
|
||||
$('#email').val(checkout_biodata.email);
|
||||
$('#alamat').val(checkout_biodata.alamat);
|
||||
}
|
||||
}
|
||||
|
||||
function isiKonfirmasi() {
|
||||
|
||||
function isiKonfirmasi() {
|
||||
const biodata = {
|
||||
jenis_customer: $('input[name="jenis_customer"]:checked').val(),
|
||||
nama_pemesan: $('#nama_pemesan').val(),
|
||||
@ -312,12 +313,19 @@ function isiKonfirmasi() {
|
||||
sessionStorage.setItem('checkout_biodata', JSON.stringify(biodata));
|
||||
checkout_biodata = biodata;
|
||||
renderCartSummary();
|
||||
}
|
||||
}
|
||||
|
||||
// =======================
|
||||
// FUNGSI CART / PESANAN
|
||||
// =======================
|
||||
function renderCartSummary() {
|
||||
async function getServerTime() {
|
||||
const res = await fetch('/server-time');
|
||||
const data = await res.json();
|
||||
return new Date(data.now);
|
||||
}
|
||||
|
||||
|
||||
// =======================
|
||||
// FUNGSI CART / PESANAN
|
||||
// =======================
|
||||
function renderCartSummary() {
|
||||
const container = document.getElementById('checkout_cart_summary');
|
||||
container.innerHTML = '';
|
||||
let totalKeseluruhan = 0;
|
||||
@ -396,13 +404,14 @@ function renderCartSummary() {
|
||||
? (
|
||||
item.apakah_menu_siang && item.apakah_menu_sore
|
||||
? `
|
||||
<option value="">Select Choose</option>
|
||||
<option value="Makan Siang" ${p.kategoriPemesanan === 'Makan Siang' ? 'selected' : ''} ${disableSiang ? 'disabled' : ''}>Makan Siang</option>
|
||||
<option value="Makan Sore" ${p.kategoriPemesanan === 'Makan Sore' ? 'selected' : ''} ${disableSore ? 'disabled' : ''}>Makan Sore</option>
|
||||
`
|
||||
: item.apakah_menu_siang
|
||||
? `<option value="Makan Siang" selected ${disableSiang ? 'disabled' : ''}>Makan Siang</option>`
|
||||
? `<option value="Makan Siang" ${disableSiang ? 'disabled' : 'selected'}>Makan Siang</option>`
|
||||
: item.apakah_menu_sore
|
||||
? `<option value="Makan Sore" selected ${disableSore ? 'disabled' : ''}>Makan Sore</option>`
|
||||
? `<option value="Makan Sore" ${disableSore ? 'disabled' : 'selected'}>Makan Sore</option>`
|
||||
: `<option value="" disabled selected>Tidak tersedia</option>`
|
||||
)
|
||||
: (
|
||||
@ -538,12 +547,12 @@ function renderCartSummary() {
|
||||
`);
|
||||
|
||||
document.getElementById('no_order_price').textContent = 'Rp ' + totalKeseluruhan.toLocaleString('id-ID');
|
||||
}
|
||||
}
|
||||
|
||||
// =======================
|
||||
// EVENT HANDLER FIELD
|
||||
// =======================
|
||||
function onJumlahChange(itemId, index) {
|
||||
// =======================
|
||||
// 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)) {
|
||||
@ -551,17 +560,51 @@ function onJumlahChange(itemId, index) {
|
||||
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}`;
|
||||
}
|
||||
|
||||
function onTanggalChange(itemId, index) {
|
||||
|
||||
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');
|
||||
|
||||
// const todayStr = ymdLocal(new Date());
|
||||
const todayStr = `${year}-${month}-${day}`
|
||||
const isToday = input.value === todayStr;
|
||||
|
||||
cart.find(item => item.id === itemId).pesanan[index].tgl = input.value;
|
||||
sessionStorage.setItem('cart', JSON.stringify(cart));
|
||||
renderCartSummary();
|
||||
}
|
||||
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 onKarbohidratChange(itemId, index, el, kalori){
|
||||
Swal.fire({ title: "Perhatian!", text: msg, icon: "warning" }).then(() => {
|
||||
selectEl.value = "";
|
||||
});
|
||||
}
|
||||
renderCartSummary();
|
||||
}
|
||||
|
||||
function onKarbohidratChange(itemId, index, el, kalori){
|
||||
const selectedOption = el.options[el.selectedIndex];
|
||||
const kaloriOption = parseInt(selectedOption.getAttribute('data-kalori')) || 0;
|
||||
|
||||
@ -578,28 +621,52 @@ function onKarbohidratChange(itemId, index, el, kalori){
|
||||
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.");
|
||||
}
|
||||
|
||||
const item = cart.find(item => item.id === itemId);
|
||||
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 = kategori;
|
||||
sessionStorage.setItem('cart', JSON.stringify(cart));
|
||||
// renderCartSummary();
|
||||
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,7 +686,7 @@ function addOrderDate(itemId, sore) {
|
||||
}
|
||||
}
|
||||
|
||||
function removeOrderDate(itemId, index, count) {
|
||||
function removeOrderDate(itemId, index, count) {
|
||||
let cart = JSON.parse(sessionStorage.getItem('cart') || '[]');
|
||||
const item = cart.find(i => i.id === itemId);
|
||||
|
||||
@ -631,7 +698,7 @@ function removeOrderDate(itemId, index, count) {
|
||||
sessionStorage.setItem('cart', JSON.stringify(cart));
|
||||
}
|
||||
renderCartSummary();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function removeCartItem(itemId){
|
||||
@ -641,8 +708,8 @@ function removeOrderDate(itemId, index, count) {
|
||||
renderCartSummary()
|
||||
}
|
||||
|
||||
// validasi step one dan sebelum submit
|
||||
function validateStepOne() {
|
||||
// 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();
|
||||
@ -739,7 +806,7 @@ function validateStepOne() {
|
||||
}
|
||||
|
||||
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
|
||||
})
|
||||
@ -914,7 +980,7 @@ function decrement(itemId, index) {
|
||||
input.value = current - 1;
|
||||
onJumlahChange(itemId, index);
|
||||
}else{
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -28,14 +28,14 @@
|
||||
<li>
|
||||
Waktu pengambilan makanan:
|
||||
<ul class="ps-3 mt-1">
|
||||
<li>Siang: <strong>12.00 – 13.00 WIB</strong></li>
|
||||
<li>Sore: <strong>16.00 – 17.00 WIB</strong></li>
|
||||
<li>Siang: <strong>12.00 - 13.00 WIB</strong></li>
|
||||
<li>Sore: <strong>16.00 - 17.00 WIB</strong></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
Butuh bantuan? Hubungi WhatsApp <strong>Instalasi Gizi</strong>:
|
||||
<a href="https://wa.me/08815611382" target="_blank">08815611382</a><br>
|
||||
<small class="text-muted">Jam kerja: 08.00 – 15.00 WIB</small>
|
||||
<small class="text-muted">Jam kerja: 08.00 - 15.00 WIB</small>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -55,7 +55,7 @@
|
||||
<li>
|
||||
Butuh bantuan? Hubungi WhatsApp <strong>Instalasi Gizi</strong>:
|
||||
<a href="https://wa.me/08815611382 " target="_blank">08815611382 </a> <br>
|
||||
<small class="text-muted">Jam kerja: 08.00 – 15.00 WIB</small>
|
||||
<small class="text-muted">Jam kerja: 08.00 - 15.00 WIB</small>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -102,6 +102,7 @@ Route::post('/order-mcu', [CustomerController::class, 'storeMcu']);
|
||||
Route::get('/success-mcu', [CustomerController::class, 'successMcu']);
|
||||
Route::get('/karyawan', [CustomerController::class, 'karyawan']);
|
||||
Route::get('/unit-instalasi', [CustomerController::class, 'unitInstalasi']);
|
||||
Route::get('/server-time', fn()=> response()->json(['now' => now()]));
|
||||
|
||||
// Route::get('/send-mail', function(){
|
||||
// Mail::to('skyjok14@gmail.com')->queue(new NotifikasiCustomer('Test'));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user