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

This commit is contained in:
Timoti313 2025-09-01 17:07:51 +07:00
commit d51b73c347
10 changed files with 306 additions and 32 deletions

View File

@ -127,7 +127,7 @@ class ProdukController extends Controller
// Update data produk // Update data produk
$produk->update([ $produk->update([
'nama' => $validated['nama'], 'nama' => $validated['nama'],
'kategori' => $validated['kategori'], 'id_kategori' => $validated['id_kategori'],
'berat' => $validated['berat'], 'berat' => $validated['berat'],
'kadar' => $validated['kadar'], 'kadar' => $validated['kadar'],
'harga_per_gram' => $validated['harga_per_gram'], 'harga_per_gram' => $validated['harga_per_gram'],

View File

@ -10,9 +10,16 @@
'Segoe UI Symbol', 'Noto Color Emoji'; 'Segoe UI Symbol', 'Noto Color Emoji';
} }
@theme { /* @theme {
--color-A: #F8F0E5; --color-A: #F8F0E5;
--color-B: #EADBC8; --color-B: #EADBC8;
--color-C: #DAC0A3; --color-C: #DAC0A3;
--color-D: #024768; --color-D: #024768;
} */
@theme {
--color-A: #EBF1F5;
--color-B: #AFE5FF;
--color-C: #77C7EE;
--color-D: #024768;
} }

View File

@ -16,7 +16,7 @@
v-model="form.nama" v-model="form.nama"
type="text" type="text"
placeholder="Masukkan nama kategori" placeholder="Masukkan nama kategori"
class="mt-1 block w-full border border-gray-300 rounded-md px-3 py-2 focus:ring focus:ring-[#c6a77d]" class="mt-1 block w-full border border-gray-300 rounded-md px-3 py-2 focus:ring focus:ring-C"
/> />
</div> </div>
@ -31,7 +31,7 @@
<button <button
@click="saveKategori" @click="saveKategori"
:disabled="!form.nama" :disabled="!form.nama"
class="px-4 py-2 bg-[#c6a77d] text-white rounded hover:bg-[#b09065] disabled:opacity-50" class="px-4 py-2 bg-C text-white rounded hover:bg-B disabled:opacity-50"
> >
Simpan Simpan
</button> </button>

View File

@ -1,5 +1,5 @@
<template> <template>
<footer class="bg-[#f9f3eb] border-t border-gray-200 py-4 px-6 flex flex-col md:flex-row items-center justify-between"> <footer class="bg-B border-t border-D py-4 px-6 flex flex-col md:flex-row items-center justify-between">
<!-- Left: Logo --> <!-- Left: Logo -->
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<img :src="logo" alt="Logo" class="h-10"> <img :src="logo" alt="Logo" class="h-10">

View File

@ -4,7 +4,7 @@
<div v-else-if="error" class="text-center text-red-500 py-6">{{ error }}</div> <div v-else-if="error" class="text-center text-red-500 py-6">{{ error }}</div>
<div v-else-if="filteredTrays.length === 0" class="text-center text-gray-500 py-6"> <div v-else-if="filteredTrays.length === 0" class="text-center text-gray-500 py-30">
Nampan tidak ditemukan. Nampan tidak ditemukan.
</div> </div>

View File

@ -0,0 +1,266 @@
<template>
<mainLayout>
<!-- Modal Buat Item -->
<CreateItemModal
:isOpen="openItemModal"
:product="editedProduct"
@close="closeItemModal"
/>
<div class="p-6">
<p class="font-serif italic text-[25px] text-D">Edit Produk</p>
<div class="flex flex-col md:flex-row mt-5 gap-6">
<!-- Form Section -->
<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" />
</div>
<div class="mb-3">
<label class="block text-D mb-1">Kategori</label>
<InputSelect v-model="form.id_kategori" :options="category" placeholder="Pilih kategori" />
</div>
<div class="mb-3 flex flex-row w-full gap-3">
<div class="flex-1">
<label class="block text-D mb-1">Berat (g)</label>
<InputField v-model="form.berat" type="number" step="0.01" placeholder="Masukkan berat" @input="calculateHargaJual" />
</div>
<div class="flex-1">
<label class="block text-D mb-1">Kadar (K)</label>
<InputField v-model="form.kadar" type="number" placeholder="Masukkan kadar" />
</div>
</div>
<div class="mb-3 flex flex-row w-full gap-3">
<div class="flex-1">
<label class="block text-D mb-1">Harga per Gram</label>
<InputField v-model="form.harga_per_gram" type="number" step="0.01" placeholder="Masukkan harga per gram" @input="calculateHargaJual" />
</div>
<div class="flex-1">
<label class="block text-D mb-1">Harga Jual</label>
<InputField v-model="form.harga_jual" type="number" step="0.01" placeholder="Masukkan harga jual" />
</div>
</div>
</div>
<!-- Image Upload Section -->
<div class="flex-1">
<label class="block text-D mb-1">Foto</label>
<div class="grid grid-cols-3 gap-3">
<!-- Existing Images -->
<div v-for="(image, index) in uploadedImages" :key="`img-${image.id}`" class="relative group aspect-square">
<div class="w-full h-full bg-gray-100 rounded-lg border-2 border-gray-200 overflow-hidden">
<img :src="image.url" :alt="`Foto ${index + 1}`" class="w-full h-full object-cover" />
<button @click="removeImage(image.id)" :disabled="uploadLoading"
class="absolute -top-2 -right-2 bg-red-500 text-white rounded-full w-6 h-6 flex items-center justify-center text-sm font-bold shadow-lg hover:bg-red-600 transition-colors disabled:bg-gray-400">
×
</button>
</div>
</div>
<!-- Upload Button -->
<div v-if="uploadedImages.length < 6" @drop="handleDrop" @dragover.prevent
@dragenter.prevent="isDragging = true" @dragleave.prevent="isDragging = false" @click="triggerFileInput"
class="aspect-square bg-gray-50 border-2 border-dashed border-gray-300 rounded-lg flex flex-col items-center justify-center cursor-pointer hover:border-D hover:bg-blue-50 transition-colors group"
:class="{ 'border-blue-400 bg-blue-50': isDragging, 'cursor-not-allowed opacity-50': uploadLoading }">
<div class="text-center">
<div v-if="!uploadLoading"
class="w-12 h-12 bg-D rounded-lg flex items-center justify-center mx-auto mb-2 group-hover:bg-D transition-colors">
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
</svg>
</div>
<div v-else class="w-12 h-12 bg-D rounded-lg flex items-center justify-center mx-auto mb-2">
<svg class="animate-spin w-6 h-6 text-white" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor"
d="m4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>
</div>
<p class="text-xs text-gray-600 font-medium" v-html="uploadLoading ? 'Uploading...' : 'Unggah<br/>Foto'"></p>
</div>
</div>
</div>
<input ref="fileInput" type="file" multiple accept="image/jpeg,image/jpg,image/png" @change="handleFileSelect" class="hidden" />
<p class="text-xs text-gray-500 mt-2">Format: JPG, JPEG, PNG (Max: 2MB per file, Max: 6 foto)</p>
<div v-if="uploadError" class="mt-2 p-2 bg-red-50 border border-red-200 rounded text-sm text-red-600">
{{ uploadError }}
</div>
</div>
</div>
<div class="mt-6 flex justify-end flex-row gap-3">
<button @click="back" class="px-6 py-2 rounded-md bg-gray-400 hover:bg-gray-500 text-white">Batal</button>
<button @click="submitForm" :disabled="loading || !isFormValid"
class="bg-C text-D px-6 py-2 rounded-md hover:bg-B disabled:bg-B disabled:text-white disabled:cursor-not-allowed">
{{ loading ? 'Menyimpan...' : 'Simpan Perubahan' }}
</button>
</div>
</div>
</mainLayout>
</template>
<script setup>
import { ref, computed, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import axios from "axios";
import mainLayout from "../layouts/mainLayout.vue";
import InputField from "../components/InputField.vue";
import InputSelect from "../components/InputSelect.vue";
import CreateItemModal from "../components/CreateItemModal.vue";
const route = useRoute();
const router = useRouter();
const productId = route.params.id;
const form = ref({
nama: "",
id_kategori: null,
berat: 0,
kadar: 0,
harga_per_gram: 0,
harga_jual: 0,
});
const category = ref([]);
const uploadedImages = ref([]);
const loading = ref(false);
const uploadLoading = ref(false);
const uploadError = ref("");
const isDragging = ref(false);
const fileInput = ref(null);
const openItemModal = ref(false);
const editedProduct = ref(null);
const userId = ref(1); // TODO: ambil dari auth
const isFormValid = computed(() => {
return (
form.value.nama &&
form.value.id_kategori &&
form.value.berat > 0 &&
form.value.kadar > 0 &&
form.value.harga_per_gram > 0 &&
form.value.harga_jual > 0
);
});
const calculateHargaJual = () => {
const berat = parseFloat(form.value.berat) || 0;
const hargaPerGram = parseFloat(form.value.harga_per_gram) || 0;
if (berat > 0 && hargaPerGram > 0) {
form.value.harga_jual = berat * hargaPerGram;
}
};
const loadKategori = async () => {
const response = await axios.get("/api/kategori");
category.value = response.data.map((c) => ({ value: c.id, label: c.nama }));
};
const loadProduk = async () => {
const response = await axios.get(`/api/produk/${productId}`);
const produk = response.data;
form.value = {
nama: produk.nama,
id_kategori: produk.id_kategori,
berat: produk.berat,
kadar: produk.kadar,
harga_per_gram: produk.harga_per_gram,
harga_jual: produk.harga_jual,
};
uploadedImages.value = produk.foto || [];
};
const triggerFileInput = () => {
if (!uploadLoading.value && uploadedImages.value.length < 6) {
fileInput.value?.click();
}
};
const handleFileSelect = (e) => {
const files = Array.from(e.target.files);
uploadFiles(files);
};
const handleDrop = (e) => {
e.preventDefault();
isDragging.value = false;
if (uploadLoading.value || uploadedImages.value.length >= 6) return;
const files = Array.from(e.dataTransfer.files);
uploadFiles(files);
};
const uploadFiles = async (files) => {
uploadError.value = "";
const validFiles = files.filter(
(file) =>
["image/jpeg", "image/jpg", "image/png"].includes(file.type) &&
file.size <= 2 * 1024 * 1024
);
if (!validFiles.length) return;
uploadLoading.value = true;
try {
for (const file of validFiles) {
const formData = new FormData();
formData.append("foto", file);
formData.append("id_user", userId.value);
const res = await axios.post("/api/foto/upload", formData, {
headers: { "Content-Type": "multipart/form-data" },
});
uploadedImages.value.push(res.data);
}
} finally {
uploadLoading.value = false;
}
};
const removeImage = async (id) => {
try {
await axios.delete(`/api/foto/hapus/${id}`);
uploadedImages.value = uploadedImages.value.filter((i) => i.id !== id);
} catch {
uploadError.value = "Gagal menghapus foto";
}
};
const submitForm = async () => {
loading.value = true;
try {
await axios.put(`/api/produk/${productId}`, {
...form.value,
id_user: userId.value,
});
alert("Produk berhasil diupdate!");
router.push("/produk");
} catch (err) {
alert("Gagal update produk!");
console.error(err);
} finally {
loading.value = false;
}
};
const closeItemModal = () => {
openItemModal.value = false;
};
const back = () => {
router.push("/produk");
};
onMounted(() => {
loadKategori();
loadProduk();
});
</script>

View File

@ -9,7 +9,7 @@
<div class="flex justify-between items-center mb-6"> <div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold text-gray-800">Kategori</h1> <h1 class="text-2xl font-bold text-gray-800">Kategori</h1>
<button @click="tambahKategori" <button @click="tambahKategori"
class="px-4 py-2 bg-[#c6a77d] text-white rounded-md hover:bg-[#b09065] transition duration-200 flex items-center gap-2"> class="px-4 py-2 bg-C text-black rounded-md hover:bg-B transition duration-200 flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" /> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
</svg> </svg>
@ -21,11 +21,11 @@
<div class="bg-white rounded-lg shadow-md border border-gray-200 overflow-hidden"> <div class="bg-white rounded-lg shadow-md border border-gray-200 overflow-hidden">
<table class="w-full"> <table class="w-full">
<thead> <thead>
<tr class="bg-[#c6a77d] text-white"> <tr class="bg-C text-black">
<th class="px-6 py-4 text-left font-semibold border-r border-[#b09065]"> <th class="px-6 py-4 text-left font-semibold border-r border-C">
No No
</th> </th>
<th class="px-6 py-4 text-left font-semibold border-r border-[#b09065]"> <th class="px-6 py-4 text-left font-semibold border-r border-C">
Nama Kategori Nama Kategori
</th> </th>
<th class="px-6 py-4 text-center font-semibold"> <th class="px-6 py-4 text-center font-semibold">
@ -35,7 +35,7 @@
</thead> </thead>
<tbody> <tbody>
<tr v-for="(item, index) in kategori" :key="item.id" <tr v-for="(item, index) in kategori" :key="item.id"
class="border-b border-gray-200 hover:bg-gray-50 transition duration-150" class="border-b border-gray-200 hover:bg-A transition duration-150"
:class="{ 'bg-gray-50': index % 2 === 1 }"> :class="{ 'bg-gray-50': index % 2 === 1 }">
<td class="px-6 py-4 border-r border-gray-200 font-medium text-gray-900"> <td class="px-6 py-4 border-r border-gray-200 font-medium text-gray-900">
{{ index + 1 }} {{ index + 1 }}
@ -74,8 +74,8 @@
</div> </div>
<!-- Loading State --> <!-- Loading State -->
<div v-if="loading" class="flex justify-center items-center py-8"> <div v-if="loading" class="flex justify-center items-center h-screen">
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-[#c6a77d]"></div> <div class="animate-spin rounded-full h-8 w-8 border-b-2 border-C"></div>
<span class="ml-2 text-gray-600">Memuat data...</span> <span class="ml-2 text-gray-600">Memuat data...</span>
</div> </div>
</div> </div>
@ -159,10 +159,3 @@ onMounted(() => {
fetchKategoris(); fetchKategoris();
}); });
</script> </script>
<style scoped>
/* Custom styles jika diperlukan */
.table-hover-row:hover {
background-color: #f9fafb;
}
</style>

View File

@ -123,10 +123,12 @@
<!-- Tombol Aksi --> <!-- Tombol Aksi -->
<div class="flex w-full gap-3"> <div class="flex w-full gap-3">
<button <button
@click="$router.push(`/produk/${detail.id}/edit`)"
class="flex-1 bg-yellow-400 text-black py-2 rounded font-bold" class="flex-1 bg-yellow-400 text-black py-2 rounded font-bold"
> >
Ubah Ubah
</button> </button>
<button <button
@click="openItemModal" @click="openItemModal"
class="bg-green-400 text-black px-4 py-2 rounded font-bold" class="bg-green-400 text-black px-4 py-2 rounded font-bold"

View File

@ -20,8 +20,7 @@
<!-- Tambah Nampan --> <!-- Tambah Nampan -->
<button <button
@click="openModal" @click="openModal"
class="px-4 py-2 hover:bg-green-700 rounded-md shadow font-semibold" class="px-4 py-2 hover:bg-B bg-C rounded-md shadow font-semibold" >
style="background-color: #DAC0A3; color: #102C57;">
Tambah Nampan Tambah Nampan
</button> </button>

View File

@ -7,6 +7,7 @@ import Kasir from '../pages/Kasir.vue'
import InputProduk from '../pages/InputProduk.vue' import InputProduk from '../pages/InputProduk.vue'
import Kategori from '../pages/Kategori.vue' import Kategori from '../pages/Kategori.vue'
import Sales from '../pages/Sales.vue' import Sales from '../pages/Sales.vue'
import EditProduk from '../pages/EditProduk.vue'
const routes = [ const routes = [
@ -50,6 +51,12 @@ const routes = [
name: 'Sales', name: 'Sales',
component: Sales component: Sales
}, },
{
path: '/produk/:id/edit', // :id = parameter dinamis
name: 'EditProduk',
component: EditProduk,
props: true // biar id bisa langsung jadi props di komponen
}
] ]