Merge branch 'production' of https://git.abbauf.com/Magang-2025/Kasir into production
This commit is contained in:
commit
6204acc6aa
@ -10,8 +10,12 @@ class FotoSementaraController extends Controller
|
|||||||
{
|
{
|
||||||
public function upload(Request $request)
|
public function upload(Request $request)
|
||||||
{
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
if (!$user) {
|
||||||
|
return response()->json(['message' => 'Unauthorized'], 401);
|
||||||
|
}
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'id_user' => 'required|exists:users,id',
|
|
||||||
'foto' => 'required|image|mimes:jpg,jpeg,png|max:2048',
|
'foto' => 'required|image|mimes:jpg,jpeg,png|max:2048',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -19,15 +23,20 @@ class FotoSementaraController extends Controller
|
|||||||
$url = asset('storage/' . $path);
|
$url = asset('storage/' . $path);
|
||||||
|
|
||||||
$foto = FotoSementara::create([
|
$foto = FotoSementara::create([
|
||||||
'id_user' => $request->id_user,
|
'id_user' => $user->id,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response()->json($foto, 201);
|
return response()->json($foto, 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hapus($id)
|
public function hapus(Request $request, int $id)
|
||||||
{
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
if (!$user) {
|
||||||
|
return response()->json(['message' => 'Unauthorized'], 401);
|
||||||
|
}
|
||||||
|
|
||||||
$foto = FotoSementara::findOrFail($id);
|
$foto = FotoSementara::findOrFail($id);
|
||||||
|
|
||||||
// Extract the relative path from the URL
|
// Extract the relative path from the URL
|
||||||
@ -42,18 +51,25 @@ class FotoSementaraController extends Controller
|
|||||||
return response()->json(['message' => 'Foto berhasil dihapus']);
|
return response()->json(['message' => 'Foto berhasil dihapus']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAll($user_id)
|
public function getAll(Request $request)
|
||||||
{
|
{
|
||||||
$data = FotoSementara::where('id_user', $user_id);
|
$user = $request->user();
|
||||||
if (!$data->exists()) {
|
if (!$user) {
|
||||||
return response()->json(['message' => 'Tidak ada foto ditemukan'], 404);
|
return response()->json(['message' => 'Unauthorized'], 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$data = FotoSementara::where('id_user', $user->id)->get();
|
||||||
return response()->json($data);
|
return response()->json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset($user_id)
|
public function reset(Request $request)
|
||||||
{
|
{
|
||||||
FotoSementara::where('id_user', $user_id)->delete();
|
$user = $request->user();
|
||||||
|
if (!$user) {
|
||||||
|
return response()->json(['message' => 'Unauthorized'], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
FotoSementara::where('id_user', $user->id)->delete();
|
||||||
return response()->json(['message' => 'Foto sementara berhasil direset']);
|
return response()->json(['message' => 'Foto sementara berhasil direset']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,8 @@ class ItemController extends Controller
|
|||||||
|
|
||||||
$item = Item::create($validated);
|
$item = Item::create($validated);
|
||||||
|
|
||||||
|
$item->load('nampan');
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'Item berhasil dibuat',
|
'message' => 'Item berhasil dibuat',
|
||||||
'data' => $item
|
'data' => $item
|
||||||
|
|||||||
@ -26,39 +26,35 @@ class ProdukController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$validated = $request->validate([
|
$user = $request->user();
|
||||||
|
if (!$user) {
|
||||||
|
return response()->json(['message' => 'Unauthorized'], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
$validated = $request->validate(
|
||||||
|
[
|
||||||
'nama' => 'required|string|max:100',
|
'nama' => 'required|string|max:100',
|
||||||
'id_kategori' => 'required|exists:kategoris,id',
|
'id_kategori' => 'required|exists:kategoris,id',
|
||||||
'berat' => 'required|numeric',
|
'berat' => 'required|numeric',
|
||||||
'kadar' => 'required|integer',
|
'kadar' => 'required|integer',
|
||||||
'harga_per_gram' => 'required|numeric',
|
'harga_per_gram' => 'required|numeric',
|
||||||
'harga_jual' => 'required|numeric',
|
'harga_jual' => 'required|numeric',
|
||||||
'id_user' => 'nullable|exists:users,id',
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'nama.required' => 'Nama produk harus diisi.',
|
'nama.required' => 'Nama produk harus diisi.',
|
||||||
'id_kategori' => 'Kategori tidak valid.',
|
'id_kategori' => 'Kategori tidak valid.',
|
||||||
'berat.required' => 'Berat harus diisi.',
|
'berat.required' => 'Berat harus diisi.',
|
||||||
'kadar.required' => 'Kadar harus diisi',
|
'kadar.required' => 'Kadar harus diisi.',
|
||||||
'harga_per_gram.required' => 'Harga per gram harus diisi',
|
'harga_per_gram.required' => 'Harga per gram harus diisi.',
|
||||||
'harga_jual.required' => 'Harga jual harus diisi'
|
'harga_jual.required' => 'Harga jual harus diisi.'
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
|
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
try {
|
try {
|
||||||
// Create produk
|
$produk = Produk::create($validated);
|
||||||
$produk = Produk::create([
|
|
||||||
'nama' => $validated['nama'],
|
|
||||||
'id_kategori' => $validated['id_kategori'],
|
|
||||||
'berat' => $validated['berat'],
|
|
||||||
'kadar' => $validated['kadar'],
|
|
||||||
'harga_per_gram' => $validated['harga_per_gram'],
|
|
||||||
'harga_jual' => $validated['harga_jual'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Pindahkan foto sementara ke foto permanen jika ada
|
$fotoSementara = FotoSementara::where('id_user', $user->id)->get();
|
||||||
if (isset($validated['id_user'])) {
|
|
||||||
$fotoSementara = FotoSementara::where('id_user', $validated['id_user'])->get();
|
|
||||||
|
|
||||||
foreach ($fotoSementara as $fs) {
|
foreach ($fotoSementara as $fs) {
|
||||||
Foto::create([
|
Foto::create([
|
||||||
@ -66,10 +62,8 @@ class ProdukController extends Controller
|
|||||||
'url' => $fs->url
|
'url' => $fs->url
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Hapus foto sementara setelah dipindah
|
|
||||||
$fs->delete();
|
$fs->delete();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
||||||
@ -77,7 +71,6 @@ class ProdukController extends Controller
|
|||||||
'message' => 'Produk berhasil dibuat',
|
'message' => 'Produk berhasil dibuat',
|
||||||
'data' => $produk->load('foto')
|
'data' => $produk->load('foto')
|
||||||
], 201);
|
], 201);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
DB::rollback();
|
DB::rollback();
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@ -96,20 +89,45 @@ class ProdukController extends Controller
|
|||||||
return response()->json($produk);
|
return response()->json($produk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the specified resource to edit.
|
||||||
|
*/
|
||||||
|
public function edit(Request $request, int $id)
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
if (!$user) {
|
||||||
|
return response()->json(['message' => 'Unauthorized'], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
$produk = Produk::with('foto', 'kategori')->findOrFail($id);
|
||||||
|
$foto_sementara = [];
|
||||||
|
foreach ($produk->foto as $foto) {
|
||||||
|
$foto_sementara[] = FotoSementara::create([
|
||||||
|
'id_user' => $user->id,
|
||||||
|
'url' => $foto->url
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return response()->json($produk);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, int $id)
|
public function update(Request $request, int $id)
|
||||||
{
|
{
|
||||||
$validated = $request->validate([
|
$user = $request->user();
|
||||||
|
if (!$user) {
|
||||||
|
return response()->json(['message' => 'Unauthorized'], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
$validated = $request->validate(
|
||||||
|
[
|
||||||
'nama' => 'required|string|max:100',
|
'nama' => 'required|string|max:100',
|
||||||
'id_kategori' => 'required|exists:kategoris,id',
|
'id_kategori' => 'required|exists:kategoris,id',
|
||||||
'berat' => 'required|numeric',
|
'berat' => 'required|numeric',
|
||||||
'kadar' => 'required|integer',
|
'kadar' => 'required|integer',
|
||||||
'harga_per_gram' => 'required|numeric',
|
'harga_per_gram' => 'required|numeric',
|
||||||
'harga_jual' => 'required|numeric',
|
'harga_jual' => 'required|numeric',
|
||||||
'id_user' => 'nullable|exists:users,id', // untuk mengambil foto sementara baru
|
|
||||||
'hapus_foto_lama' => 'nullable|boolean', // flag untuk menghapus foto lama
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'nama.required' => 'Nama produk harus diisi.',
|
'nama.required' => 'Nama produk harus diisi.',
|
||||||
@ -117,8 +135,9 @@ class ProdukController extends Controller
|
|||||||
'berat.required' => 'Berat harus diisi.',
|
'berat.required' => 'Berat harus diisi.',
|
||||||
'kadar.required' => 'Kadar harus diisi',
|
'kadar.required' => 'Kadar harus diisi',
|
||||||
'harga_per_gram.required' => 'Harga per gram harus diisi',
|
'harga_per_gram.required' => 'Harga per gram harus diisi',
|
||||||
'harga_jual.required' => 'Harga jual harus diisi'
|
'harga_jual.required' => 'Harga jual harus diisi',
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
|
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
try {
|
try {
|
||||||
@ -134,21 +153,21 @@ class ProdukController extends Controller
|
|||||||
'harga_jual' => $validated['harga_jual'],
|
'harga_jual' => $validated['harga_jual'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Hapus foto lama jika diminta
|
// Hapus foto lama
|
||||||
if (isset($validated['hapus_foto_lama']) && $validated['hapus_foto_lama']) {
|
|
||||||
foreach ($produk->foto as $foto) {
|
foreach ($produk->foto as $foto) {
|
||||||
// Hapus file fisik
|
// Hapus file fisik jika memungkinkan
|
||||||
|
try {
|
||||||
$relativePath = str_replace(asset('storage') . '/', '', $foto->url);
|
$relativePath = str_replace(asset('storage') . '/', '', $foto->url);
|
||||||
if (Storage::disk('public')->exists($relativePath)) {
|
if (Storage::disk('public')->exists($relativePath)) {
|
||||||
Storage::disk('public')->delete($relativePath);
|
Storage::disk('public')->delete($relativePath);
|
||||||
}
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// Maklum Pak, soalnya kadang url aja, ga ada file fisiknya #Bagas
|
||||||
|
}
|
||||||
$foto->delete();
|
$foto->delete();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Tambahkan foto baru dari foto sementara jika ada
|
$fotoSementara = FotoSementara::where('id_user', $user->id)->get();
|
||||||
if (isset($validated['id_user'])) {
|
|
||||||
$fotoSementara = FotoSementara::where('id_user', $validated['id_user'])->get();
|
|
||||||
|
|
||||||
foreach ($fotoSementara as $fs) {
|
foreach ($fotoSementara as $fs) {
|
||||||
Foto::create([
|
Foto::create([
|
||||||
@ -156,10 +175,8 @@ class ProdukController extends Controller
|
|||||||
'url' => $fs->url
|
'url' => $fs->url
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Hapus foto sementara setelah dipindah
|
|
||||||
$fs->delete();
|
$fs->delete();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
||||||
@ -167,7 +184,6 @@ class ProdukController extends Controller
|
|||||||
'message' => 'Produk berhasil diubah',
|
'message' => 'Produk berhasil diubah',
|
||||||
'data' => $produk->load('foto')
|
'data' => $produk->load('foto')
|
||||||
], 200);
|
], 200);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
DB::rollback();
|
DB::rollback();
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@ -203,7 +219,6 @@ class ProdukController extends Controller
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'Produk berhasil dihapus.'
|
'message' => 'Produk berhasil dihapus.'
|
||||||
], 200);
|
], 200);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
DB::rollback();
|
DB::rollback();
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
// brankas list
|
|
||||||
<template>
|
<template>
|
||||||
<div v-if="loading" class="flex justify-center items-center h-screen">
|
<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-C"></div>
|
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-C"></div>
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<Modal :active="isOpen" size="md" @close="handleClose" clickOutside="false">
|
<Modal :active="isOpen" size="md" @close="handleClose" clickOutside="false">
|
||||||
<div class="p-6">
|
<div class="p-6">
|
||||||
<h3 class="text-lg font-semibold text-gray-900 mb-4">Item {{ product?.nama }}</h3>
|
|
||||||
|
|
||||||
<div v-if="!success">
|
<div v-if="!success">
|
||||||
|
<h3 class="text-lg font-semibold text-gray-900 mb-4">Item {{ product?.nama }}</h3>
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<label class="block text-gray-700 mb-2">Pilih Nampan</label>
|
<label class="block text-gray-700 mb-2">Pilih Nampan</label>
|
||||||
<InputSelect v-model="selectedNampan" :options="positionListOptions" :disabled="loading" />
|
<InputSelect v-model="selectedNampan" :options="positionListOptions" :disabled="loading" />
|
||||||
@ -31,21 +31,22 @@
|
|||||||
<!-- Success State -->
|
<!-- Success State -->
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
|
<h4 class="text-lg font-semibold text-gray-900 mb-2">Item Berhasil Dibuat!</h4>
|
||||||
<svg class="w-8 h-8 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7">
|
<!-- QR Code -->
|
||||||
</path>
|
<div class="flex justify-center mb-4">
|
||||||
</svg>
|
<div class="p-2 border border-gray-300 rounded-lg">
|
||||||
|
<img :src="qrCodeUrl" alt="QR Code" class="w-36 h-36" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h4 class="text-lg font-semibold text-gray-900 mb-2">Item Berhasil Dibuat!</h4>
|
<!-- Item Info -->
|
||||||
<p class="text-gray-600 mb-2">
|
<div class="text-center text-gray-700 font-medium mb-1">
|
||||||
Item dari produk "<strong>{{ product?.nama }}</strong>" telah ditambahkan ke {{
|
{{ createdItem?.kode_item }}
|
||||||
selectedNampanName }}.
|
</div>
|
||||||
</p>
|
<div class="text-center text-gray-500 text-sm mb-6">
|
||||||
<p class="text-sm text-gray-500 mb-6">
|
{{ product?.nama }} - {{ createdItem?.nampan?.nama || 'Brankas' }}
|
||||||
ID Item: <strong>{{ createdItem.id }}</strong>
|
</div>
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="flex flex-row justify-between gap-3">
|
<div class="flex flex-row justify-between gap-3">
|
||||||
<button @click="handleClose"
|
<button @click="handleClose"
|
||||||
@ -53,9 +54,8 @@
|
|||||||
Selesai
|
Selesai
|
||||||
</button>
|
</button>
|
||||||
<button @click="printItem"
|
<button @click="printItem"
|
||||||
class="flex-1 px-6 py-2 bg-C hover:bg-B text-D rounded-lg transition-colors opacity-50 cursor-not-allowed"
|
class="flex-1 px-6 py-2 bg-C hover:bg-B text-D rounded-lg transition-colors">
|
||||||
disabled>
|
<i class="fas fa-print mr-1"></i>Print
|
||||||
Print
|
|
||||||
</button>
|
</button>
|
||||||
<button @click="addNewItem"
|
<button @click="addNewItem"
|
||||||
class="flex-1 px-6 py-2 bg-C hover:bg-B text-D rounded-lg transition-colors">
|
class="flex-1 px-6 py-2 bg-C hover:bg-B text-D rounded-lg transition-colors">
|
||||||
@ -99,15 +99,15 @@ const success = ref(false);
|
|||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const createdItem = ref(null);
|
const createdItem = ref(null);
|
||||||
|
|
||||||
// Computed
|
// QR Code generator - berdasarkan logika dari brankas list
|
||||||
const selectedNampanName = computed(() => {
|
const qrCodeUrl = computed(() => {
|
||||||
if (!selectedNampan.value) return 'Brankas';
|
if (createdItem.value && props.product) {
|
||||||
|
const itemId = createdItem.value.id || createdItem.value.kode_item;
|
||||||
console.log("Selected nampan ID:", selectedNampan.value);
|
const productName = props.product.nama.replace(/\s/g, "");
|
||||||
const nampan = nampanList.value.find(n => n.id === Number(selectedNampan.value));
|
const data = `ITM-${itemId}-${productName}`;
|
||||||
console.log("All nampan:", nampanList.value);
|
return `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${encodeURIComponent(data)}`;
|
||||||
console.log("Selected nampan:", nampan);
|
}
|
||||||
return nampan ? nampan.nama : 'Brankas';
|
return "";
|
||||||
});
|
});
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
@ -156,6 +156,7 @@ const createItem = async () => {
|
|||||||
createdItem.value = response.data.data
|
createdItem.value = response.data.data
|
||||||
console.log('Item created:', createdItem);
|
console.log('Item created:', createdItem);
|
||||||
|
|
||||||
|
loadNampanList();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating item:', error);
|
console.error('Error creating item:', error);
|
||||||
alert('Gagal membuat item: ' + (error.response?.data?.message || error.message));
|
alert('Gagal membuat item: ' + (error.response?.data?.message || error.message));
|
||||||
@ -167,10 +168,52 @@ const createItem = async () => {
|
|||||||
const addNewItem = () => {
|
const addNewItem = () => {
|
||||||
success.value = false;
|
success.value = false;
|
||||||
selectedNampan.value = '';
|
selectedNampan.value = '';
|
||||||
|
createdItem.value = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Fungsi print berdasarkan logika dari brankas list
|
||||||
const printItem = () => {
|
const printItem = () => {
|
||||||
alert('Wak waw');
|
if (qrCodeUrl.value && createdItem.value && props.product) {
|
||||||
|
const printWindow = window.open('', '_blank');
|
||||||
|
const itemCode = createdItem.value.kode_item || createdItem.value.id;
|
||||||
|
|
||||||
|
printWindow.document.write(`
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Print QR Code - ${itemCode}</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
text-align: center;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
.qr-container {
|
||||||
|
border: 2px solid #ccc;
|
||||||
|
padding: 20px;
|
||||||
|
display: inline-block;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
.item-info {
|
||||||
|
margin-top: 10px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
</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;">${itemCode}</div>
|
||||||
|
<div>${props.product.nama}</div>
|
||||||
|
<div style="color: #666; margin-top: 5px;">${props.product.berat}g</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`);
|
||||||
|
printWindow.document.close();
|
||||||
|
printWindow.print();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
@ -178,6 +221,7 @@ const handleClose = () => {
|
|||||||
selectedNampan.value = '';
|
selectedNampan.value = '';
|
||||||
success.value = false;
|
success.value = false;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
createdItem.value = null;
|
||||||
|
|
||||||
emit('close');
|
emit('close');
|
||||||
};
|
};
|
||||||
@ -188,6 +232,7 @@ watch(() => props.isOpen, (newValue) => {
|
|||||||
selectedNampan.value = '';
|
selectedNampan.value = '';
|
||||||
success.value = false;
|
success.value = false;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
createdItem.value = null;
|
||||||
|
|
||||||
loadNampanList();
|
loadNampanList();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -194,6 +194,15 @@ const tambahItem = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pesanan.value.length >= 2) {
|
||||||
|
error.value = "Maksimal hanya bisa memesan 2 item.";
|
||||||
|
clearTimeout(errorTimeout);
|
||||||
|
errorTimeout = setTimeout(() => {
|
||||||
|
error.value = "";
|
||||||
|
}, 3000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// harga deal
|
// harga deal
|
||||||
item.value.kode_item = kodeItem.value;
|
item.value.kode_item = kodeItem.value;
|
||||||
item.value.harga_deal = Number(hargaJual.value);
|
item.value.harga_deal = Number(hargaJual.value);
|
||||||
|
|||||||
@ -1,69 +1,51 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div v-if="isOpen"
|
||||||
v-if="isOpen"
|
class="text-D pt-serif-regular-italic fixed inset-0 bg-black/75 flex items-center justify-center z-[9999]">
|
||||||
class="text-D pt-serif-regular-italic fixed inset-0 bg-black/75 flex items-center justify-center z-[9999]"
|
<div class="bg-white w-[1224px] h-[528px] rounded-md shadow-lg relative overflow-hidden">
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="bg-white w-[1224px] h-[528px] rounded-md shadow-lg relative overflow-hidden"
|
|
||||||
>
|
|
||||||
<div class="bg-D h-8 w-full"></div>
|
<div class="bg-D h-8 w-full"></div>
|
||||||
|
|
||||||
<div class="p-6 text-sm flex flex-col h-full relative">
|
<div class="p-6 text-sm flex flex-col h-full relative">
|
||||||
<!-- Header -->
|
|
||||||
<div class="relative flex items-center justify-between pb-2 mb-2">
|
<div class="relative flex items-center justify-between pb-2 mb-2">
|
||||||
<!-- Sosmed -->
|
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4">
|
||||||
<p class="flex items-center gap-2">
|
<p class="flex items-center gap-2">
|
||||||
<i class="fab fa-instagram text-red-500 text-xl"></i> tokomas_Jakartacitayam
|
<i class="fab fa-instagram text-D text-xl"></i> tokomas_Jakartacitayam
|
||||||
</p>
|
</p>
|
||||||
<p class="flex items-center gap-2">
|
<p class="flex items-center gap-2">
|
||||||
<i class="fab fa-tiktok text-black text-xl"></i> tokomas_Jakartacitayam
|
<i class="fab fa-tiktok text-D text-xl"></i> tokomas_Jakartacitayam
|
||||||
</p>
|
</p>
|
||||||
<p class="flex items-center gap-2">
|
<p class="flex items-center gap-2">
|
||||||
<i class="fab fa-whatsapp text-green-500 text-xl"></i> 08158851178
|
<i class="fab fa-whatsapp text-D text-xl"></i> 08158851178
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Logo & tanggal (absolute di tengah) -->
|
|
||||||
<div class="absolute inset-x-0 top-0 flex flex-col items-center">
|
<div class="absolute inset-x-0 top-0 flex flex-col items-center">
|
||||||
<img :src="logo" alt="Logo" class="h-15" />
|
<img :src="logo" alt="Logo" class="h-15" />
|
||||||
<!-- ==== MODIFIKASI: Tanggal sekarang dinamis ==== -->
|
|
||||||
<p class="mt-1 text-center">{{ getCurrentDate() }}</p>
|
<p class="mt-1 text-center">{{ getCurrentDate() }}</p>
|
||||||
<!-- ==== END MODIFIKASI ==== -->
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Data Pembeli -->
|
|
||||||
<div
|
<div class="grid grid-cols-[130px_1fr] gap-y-2 items-center relative z-10">
|
||||||
class="grid grid-cols-[130px_1fr] gap-y-2 items-center relative z-10"
|
|
||||||
>
|
|
||||||
<div class="text-right font-semibold pr-3">Nama Pembeli</div>
|
<div class="text-right font-semibold pr-3">Nama Pembeli</div>
|
||||||
<!-- ==== MODIFIKASI: Input field sekarang v-model ==== -->
|
|
||||||
<inputField
|
<inputField v-model="namaPembeli" class="h-7 px-2 text-sm rounded bg-blue-200 w-full" />
|
||||||
v-model="namaPembeli"
|
|
||||||
class="h-7 px-2 text-sm rounded bg-blue-200 w-full"
|
|
||||||
/>
|
|
||||||
<!-- ==== END MODIFIKASI ==== -->
|
|
||||||
<div class="text-right font-semibold pr-3">Nomor Telepon</div>
|
<div class="text-right font-semibold pr-3">Nomor Telepon</div>
|
||||||
<!-- ==== MODIFIKASI: Input field sekarang v-model ==== -->
|
|
||||||
<inputField
|
<inputField v-model="nomorTelepon" class="h-7 px-2 text-sm rounded bg-blue-200 w-full" />
|
||||||
v-model="nomorTelepon"
|
|
||||||
class="h-7 px-2 text-sm rounded bg-blue-200 w-full"
|
|
||||||
/>
|
|
||||||
<!-- ==== END MODIFIKASI ==== -->
|
|
||||||
<div class="text-right font-semibold pr-3">Alamat</div>
|
<div class="text-right font-semibold pr-3">Alamat</div>
|
||||||
<!-- ==== MODIFIKASI: Input field sekarang v-model ==== -->
|
|
||||||
<inputField
|
<inputField v-model="alamat" class="h-7 px-2 text-sm rounded bg-blue-200 w-full" />
|
||||||
v-model="alamat"
|
|
||||||
class="h-7 px-2 text-sm rounded bg-blue-200 w-full"
|
|
||||||
/>
|
|
||||||
<!-- ==== END MODIFIKASI ==== -->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Nomor Transaksi -->
|
|
||||||
<!-- ==== MODIFIKASI: Kode transaksi dinamis ==== -->
|
|
||||||
<p class="mt-1 text-sm">{{ generateTransactionCode() }}</p>
|
<p class="mt-1 text-sm">{{ generateTransactionCode() }}</p>
|
||||||
<!-- ==== END MODIFIKASI ==== -->
|
|
||||||
|
|
||||||
<table class="w-full border-D mt-0 text-sm table-fixed">
|
<table class="w-full border-D mt-0 text-sm table-fixed">
|
||||||
<thead>
|
<thead>
|
||||||
@ -77,29 +59,49 @@
|
|||||||
<th class="w-[140px]">Total Harga</th>
|
<th class="w-[140px]">Total Harga</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
|
||||||
<!-- ==== MODIFIKASI: Loop pesanan dari props ==== -->
|
|
||||||
<tr v-for="(item, index) in pesanan" :key="index" class="text-center">
|
|
||||||
<td class="flex items-center gap-2 p-2 border-r border-D">
|
|
||||||
<img :src="item.produk.foto?.[0]?.url || ''" class="w-12 h-12 object-cover" />
|
|
||||||
{{ item.produk.nama }}
|
|
||||||
</td>
|
|
||||||
<td class="border-r border-D">{{ item.posisi || 'Brankas' }}</td>
|
|
||||||
<td class="border-r border-D">{{ item.produk.berat || '-' }}</td>
|
|
||||||
<td class="border-r border-D">{{ item.produk.kadar || '-' }}</td>
|
|
||||||
<td class="border-r border-D">Rp{{ item.harga_deal.toLocaleString() }}</td>
|
|
||||||
<td class="border-r border-D">1</td>
|
|
||||||
<td>Rp{{ item.harga_deal.toLocaleString() }}</td>
|
|
||||||
</tr>
|
|
||||||
<!-- ==== END MODIFIKASI ==== -->
|
|
||||||
|
|
||||||
<!-- Baris Ongkos + Total -->
|
<tbody>
|
||||||
<tr class="align-top">
|
<tr v-for="(item, index) in pesananMinimal" :key="index" class="text-center">
|
||||||
|
<td class="flex items-center gap-2 p-2 border-r border-D">
|
||||||
|
<template v-if="item.produk?.foto?.[0]?.url">
|
||||||
|
<img :src="item.produk.foto[0].url" class="w-12 h-12 object-cover" />
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div class="w-12 h-12"></div>
|
||||||
|
</template>
|
||||||
|
{{ item.produk?.nama || '' }}
|
||||||
|
</td>
|
||||||
|
<td class="border-r border-D">{{ item.posisi || '' }}</td>
|
||||||
|
<td class="border-r border-D">
|
||||||
|
<span v-if="item.produk?.berat">{{ item.produk.berat }}g</span>
|
||||||
|
</td>
|
||||||
|
<td class="border-r border-D">
|
||||||
|
<span v-if="item.produk?.kadar">{{ item.produk.kadar }}k</span>
|
||||||
|
</td>
|
||||||
|
<td class="border-r border-D">
|
||||||
|
<span v-if="item.harga_deal">Rp{{ item.harga_deal.toLocaleString() }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="border-r border-D">
|
||||||
|
<span v-if="item.harga_deal">1</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span v-if="item.harga_deal">Rp{{ item.harga_deal.toLocaleString() }}</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<tfoot>
|
||||||
|
|
||||||
|
<tr class="align-top border-t">
|
||||||
<td colspan="2" rowspan="2" class="p-2 text-left align-top">
|
<td colspan="2" rowspan="2" class="p-2 text-left align-top">
|
||||||
<p class="font-semibold">PERHATIAN</p>
|
<p class="font-semibold">PERHATIAN</p>
|
||||||
<ol class="list-decimal ml-4 text-xs space-y-1">
|
<ol class="list-decimal ml-4 text-xs space-y-1">
|
||||||
<li>Berat barang telah ditimbang dan disaksikan oleh pembeli.</li>
|
<li>Berat barang telah ditimbang dan disaksikan oleh pembeli.</li>
|
||||||
<li>Barang yang dikembalikan menurut harga pasaran dan <br> dipotong ongkos bikin, barang rusak lain harga.</li>
|
<li>Barang yang dikembalikan menurut harga pasaran dan <br> dipotong ongkos bikin,
|
||||||
|
barang rusak lain
|
||||||
|
harga.</li>
|
||||||
<li>Barang yang sudah dibeli berarti sudah diperiksa dan disetujui.</li>
|
<li>Barang yang sudah dibeli berarti sudah diperiksa dan disetujui.</li>
|
||||||
<li>Surat ini harap dibawa pada saat menjual kembali.</li>
|
<li>Surat ini harap dibawa pada saat menjual kembali.</li>
|
||||||
</ol>
|
</ol>
|
||||||
@ -108,13 +110,8 @@
|
|||||||
<td colspan="2" rowspan="2" class="p-2 text-center align-top">
|
<td colspan="2" rowspan="2" class="p-2 text-center align-top">
|
||||||
<div class="flex flex-col items-center justify-center h-full">
|
<div class="flex flex-col items-center justify-center h-full">
|
||||||
<p><strong>Sales</strong></p>
|
<p><strong>Sales</strong></p>
|
||||||
<!-- ==== MODIFIKASI: Sales dropdown dinamis ==== -->
|
<inputSelect v-model="selectedSales" :options="salesOptions"
|
||||||
<inputSelect
|
class="mt-16 text-sm rounded bg-B cursor-pointer !w-[160px] text-center [option]:text-left" />
|
||||||
v-model="selectedSales"
|
|
||||||
:options="salesOptions"
|
|
||||||
class="mt-16 text-sm rounded bg-B cursor-pointer !w-[160px] text-center [option]:text-left"
|
|
||||||
/>
|
|
||||||
<!-- ==== END MODIFIKASI ==== -->
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
@ -130,52 +127,37 @@
|
|||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<p>Rp</p>
|
<p>Rp</p>
|
||||||
<!-- ==== MODIFIKASI: Ongkos bikin input ==== -->
|
<inputField v-model.number="ongkosBikin" type="number"
|
||||||
<inputField
|
class="h-7 px-2 text-sm rounded bg-blue-200 text-left w-full" />
|
||||||
v-model.number="ongkosBikin"
|
|
||||||
type="number"
|
|
||||||
class="h-7 px-2 text-sm rounded bg-blue-200 text-left w-full"
|
|
||||||
/>
|
|
||||||
<!-- ==== END MODIFIKASI ==== -->
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<p>Rp</p>
|
<p>Rp</p>
|
||||||
<!-- ==== MODIFIKASI: Total dinamis ==== -->
|
<p class="px-3 py-1 text-left text-sm w-full">{{ grandTotal.toLocaleString() }}
|
||||||
<p class="px-3 py-1 text-left text-sm w-full">{{ grandTotal.toLocaleString() }}</p>
|
</p>
|
||||||
<!-- ==== END MODIFIKASI ==== -->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<!-- Baris Tombol -->
|
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td class="p-2 text-center">
|
<td class="p-2 text-center">
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<!-- ==== MODIFIKASI: Tombol Batal dengan emit close ==== -->
|
<button @click="$emit('close')" class="bg-gray-400 text-white px-6 py-2 rounded w-full">Batal</button>
|
||||||
<button @click="$emit('close')" class="bg-gray-400 text-white px-6 py-2 rounded w-full">
|
<button @click="handleSimpan" class="bg-C text-white px-6 py-2 rounded w-full">Simpan</button>
|
||||||
Batal
|
|
||||||
</button>
|
|
||||||
<!-- ==== END MODIFIKASI ==== -->
|
|
||||||
<!-- ==== MODIFIKASI: Tombol Simpan dengan validasi ==== -->
|
|
||||||
<button @click="handleSimpan" class="bg-C text-white px-6 py-2 rounded w-full">
|
|
||||||
Simpan
|
|
||||||
</button>
|
|
||||||
<!-- ==== END MODIFIKASI ==== -->
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Pesan bawah -->
|
|
||||||
<p
|
<p class="absolute bottom-0 left-0 text-xs bg-D text-white px-2 py-1 rounded-tr-md">
|
||||||
class="absolute bottom-0 left-0 text-xs bg-D text-white px-2 py-1 rounded-tr-md"
|
|
||||||
>
|
|
||||||
Terima kasih sudah berbelanja dengan kami
|
Terima kasih sudah berbelanja dengan kami
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@ -187,11 +169,9 @@ import { ref, computed, onMounted } from 'vue'
|
|||||||
import logo from '@/../images/logo.png'
|
import logo from '@/../images/logo.png'
|
||||||
import inputField from '@/components/inputField.vue'
|
import inputField from '@/components/inputField.vue'
|
||||||
import inputSelect from '@/components/inputSelect.vue'
|
import inputSelect from '@/components/inputSelect.vue'
|
||||||
// ==== TAMBAHAN: Import axios ====
|
|
||||||
import axios from 'axios'
|
|
||||||
// ==== END TAMBAHAN ====
|
|
||||||
|
|
||||||
// ==== MODIFIKASI: Props sekarang menerima pesanan dan total ====
|
import axios from 'axios'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
isOpen: {
|
isOpen: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@ -206,28 +186,21 @@ const props = defineProps({
|
|||||||
default: 0
|
default: 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// ==== END MODIFIKASI ====
|
|
||||||
|
|
||||||
// ==== TAMBAHAN: Define emits ====
|
|
||||||
const emit = defineEmits(['close', 'confirm'])
|
const emit = defineEmits(['close', 'confirm'])
|
||||||
// ==== END TAMBAHAN ====
|
|
||||||
|
|
||||||
// ==== TAMBAHAN: Reactive variables untuk form ====
|
|
||||||
const namaPembeli = ref('')
|
const namaPembeli = ref('')
|
||||||
const nomorTelepon = ref('')
|
const nomorTelepon = ref('')
|
||||||
const alamat = ref('')
|
const alamat = ref('')
|
||||||
const ongkosBikin = ref(0)
|
const ongkosBikin = ref(0)
|
||||||
const selectedSales = ref(null)
|
const selectedSales = ref(null)
|
||||||
const salesOptions = ref([])
|
const salesOptions = ref([])
|
||||||
// ==== END TAMBAHAN ====
|
|
||||||
|
|
||||||
// ==== TAMBAHAN: Computed untuk grand total ====
|
|
||||||
const grandTotal = computed(() => {
|
const grandTotal = computed(() => {
|
||||||
return props.total + (ongkosBikin.value || 0)
|
return props.total + (ongkosBikin.value || 0)
|
||||||
})
|
})
|
||||||
// ==== END TAMBAHAN ====
|
|
||||||
|
|
||||||
// ==== TAMBAHAN: Fungsi untuk generate tanggal ====
|
|
||||||
const getCurrentDate = () => {
|
const getCurrentDate = () => {
|
||||||
const days = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu']
|
const days = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu']
|
||||||
const months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
|
const months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
|
||||||
@ -240,17 +213,13 @@ const getCurrentDate = () => {
|
|||||||
|
|
||||||
return `${dayName}/${day}-${month}-${year}`
|
return `${dayName}/${day}-${month}-${year}`
|
||||||
}
|
}
|
||||||
// ==== END TAMBAHAN ====
|
|
||||||
|
|
||||||
// ==== TAMBAHAN: Fungsi untuk generate kode transaksi ====
|
|
||||||
const generateTransactionCode = () => {
|
const generateTransactionCode = () => {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const timestamp = now.getTime().toString().slice(-6)
|
const timestamp = now.getTime().toString().slice(-6)
|
||||||
return `TRS-${timestamp}`
|
return `TRS-${timestamp}`
|
||||||
}
|
}
|
||||||
// ==== END TAMBAHAN ====
|
|
||||||
|
|
||||||
// ==== TAMBAHAN: Fetch sales data ====
|
|
||||||
const fetchSales = async () => {
|
const fetchSales = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get('/api/sales', {
|
const response = await axios.get('/api/sales', {
|
||||||
@ -264,7 +233,7 @@ const fetchSales = async () => {
|
|||||||
label: sales.nama
|
label: sales.nama
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Set default sales jika ada
|
|
||||||
if (salesOptions.value.length > 0) {
|
if (salesOptions.value.length > 0) {
|
||||||
selectedSales.value = salesOptions.value[0].value
|
selectedSales.value = salesOptions.value[0].value
|
||||||
}
|
}
|
||||||
@ -272,11 +241,9 @@ const fetchSales = async () => {
|
|||||||
console.error('Error fetching sales:', error)
|
console.error('Error fetching sales:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ==== END TAMBAHAN ====
|
|
||||||
|
|
||||||
// ==== TAMBAHAN: Handle simpan dengan validasi ====
|
|
||||||
const handleSimpan = () => {
|
const handleSimpan = () => {
|
||||||
// Validasi input wajib
|
|
||||||
if (!namaPembeli.value.trim()) {
|
if (!namaPembeli.value.trim()) {
|
||||||
alert('Nama pembeli harus diisi!')
|
alert('Nama pembeli harus diisi!')
|
||||||
return
|
return
|
||||||
@ -297,7 +264,7 @@ const handleSimpan = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit data ke parent
|
|
||||||
simpanTransaksi({
|
simpanTransaksi({
|
||||||
id_sales: selectedSales.value,
|
id_sales: selectedSales.value,
|
||||||
nama_pembeli: namaPembeli.value,
|
nama_pembeli: namaPembeli.value,
|
||||||
@ -309,7 +276,7 @@ const handleSimpan = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==== TAMBAHAN: Fungsi untuk menyimpan transaksi ====
|
|
||||||
const simpanTransaksi = async (dataTransaksi) => {
|
const simpanTransaksi = async (dataTransaksi) => {
|
||||||
console.log('Data transaksi yang akan disimpan:', dataTransaksi);
|
console.log('Data transaksi yang akan disimpan:', dataTransaksi);
|
||||||
|
|
||||||
@ -320,7 +287,7 @@ const simpanTransaksi = async (dataTransaksi) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reset form setelah berhasil
|
|
||||||
props.pesanan.value = [];
|
props.pesanan.value = [];
|
||||||
props.isOpen = false;
|
props.isOpen = false;
|
||||||
|
|
||||||
@ -332,23 +299,28 @@ const simpanTransaksi = async (dataTransaksi) => {
|
|||||||
alert('Error menyimpan transaksi: ' + (error.response?.data?.message || error.message));
|
alert('Error menyimpan transaksi: ' + (error.response?.data?.message || error.message));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// ==== END TAMBAHAN ====
|
|
||||||
// ==== END TAMBAHAN ====
|
|
||||||
|
|
||||||
// ==== TAMBAHAN: Fetch sales saat component mounted ====
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.isOpen) {
|
if (props.isOpen) {
|
||||||
fetchSales()
|
fetchSales()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// ==== END TAMBAHAN ====
|
|
||||||
|
const pesananMinimal = computed(() => {
|
||||||
|
const arr = [...props.pesanan]
|
||||||
|
while (arr.length < 2) {
|
||||||
|
arr.push({ produk: {}, harga_deal: 0, posisi: '' })
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@import url('https://fonts.googleapis.com/css2?family=PT+Serif:ital,wght@0,400;0,700;1,400;1,700&display=swap');
|
@import url('https://fonts.googleapis.com/css2?family=PT+Serif:ital,wght@0,400;0,700;1,400;1,700&display=swap');
|
||||||
|
|
||||||
.pt-serif-regular-italic {
|
.pt-serif-regular-italic {
|
||||||
font-family: "PT Serif", serif;
|
font-family: "PT Serif", serif;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -49,13 +49,23 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Isi Card (Max tinggi 3 item + scroll kalau lebih) -->
|
<!-- 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 h-[160px] pr-1">
|
<div
|
||||||
<div v-for="item in tray.items" :key="item.id"
|
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"
|
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">
|
<div class="flex items-center gap-3">
|
||||||
<img v-if="item.produk.foto && item.produk.foto.length > 0" :src="item.produk.foto[0].url"
|
<img
|
||||||
alt="foto produk" class="size-12 object-cover rounded" />
|
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">
|
<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>
|
<p class="text-sm font-medium">{{ item.kode_item }}</p>
|
||||||
@ -65,7 +75,7 @@
|
|||||||
<span class="font-medium">{{ item.produk.berat }}g</span>
|
<span class="font-medium">{{ item.produk.berat }}g</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Kalau kosong -->
|
<!-- Kalau kosong -->
|
||||||
<div v-else class="text-gray-400 text-center py-4 flex-1">
|
<div v-else class="text-gray-400 text-center py-4 flex-1">
|
||||||
|
|||||||
@ -225,6 +225,7 @@ import mainLayout from "../layouts/mainLayout.vue";
|
|||||||
import InputField from "../components/InputField.vue";
|
import InputField from "../components/InputField.vue";
|
||||||
import InputSelect from "../components/InputSelect.vue";
|
import InputSelect from "../components/InputSelect.vue";
|
||||||
import CreateItemModal from "../components/CreateItemModal.vue";
|
import CreateItemModal from "../components/CreateItemModal.vue";
|
||||||
|
import { errorMessages } from "@vue/compiler-core";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -250,7 +251,6 @@ const fileInput = ref(null);
|
|||||||
|
|
||||||
const openItemModal = ref(false);
|
const openItemModal = ref(false);
|
||||||
const editedProduct = ref(null);
|
const editedProduct = ref(null);
|
||||||
const userId = ref(1); // TODO: ambil dari auth
|
|
||||||
|
|
||||||
const isFormValid = computed(() => {
|
const isFormValid = computed(() => {
|
||||||
return (
|
return (
|
||||||
@ -281,12 +281,14 @@ const loadKategori = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadProduk = async () => {
|
const loadProduk = async () => {
|
||||||
const response = await axios.get(`/api/produk/${productId}`, {
|
const response = await axios.get(`/api/produk/edit/${productId}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const produk = response.data;
|
const produk = response.data;
|
||||||
|
console.log(produk);
|
||||||
|
|
||||||
form.value = {
|
form.value = {
|
||||||
nama: produk.nama,
|
nama: produk.nama,
|
||||||
id_kategori: produk.id_kategori,
|
id_kategori: produk.id_kategori,
|
||||||
@ -295,7 +297,22 @@ const loadProduk = async () => {
|
|||||||
harga_per_gram: produk.harga_per_gram,
|
harga_per_gram: produk.harga_per_gram,
|
||||||
harga_jual: produk.harga_jual,
|
harga_jual: produk.harga_jual,
|
||||||
};
|
};
|
||||||
uploadedImages.value = produk.foto || [];
|
};
|
||||||
|
|
||||||
|
const loadFoto = async () => {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`/api/foto`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
uploadedImages.value = response.data;
|
||||||
|
console.log(uploadedImages.value);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
|
||||||
|
uploadError.value = "Gagal memuat foto";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const triggerFileInput = () => {
|
const triggerFileInput = () => {
|
||||||
@ -318,27 +335,57 @@ const handleDrop = (e) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const uploadFiles = async (files) => {
|
const uploadFiles = async (files) => {
|
||||||
uploadError.value = "";
|
uploadError.value = '';
|
||||||
const validFiles = files.filter(
|
|
||||||
(file) =>
|
if (uploadedImages.value.length + files.length > 6) {
|
||||||
["image/jpeg", "image/jpg", "image/png"].includes(file.type) &&
|
uploadError.value = 'Maksimal 6 foto yang dapat diupload';
|
||||||
file.size <= 2 * 1024 * 1024
|
return;
|
||||||
);
|
}
|
||||||
if (!validFiles.length) return;
|
|
||||||
|
const validFiles = files.filter(file => {
|
||||||
|
const isValidType = ['image/jpeg', 'image/jpg', 'image/png'].includes(file.type);
|
||||||
|
const isValidSize = file.size <= 2 * 1024 * 1024;
|
||||||
|
|
||||||
|
if (!isValidType) {
|
||||||
|
uploadError.value = 'Format file harus JPG, JPEG, atau PNG';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValidSize) {
|
||||||
|
uploadError.value = 'Ukuran file maksimal 2MB';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (validFiles.length === 0) return;
|
||||||
|
|
||||||
uploadLoading.value = true;
|
uploadLoading.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (const file of validFiles) {
|
for (const file of validFiles) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("foto", file);
|
formData.append('foto', file);
|
||||||
formData.append("id_user", userId.value);
|
|
||||||
const res = await axios.post("/api/foto/upload", formData, {
|
const response = await axios.post('/api/foto', formData, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
"Content-Type": "multipart/form-data",
|
'Content-Type': 'multipart/form-data',
|
||||||
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
uploadedImages.value.push(res.data);
|
|
||||||
|
uploadedImages.value.push(response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fileInput.value) {
|
||||||
|
fileInput.value.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Upload error:', error);
|
||||||
|
uploadError.value = error.response?.data?.message || 'Gagal mengupload foto';
|
||||||
} finally {
|
} finally {
|
||||||
uploadLoading.value = false;
|
uploadLoading.value = false;
|
||||||
}
|
}
|
||||||
@ -346,7 +393,7 @@ const uploadFiles = async (files) => {
|
|||||||
|
|
||||||
const removeImage = async (id) => {
|
const removeImage = async (id) => {
|
||||||
try {
|
try {
|
||||||
await axios.delete(`http://127.0.0.1:8000/api/foto/hapus/${id}`, {
|
await axios.delete(`/api/foto/${id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
},
|
},
|
||||||
@ -361,21 +408,16 @@ const submitForm = async () => {
|
|||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
await axios.put(
|
await axios.put(
|
||||||
`/api/produk/${productId}`,
|
`/api/produk/${productId}`,form.value,
|
||||||
{
|
|
||||||
...form.value,
|
|
||||||
id_user: userId.value,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
alert("Produk berhasil diupdate!");
|
|
||||||
router.push("/produk");
|
router.push("/produk");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert("Gagal update produk!");
|
errorMessages.value = err.response?.data?.message || "Gagal menyimpan produk";
|
||||||
console.error(err);
|
console.error(err);
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
@ -390,8 +432,10 @@ const back = () => {
|
|||||||
router.push("/produk");
|
router.push("/produk");
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
loadKategori();
|
await loadKategori();
|
||||||
loadProduk();
|
await loadProduk();
|
||||||
|
loadFoto();
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -1,11 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<mainLayout>
|
<mainLayout>
|
||||||
<!-- Modal Buat Item - Sekarang menggunakan komponen terpisah -->
|
<!-- Modal Buat Item - Sekarang menggunakan komponen terpisah -->
|
||||||
<CreateItemModal
|
<CreateItemModal :isOpen="openItemModal" :product="createdProduct" @close="closeItemModal" />
|
||||||
:isOpen="openItemModal"
|
|
||||||
:product="createdProduct"
|
|
||||||
@close="closeItemModal"
|
|
||||||
/>
|
|
||||||
<div class="p-6">
|
<div class="p-6">
|
||||||
<p class="font-serif italic text-[25px] text-D">Produk Baru</p>
|
<p class="font-serif italic text-[25px] text-D">Produk Baru</p>
|
||||||
|
|
||||||
@ -168,8 +164,6 @@ const uploadedImages = ref([]);
|
|||||||
const isDragging = ref(false);
|
const isDragging = ref(false);
|
||||||
const uploadError = ref('');
|
const uploadError = ref('');
|
||||||
const fileInput = ref(null);
|
const fileInput = ref(null);
|
||||||
// TODO: Logika autentikasi user
|
|
||||||
const userId = ref(1);
|
|
||||||
|
|
||||||
const openItemModal = ref(false);
|
const openItemModal = ref(false);
|
||||||
const createdProduct = ref(null);
|
const createdProduct = ref(null);
|
||||||
@ -192,22 +186,24 @@ const calculateHargaJual = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadExistingPhotos = async () => {
|
const loadFoto = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`/api/foto/${userId.value}`, {
|
const response = await axios.get(`/api/foto`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (response.data && Array.isArray(response.data)) {
|
|
||||||
uploadedImages.value = response.data;
|
uploadedImages.value = response.data;
|
||||||
|
console.log(uploadedImages.value);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
|
||||||
|
uploadError.value = "Gagal memuat foto";
|
||||||
}
|
}
|
||||||
} catch (error) {
|
loading.value = false;
|
||||||
if (error.response?.status !== 404) {
|
}
|
||||||
console.error('Error loading existing photos:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const openCreateItemModal = (product) => {
|
const openCreateItemModal = (product) => {
|
||||||
createdProduct.value = product;
|
createdProduct.value = product;
|
||||||
@ -275,9 +271,8 @@ const uploadFiles = async (files) => {
|
|||||||
for (const file of validFiles) {
|
for (const file of validFiles) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('foto', file);
|
formData.append('foto', file);
|
||||||
formData.append('id_user', userId.value);
|
|
||||||
|
|
||||||
const response = await axios.post('/api/foto/upload', formData, {
|
const response = await axios.post('/api/foto', formData, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
'Content-Type': 'multipart/form-data',
|
'Content-Type': 'multipart/form-data',
|
||||||
@ -300,19 +295,16 @@ const uploadFiles = async (files) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeImage = async (imageId) => {
|
const removeImage = async (id) => {
|
||||||
try {
|
try {
|
||||||
await axios.delete(`/api/foto/hapus/${imageId}`, {
|
await axios.delete(`/api/foto/${id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
;
|
uploadedImages.value = uploadedImages.value.filter((i) => i.id !== id);
|
||||||
uploadedImages.value = uploadedImages.value.filter(img => img.id !== imageId);
|
} catch {
|
||||||
uploadError.value = '';
|
uploadError.value = "Gagal menghapus foto";
|
||||||
} catch (error) {
|
|
||||||
console.error('Delete error:', error);
|
|
||||||
uploadError.value = 'Gagal menghapus foto';
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -325,16 +317,13 @@ const submitForm = async (addItem) => {
|
|||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post('/api/produk', {
|
const response = await axios.post('/api/produk', form.value,
|
||||||
...form.value,
|
|
||||||
id_user: userId.value,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const createdProductData = response.data.data;
|
const createdProductData = response.data.data;
|
||||||
|
|
||||||
@ -405,7 +394,7 @@ const back = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadExistingPhotos();
|
loadFoto();
|
||||||
loadKategori();
|
loadKategori();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -32,10 +32,11 @@ Route::prefix('api')->group(function () {
|
|||||||
Route::delete('kosongkan-nampan', [NampanController::class, 'kosongkan']);
|
Route::delete('kosongkan-nampan', [NampanController::class, 'kosongkan']);
|
||||||
|
|
||||||
// Foto Sementara
|
// Foto Sementara
|
||||||
Route::post('foto/upload', [FotoSementaraController::class, 'upload']);
|
Route::get('foto', [FotoSementaraController::class, 'getAll']);
|
||||||
Route::delete('foto/hapus/{id}', [FotoSementaraController::class, 'hapus']);
|
Route::post('foto', [FotoSementaraController::class, 'upload']);
|
||||||
Route::get('foto/{user_id}', [FotoSementaraController::class, 'getAll']);
|
Route::delete('foto/{id}', [FotoSementaraController::class, 'hapus']);
|
||||||
Route::delete('foto/reset/{user_id}', [FotoSementaraController::class, 'reset']);
|
Route::get('produk/edit/{id}', [ProdukController::class, 'edit']);
|
||||||
|
Route::delete('foto/all', [FotoSementaraController::class, 'reset']);
|
||||||
|
|
||||||
// Laporan
|
// Laporan
|
||||||
Route::prefix('laporan')->group(function () {
|
Route::prefix('laporan')->group(function () {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user