fix harga

This commit is contained in:
Muzakki Parsaoran Siregar 2025-09-09 13:53:48 +07:00
parent 07aac28e8a
commit fb8236daf3
4 changed files with 105 additions and 102 deletions

View File

@ -26,7 +26,7 @@ class TemplateController extends Controller
'kategori_id' => 'required|exists:kategoris,id', 'kategori_id' => 'required|exists:kategoris,id',
'fitur_id' => 'required|exists:fiturs,id', 'fitur_id' => 'required|exists:fiturs,id',
'foto' => 'nullable|image|mimes:jpg,jpeg,png,gif|max:5120', 'foto' => 'nullable|image|mimes:jpg,jpeg,png,gif|max:5120',
'harga' => 'required|numeric', 'harga' => 'required|numeric|min:0'
]); ]);
if ($request->hasFile('foto')) { if ($request->hasFile('foto')) {
@ -44,7 +44,7 @@ class TemplateController extends Controller
'kategori_id' => 'required|exists:kategoris,id', 'kategori_id' => 'required|exists:kategoris,id',
'fitur_id' => 'required|exists:fiturs,id', 'fitur_id' => 'required|exists:fiturs,id',
'foto' => 'nullable|image|mimes:jpg,jpeg,png,gif|max:5120', 'foto' => 'nullable|image|mimes:jpg,jpeg,png,gif|max:5120',
'harga' => 'required|numeric', 'harga' => 'required|numeric|min:0'
]); ]);
if ($request->hasFile('foto')) { if ($request->hasFile('foto')) {
@ -77,6 +77,6 @@ class TemplateController extends Controller
$kategoris = Kategori::all(); $kategoris = Kategori::all();
$fiturs = Fitur::all(); $fiturs = Fitur::all();
return view('admin.templates.index', compact('templates', 'kategoris', 'fiturs', 'kategori', 'harga')); return view('admin.templates.index', compact('templates', 'kategoris', 'fiturs', 'kategori'));
} }
} }

