fix handle error and add note for shippings receive approve and reject mutations

This commit is contained in:
2025-06-13 14:19:12 +07:00
parent b2bfd666a7
commit 2f5eff9e63
28 changed files with 13055 additions and 154 deletions

View File

@@ -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;
}

View File

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

View File

@@ -1728,7 +1728,7 @@ use Illuminate\Support\Facades\Auth;
<div class="row mb-3">
<div class="col-md-12">
<strong>Diminta oleh:</strong><br>
<strong>Dikirim oleh:</strong><br>
${mutation.requested_by ? mutation.requested_by.name : '-'}
</div>
</div>
@@ -1738,7 +1738,7 @@ use Illuminate\Support\Facades\Auth;
<div class="row mb-3">
<div class="col-md-12">
<label for="mutationNotes"><strong>Catatan Penerimaan:</strong></label>
<textarea name="notes" id="mutationNotes" class="form-control" rows="3" placeholder="Masukkan catatan jika diperlukan..."></textarea>
<textarea name="reception_notes" id="mutationNotes" class="form-control" rows="3" placeholder="Masukkan catatan jika diperlukan..."></textarea>
</div>
</div>

View File

@@ -90,7 +90,7 @@
<div class="form-group">
<label>Catatan Persetujuan</label>
<textarea name="notes" class="form-control" rows="3" placeholder="Opsional: tambahkan catatan..."></textarea>
<textarea name="approval_notes" class="form-control" rows="3" placeholder="Opsional: tambahkan catatan..."></textarea>
</div>
<h6>Detail Produk yang Diterima:</h6>
@@ -182,7 +182,7 @@
<div class="form-group">
<label>Catatan Penerimaan</label>
<textarea name="notes" class="form-control" rows="3" placeholder="Catatan kondisi barang saat diterima (opsional)"></textarea>
<textarea name="reception_notes" class="form-control" rows="3" placeholder="Catatan kondisi barang saat diterima (opsional)"></textarea>
</div>
<h6>Detail Produk yang Diterima:</h6>

View File

@@ -13,7 +13,7 @@
<div class="kt-portlet__head-toolbar">
<div class="kt-portlet__head-wrapper">
<div class="kt-portlet__head-actions">
<a href="{{ route('mutations.index') }}" class="btn btn-clean btn-sm">
<a href="{{ route('mutations.index') }}" class="btn btn-secondary">
<i class="la la-arrow-left"></i>
Kembali
</a>
@@ -65,6 +65,17 @@
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="shipping_notes">Catatan Pengiriman</label>
<textarea name="shipping_notes" id="shipping_notes" class="form-control" rows="3"
placeholder="Catatan khusus untuk pengiriman mutasi ini (opsional)">{{ old('shipping_notes') }}</textarea>
<small class="form-text text-muted">Catatan ini akan dilihat oleh dealer penerima</small>
</div>
</div>
</div>
<div class="kt-separator kt-separator--border-dashed kt-separator--space-lg"></div>
<div class="form-group">

View File

