Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ring into ipan
  • Loading branch information
Diandaru committed Nov 28, 2024
2 parents e56edae + 6f25f08 commit b1919b5
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 42 deletions.
31 changes: 26 additions & 5 deletions app/Http/Controllers/SiswaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,41 @@ public function storeMultiple(Request $request)
return redirect()->route('siswa.index')->with('success', 'Laporan berhasil ditambahkan.');
}

public function store(Request $request)
public function updateAndCreate(Request $request, $id)
{
$item = Siswa::where('id', $id)->where('user_id', Auth::id())->firstOrFail();

$request->validate([
'kategori' => 'required|string',
'report' => 'required|string',
'bukti' => 'nullable|array',
'bukti.*' => 'image|mimes:jpeg,png,jpg,gif,svg',
]);

$filePath = null;
if ($request->hasFile('bukti')) {
$filePaths = [];
foreach ($request->file('bukti') as $file) {
$originalFileName = $file->getClientOriginalName();
$filePaths[] = $file->storeAs('bukti', $originalFileName, 'public');
}
$filePath = implode(',', $filePaths);
}

$item->update([
'waktu_selesai' => now(),
'status' => 'done',
'report' => $request->report,
'bukti' => $filePath,
]);

Siswa::create([
'kategori' => 'Keluar Dengan Teknisi',
'status' => 'to do',
'status' => 'doing',
'user_id' => Auth::id(),
'report' => $request->report,
'waktu_mulai' => now(),
]);

return redirect()->route('siswa.index')->with('success', 'Laporan berhasil ditambahkan.');
return redirect()->route('siswa.index')->with('success', 'Data diperbarui dan entri baru berhasil ditambahkan.');
}

public function start($id)
Expand Down
111 changes: 74 additions & 37 deletions resources/views/monitoring_siswa/siswa.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ class="btn btn-sm btn-success mb-0">
data-bs-toggle="modal"
data-id="{{ $item->id }}"
data-report="{{ $item->report }}"
data-waktu_selesai="{{ $item->waktu_selesai }}">
data-waktu_selesai="{{ $item->waktu_selesai }}"
data-kategori="{{ $item->kategori }}">
<i class="fa-solid fa-square" style="font-size: 12px"></i>
</button>
@else
Expand Down Expand Up @@ -389,7 +390,8 @@ class="btn btn-info">Simpan</button>
<div class="mb-3">
<label for="waktu_selesai{{ $item->id }}" class="form-label fw-bold">Waktu Selesai</label>
<input type="time" class="form-control" id="waktu_selesai{{ $item->id }}" name="waktu_selesai"
value="{{ \Carbon\Carbon::parse($item->waktu_selesai)->format('H:i') }}" required>
value="{{ \Carbon\Carbon::parse($item->waktu_selesai)->format('H:i') }}" required
min="{{ \Carbon\Carbon::parse($item->waktu_mulai)->format('H:i') }}">
</div>

<!-- Bukti Upload Input -->
Expand Down Expand Up @@ -496,29 +498,37 @@ class="btn btn-info">Simpan</button>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="tambahLaporanTeknisiLabel">Tambah Laporan Keluar Dengan Teknisi</h5>
<h5 class="modal-title" id="tambahLaporanTeknisiLabel">Selesaikan Aktivitas Terlebih Dahulu</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="tambahLaporanTeknisitkj" action="{{ route('siswa.store') }}" method="POST">
<form id="tambahLaporanTeknisiForm" method="POST" action="#" enctype="multipart/form-data">
@csrf
@method('POST')
<!-- Input untuk laporan -->
<div class="mb-3">
<label for="kategoriSelect" class="form-label">Kategori</label>
<select class="form-select" id="kategori" name="kategori" required>
<option selected value="Keluar Dengan Teknisi">Keluar Dengan Teknisi</option>
</select>
<label for="report" class="form-label">Catatan Siswa</label>
<textarea id="report" name="report" class="form-control" rows="3" required></textarea>
</div>
<!-- Input untuk bukti -->
<div class="mb-3">
<label for="bukti" class="form-label">Unggah Bukti</label>
<input type="file" id="bukti" name="bukti[]" class="form-control" multiple>
</div>
<!-- Tombol Submit -->
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
<button type="submit" class="btn btn-info">Simpan</button>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
<button type="submit" form="tambahLaporanTeknisitkj" class="btn btn-info">Simpan</button>
</div>
</div>
</div>
</div>




