fix handle error and add note for shippings receive approve and reject mutations
This commit is contained in:
@@ -21,7 +21,12 @@ $(document).ready(function () {
|
||||
|
||||
if (fromDealerId && toDealerId && fromDealerId === toDealerId) {
|
||||
$(this).val("").trigger("change");
|
||||
alert("Dealer asal dan tujuan tidak boleh sama!");
|
||||
Swal.fire({
|
||||
type: "error",
|
||||
title: "Oops...",
|
||||
text: "Dealer asal dan tujuan tidak boleh sama",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update available stock when dealer changes
|
||||
@@ -216,24 +221,40 @@ $(document).ready(function () {
|
||||
|
||||
// Check dealers
|
||||
if (!fromDealerId) {
|
||||
alert("Pilih dealer asal");
|
||||
Swal.fire({
|
||||
type: "error",
|
||||
title: "Oops...",
|
||||
text: "Pilih dealer asal",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!toDealerId) {
|
||||
alert("Pilih dealer tujuan");
|
||||
Swal.fire({
|
||||
type: "error",
|
||||
title: "Oops...",
|
||||
text: "Pilih dealer tujuan",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fromDealerId === toDealerId) {
|
||||
alert("Dealer asal dan tujuan tidak boleh sama");
|
||||
Swal.fire({
|
||||
type: "error",
|
||||
title: "Oops...",
|
||||
text: "Dealer asal dan tujuan tidak boleh sama",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check products
|
||||
const productRows = $(".product-row");
|
||||
if (productRows.length === 0) {
|
||||
alert("Tambahkan minimal satu produk");
|
||||
Swal.fire({
|
||||
type: "error",
|
||||
title: "Oops...",
|
||||
text: "Tambahkan minimal satu produk",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -248,7 +269,11 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
if (!hasValidProduct) {
|
||||
alert("Pilih minimal satu produk dengan quantity yang valid");
|
||||
Swal.fire({
|
||||
type: "error",
|
||||
title: "Oops...",
|
||||
text: "Pilih minimal satu produk dengan quantity yang valid",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
$(document).ready(function () {
|
||||
console.log("Opnames create.js loaded - SweetAlert version");
|
||||
|
||||
$(".select2").select2({
|
||||
placeholder: "Pilih...",
|
||||
allowClear: true,
|
||||
});
|
||||
|
||||
// Initialize select2 for all product selects
|
||||
function initializeProductSelects() {
|
||||
$(".product-select").select2({
|
||||
placeholder: "Pilih Produk...",
|
||||
allowClear: true,
|
||||
width: "100%",
|
||||
});
|
||||
}
|
||||
|
||||
// Initial initialization
|
||||
initializeProductSelects();
|
||||
|
||||
// Fungsi untuk mengambil data stok
|
||||
function fetchStockData() {
|
||||
const dealerId = $("#dealer").val();
|
||||
@@ -88,6 +102,15 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
|
||||
// Handle physical quantity changes using event delegation
|
||||
$(document).on(
|
||||
"change input",
|
||||
'input[name^="physical_quantity"]',
|
||||
function () {
|
||||
calculateDifference(this);
|
||||
}
|
||||
);
|
||||
|
||||
// Fungsi untuk menambah baris produk
|
||||
$("#btn-add-row").click(function () {
|
||||
const template = document.getElementById("product-row-template");
|
||||
@@ -122,7 +145,16 @@ $(document).ready(function () {
|
||||
$(newRow).find("select").val("");
|
||||
$(newRow).find("input:not(.system-quantity)").val("");
|
||||
|
||||
// Append to DOM first
|
||||
tbody.append(newRow);
|
||||
|
||||
// Initialize select2 for the new row AFTER it's added to DOM
|
||||
tbody.find("tr:last-child .product-select").select2({
|
||||
placeholder: "Pilih Produk...",
|
||||
allowClear: true,
|
||||
width: "100%",
|
||||
});
|
||||
|
||||
updateRemoveButtons();
|
||||
});
|
||||
|
||||
@@ -143,30 +175,50 @@ $(document).ready(function () {
|
||||
// Fungsi untuk reindex semua baris
|
||||
function reindexRows() {
|
||||
$(".product-row").each(function (index) {
|
||||
$(this)
|
||||
.find('select[name^="product"]')
|
||||
.attr("name", `product[${index}]`);
|
||||
$(this)
|
||||
.find('input[name^="system_quantity"]')
|
||||
.attr("name", `system_quantity[${index}]`);
|
||||
$(this)
|
||||
.find('input[name^="physical_quantity"]')
|
||||
.attr("name", `physical_quantity[${index}]`);
|
||||
$(this)
|
||||
.find('input[name^="item_notes"]')
|
||||
.attr("name", `item_notes[${index}]`);
|
||||
const $row = $(this);
|
||||
const $select = $row.find('select[name^="product"]');
|
||||
|
||||
// Destroy select2 before changing attributes
|
||||
if ($select.data("select2")) {
|
||||
$select.select2("destroy");
|
||||
}
|
||||
|
||||
$select.attr("name", `product[${index}]`);
|
||||
$row.find('input[name^="system_quantity"]').attr(
|
||||
"name",
|
||||
`system_quantity[${index}]`
|
||||
);
|
||||
$row.find('input[name^="physical_quantity"]').attr(
|
||||
"name",
|
||||
`physical_quantity[${index}]`
|
||||
);
|
||||
$row.find('input[name^="item_notes"]').attr(
|
||||
"name",
|
||||
`item_notes[${index}]`
|
||||
);
|
||||
|
||||
// Reinitialize select2
|
||||
$select.select2({
|
||||
placeholder: "Pilih Produk...",
|
||||
allowClear: true,
|
||||
width: "100%",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Update calculateDifference function
|
||||
function calculateDifference(input) {
|
||||
// Update calculateDifference function - make it globally accessible
|
||||
window.calculateDifference = function (input) {
|
||||
const row = $(input).closest("tr");
|
||||
const systemQty = parseFloat(row.find(".system-quantity").val()) || 0;
|
||||
const physicalQty =
|
||||
parseFloat(row.find('input[name^="physical_quantity"]').val()) || 0;
|
||||
const noteInput = row.find('input[name^="item_notes"]');
|
||||
|
||||
if (Math.abs(systemQty - physicalQty) > 0.01) {
|
||||
// Round both values to 2 decimal places for comparison
|
||||
const roundedSystemQty = Math.round(systemQty * 100) / 100;
|
||||
const roundedPhysicalQty = Math.round(physicalQty * 100) / 100;
|
||||
|
||||
if (roundedSystemQty !== roundedPhysicalQty) {
|
||||
noteInput.addClass("is-invalid");
|
||||
noteInput.attr("required", true);
|
||||
noteInput.attr(
|
||||
@@ -180,7 +232,7 @@ $(document).ready(function () {
|
||||
noteInput.attr("placeholder", "Catatan item");
|
||||
row.removeClass("table-warning");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Prevent manual editing of system quantity
|
||||
$(document).on("keydown", ".system-quantity", function (e) {
|
||||
@@ -198,7 +250,11 @@ $(document).ready(function () {
|
||||
const dealerId = $("#dealer").val();
|
||||
if (!dealerId) {
|
||||
e.preventDefault();
|
||||
alert("Silakan pilih dealer terlebih dahulu!");
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Oops...",
|
||||
text: "Silakan pilih dealer terlebih dahulu!",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -212,14 +268,22 @@ $(document).ready(function () {
|
||||
const uniqueProducts = [...new Set(products)];
|
||||
if (products.length !== uniqueProducts.length) {
|
||||
e.preventDefault();
|
||||
alert("Produk tidak boleh duplikat!");
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Oops...",
|
||||
text: "Produk tidak boleh duplikat!",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cek produk kosong
|
||||
if (products.includes("")) {
|
||||
e.preventDefault();
|
||||
alert("Semua produk harus dipilih!");
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Oops...",
|
||||
text: "Semua produk harus dipilih!",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -236,7 +300,11 @@ $(document).ready(function () {
|
||||
) || 0;
|
||||
const note = $(this).find('input[name^="item_notes"]').val();
|
||||
|
||||
if (Math.abs(systemQty - physicalQty) > 0.01 && !note) {
|
||||
// Round both values to 2 decimal places for comparison
|
||||
const roundedSystemQty = Math.round(systemQty * 100) / 100;
|
||||
const roundedPhysicalQty = Math.round(physicalQty * 100) / 100;
|
||||
|
||||
if (roundedSystemQty !== roundedPhysicalQty && !note) {
|
||||
hasInvalidNotes = true;
|
||||
$(this).addClass("table-danger");
|
||||
}
|
||||
@@ -244,9 +312,11 @@ $(document).ready(function () {
|
||||
|
||||
if (hasInvalidNotes) {
|
||||
e.preventDefault();
|
||||
alert(
|
||||
"Catatan wajib diisi untuk produk yang memiliki perbedaan stock!"
|
||||
);
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Oops...",
|
||||
text: "Catatan wajib diisi untuk produk yang memiliki perbedaan stock!",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user