fix redirect active tab after submit opname mutations and receive mutations

This commit is contained in:
2025-06-12 18:19:26 +07:00
parent b04b8f88cb
commit 2fa60c583a
2 changed files with 76 additions and 12 deletions

View File

@@ -350,10 +350,11 @@ class OpnamesController extends Controller
DB::commit();
if ($isTransactionForm) {
// Redirect back to transaction page with success message
// Redirect back to transaction page with success message and tab indicator
return redirect()
->route('transaction')
->with('success', "Opname berhasil disimpan dan disetujui. {$processedCount} produk telah diproses.");
->with('success', "Opname berhasil disimpan dan disetujui. {$processedCount} produk telah diproses.")
->with('active_tab', 'opname');
} else {
// Redirect to opname index for regular form
return redirect()
@@ -373,7 +374,8 @@ class OpnamesController extends Controller
->route('transaction')
->withErrors($e->validator)
->withInput()
->with('error', 'Terjadi kesalahan validasi. Periksa kembali data yang dimasukkan.');
->with('error', 'Terjadi kesalahan validasi. Periksa kembali data yang dimasukkan.')
->with('active_tab', 'opname');
} else {
return back()->withErrors($e->validator)->withInput();
}
@@ -389,7 +391,8 @@ class OpnamesController extends Controller
return redirect()
->route('transaction')
->with('error', $errorMessage)
->withInput();
->withInput()
->with('active_tab', 'opname');
} else {
return back()
->with('error', $errorMessage)

View File

@@ -891,6 +891,9 @@ use Illuminate\Support\Facades\Auth;
$("#opnameForm").submit(function(e) {
e.preventDefault();
// Save current tab to localStorage
localStorage.setItem('activeTab', '#opname');
// Validate form
var hasValidStock = false;
var invalidRows = [];
@@ -1018,6 +1021,9 @@ use Illuminate\Support\Facades\Auth;
$(document).on('submit', '#mutasiForm', function(e) {
e.preventDefault();
// Save current tab to localStorage
localStorage.setItem('activeTab', '#mutasi');
// Validate form
var isValid = true;
var errorMessages = [];
@@ -1292,13 +1298,21 @@ use Illuminate\Support\Facades\Auth;
// Initialize mutasi form
updateRemoveButtonsMutasi();
// Check if we should show mutasi tab (after form submission)
// Check if we should show specific tab (after form submission)
@if(session('success') || session('error') || $errors->any())
// Activate stock tab and mutasi sub-tab
$('.nav-link[href="#stock"]').tab('show');
setTimeout(function() {
$('.nav-link[href="#mutasi"]').tab('show');
}, 100);
@if(session('active_tab') == 'opname')
// Activate stock tab and opname sub-tab
$('.nav-link[href="#stock"]').tab('show');
setTimeout(function() {
$('.nav-link[href="#opname"]').tab('show');
}, 100);
@elseif(session('active_tab') == 'mutasi')
// Activate stock tab and mutasi sub-tab
$('.nav-link[href="#stock"]').tab('show');
setTimeout(function() {
$('.nav-link[href="#mutasi"]').tab('show');
}, 100);
@endif
@endif
// Check if there are validation errors
@@ -1332,7 +1346,9 @@ use Illuminate\Support\Facades\Auth;
}).then(() => {
// Check if this is from mutasi form (contains "Mutasi" in message)
var successMessage = '{{ session("success") }}';
if (successMessage.toLowerCase().includes('mutasi')) {
var activeTab = '{{ session("active_tab") }}';
if (successMessage.toLowerCase().includes('mutasi') || activeTab === 'mutasi') {
// Reset mutasi form after success
$('#mutasiForm')[0].reset();
$('#products-tbody-mutasi').html(`
@@ -1369,7 +1385,7 @@ use Illuminate\Support\Facades\Auth;
$("#btn-save-mutasi").attr("disabled", false);
$("#btn-save-mutasi").removeClass("disabled");
$("#btn-save-mutasi").html('Kirim Mutasi');
} else if (successMessage.toLowerCase().includes('opname')) {
} else if (successMessage.toLowerCase().includes('opname') || activeTab === 'opname') {
// Reset opname form after success
$('#opnameForm')[0].reset();
$('.physical-stock').val('').removeClass('is-invalid');
@@ -1380,6 +1396,8 @@ use Illuminate\Support\Facades\Auth;
// Set default date
var today = new Date().toISOString().split('T')[0];
$('#date-opname').val(today);
// Update product counter
updateProductCounter();
}
});
@endif
@@ -1390,6 +1408,20 @@ use Illuminate\Support\Facades\Auth;
title: 'Terjadi Kesalahan',
text: '{{ session("error") }}',
confirmButtonText: 'OK'
}).then(() => {
// Check if this is from opname form error
var activeTab = '{{ session("active_tab") }}';
if (activeTab === 'opname') {
// Reset button states for opname form
$("#btn-save-opname").attr("disabled", false);
$("#btn-save-opname").removeClass("disabled");
$("#btn-save-opname").html('Simpan Opname');
} else if (activeTab === 'mutasi') {
// Reset button states for mutasi form
$("#btn-save-mutasi").attr("disabled", false);
$("#btn-save-mutasi").removeClass("disabled");
$("#btn-save-mutasi").html('Kirim Mutasi');
}
});
@endif
@@ -1864,6 +1896,35 @@ use Illuminate\Support\Facades\Auth;
}, 100);
});
// Save active tab to localStorage
$('.nav-link').on('click', function() {
var target = $(this).attr('href');
if (target) {
localStorage.setItem('activeTab', target);
}
});
// Restore active tab from localStorage if no server-side active tab
$(document).ready(function() {
var serverActiveTab = '{{ session("active_tab") }}';
// Only restore from localStorage if no server-side active tab
if (!serverActiveTab) {
var savedTab = localStorage.getItem('activeTab');
if (savedTab) {
// Activate main tab first if it's a sub-tab
if (savedTab.includes('opname') || savedTab.includes('mutasi') || savedTab.includes('penerimaan')) {
$('.nav-link[href="#stock"]').tab('show');
setTimeout(function() {
$('.nav-link[href="' + savedTab + '"]').tab('show');
}, 100);
} else {
$('.nav-link[href="' + savedTab + '"]').tab('show');
}
}
}
});
function createTransaction(form) {
let work_ids;
if(form == 'work') {