Merge branch 'production' of https://git.abbauf.com/Magang-2025/Kasir into production

This commit is contained in:
dhilanradya 2025-09-18 16:02:31 +07:00
commit f4e0392331
2 changed files with 147 additions and 40 deletions

View File

@ -107,19 +107,37 @@
</div>
<!-- Tombol -->
<div class="flex justify-end gap-2">
<!-- Tombol -->
<div class="flex justify-end gap-2">
<button @click="closePopup" class="px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-50 transition">
Batal
</button>
<button @click="showDeleteConfirm = true"
class="px-4 py-2 rounded bg-red-500 text-white hover:bg-red-600 transition flex items-center">
<i class="fas fa-trash mr-2"></i>Hapus
</button>
<button @click="saveMove" :disabled="!selectedTrayId || isMoving"
class="px-4 py-2 rounded text-D transition flex items-center"
:class="(selectedTrayId && !isMoving) ? 'bg-C hover:bg-C/80' : 'bg-gray-400 cursor-not-allowed'">
<div v-if="isMoving" class="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
{{ isMoving ? 'Memindahkan...' : 'Pindahkan' }}
</button>
</div>
</div>
</div>
</div>
<!-- Modal Konfirmasi Hapus -->
<ConfirmDeleteModal
:isOpen="showDeleteConfirm"
title="Konfirmasi Hapus Item"
message="Apakah kamu yakin ingin menghapus item ini?"
confirmText="Ya, Hapus"
cancelText="Batal"
@confirm="confirmDelete"
@cancel="cancelDelete"
/>
<!-- Confirm Modal untuk aksi berbahaya (jika diperlukan di masa depan) -->
<div v-if="isConfirmModalVisible" class="fixed inset-0 bg-black/75 flex items-center justify-center p-4 z-50 backdrop-blur-sm">
@ -151,6 +169,7 @@
<script setup>
import { ref, computed, onMounted } from "vue";
import axios from "axios";
import ConfirmDeleteModal from './ConfirmDeleteModal.vue';
const props = defineProps({
search: {
@ -173,6 +192,8 @@ const selectedTrayId = ref("");
const errorMove = ref("");
const isMoving = ref(false);
const showDeleteConfirm = ref(false);
// State modal konfirmasi
const isConfirmModalVisible = ref(false);
const confirmModalTitle = ref("");
@ -221,6 +242,44 @@ const closePopup = () => {
isMoving.value = false;
};
const confirmDelete = async () => {
if (!selectedItem.value) return;
try {
// Panggil API hapus item
await axios.delete(`/api/item/${selectedItem.value.id}`, {
headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
});
// Tampilkan alert sukses
alert.value = { success: `Item ${selectedItem.value.kode_item} berhasil dihapus.` };
// Refresh data
await refreshData();
// Tutup modal & popup
showDeleteConfirm.value = false;
closePopup();
// Auto hide alert
clearTimeout(timer.value);
timer.value = setTimeout(() => { alert.value = null; }, 3000);
} catch (err) {
console.error("Gagal menghapus item:", err.response?.data || err);
alert.value = { error: err.response?.data?.message || "Gagal menghapus item. Silakan coba lagi." };
// Auto hide alert error
clearTimeout(timer.value);
timer.value = setTimeout(() => { alert.value = null; }, 5000);
}
};
const cancelDelete = () => {
showDeleteConfirm.value = false;
};
const saveMove = async () => {
if (!selectedTrayId.value || !selectedItem.value || isMoving.value) return;

View File

@ -49,33 +49,23 @@
</div>
<!-- Isi Card (Max tinggi 3 item + scroll kalau lebih) -->
<div
v-if="tray.items && tray.items.length"
class="space-y-2 flex-1 overflow-y-auto max-h-[168px] pr-1"
>
<div
v-for="item in tray.items"
:key="item.id"
<div v-if="tray.items && tray.items.length" class="space-y-2 flex-1 overflow-y-auto max-h-[168px] pr-1">
<div v-for="item in tray.items" :key="item.id"
class="flex justify-between items-center border border-C rounded-lg p-2 cursor-pointer hover:bg-gray-50"
@click="openMovePopup(item)"
>
@click="openMovePopup(item)">
<div class="flex items-center gap-3">
<img
v-if="item.produk?.foto && item.produk?.foto.length > 0"
:src="item.produk?.foto[0].url"
alt="foto produk"
class="size-12 object-cover rounded"
/>
<img v-if="item.produk.foto && item.produk.foto.length > 0" :src="item.produk.foto[0].url"
alt="foto produk" class="size-12 object-cover rounded" />
<div class="text-D">
<p class="text-sm">{{ item.produk?.nama }}</p>
<p class="text-sm">{{ item.produk.nama }}</p>
<p class="text-sm font-medium">{{ item.kode_item }}</p>
</div>
</div>
<div class="flex items-center gap-2">
<span class="font-medium">{{ item.produk?.berat }}g</span>
<span class="font-medium">{{ item.produk.berat }}g</span>
</div>
</div>
</div>
</div>
<!-- Kalau kosong -->
<div v-else class="text-gray-400 text-center py-4 flex-1">
@ -107,7 +97,7 @@
{{ selectedItem.kode_item }}
</div>
<div class="text-center text-gray-700 font-medium mb-3">
{{ selectedItem.produk?.nama }}
{{ selectedItem.produk.nama }}
</div>
<div class="flex justify-center mb-4">
@ -128,9 +118,14 @@
</div>
<div class="flex justify-end gap-2">
<button @click="closePopup" class="px-4 py-2 rounded bg-gray-400 hover:bg-gray-500 text-white transition">
{{ isAdmin ? 'Batal' : 'Tutup' }}
</button>
<button @click="showDeleteConfirm = true"
class="px-4 py-2 rounded bg-red-500 text-white hover:bg-red-600 transition flex items-center">
<i class="fas fa-trash mr-2"></i>Hapus
</button>
<button v-if="isAdmin" @click="saveMove" :disabled="!selectedTrayId" class="px-4 py-2 rounded transition"
:class="selectedTrayId ? 'bg-C hover:bg-C/80 text-D' : 'bg-gray-400 cursor-not-allowed'">
Simpan
@ -138,12 +133,24 @@
</div>
</div>
</div>
<!-- Modal Konfirmasi Hapus -->
<ConfirmDeleteModal
:isOpen="showDeleteConfirm"
title="Konfirmasi Hapus Item"
message="Apakah kamu yakin ingin menghapus item ini?"
confirmText="Ya, Hapus"
cancelText="Batal"
@confirm="confirmDelete"
@cancel="cancelDelete"
/>
</template>
<script setup>
import { ref, onMounted, computed } from "vue";
import axios from "axios";
import InputSelect from "./InputSelect.vue";
import ConfirmDeleteModal from './ConfirmDeleteModal.vue';
const isAdmin = localStorage.getItem("role") === "owner";
@ -212,6 +219,47 @@ const printQR = () => {
}
};
const showDeleteConfirm = ref(false);
const confirmDelete = async () => {
if (!selectedItem.value) return;
try {
// Panggil API hapus item
await axios.delete(`/api/item/${selectedItem.value.id}`, {
headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
});
// Tampilkan alert sukses
alert.value = { success: `Item ${selectedItem.value.kode_item} berhasil dihapus.` };
// Refresh data
await refreshData();
// Tutup modal & popup
showDeleteConfirm.value = false;
closePopup();
// Auto hide alert
clearTimeout(timer.value);
timer.value = setTimeout(() => { alert.value = null; }, 3000);
} catch (err) {
console.error("Gagal menghapus item:", err.response?.data || err);
alert.value = { error: err.response?.data?.message || "Gagal menghapus item. Silakan coba lagi." };
// Auto hide alert error
clearTimeout(timer.value);
timer.value = setTimeout(() => { alert.value = null; }, 5000);
}
};
const cancelDelete = () => {
showDeleteConfirm.value = false;
};
// --- Fungsi Pop-up ---
const openMovePopup = (item) => {
selectedItem.value = item;
@ -248,7 +296,7 @@ const saveMove = async () => {
// Hitung total berat
const totalWeight = (tray) => {
if (!tray.items) return 0;
const total = tray.items.reduce((sum, item) => sum + (item.produk?.berat || 0), 0);
const total = tray.items.reduce((sum, item) => sum + (item.produk.berat || 0), 0);
return total.toFixed(2);
};