@@ -14,9 +14,8 @@
<div class="kt-portlet__head-toolbar">
<div class="kt-portlet__head-wrapper">
<div class="kt-portlet__head-actions">
<a href="{{ route('mutations.index') }}" class="btn btn-secondary btn-sm">
<i class="la la-arrow-left"></i>
Kembali
<a href="{{ route('mutations.index') }}" class="btn btn-secondary">
<i class="la la-arrow-left"></i> Kembali
</a>
</div>
</div>
@@ -74,12 +73,45 @@
<p>{{ $mutation->approved_at->format('d/m/Y H:i:s') }}</p>
</div>
@endif
@if($mutation->rejectedBy)
<div class="form-group">
<label><strong>Ditolak Oleh:</strong></label>
<p>{{ $mutation->rejectedBy->name }}</p>
</div>
<div class="form-group">
<label><strong>Tanggal Ditolak:</strong></label>
<p>{{ $mutation->rejected_at->format('d/m/Y H:i:s') }}</p>
</div>
@endif
@if($mutation->cancelledBy)
<div class="form-group">
<label><strong>Dibatalkan Oleh:</strong></label>
<p>{{ $mutation->cancelledBy->name }}</p>
</div>
<div class="form-group">
<label><strong>Tanggal Dibatalkan:</strong></label>
<p>{{ $mutation->cancelled_at->format('d/m/Y H:i:s') }}</p>
</div>
@endif
</div>
</div>
@if($mutation->notes)
<!-- Notes Section -->
@if($mutation->shipping_notes)
<div class="form-group">
<label><strong>Catatan:</strong></label>
<p>{{ $mutation->notes }}</p>
<label><strong>Catatan Pengiriman:</strong></label>
<div class="alert alert-info">{{ $mutation->shipping_notes }}</div>
</div>
@endif
@if($mutation->reception_notes)
<div class="form-group">
<label><strong>Catatan Penerimaan:</strong></label>
<div class="alert alert-primary">{{ $mutation->reception_notes }}</div>
</div>
@endif
@if($mutation->approval_notes)
<div class="form-group">
<label><strong>Catatan Persetujuan:</strong></label>
<div class="alert alert-success">{{ $mutation->approval_notes }}</div>
</div>
@endif
@if($mutation->rejection_reason)
@@ -88,6 +120,12 @@
<div class="alert alert-danger">{{ $mutation->rejection_reason }}</div>
</div>
@endif
@if($mutation->cancellation_reason)
<div class="form-group">
<label><strong>Alasan Pembatalan:</strong></label>
<div class="alert alert-warning">{{ $mutation->cancellation_reason }}</div>
</div>
@endif
</div>
</div>
@@ -229,7 +267,7 @@
<div class="form-group">
<label>Catatan Penerimaan</label>
<textarea name="notes" class="form-control" rows="3" placeholder="Catatan kondisi barang saat diterima (opsional)"></textarea>
<textarea name="reception_notes" class="form-control" rows="3" placeholder="Catatan kondisi barang saat diterima (opsional)"></textarea>
</div>
<h6>Detail Produk yang Diterima:</h6>
@@ -302,7 +340,7 @@
<div class="form-group">
<label>Catatan Persetujuan</label>
<textarea name="notes" class="form-control" rows="3" placeholder="Opsional: tambahkan catatan..."></textarea>
<textarea name="approval_notes" class="form-control" rows="3" placeholder="Opsional: tambahkan catatan..."></textarea>
</div>
<h6>Detail Produk yang Diterima:</h6>
@@ -428,6 +466,10 @@
<div class="alert alert-warning">
<strong>Peringatan!</strong> Mutasi yang dibatalkan tidak dapat diubah lagi.
</div>
<div class="form-group">
<label>Alasan Pembatalan</label>
<textarea name="cancellation_reason" class="form-control" rows="3" placeholder="Masukkan alasan pembatalan (opsional)"></textarea>
</div>
<p>Apakah Anda yakin ingin membatalkan mutasi ini?</p>
</div>
<div class="modal-footer">
@@ -457,8 +499,6 @@
text-align: center !important;
}
/* Ensure proper alignment in approval modal */
.approve-form .form-control.text-center {
text-align: center;

View File

@@ -94,7 +94,7 @@
@endphp
<tr class="product-row">
<td>
<select name="product[0]" class="form-control product-select @error('product.0') is-invalid @enderror" required>
<select name="product[0]" class="form-control product-select select2 @error('product.0') is-invalid @enderror" required>
<option value="">Pilih Produk</option>
@foreach($products as $product)
<option value="{{ $product->id }}" {{ (isset($oldProducts[0]) && $oldProducts[0] == $product->id) ? 'selected' : '' }}>
@@ -124,8 +124,7 @@
class="form-control @error('physical_quantity.0') is-invalid @enderror"
step="0.01" min="0"
value="{{ $oldPhysicalQuantities[0] ?? '' }}"
required
onchange="calculateDifference(this)">
required>
</div>
@error('physical_quantity.0')
<div class="invalid-feedback d-block">{{ $message }}</div>
@@ -168,7 +167,7 @@
<template id="product-row-template">
<tr class="product-row">
<td>
<select name="product[]" class="form-control product-select" required>
<select name="product[]" class="form-control product-select select2" required>
<option value="">Pilih Produk</option>
@foreach($products as $product)
<option value="{{ $product->id }}">{{ $product->name }}</option>
@@ -184,8 +183,7 @@
<td>
<div class="input-group">
<input type="number" name="physical_quantity[]" class="form-control"
step="0.01" min="0" value="" required
onchange="calculateDifference(this)">
step="0.01" min="0" value="" required>
</div>
</td>
<td>

View File

@@ -44,5 +44,5 @@
@endsection
@section('javascripts')
<script src="{{ asset('js/warehouse_management/opnames/index.js') }}"></script>
<script src="{{ mix('js/warehouse_management/opnames/index.js') }}"></script>
@endsection