Mengubah tombol aksi ketika nomor registrasi ada di tabel penawaran maka munculkan tombol penawaran ulang begitu juga sebaliknya
This commit is contained in:
@@ -398,4 +398,14 @@ class TenderController extends Controller
|
|||||||
{
|
{
|
||||||
return view('lpj::proses_penawaran/index');
|
return view('lpj::proses_penawaran/index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tambahkan method untuk API di controller
|
||||||
|
public function checkPenawaranExistence($nomor_registrasi)
|
||||||
|
{
|
||||||
|
// Cek apakah nomor_registrasi ada dalam tabel penawaran
|
||||||
|
$exists = PenawaranTender::where('nomor_registrasi', $nomor_registrasi)->exists();
|
||||||
|
|
||||||
|
// Kembalikan hasil pengecekan sebagai JSON
|
||||||
|
return response()->json(['exists' => $exists]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,45 @@
|
|||||||
return char.toUpperCase();
|
return char.toUpperCase();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to check the existence of penawaran and update button
|
||||||
|
function checkPenawaranExistence(nomor_registrasi) {
|
||||||
|
// URL API untuk cek penawaran
|
||||||
|
const url = `/api/check-penawaran/${nomor_registrasi}`;
|
||||||
|
|
||||||
|
// Fetch data dari server
|
||||||
|
fetch(url)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const actionDiv = document.getElementById(`action-${nomor_registrasi}`);
|
||||||
|
if (data.exists) {
|
||||||
|
// Jika penawaran ada, ganti tombol menjadi "Penawaran Ulang"
|
||||||
|
actionDiv.innerHTML = `
|
||||||
|
<a class="btn btn-sm btn-icon btn-clear btn-warning" title="Detail" href="/tender/penawaran/${nomor_registrasi}/show">
|
||||||
|
<i class="ki-outline ki-abstract-26"></i>
|
||||||
|
</a>
|
||||||
|
<a href="/tender/penawaran/${nomor_registrasi}/edit" class="btn btn-sm btn-icon btn-clear btn-info" title="Penawaran">
|
||||||
|
<i class="ki-outline ki-arrow-circle-right"></i>
|
||||||
|
</a>
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
// Jika tidak ada, tampilkan tombol "Tambah Penawaran"
|
||||||
|
actionDiv.innerHTML = `
|
||||||
|
<a class="btn btn-sm btn-icon btn-clear btn-warning" title="Detail" href="/tender/penawaran/${nomor_registrasi}/show">
|
||||||
|
<i class="ki-outline ki-abstract-26"></i>
|
||||||
|
</a>
|
||||||
|
<a href="/tender/penawaran/${nomor_registrasi}/create" class="btn btn-sm btn-icon btn-clear btn-primary" title="Penawaran">
|
||||||
|
<i class="ki-outline ki-arrow-circle-right"></i>
|
||||||
|
</a>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
const actionDiv = document.getElementById(`action-${nomor_registrasi}`);
|
||||||
|
actionDiv.innerHTML = `<span class="text-danger">Error loading action</span>`;
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
const element = document.querySelector('#penawaran-table');
|
const element = document.querySelector('#penawaran-table');
|
||||||
@@ -173,35 +212,23 @@
|
|||||||
actions: {
|
actions: {
|
||||||
title: 'Action',
|
title: 'Action',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
// Display default links first
|
// Default action button, to be updated later
|
||||||
return `<div class="flex flex-nowrap justify-center" id="action-${data.nomor_registrasi}">
|
let actionHtml = `
|
||||||
<a class="btn btn-sm btn-icon btn-clear btn-primary" title="Detail" href="tender/penawaran/${data.nomor_registrasi}/show">
|
<div class="flex flex-nowrap justify-center" id="action-${data.nomor_registrasi}">
|
||||||
<i class="ki-outline ki-abstract-26"></i>
|
<a class="btn btn-sm btn-icon btn-clear btn-secondary" title="Loading..." href="#">
|
||||||
</a>
|
<i class="ki-outline ki-loading"></i>
|
||||||
<a class="btn btn-sm btn-icon btn-clear btn-info" title="Penawaran" href="tender/penawaran/${data.nomor_registrasi}/create" id="penawaran-link-${data.nomor_registrasi}">
|
</a>
|
||||||
<i class="ki-outline ki-arrow-circle-right"></i>
|
</div>
|
||||||
</a>
|
`;
|
||||||
</div>`;
|
|
||||||
},
|
|
||||||
createdRow: function(row, data, dataIndex) {
|
|
||||||
// Call checkPenawaranExistence after the row is rendered
|
|
||||||
checkPenawaranExistence(data.nomor_registrasi)
|
|
||||||
.then(penawaranExists => {
|
|
||||||
// Update link based on penawaranExists status
|
|
||||||
let penawaranUrl = penawaranExists ?
|
|
||||||
`tender/penawaran/${data.nomor_registrasi}/edit` :
|
|
||||||
`tender/penawaran/${data.nomor_registrasi}/create`;
|
|
||||||
|
|
||||||
// Update href of the Penawaran link
|
// Call the checkPenawaranExistence function to update the action button dynamically
|
||||||
$(`#penawaran-link-${data.nomor_registrasi}`).attr('href', penawaranUrl);
|
setTimeout(() => { // Using setTimeout to ensure DOM elements are rendered before updating
|
||||||
})
|
checkPenawaranExistence(data.nomor_registrasi);
|
||||||
.catch(error => {
|
}, 0);
|
||||||
console.error("Error fetching penawaran existence:", error);
|
|
||||||
});
|
return actionHtml;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,45 @@
|
|||||||
return char.toUpperCase();
|
return char.toUpperCase();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to check the existence of penawaran and update button
|
||||||
|
function checkPenawaranExistence(nomor_registrasi) {
|
||||||
|
// URL API untuk cek penawaran
|
||||||
|
const url = `/api/check-penawaran/${nomor_registrasi}`;
|
||||||
|
|
||||||
|
// Fetch data dari server
|
||||||
|
fetch(url)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const actionDiv = document.getElementById(`action-${nomor_registrasi}`);
|
||||||
|
if (data.exists) {
|
||||||
|
// Jika penawaran ada, ganti tombol menjadi "Penawaran Ulang"
|
||||||
|
actionDiv.innerHTML = `
|
||||||
|
<a class="btn btn-sm btn-icon btn-clear btn-warning" title="Detail" href="/tender/penawaran/${nomor_registrasi}/show">
|
||||||
|
<i class="ki-outline ki-abstract-26"></i>
|
||||||
|
</a>
|
||||||
|
<a href="/tender/penawaran/${nomor_registrasi}/edit" class="btn btn-sm btn-icon btn-clear btn-info" title="Penawaran">
|
||||||
|
<i class="ki-outline ki-arrow-circle-right"></i>
|
||||||
|
</a>
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
// Jika tidak ada, tampilkan tombol "Tambah Penawaran"
|
||||||
|
actionDiv.innerHTML = `
|
||||||
|
<a class="btn btn-sm btn-icon btn-clear btn-warning" title="Detail" href="/tender/penawaran/${nomor_registrasi}/show">
|
||||||
|
<i class="ki-outline ki-abstract-26"></i>
|
||||||
|
</a>
|
||||||
|
<a href="/tender/penawaran/${nomor_registrasi}/create" class="btn btn-sm btn-icon btn-clear btn-primary" title="Penawaran">
|
||||||
|
<i class="ki-outline ki-arrow-circle-right"></i>
|
||||||
|
</a>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
const actionDiv = document.getElementById(`action-${nomor_registrasi}`);
|
||||||
|
actionDiv.innerHTML = `<span class="text-danger">Error loading action</span>`;
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
const element = document.querySelector('#penawaran-table');
|
const element = document.querySelector('#penawaran-table');
|
||||||
@@ -174,16 +213,22 @@
|
|||||||
actions: {
|
actions: {
|
||||||
title: 'Action',
|
title: 'Action',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
return `<div class="flex flex-nowrap justify-center">
|
// Default action button, to be updated later
|
||||||
<a class="btn btn-sm btn-icon btn-clear btn-primary" title="Detail" href="tender/penawaran/${data.nomor_registrasi}/show">
|
let actionHtml = `
|
||||||
<i class="ki-outline ki-abstract-26"></i>
|
<div class="flex flex-nowrap justify-center" id="action-${data.nomor_registrasi}">
|
||||||
</a>
|
<a class="btn btn-sm btn-icon btn-clear btn-secondary" title="Loading..." href="#">
|
||||||
<a class="btn btn-sm btn-icon btn-clear btn-info" title="Penawaran" href="tender/penawaran/${data.nomor_registrasi}/edit">
|
<i class="ki-outline ki-loading"></i>
|
||||||
<i class="ki-outline ki-arrow-circle-right"></i>
|
</a>
|
||||||
</a>
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
</div>`;
|
// Call the checkPenawaranExistence function to update the action button dynamically
|
||||||
},
|
setTimeout(() => { // Using setTimeout to ensure DOM elements are rendered before updating
|
||||||
|
checkPenawaranExistence(data.nomor_registrasi);
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
return actionHtml;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ use Modules\Lpj\Http\Controllers\SurveyorController;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Route::middleware(['auth'])->group(function () {
|
Route::middleware(['auth'])->group(function () {
|
||||||
|
Route::get('api/check-penawaran/{nomor_registrasi}', [TenderController::class, 'checkPenawaranExistence']);
|
||||||
|
|
||||||
Route::name('basicdata.')->prefix('basic-data')->group(function () {
|
Route::name('basicdata.')->prefix('basic-data')->group(function () {
|
||||||
Route::name('jenis-fasilitas-kredit.')->prefix('jenis-fasilitas-kredit')->group(function () {
|
Route::name('jenis-fasilitas-kredit.')->prefix('jenis-fasilitas-kredit')->group(function () {
|
||||||
Route::get('restore/{id}', [JenisFasilitasKreditController::class, 'restore'])->name('restore');
|
Route::get('restore/{id}', [JenisFasilitasKreditController::class, 'restore'])->name('restore');
|
||||||
|
|||||||
Reference in New Issue
Block a user