View File

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class Template extends Model class Template extends Model
{ {
protected $fillable = ['nama_template', 'kategori_id', 'fitur_id', 'foto']; protected $fillable = ['nama_template', 'kategori_id', 'fitur_id', 'foto', 'harga'];
public function kategori() { public function kategori() {
return $this->belongsTo(Kategori::class); return $this->belongsTo(Kategori::class);

View File

@ -12,6 +12,7 @@ return new class extends Migration {
$table->string('nama_template'); $table->string('nama_template');
$table->foreignId('kategori_id')->constrained()->cascadeOnDelete(); $table->foreignId('kategori_id')->constrained()->cascadeOnDelete();
$table->foreignId('fitur_id')->constrained()->cascadeOnDelete(); $table->foreignId('fitur_id')->constrained()->cascadeOnDelete();
$table->decimal('harga', 10, 2)->default(0);
$table->string('foto')->nullable(); $table->string('foto')->nullable();
$table->timestamps(); $table->timestamps();
}); });

View File

@ -3,102 +3,98 @@
@section('title', 'Manajemen Template') @section('title', 'Manajemen Template')
@section('content') @section('content')
<div class="container mx-auto py-4"> <div class="container mx-auto py-4">
<!-- Header --> <!-- Header -->
<div class="flex justify-between items-center mb-4"> <div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-bold"> <h3 class="text-xl font-bold">
@isset($kategori) @isset($kategori)
Template Kategori: {{ $kategori->nama }} Template Kategori: {{ $kategori->nama }}
@else @else
Semua Template Semua Template
@endisset @endisset
</h3> </h3>
@if (!isset($kategori)) @if (!isset($kategori))
<button id="openTambahModal" class="bg-blue-600 text-white px-3 py-2.5 rounded flex items-center"> <button id="openTambahModal" class="bg-blue-600 text-white px-3 py-2.5 rounded flex items-center">
<i class="bi bi-plus-lg mr-1"></i> Tambah Template <i class="bi bi-plus-lg mr-1"></i> Tambah Template
</button> </button>
@endif @endif
</div>
<!-- Flash Message -->
@if (session('success'))
<div id="toast-success" class="mb-4 p-3 rounded bg-green-100 text-green-800 border border-green-300 shadow">
{{ session('success') }}
</div> </div>
<script>setTimeout(() => document.getElementById('toast-success')?.remove(), 3000);</script>
@endif
<!-- Flash Message --> @if ($errors->any())
@if (session('success')) <div id="toast-error" class="mb-4 p-3 rounded bg-red-100 text-red-800 border border-red-300 shadow">
<div id="toast-success" class="mb-4 p-3 rounded bg-green-100 text-green-800 border border-green-300 shadow"> <ul class="list-disc ml-5">
{{ session('success') }} @foreach ($errors->all() as $error)
</div> <li>{{ $error }}</li>
<script> @endforeach
setTimeout(() => document.getElementById('toast-success')?.remove(), 3000); </ul>
</script> </div>
@endif <script>setTimeout(() => document.getElementById('toast-error')?.remove(), 5000);</script>
@endif
@if ($errors->any()) <!-- Tabel Template -->
<div id="toast-error" class="mb-4 p-3 rounded bg-red-100 text-red-800 border border-red-300 shadow"> <div class="bg-white rounded-lg shadow-sm">
<ul class="list-disc ml-5"> <div class="p-4 overflow-x-auto">
@foreach ($errors->all() as $error) <table class="w-full table-fixed text-left border border-gray-300 border-collapse">
<li>{{ $error }}</li> <thead class="bg-gray-100">
@endforeach <tr>
</ul> <th class="p-2 border border-gray-300 w-[50px] text-center">No</th>
</div> <th class="p-2 border border-gray-300 w-[200px]">Nama Template</th>
<script> <th class="p-2 border border-gray-300 w-[150px]">Kategori</th>
setTimeout(() => document.getElementById('toast-error')?.remove(), 5000); <th class="p-2 border border-gray-300 w-[150px]">Fitur</th>
</script> <th class="p-2 border border-gray-300 w-[90px] text-center">Foto</th>
@endif <th class="p-2 border border-gray-300 w-[100px] text-center">Harga</th>
<th class="p-2 border border-gray-300 w-[130px] text-center">Aksi</th>
<!-- Tabel Template --> </tr>
<div class="bg-white rounded-lg shadow-sm"> </thead>
<div class="p-4 overflow-x-auto"> <tbody>
<table class="w-full table-fixed text-left border border-gray-300 border-collapse"> @forelse($templates as $key => $template)
<thead class="bg-gray-100">
<tr> <tr>
<th class="p-2 border border-gray-300 w-[50px] text-center">No</th> <td class="p-2 border border-gray-300 text-center">{{ $key + 1 }}</td>
<th class="p-2 border border-gray-300 w-[200px]">Nama Template</th> <td class="p-2 border border-gray-300 truncate">{{ $template->nama_template }}</td>
<th class="p-2 border border-gray-300 w-[150px]">Kategori</th> <td class="p-2 border border-gray-300 truncate">{{ $template->kategori->nama ?? '-' }}</td>
<th class="p-2 border border-gray-300 w-[150px]">Fitur</th> <td class="p-2 border border-gray-300 truncate">{{ $template->fitur->deskripsi ?? '-' }}</td>
<th class="p-2 border border-gray-300 w-[90px] text-center">Foto</th> <td class="p-2 border border-gray-300 text-center">
<th class="p-2 border border-gray-300 w-[130px] text-center">Aksi</th> <div class="w-12 h-12 overflow-hidden rounded bg-gray-100 flex items-center justify-center mx-auto">
</tr> <img src="{{ $template->foto ? asset('storage/' . $template->foto) : asset('default-image.png') }}"
</thead> alt="foto" class="max-w-full max-h-full object-contain">
<tbody> </div>
@forelse($templates as $key => $template) </td>
<tr> <td class="p-2 border border-gray-300 text-right font-semibold">
<td class="p-2 border border-gray-300 text-center">{{ $key + 1 }}</td> Rp {{ number_format($template->harga, 0, ',', '.') }}
<td class="p-2 border border-gray-300 truncate">{{ $template->nama_template }}</td> </td>
<td class="p-2 border border-gray-300 truncate">{{ $template->kategori->nama ?? '-' }}</td> <td class="p-2 border border-gray-300 text-center">
<td class="p-2 border border-gray-300 truncate">{{ $template->fitur->deskripsi ?? '-' }} <div class="flex justify-center space-x-2">
</td> <button class="text-blue-600 hover:underline flex items-center openEditModalBtn"
<td class="p-2 border border-gray-300 text-center"> data-id="{{ $template->id }}">
<div <i class="bi bi-pencil mr-1"></i> Edit
class="w-12 h-12 overflow-hidden rounded bg-gray-100 flex items-center justify-center mx-auto"> </button>
<img src="{{ $template->foto ? asset('storage/' . $template->foto) : asset('default-image.png') }}" <form action="{{ route('templates.destroy', $template->id) }}" method="POST"
alt="foto" class="max-w-full max-h-full object-contain"> class="inline" onsubmit="return confirm('Hapus template ini?')">
</div> @csrf
</td> @method('DELETE')
<td class="p-2 border border-gray-300 text-center"> <button class="text-red-600 hover:underline flex items-center">
<div class="flex justify-center space-x-2"> <i class="bi bi-trash mr-1"></i> Hapus
<button class="text-blue-600 hover:underline flex items-center openEditModalBtn"
data-id="{{ $template->id }}">
<i class="bi bi-pencil mr-1"></i> Edit
</button> </button>
<form action="{{ route('templates.destroy', $template->id) }}" method="POST" </form>
class="inline" onsubmit="return confirm('Hapus template ini?')"> </div>
@csrf </td>
@method('DELETE') </tr>
<button class="text-red-600 hover:underline flex items-center"> @empty
<i class="bi bi-trash mr-1"></i> Hapus <tr>
</button> <td colspan="7" class="p-2 text-center text-gray-500 border border-gray-300">Belum ada template</td>
</form> </tr>
</div> @endforelse
</td> </tbody>
</tr> </table>
@empty
<tr>
<td colspan="6" class="p-2 text-center text-gray-500 border border-gray-300">Belum ada
template</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div> </div>
</div> </div>
@ -133,6 +129,10 @@
@endforeach @endforeach
</select> </select>
</div> </div>
<div>
<label class="block text-sm font-medium">Harga</label>
<input type="number" name="harga" class="w-full p-2 border rounded" required min="0" step="1000">
</div>
<div> <div>
<label class="block text-sm font-medium">Foto (opsional)</label> <label class="block text-sm font-medium">Foto (opsional)</label>
<input type="file" name="foto" class="w-full p-2 border rounded" accept="image/*"> <input type="file" name="foto" class="w-full p-2 border rounded" accept="image/*">
@ -140,8 +140,7 @@
</div> </div>
</div> </div>
<div class="p-4 border-t flex justify-end space-x-2"> <div class="p-4 border-t flex justify-end space-x-2">
<button type="button" id="closeTambahBtn" <button type="button" id="closeTambahBtn" class="bg-gray-300 text-black px-3 py-1 rounded">Batal</button>
class="bg-gray-300 text-black px-3 py-1 rounded">Batal</button>
<button class="bg-blue-600 text-white px-3 py-1 rounded">Simpan</button> <button class="bg-blue-600 text-white px-3 py-1 rounded">Simpan</button>
</div> </div>
</form> </form>
@ -169,8 +168,7 @@
<label class="block text-sm font-medium">Kategori</label> <label class="block text-sm font-medium">Kategori</label>
<select name="kategori_id" class="w-full p-2 border rounded" required> <select name="kategori_id" class="w-full p-2 border rounded" required>
@foreach ($kategoris as $kategori) @foreach ($kategoris as $kategori)
<option value="{{ $kategori->id }}" @selected($kategori->id == $template->kategori_id)>{{ $kategori->nama }} <option value="{{ $kategori->id }}" @selected($kategori->id == $template->kategori_id)>{{ $kategori->nama }}</option>
</option>
@endforeach @endforeach
</select> </select>
</div> </div>
@ -178,18 +176,21 @@
<label class="block text-sm font-medium">Fitur</label> <label class="block text-sm font-medium">Fitur</label>
<select name="fitur_id" class="w-full p-2 border rounded" required> <select name="fitur_id" class="w-full p-2 border rounded" required>
@foreach ($fiturs as $fitur) @foreach ($fiturs as $fitur)
<option value="{{ $fitur->id }}" @selected($fitur->id == $template->fitur_id)> <option value="{{ $fitur->id }}" @selected($fitur->id == $template->fitur_id)>{{ $fitur->deskripsi }}</option>
{{ $fitur->deskripsi }}</option>
@endforeach @endforeach
</select> </select>
</div> </div>
<div>
<label class="block text-sm font-medium">Harga</label>
<input type="number" name="harga" value="{{ $template->harga }}"
class="w-full p-2 border rounded" required min="0" step="1000">
</div>
<div> <div>
<label class="block text-sm font-medium">Foto (opsional)</label> <label class="block text-sm font-medium">Foto (opsional)</label>
@if ($template->foto) @if ($template->foto)
<div class="mb-2"> <div class="mb-2">
<small class="text-gray-500">Foto saat ini:</small> <small class="text-gray-500">Foto saat ini:</small>
<div <div class="w-20 h-20 mt-1 overflow-hidden rounded bg-gray-100 flex items-center justify-center border">
class="w-20 h-20 mt-1 overflow-hidden rounded bg-gray-100 flex items-center justify-center border">
<img src="{{ asset('storage/' . $template->foto) }}" alt="foto" <img src="{{ asset('storage/' . $template->foto) }}" alt="foto"
class="max-w-full max-h-full object-contain"> class="max-w-full max-h-full object-contain">
</div> </div>
@ -274,4 +275,5 @@
}); });
}); });
</script> </script>
</div>
@endsection @endsection