Merge branch 'production' of https://git.abbauf.com/Magang-2025/Kasir into production
This commit is contained in:
commit
7ef8f79b6c
@ -33,7 +33,7 @@ class ProdukController extends Controller
|
||||
|
||||
$validated = $request->validate(
|
||||
[
|
||||
'nama' => 'required|string|max:100',
|
||||
'nama' => 'required|string|max:100|unique:produks,nama',
|
||||
'id_kategori' => 'required|exists:kategoris,id',
|
||||
'berat' => 'required|numeric',
|
||||
'kadar' => 'required|integer',
|
||||
@ -42,6 +42,7 @@ class ProdukController extends Controller
|
||||
],
|
||||
[
|
||||
'nama.required' => 'Nama produk harus diisi.',
|
||||
'nama.unique' => 'Nama produk sudah digunakan.',
|
||||
'id_kategori' => 'Kategori tidak valid.',
|
||||
'berat.required' => 'Berat harus diisi.',
|
||||
'kadar.required' => 'Kadar harus diisi.',
|
||||
@ -122,7 +123,7 @@ class ProdukController extends Controller
|
||||
|
||||
$validated = $request->validate(
|
||||
[
|
||||
'nama' => 'required|string|max:100',
|
||||
'nama' => 'required|string|max:100|unique:produks,nama,' . $id,
|
||||
'id_kategori' => 'required|exists:kategoris,id',
|
||||
'berat' => 'required|numeric',
|
||||
'kadar' => 'required|integer',
|
||||
@ -131,6 +132,7 @@ class ProdukController extends Controller
|
||||
],
|
||||
[
|
||||
'nama.required' => 'Nama produk harus diisi.',
|
||||
'nama.unique' => 'Nama produk sudah digunakan.',
|
||||
'id_kategori' => 'Kategori tidak valid.',
|
||||
'berat.required' => 'Berat harus diisi.',
|
||||
'kadar.required' => 'Kadar harus diisi',
|
||||
|
||||
@ -340,40 +340,50 @@ const printQR = () => {
|
||||
<head>
|
||||
<title>Print QR Code - ${selectedItem.value.kode_item}</title>
|
||||
<style>
|
||||
@page {
|
||||
size: 60mm 50mm;
|
||||
margin: 1mm;
|
||||
}
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
}
|
||||
.qr-container {
|
||||
border: 2px solid #ccc;
|
||||
padding: 20px;
|
||||
display: inline-block;
|
||||
margin: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.qr-img {
|
||||
width: 40mm;
|
||||
height: 40mm;
|
||||
margin-bottom: 2mm;
|
||||
}
|
||||
.item-info {
|
||||
margin-top: 10px;
|
||||
font-size: 14px;
|
||||
font-size: 14pt;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="qr-container">
|
||||
<img src="${qrCodeUrl.value}" alt="QR Code" style="width: 200px; height: 200px;" />
|
||||
<img class="qr-img" src="${qrCodeUrl.value}" alt="QR Code"
|
||||
onload="window.print()" />
|
||||
<div class="item-info">
|
||||
<div style="font-weight: bold; margin-bottom: 5px;">${selectedItem.value.kode_item}</div>
|
||||
<div>${selectedItem.value.produk.nama}</div>
|
||||
<div style="color: #666; margin-top: 5px;">${selectedItem.value.produk.berat}g</div>
|
||||
${selectedItem.value.kode_item}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
printWindow.document.close();
|
||||
printWindow.print();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const handleImageError = (event) => {
|
||||
event.target.style.display = 'none';
|
||||
};
|
||||
|
||||
@ -87,7 +87,7 @@ const props = defineProps({
|
||||
});
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits(['close']);
|
||||
const emit = defineEmits(['close','itemAdded']);
|
||||
|
||||
// State
|
||||
const selectedNampan = ref('');
|
||||
@ -147,15 +147,17 @@ const createItem = async () => {
|
||||
}
|
||||
|
||||
const response = await axios.post('/api/item', payload, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||
},
|
||||
});;
|
||||
headers: {
|
||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||
},
|
||||
});
|
||||
|
||||
success.value = true;
|
||||
createdItem.value = response.data.data
|
||||
createdItem.value = response.data.data;
|
||||
console.log('Item created:', createdItem);
|
||||
|
||||
emit('itemAdded'); // 🔔 penting
|
||||
|
||||
loadNampanList();
|
||||
} catch (error) {
|
||||
console.error('Error creating item:', error);
|
||||
@ -165,6 +167,7 @@ const createItem = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const addNewItem = () => {
|
||||
success.value = false;
|
||||
selectedNampan.value = '';
|
||||
|
||||
@ -185,40 +185,57 @@ const printQR = () => {
|
||||
<head>
|
||||
<title>Print QR Code - ${selectedItem.value.kode_item}</title>
|
||||
<style>
|
||||
@page {
|
||||
size: 60mm 50mm;
|
||||
margin: 1mm;
|
||||
}
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
}
|
||||
.qr-container {
|
||||
border: 2px solid #ccc;
|
||||
padding: 20px;
|
||||
display: inline-block;
|
||||
margin: 20px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
}
|
||||
.item-info {
|
||||
margin-top: 10px;
|
||||
font-size: 14px;
|
||||
.qr-img {
|
||||
width: 40mm;
|
||||
height: 40mm;
|
||||
margin-bottom: 2mm;
|
||||
}
|
||||
.kode-item {
|
||||
font-weight: bold;
|
||||
font-size: 14pt;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="qr-container">
|
||||
<img src="${qrCodeUrl.value}" alt="QR Code" style="width: 200px; height: 200px;" />
|
||||
<div class="item-info">
|
||||
<div style="font-weight: bold; margin-bottom: 5px;">${selectedItem.value.kode_item}</div>
|
||||
<div>${selectedItem.value.produk.nama}</div>
|
||||
<div style="color: #666; margin-top: 5px;">${selectedItem.value.produk.berat}g</div>
|
||||
</div>
|
||||
<img id="qr-img" class="qr-img" src="${qrCodeUrl.value}" alt="QR Code" />
|
||||
<div class="kode-item">${selectedItem.value.kode_item}</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
|
||||
printWindow.document.close();
|
||||
printWindow.print();
|
||||
|
||||
const img = printWindow.document.getElementById("qr-img");
|
||||
img.onload = () => {
|
||||
printWindow.focus();
|
||||
printWindow.print();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const showDeleteConfirm = ref(false);
|
||||
|
||||
const confirmDelete = async () => {
|
||||
|
||||
@ -10,7 +10,10 @@
|
||||
<div class="flex-1">
|
||||
<div class="mb-3">
|
||||
<label class="block text-D mb-1">Nama Produk</label>
|
||||
<InputField v-model="form.nama" type="text" placeholder="Masukkan nama produk" />
|
||||
<InputField v-model="form.nama" type="text" placeholder="Masukkan nama produk" @input="errors.nama = null" />
|
||||
<p v-if="errors.nama" class="text-sm text-red-500 mt-1">
|
||||
{{ errors.nama[0] }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
@ -164,7 +167,7 @@ const uploadedImages = ref([]);
|
||||
const isDragging = ref(false);
|
||||
const uploadError = ref('');
|
||||
const fileInput = ref(null);
|
||||
|
||||
const errors = ref({});
|
||||
const openItemModal = ref(false);
|
||||
const createdProduct = ref(null);
|
||||
|
||||
@ -350,15 +353,16 @@ const submitForm = async (addItem) => {
|
||||
window.location.href = '/produk?message=Produk berhasil disimpan';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Submit error:', error);
|
||||
console.error('Submit error:', error);
|
||||
|
||||
if (error.response?.data?.errors) {
|
||||
const errors = Object.values(error.response.data.errors).flat();
|
||||
alert('Error: ' + errors.join(', '));
|
||||
} else {
|
||||
alert('Gagal menyimpan produk: ' + (error.response?.data?.message || error.message));
|
||||
}
|
||||
} finally {
|
||||
if (error.response?.status === 422 && error.response.data?.errors) {
|
||||
// 🔥 simpan error validasi dari backend
|
||||
errors.value = error.response.data.errors;
|
||||
} else {
|
||||
uploadError.value = error.response?.data?.message || 'Gagal menyimpan produk';
|
||||
}
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
<template>
|
||||
<mainLayout>
|
||||
<!-- Modal Buat Item -->
|
||||
<CreateItemModal :isOpen="creatingItem" :product="detail" @close="closeItemModal" />
|
||||
<CreateItemModal
|
||||
:isOpen="creatingItem"
|
||||
:product="detail"
|
||||
@close="closeItemModal"
|
||||
@itemAdded="handleItemAdded"
|
||||
/>
|
||||
|
||||
|
||||
<!-- Modal Konfirmasi Hapus Produk -->
|
||||
<ConfirmDeleteModal :isOpen="deleting" @cancel="deleting = false" @confirm="deleteProduk" title="Hapus Produk"
|
||||
@ -268,6 +274,15 @@ function formatNumber(num) {
|
||||
return new Intl.NumberFormat().format(num || 0);
|
||||
}
|
||||
|
||||
function handleItemAdded() {
|
||||
if (detail.value) {
|
||||
detail.value.items_count++;
|
||||
}
|
||||
creatingItem.value = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Hapus produk
|
||||
async function deleteProduk() {
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user