<script>
function toggleMateriDropdown(kategoriId, materiId) {
const kategoriSelect = document.getElementById(kategoriId);
Expand All @@ -539,39 +549,66 @@ function toggleMateriDropdown(kategoriId, materiId) {
startTimer('{{ $item->waktu_mulai }}', 'total-waktu-{{ $item->id }}');
@endif
@endforeach
document.querySelectorAll('.btn-danger').forEach(button => {
button.addEventListener('click', function(event) {
document.querySelectorAll('.btn-danger').forEach(button => {
button.addEventListener('click', function (event) {
const id = this.getAttribute('data-id');
const kategori = this.getAttribute('data-kategori');
const report = this.getAttribute('data-report');
const waktu_selesai = this.getAttribute('data-waktu_selesai');
Swal.fire({
title: 'Apakah Anda yakin?',
text: "Aktivitas ini akan diselesaikan atau tambahkan laporan teknisi.",
icon: 'warning',
showCancelButton: true,
showDenyButton: true,
confirmButtonText: 'Ya, Selesaikan!',
denyButtonText: 'Keluar Dengan Teknisi',
cancelButtonText: 'Batal'
}).then((result) => {
if (result.isConfirmed) {
const modal = new bootstrap.Modal(document.getElementById('EditLaporanModal' + id));
modal.show();
const modalElement = document.getElementById('EditLaporanModal' + id);
modalElement.querySelector('input[name="id"]').value = id;
modalElement.querySelector('textarea[name="report"]').value = report;
modalElement.querySelector('input[name="waktu_selesai"]').value = waktu_selesai;
} else if (result.isDenied) {
const teknisiModal = new bootstrap.Modal(document.getElementById('tambahLaporanTeknisi'));
teknisiModal.show();
}
});
if (kategori === 'Keluar Dengan Teknisi') {
const modal = new bootstrap.Modal(document.getElementById('EditLaporanModal' + id));
modal.show();
const modalElement = document.getElementById('EditLaporanModal' + id);
modalElement.querySelector('textarea[name="report"]').value = report;
modalElement.querySelector('input[name="waktu_selesai"]').value = waktu_selesai;
} else {
Swal.fire({
title: 'Apakah Anda yakin?',
text: "Aktivitas ini akan diselesaikan.",
icon: 'warning',
showCancelButton: true,
showDenyButton: true,
confirmButtonText: 'Ya, Selesaikan!',
denyButtonText: 'Keluar Dengan Teknisi',
cancelButtonText: 'Batal'
}).then((result) => {
if (result.isConfirmed) {
const modal = new bootstrap.Modal(document.getElementById('EditLaporanModal' + id));
modal.show();
const modalElement = document.getElementById('EditLaporanModal' + id);
modalElement.querySelector('textarea[name="report"]').value = report;
modalElement.querySelector('input[name="waktu_selesai"]').value = waktu_selesai;
} else if (result.isDenied) {
const teknisiModal = new bootstrap.Modal(document.getElementById('tambahLaporanTeknisi'));
teknisiModal.show();
const teknisiForm = document.getElementById('tambahLaporanTeknisiForm');
teknisiForm.setAttribute('action', `/siswa/updateAndCreate/${id}`);
}
});
}
});
});
});
document.addEventListener('DOMContentLoaded', function () {
const waktuMulai = "{{ \Carbon\Carbon::parse($item->waktu_mulai)->format('H:i') }}";
const waktuSelesaiInput = document.getElementById('waktu_selesai{{ $item->id }}');
waktuSelesaiInput.setAttribute('min', waktuMulai);
waktuSelesaiInput.addEventListener('change', function () {
if (waktuSelesaiInput.value < waktuMulai) {
alert('Waktu selesai tidak boleh lebih awal dari waktu mulai!');
waktuSelesaiInput.value = waktuMulai;
}
});
});
function startTimer(waktuMulai, elementId) {
const startTime = new Date(waktuMulai).getTime();
Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,6 @@

Route::post('/login', [LoginController::class, 'store'])->name('login.store');
Route::get('/dashboard-rpl', [DashboardRplController::class, 'index'])->name('dashboardrpl.index');

Route::post('/siswa/updateAndCreate/{id}', [SiswaController::class, 'updateAndCreate'])->name('siswa.updateAndCreate');
Route::put('/siswa/{id}/update-create', [SiswaController::class, 'updateAndCreate'])->name('siswa.updateAndCreate');

0 comments on commit b1919b5

Please sign in to comment.