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

@@ -1,74 +1,96 @@
$(document).ready(function () {
console.log("Mutations index.js loaded");
// Check if DataTables is available
if (typeof $.fn.DataTable === "undefined") {
console.error("DataTables not available!");
return;
}
// Destroy existing table if any
if ($.fn.DataTable.isDataTable("#mutations-table")) {
$("#mutations-table").DataTable().destroy();
}
// Initialize DataTable
var table = $("#mutations-table").DataTable({
processing: true,
serverSide: true,
destroy: true,
ajax: {
url: $("#mutations-table").data("url"),
type: "GET",
error: function (xhr, error, code) {
console.error("DataTables AJAX error:", error, code);
},
},
columns: [
columnDefs: [
{
data: "DT_RowIndex",
name: "DT_RowIndex",
targets: 0, // No. column
orderable: false,
searchable: false,
width: "5%",
},
{
data: "mutation_number",
name: "mutation_number",
width: "12%",
targets: [1, 2, 3, 4, 5, 6, 7], // All sortable columns
orderable: true,
searchable: true,
},
{
data: "created_at",
name: "created_at",
width: "12%",
},
{
data: "from_dealer",
name: "fromDealer.name",
width: "13%",
},
{
data: "to_dealer",
name: "toDealer.name",
width: "13%",
},
{
data: "requested_by",
name: "requestedBy.name",
width: "12%",
},
{
data: "total_items",
name: "total_items",
width: "8%",
className: "text-center",
},
{
data: "status",
name: "status",
width: "12%",
className: "text-center",
},
{
data: "action",
name: "action",
targets: 8, // Action column
orderable: false,
searchable: false,
width: "20%",
className: "text-center",
},
{
targets: [6, 7], // Total Items and Status columns
className: "text-center",
},
],
order: [[2, "desc"]], // Order by created_at desc
columns: [
{
data: "DT_RowIndex",
name: "DT_RowIndex",
},
{
data: "mutation_number",
name: "mutation_number",
},
{
data: "created_at",
name: "created_at",
},
{
data: "from_dealer",
name: "fromDealer.name",
},
{
data: "to_dealer",
name: "toDealer.name",
},
{
data: "requested_by",
name: "requestedBy.name",
},
{
data: "total_items",
name: "total_items",
},
{
data: "status",
name: "status",
},
{
data: "action",
name: "action",
},
],
order: [[1, "desc"]], // Order by mutation_number desc (which follows ID order)
pageLength: 10,
responsive: true,
});
// Modal event handlers are now handled by Bootstrap 5 data attributes
// No need for manual modal show/hide handlers
// Handle Cancel Button Click with SweetAlert
$(document).on("click", ".btn-cancel", function () {
var mutationId = $(this).data("id");

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");
});