optimize dockerfile and copy js library used

This commit is contained in:
2025-07-14 16:10:52 +07:00
parent 5b14523f84
commit 4b9be55d32
17 changed files with 2439 additions and 174 deletions

View File

@@ -144,5 +144,256 @@ table.dataTable thead th.sorting:hover:before {
@endsection
@section('javascripts')
<script src="{{ asset('js/warehouse_management/products/index.js') }}"></script>
<script>
$(document).ready(function () {
console.log("Products index.js loaded");
// Check if DataTables is available
if (typeof $.fn.DataTable === "undefined") {
console.error("DataTables not available!");
return;
}
// Wait for DOM to be fully ready
setTimeout(function () {
initializeDataTable();
}, 100);
});
function initializeDataTable() {
console.log("Initializing DataTable...");
// Destroy existing table if any
if ($.fn.DataTable.isDataTable("#products-table")) {
$("#products-table").DataTable().destroy();
}
// Initialize DataTable
var table = $("#products-table").DataTable({
processing: true,
serverSide: true,
destroy: true,
ajax: {
url: $("#products-table").data("url"),
type: "GET",
data: function (d) {
console.log("DataTables request data:", d);
return d;
},
error: function (xhr, error, code) {
console.error("DataTables AJAX error:", error, code);
console.error("Response:", xhr.responseText);
},
},
columns: [
{
data: "DT_RowIndex",
name: "DT_RowIndex",
orderable: false,
searchable: false,
},
{
data: "code",
name: "code",
orderable: true,
},
{
data: "name",
name: "name",
orderable: true,
},
{
data: "category_name",
name: "category_name",
orderable: true,
},
{
data: "unit",
name: "unit",
orderable: true,
},
{
data: "total_stock",
name: "total_stock",
orderable: false,
},
{
data: "action",
name: "action",
orderable: false,
searchable: false,
},
],
order: [[1, "asc"]], // Order by code asc
pageLength: 10,
responsive: true,
ordering: true,
orderMulti: false,
});
}
$(document).on("click", ".btn-destroy-product", function () {
Swal.fire({
title: "Hapus produk?",
text: "Anda tidak akan bisa mengembalikannya!",
showCancelButton: true,
confirmButtonColor: "#d33",
cancelButtonColor: "#dedede",
confirmButtonText: "Hapus",
}).then((result) => {
if (result.value) {
const url = $(this).data("action");
$.ajax({
url: url,
method: "POST",
data: {
_method: "DELETE",
_token: $('meta[name="csrf-token"]').attr("content"),
},
success: function () {
Swal.fire(
"Berhasil!",
"Produk berhasil dihapus.",
"success"
);
try {
if ($.fn.DataTable.isDataTable("#products-table")) {
$("#products-table").DataTable().ajax.reload();
}
} catch (e) {
console.error("Error reloading table:", e);
location.reload(); // Fallback to page reload
}
},
error: function (xhr) {
Swal.fire("Error!", "Gagal menghapus produk.", "error");
console.error(xhr.responseText);
},
});
}
});
});
$(document).on("click", ".btn-toggle-active", function () {
let button = $(this);
let url = button.data("url");
Swal.fire({
title: "Status produk?",
text: "Anda yakin ingin mengganti status produk!",
showCancelButton: true,
confirmButtonColor: "#d33",
cancelButtonColor: "#dedede",
confirmButtonText: "Ya",
}).then((result) => {
if (result.value) {
$.ajax({
url: url,
method: "POST",
data: {
_token: $('meta[name="csrf-token"]').attr("content"),
},
success: function (response) {
if (response.success) {
try {
if ($.fn.DataTable.isDataTable("#products-table")) {
$("#products-table")
.DataTable()
.ajax.reload(null, false);
}
} catch (e) {
console.error("Error reloading table:", e);
location.reload(); // Fallback to page reload
}
Swal.fire("Berhasil!", response.message, "success");
}
},
error: function () {
Swal.fire(
"Error!",
"Gagal mengubah status produk.",
"error"
);
},
});
}
});
});
$(document).on("click", ".btn-product-stock-dealers", function () {
const productId = $(this).data("id");
const productName = $(this).data("name");
const ajaxUrl = $(this).data("url");
// Check if modal elements exist
if ($("#product-name-title").length === 0) {
console.error("Modal title element not found");
return;
}
if ($("#dealer-stock-table").length === 0) {
console.error("Dealer stock table element not found");
return;
}
// Set product name in modal title
$("#product-name-title").text(productName);
// Destroy existing DataTable if any
if ($.fn.DataTable.isDataTable("#dealer-stock-table")) {
$("#dealer-stock-table").DataTable().destroy();
}
// Initialize or reload DataTable inside modal
$("#dealer-stock-table").DataTable({
destroy: true,
processing: true,
serverSide: true,
ajax: {
url: ajaxUrl,
data: {
product_id: productId,
},
error: function (xhr, error, thrown) {
console.error(
"Dealer stock DataTables Ajax Error:",
error,
thrown
);
console.error("Response:", xhr.responseText);
},
},
columns: [
{
data: "dealer_name",
name: "dealer_name",
orderable: true,
searchable: true,
},
{
data: "quantity",
name: "quantity",
orderable: true,
searchable: false,
},
],
initComplete: function () {
try {
if ($("#dealerStockModal").length > 0) {
$("#dealerStockModal").modal("show");
} else {
console.error("Modal #dealerStockModal not found");
}
} catch (e) {
console.error("Error showing modal:", e);
}
},
});
});
$(document).on("click", "#dealerStockModal .close", function () {
$("#dealerStockModal").modal("hide");
});
</script>
@endsection