feat(spk): tambahkan fitur pembaruan SLA

- Menambahkan metode updateSla pada SpkController untuk memperbarui SLA.
- Memvalidasi input SLA agar wajib diisi dan berupa angka positif.
- Mengupdate tampilan untuk meminta input SLA sebelum membuat SPK.
- Menambahkan rute baru untuk pembaruan SLA di registrasi.php.
This commit is contained in:
Daeng Deni Mardaeni
2025-03-05 12:55:57 +07:00
parent 42ed13e0ef
commit 4a05b9e903
3 changed files with 73 additions and 7 deletions

View File

@@ -385,4 +385,17 @@ use Illuminate\Support\Facades\Auth;
return response()->download(storage_path('app/public/' .$document->spk_dokumen_path));
}
public function updateSla(Request $request, $id): JsonResponse
{
$request->validate([
'sla' => 'required|integer|min:1',
]);
$permohonan = Permohonan::where('nomor_registrasi','=',$id)->first();
$permohonan->sla = $request->sla;
$permohonan->save();
return response()->json(['message' => 'SLA updated successfully']);
}
}

View File

@@ -98,12 +98,63 @@
@push('scripts')
<script type="text/javascript">
function spkCreate(regId)
function spkCreate(regId, sla)
{
var url1 = "/spk/"+regId+"/edit";
var url = "{{ url('/') }}"+url1;
$(location).attr('href',url);
const csrf = '{{ @csrf_token() }}';
if (!sla) {
Swal.fire({
title: 'Input SLA',
input: 'number',
inputAttributes: {
min: 1,
step: 1
},
showCancelButton: true,
confirmButtonText: 'Submit',
showLoaderOnConfirm: true,
preConfirm: (inputValue) => {
if (inputValue) {
return fetch(`/spk/update-sla/${regId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': `${csrf}`
},
body: JSON.stringify({ sla: inputValue })
})
.then(response => {
if (!response.ok) {
throw new Error(response.statusText)
}
return response.json()
})
.catch(error => {
Swal.showValidationMessage(
`Request failed: ${error}`
)
})
} else {
Swal.showValidationMessage('SLA is required')
}
},
allowOutsideClick: () => !Swal.isLoading()
}).then((result) => {
if (result.isConfirmed) {
Swal.fire({
title: 'SLA updated successfully',
icon: 'success'
}).then(() => {
// Redirect to edit page after successful SLA update
window.location.href = "{{ url('/') }}/spk/"+regId+"/edit";
});
}
});
} else {
// If SLA is not empty, directly redirect to edit page
window.location.href = "{{ url('/') }}/spk/"+regId+"/edit";
}
}
</script>
<script type="module">
const element = document.querySelector('#spk-table');
@@ -203,11 +254,12 @@
actions: {
title: 'Status',
render: (item, data) => {
console.log(data.id);
var spkShow ='';
var spkCreate='';
if(!data.spk_dokumen_path)
{
spkCreate=`<a class="btn btn-sm btn-icon btn-clear btn-info" title="Buat SPK" onclick="spkCreate(${data.id})" >
spkCreate=`<a class="btn btn-sm btn-icon btn-clear btn-info" title="Buat SPK" onclick="spkCreate(${data.id}, ${data.permohonan.sla})" >
<i class="ki-outline ki-notepad-edit"></i>
</a>`;
}
@@ -218,14 +270,14 @@
<i class="ki-filled ki-cloud-download"></i>
</a> `;
if(data.status==='spk') {
spkCreate = `<a class="btn btn-sm btn-icon btn-clear btn-info" title="Buat SPK" onclick="spkCreate(${data.id})" >
spkCreate = `<a class="btn btn-sm btn-icon btn-clear btn-info" title="Buat SPK" onclick="spkCreate(${data.id}, ${data.permohonan.sla})" >
<i class="ki-outline ki-notepad-edit"></i>
</a>`;
}
}
return `<div class="flex flex-nowrap justify-center">`
+spkShow+spkCreate+
+spkShow+spkCreate+data.permohonan.sla+
`</div>`;
},
}

View File

@@ -110,6 +110,7 @@ Route::middleware(['auth'])->group(function () {
Route::get('/spk', 'index')->name('spk.index');
Route::get('/spk/datatables', 'dataForDatatables')->name('spk.datatables');
Route::POST('/spk/update-sla/{id}', 'updateSla')->name('spk.update-sla');
Route::get('/spk/{spk}', 'show')->name('spk.show');
Route::get('/spk/{spk}/edit', 'edit')->name('spk.edit');
Route::put('/spk/{spk}', 'update')->name('spk.update');