localize library cdn, remove approve button from transaction page, fix all fitur running datatable as well, fixing sortable datatable using new cdn, fix modal approve, add note to receiver mutations

This commit is contained in:
2025-06-16 15:01:08 +07:00
parent 9cfb566aee
commit 567e4aa5fc
45 changed files with 16202 additions and 365 deletions

View File

@@ -3,26 +3,119 @@ $.ajaxSetup({
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
});
let tableContainer = $("#products-table");
let url = tableContainer.data("url");
let table = $("#products-table").DataTable({
processing: true,
serverSide: true,
ajax: url,
order: [[0, "desc"]],
columns: [
{ data: "code", name: "code" },
{ data: "name", name: "name" },
{ data: "category_name", name: "category.name" },
{ data: "unit", name: "unit" },
{
data: "total_stock",
name: "total_stock",
orderable: false,
searchable: false,
// Wait for DataTables to be available
function initializeDataTable() {
// Debug: Check if DataTables is loaded
console.log("DataTables available:", typeof $.fn.DataTable !== "undefined");
console.log("jQuery version:", $.fn.jquery);
if (typeof $.fn.DataTable === "undefined") {
console.error("DataTables is not loaded! Retrying in 1 second...");
setTimeout(initializeDataTable, 1000);
return;
}
let tableContainer = $("#products-table");
let url = tableContainer.data("url");
console.log("Table URL:", url);
console.log("Initializing DataTable...");
let table = $("#products-table").DataTable({
processing: true,
serverSide: true,
ajax: {
url: url,
error: function (xhr, error, thrown) {
console.error("DataTables Ajax Error:", error, thrown);
console.error("Response:", xhr.responseText);
},
},
{ data: "action", name: "action", orderable: false, searchable: false },
],
order: [[0, "asc"]], // Order by first column (code) ascending
columns: [
{
data: "code",
name: "code",
orderable: true,
searchable: true,
},
{
data: "name",
name: "name",
orderable: true,
searchable: true,
},
{
data: "category_name",
name: "category.name",
orderable: true,
searchable: true,
},
{
data: "unit",
name: "unit",
orderable: true,
searchable: true,
},
{
data: "total_stock",
name: "total_stock",
orderable: false,
searchable: false,
},
{
data: "action",
name: "action",
orderable: false,
searchable: false,
},
],
columnDefs: [
{
targets: [4, 5], // total_stock and action columns
orderable: false,
},
],
initComplete: function (settings, json) {
console.log("DataTables initialized successfully");
console.log("Settings:", settings);
console.log(
"Column ordering enabled for:",
settings.aoColumns.map((col, index) => ({
index: index,
orderable: col.bSortable,
name: col.sName || col.mData,
}))
);
},
drawCallback: function (settings) {
console.log("DataTables draw completed");
},
headerCallback: function (thead, data, start, end, display) {
console.log("Header callback - sorting icons should be visible");
},
});
// Debug: Log table instance
console.log("DataTable instance:", table);
// Test column ordering programmatically
setTimeout(function () {
console.log("Testing column ordering...");
try {
table.order([1, "desc"]).draw();
console.log("Column ordering test successful");
} catch (e) {
console.error("Column ordering test failed:", e);
}
}, 2000);
}
// Initialize when document is ready
$(document).ready(function () {
console.log("Document ready, checking for DataTables...");
initializeDataTable();
});
$(document).on("click", ".btn-destroy-product", function () {
@@ -44,17 +137,22 @@ $(document).on("click", ".btn-destroy-product", function () {
_token: $('meta[name="csrf-token"]').attr("content"),
},
success: function () {
alert("Produk berhasil dihapus.");
Swal.fire(
"Berhasil!",
"Produk berhasil dihapus.",
"success"
);
$("#products-table").DataTable().ajax.reload();
},
error: function (xhr) {
alert("Gagal menghapus produk.");
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");
@@ -79,16 +177,21 @@ $(document).on("click", ".btn-toggle-active", function () {
$("#products-table")
.DataTable()
.ajax.reload(null, false);
alert(response.message);
Swal.fire("Berhasil!", response.message, "success");
}
},
error: function () {
alert("Gagal mengubah status produk.");
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");
@@ -99,7 +202,7 @@ $(document).on("click", ".btn-product-stock-dealers", function () {
// Initialize or reload DataTable inside modal
$("#dealer-stock-table").DataTable({
destroy: true, // reinit if exists
destroy: true,
processing: true,
serverSide: true,
ajax: {
@@ -109,14 +212,25 @@ $(document).on("click", ".btn-product-stock-dealers", function () {
},
},
columns: [
{ data: "dealer_name", name: "dealer_name" },
{ data: "quantity", name: "quantity" },
{
data: "dealer_name",
name: "dealer_name",
orderable: true,
searchable: true,
},
{
data: "quantity",
name: "quantity",
orderable: true,
searchable: false,
},
],
initComplete: function () {
$("#dealerStockModal").modal("show");
},
});
});
$(document).on("click", "#dealerStockModal .close", function () {
$("#dealerStockModal").modal("hide");
});