partial update create mutations workflow
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
$(document).ready(function () {
|
||||
let productIndex = 1;
|
||||
let originalProductOptions = ""; // Store original product options
|
||||
|
||||
// Initialize Select2
|
||||
$(".select2").select2({
|
||||
@@ -7,6 +8,12 @@ $(document).ready(function () {
|
||||
allowClear: true,
|
||||
});
|
||||
|
||||
// Store original product options on page load
|
||||
const firstSelect = $(".product-select").first();
|
||||
if (firstSelect.length > 0) {
|
||||
originalProductOptions = firstSelect.html();
|
||||
}
|
||||
|
||||
// Prevent same dealer selection
|
||||
$("#from_dealer_id, #to_dealer_id").on("change", function () {
|
||||
const fromDealerId = $("#from_dealer_id").val();
|
||||
@@ -26,12 +33,12 @@ $(document).ready(function () {
|
||||
const newRow = createProductRow(productIndex);
|
||||
$("#products-tbody").append(newRow);
|
||||
|
||||
// Initialize Select2 for new row
|
||||
// Initialize Select2 for new row after it's added to DOM
|
||||
const newSelect = $(
|
||||
`#products-tbody tr[data-index="${productIndex}"] .product-select`
|
||||
);
|
||||
newSelect.select2({
|
||||
placeholder: "Pilih Produk...",
|
||||
placeholder: "Pilih...",
|
||||
allowClear: true,
|
||||
});
|
||||
|
||||
@@ -100,18 +107,14 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
function createProductRow(index) {
|
||||
// Get product options from the existing select
|
||||
const existingSelect = $(".product-select").first();
|
||||
const productOptions = existingSelect.html();
|
||||
|
||||
return `
|
||||
<tr class="product-row" data-index="${index}">
|
||||
<td>
|
||||
<select name="products[${index}][product_id]" class="form-control select2 product-select" required>
|
||||
${productOptions}
|
||||
<select name="products[${index}][product_id]" class="form-control product-select" required>
|
||||
${originalProductOptions}
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<td class="text-center">
|
||||
<span class="available-stock text-muted">-</span>
|
||||
</td>
|
||||
<td>
|
||||
@@ -123,12 +126,7 @@ $(document).ready(function () {
|
||||
placeholder="0"
|
||||
required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text"
|
||||
name="products[${index}][notes]"
|
||||
class="form-control"
|
||||
placeholder="Catatan produk (opsional)">
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<button type="button" class="btn btn-danger btn-sm remove-product">
|
||||
<i class="la la-trash"></i>
|
||||
@@ -152,9 +150,6 @@ $(document).ready(function () {
|
||||
$(this)
|
||||
.find('input[name*="quantity_requested"]')
|
||||
.attr("name", `products[${index}][quantity_requested]`);
|
||||
$(this)
|
||||
.find('input[name*="notes"]')
|
||||
.attr("name", `products[${index}][notes]`);
|
||||
});
|
||||
productIndex = $(".product-row").length;
|
||||
}
|
||||
|
||||
@@ -28,12 +28,12 @@ $(document).ready(function () {
|
||||
{
|
||||
data: "from_dealer",
|
||||
name: "fromDealer.name",
|
||||
width: "15%",
|
||||
width: "13%",
|
||||
},
|
||||
{
|
||||
data: "to_dealer",
|
||||
name: "toDealer.name",
|
||||
width: "15%",
|
||||
width: "13%",
|
||||
},
|
||||
{
|
||||
data: "requested_by",
|
||||
@@ -57,117 +57,17 @@ $(document).ready(function () {
|
||||
name: "action",
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
width: "15%",
|
||||
width: "20%",
|
||||
className: "text-center",
|
||||
},
|
||||
],
|
||||
order: [[2, "desc"]], // Order by created_at desc
|
||||
pageLength: 10,
|
||||
responsive: true,
|
||||
language: {
|
||||
processing: "Memuat data...",
|
||||
lengthMenu: "Tampilkan _MENU_ data per halaman",
|
||||
zeroRecords: "Data tidak ditemukan",
|
||||
info: "Menampilkan _START_ sampai _END_ dari _TOTAL_ data",
|
||||
infoEmpty: "Menampilkan 0 sampai 0 dari 0 data",
|
||||
infoFiltered: "(difilter dari _MAX_ total data)",
|
||||
},
|
||||
});
|
||||
|
||||
// Handle Receive Button Click
|
||||
$(document).on("click", ".btn-receive", function () {
|
||||
var mutationId = $(this).data("id");
|
||||
$("#receiveModal" + mutationId).modal("show");
|
||||
});
|
||||
|
||||
// Handle Approve Button Click
|
||||
$(document).on("click", ".btn-approve", function () {
|
||||
var mutationId = $(this).data("id");
|
||||
|
||||
// Load mutation details via AJAX
|
||||
$.ajax({
|
||||
url: "/warehouse/mutations/" + mutationId + "/details",
|
||||
type: "GET",
|
||||
beforeSend: function () {
|
||||
$("#mutation-details" + mutationId).html(
|
||||
'<div class="text-center">' +
|
||||
'<div class="spinner-border" role="status">' +
|
||||
'<span class="sr-only">Loading...</span>' +
|
||||
"</div>" +
|
||||
"<p>Memuat detail produk...</p>" +
|
||||
"</div>"
|
||||
);
|
||||
},
|
||||
success: function (response) {
|
||||
var detailsHtml = "<h6>Detail Produk:</h6>";
|
||||
detailsHtml += '<div class="table-responsive">';
|
||||
detailsHtml += '<table class="table table-sm">';
|
||||
detailsHtml += "<thead>";
|
||||
detailsHtml += "<tr>";
|
||||
detailsHtml += "<th>Produk</th>";
|
||||
detailsHtml += "<th>Diminta</th>";
|
||||
detailsHtml += "<th>Disetujui</th>";
|
||||
detailsHtml += "<th>Stock Tersedia</th>";
|
||||
detailsHtml += "</tr>";
|
||||
detailsHtml += "</thead>";
|
||||
detailsHtml += "<tbody>";
|
||||
|
||||
response.details.forEach(function (detail, index) {
|
||||
detailsHtml += "<tr>";
|
||||
detailsHtml += "<td>" + detail.product.name + "</td>";
|
||||
detailsHtml +=
|
||||
"<td>" +
|
||||
parseFloat(detail.quantity_requested).toLocaleString() +
|
||||
"</td>";
|
||||
detailsHtml += "<td>";
|
||||
detailsHtml +=
|
||||
'<input type="number" name="details[' +
|
||||
detail.id +
|
||||
'][quantity_approved]" ';
|
||||
detailsHtml += 'class="form-control form-control-sm" ';
|
||||
detailsHtml += 'value="' + detail.quantity_requested + '" ';
|
||||
detailsHtml +=
|
||||
'min="0" max="' +
|
||||
Math.min(
|
||||
detail.quantity_requested,
|
||||
detail.available_stock
|
||||
) +
|
||||
'" ';
|
||||
detailsHtml += 'step="0.01" required>';
|
||||
detailsHtml += "</td>";
|
||||
detailsHtml +=
|
||||
"<td>" +
|
||||
parseFloat(detail.available_stock).toLocaleString() +
|
||||
"</td>";
|
||||
detailsHtml += "</tr>";
|
||||
});
|
||||
|
||||
detailsHtml += "</tbody>";
|
||||
detailsHtml += "</table>";
|
||||
detailsHtml += "</div>";
|
||||
|
||||
$("#mutation-details" + mutationId).html(detailsHtml);
|
||||
},
|
||||
error: function () {
|
||||
$("#mutation-details" + mutationId).html(
|
||||
'<div class="alert alert-danger">Gagal memuat detail produk</div>'
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
$("#approveModal" + mutationId).modal("show");
|
||||
});
|
||||
|
||||
// Handle other button clicks
|
||||
$(document).on("click", ".btn-reject", function () {
|
||||
var mutationId = $(this).data("id");
|
||||
$("#rejectModal" + mutationId).modal("show");
|
||||
});
|
||||
|
||||
$(document).on("click", ".btn-complete", function () {
|
||||
var mutationId = $(this).data("id");
|
||||
$("#completeModal" + mutationId).modal("show");
|
||||
});
|
||||
// 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 () {
|
||||
@@ -240,7 +140,7 @@ $(document).ready(function () {
|
||||
.html("Memproses...");
|
||||
});
|
||||
|
||||
// Auto-calculate approved quantity based on available stock
|
||||
// Validate quantity approved in receive modal
|
||||
$(document).on("input", 'input[name*="quantity_approved"]', function () {
|
||||
var maxValue = parseFloat($(this).attr("max"));
|
||||
var currentValue = parseFloat($(this).val());
|
||||
@@ -250,7 +150,7 @@ $(document).ready(function () {
|
||||
$(this).addClass("is-invalid");
|
||||
if (!$(this).siblings(".invalid-feedback").length) {
|
||||
$(this).after(
|
||||
'<div class="invalid-feedback">Jumlah melebihi stock yang tersedia</div>'
|
||||
'<div class="invalid-feedback">Quantity tidak boleh melebihi yang diminta</div>'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user