fix redirect active tab after submit opname mutations and receive mutations
This commit is contained in:
@@ -350,10 +350,11 @@ class OpnamesController extends Controller
|
|||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
||||||
if ($isTransactionForm) {
|
if ($isTransactionForm) {
|
||||||
// Redirect back to transaction page with success message
|
// Redirect back to transaction page with success message and tab indicator
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('transaction')
|
->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 {
|
} else {
|
||||||
// Redirect to opname index for regular form
|
// Redirect to opname index for regular form
|
||||||
return redirect()
|
return redirect()
|
||||||
@@ -373,7 +374,8 @@ class OpnamesController extends Controller
|
|||||||
->route('transaction')
|
->route('transaction')
|
||||||
->withErrors($e->validator)
|
->withErrors($e->validator)
|
||||||
->withInput()
|
->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 {
|
} else {
|
||||||
return back()->withErrors($e->validator)->withInput();
|
return back()->withErrors($e->validator)->withInput();
|
||||||
}
|
}
|
||||||
@@ -389,7 +391,8 @@ class OpnamesController extends Controller
|
|||||||
return redirect()
|
return redirect()
|
||||||
->route('transaction')
|
->route('transaction')
|
||||||
->with('error', $errorMessage)
|
->with('error', $errorMessage)
|
||||||
->withInput();
|
->withInput()
|
||||||
|
->with('active_tab', 'opname');
|
||||||
} else {
|
} else {
|
||||||
return back()
|
return back()
|
||||||
->with('error', $errorMessage)
|
->with('error', $errorMessage)
|
||||||
|
|||||||
@@ -891,6 +891,9 @@ use Illuminate\Support\Facades\Auth;
|
|||||||
$("#opnameForm").submit(function(e) {
|
$("#opnameForm").submit(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
// Save current tab to localStorage
|
||||||
|
localStorage.setItem('activeTab', '#opname');
|
||||||
|
|
||||||
// Validate form
|
// Validate form
|
||||||
var hasValidStock = false;
|
var hasValidStock = false;
|
||||||
var invalidRows = [];
|
var invalidRows = [];
|
||||||
@@ -1018,6 +1021,9 @@ use Illuminate\Support\Facades\Auth;
|
|||||||
$(document).on('submit', '#mutasiForm', function(e) {
|
$(document).on('submit', '#mutasiForm', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
// Save current tab to localStorage
|
||||||
|
localStorage.setItem('activeTab', '#mutasi');
|
||||||
|
|
||||||
// Validate form
|
// Validate form
|
||||||
var isValid = true;
|
var isValid = true;
|
||||||
var errorMessages = [];
|
var errorMessages = [];
|
||||||
@@ -1292,13 +1298,21 @@ use Illuminate\Support\Facades\Auth;
|
|||||||
// Initialize mutasi form
|
// Initialize mutasi form
|
||||||
updateRemoveButtonsMutasi();
|
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())
|
@if(session('success') || session('error') || $errors->any())
|
||||||
// Activate stock tab and mutasi sub-tab
|
@if(session('active_tab') == 'opname')
|
||||||
$('.nav-link[href="#stock"]').tab('show');
|
// Activate stock tab and opname sub-tab
|
||||||
setTimeout(function() {
|
$('.nav-link[href="#stock"]').tab('show');
|
||||||
$('.nav-link[href="#mutasi"]').tab('show');
|
setTimeout(function() {
|
||||||
}, 100);
|
$('.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
|
@endif
|
||||||
|
|
||||||
// Check if there are validation errors
|
// Check if there are validation errors
|
||||||
@@ -1332,7 +1346,9 @@ use Illuminate\Support\Facades\Auth;
|
|||||||
}).then(() => {
|
}).then(() => {
|
||||||
// Check if this is from mutasi form (contains "Mutasi" in message)
|
// Check if this is from mutasi form (contains "Mutasi" in message)
|
||||||
var successMessage = '{{ session("success") }}';
|
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
|
// Reset mutasi form after success
|
||||||
$('#mutasiForm')[0].reset();
|
$('#mutasiForm')[0].reset();
|
||||||
$('#products-tbody-mutasi').html(`
|
$('#products-tbody-mutasi').html(`
|
||||||
@@ -1369,7 +1385,7 @@ use Illuminate\Support\Facades\Auth;
|
|||||||
$("#btn-save-mutasi").attr("disabled", false);
|
$("#btn-save-mutasi").attr("disabled", false);
|
||||||
$("#btn-save-mutasi").removeClass("disabled");
|
$("#btn-save-mutasi").removeClass("disabled");
|
||||||
$("#btn-save-mutasi").html('Kirim Mutasi');
|
$("#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
|
// Reset opname form after success
|
||||||
$('#opnameForm')[0].reset();
|
$('#opnameForm')[0].reset();
|
||||||
$('.physical-stock').val('').removeClass('is-invalid');
|
$('.physical-stock').val('').removeClass('is-invalid');
|
||||||
@@ -1380,6 +1396,8 @@ use Illuminate\Support\Facades\Auth;
|
|||||||
// Set default date
|
// Set default date
|
||||||
var today = new Date().toISOString().split('T')[0];
|
var today = new Date().toISOString().split('T')[0];
|
||||||
$('#date-opname').val(today);
|
$('#date-opname').val(today);
|
||||||
|
// Update product counter
|
||||||
|
updateProductCounter();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@endif
|
@endif
|
||||||
@@ -1390,6 +1408,20 @@ use Illuminate\Support\Facades\Auth;
|
|||||||
title: 'Terjadi Kesalahan',
|
title: 'Terjadi Kesalahan',
|
||||||
text: '{{ session("error") }}',
|
text: '{{ session("error") }}',
|
||||||
confirmButtonText: 'OK'
|
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
|
@endif
|
||||||
|
|
||||||
@@ -1863,6 +1895,35 @@ use Illuminate\Support\Facades\Auth;
|
|||||||
initReceiveMutationsTable();
|
initReceiveMutationsTable();
|
||||||
}, 100);
|
}, 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) {
|
function createTransaction(form) {
|
||||||
let work_ids;
|
let work_ids;
|
||||||
|
|||||||
Reference in New Issue
Block a user