update nampancontroller, traylist,tray,web.php

This commit is contained in:
adityaalfarison 2025-09-02 09:23:22 +07:00
parent b2f93c4537
commit bfbe5d69a9
4 changed files with 27 additions and 41 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Models\Nampan;
use App\Models\Item;
use Illuminate\Http\Request;
class NampanController extends Controller
@ -85,4 +86,14 @@ class NampanController extends Controller
'message' => 'Nampan berhasil dihapus'
], 204);
}
public function kosongkan()
{
Item::query()->update(['id_nampan' => null]);
return response()->json([
'message' => 'Semua nampan berhasil dikosongkan'
], 200);
}
}

View File

@ -9,44 +9,27 @@
</div>
<div v-else class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
<div
v-for="tray in filteredTrays"
:key="tray.id"
class="border rounded-lg p-4 shadow-sm hover:shadow-md transition"
>
<div v-for="tray in filteredTrays" :key="tray.id"
class="border rounded-lg p-4 shadow-sm hover:shadow-md transition">
<div class="flex justify-between items-center mb-3">
<h2 class="font-bold text-lg" style="color: #102C57;">{{ tray.nama }}</h2>
<div class="flex gap-2">
<button
class="p-2 rounded bg-yellow-400 hover:bg-yellow-500"
@click="emit('edit', tray)"
>
<button class="p-2 rounded bg-yellow-400 hover:bg-yellow-500" @click="emit('edit', tray)">
</button>
<button
class="bg-red-500 text-white p-1 rounded"
@click="emit('delete', tray.id)"
>
<button class="bg-red-500 text-white p-1 rounded" @click="emit('delete', tray.id)">
🗑
</button>
</div>
</div>
<div v-if="tray.items && tray.items.length > 0" class="space-y-2 max-h-64 overflow-y-auto pr-2">
<div
v-for="item in tray.items"
:key="item.id"
class="flex justify-between items-center border rounded-lg p-2"
@click="openMovePopup(item)"
>
<div v-for="item in tray.items" :key="item.id" class="flex justify-between items-center border rounded-lg p-2"
@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="w-12 h-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="w-12 h-12 object-cover rounded" />
<div>
<p class="text-sm" style="color: #102C57;">{{ item.produk.nama }}</p>
<p class="text-sm" style="color: #102C57;">{{ item.produk.kategori }}</p>
@ -88,11 +71,8 @@
</div>
<div class="mb-4">
<label for="tray-select" class="block text-sm font-medium text-gray-700 mb-1">Nama Nampan</label>
<select
id="tray-select"
v-model="selectedTrayId"
class="block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50"
>
<select id="tray-select" v-model="selectedTrayId"
class="block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
<option value="" disabled>Pilih Nampan</option>
<option v-for="tray in availableTrays" :key="tray.id" :value="tray.id">
{{ tray.nama }}
@ -100,18 +80,12 @@
</select>
</div>
<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-100 transition"
>
<button @click="closePopup"
class="px-4 py-2 rounded border border-gray-300 text-gray-700 hover:bg-gray-100 transition">
Batal
</button>
<button
@click="saveMove"
:disabled="!selectedTrayId"
class="px-4 py-2 rounded text-white transition"
:class="selectedTrayId ? 'bg-orange-500 hover:bg-orange-600' : 'bg-gray-400 cursor-not-allowed'"
>
<button @click="saveMove" :disabled="!selectedTrayId" class="px-4 py-2 rounded text-white transition"
:class="selectedTrayId ? 'bg-orange-500 hover:bg-orange-600' : 'bg-gray-400 cursor-not-allowed'">
Simpan
</button>
</div>

View File

@ -151,7 +151,7 @@ const closeConfirmModal = () => { showConfirmModal.value = false }
const confirmEmptyTray = async () => {
try {
await axios.post("/api/brankas", { action: "move_all_from_tray" })
await axios.delete("/api/kosongkan-nampan",)
alert("Semua item berhasil dipindahkan ke Brankas")
closeConfirmModal()
location.reload()

View File

@ -19,6 +19,7 @@ Route::prefix('api')->group(function () {
Route::apiResource('transaksi', TransaksiController::class);
Route::get('brankas', [ItemController::class, 'brankasItem']);
Route::delete('kosongkan-nampan', [NampanController::class, 'kosongkan']);
// Foto Sementara
Route::post('foto/upload', [FotoSementaraController::class, 'upload']);