Perubahan barcode dan inventory
This commit is contained in:
+306
-123
@@ -108,12 +108,12 @@
|
||||
type="text"
|
||||
id="serial_number"
|
||||
class="form-control form-control-lg text-center"
|
||||
placeholder="Scan QR Barang"
|
||||
placeholder="Scan Barcode / Serial Number / Nama Barang"
|
||||
autocomplete="off"
|
||||
autofocus>
|
||||
|
||||
<small class="scan-note">
|
||||
Scanner akan otomatis menyimpan.
|
||||
Scan atau ketik Barcode / Serial Number / Nama Barang, lalu Enter.
|
||||
</small><br>
|
||||
|
||||
<button
|
||||
@@ -147,7 +147,9 @@
|
||||
|
||||
</div>
|
||||
</center>
|
||||
<div id="tableBarcode"></div>
|
||||
<div style="max-height: 200px; overflow: auto;">
|
||||
<div class="mt-2" id="tableBarcode"></div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<div id="group_account_biaya">
|
||||
@@ -246,29 +248,53 @@
|
||||
// URUSAN BARCODE INPUT DAN CAMSCANNER
|
||||
let daftarBarang = [];
|
||||
let isSaving = false;
|
||||
let searchTimer = null;
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#serial_number").focus();
|
||||
$("#serial_number").keypress(function(e){
|
||||
|
||||
$("#serial_number").on("keypress", function(e){
|
||||
if(e.which==13){
|
||||
e.preventDefault();
|
||||
if(searchTimer){
|
||||
clearTimeout(searchTimer);
|
||||
}
|
||||
if(!isSaving){
|
||||
getBarcodeId();
|
||||
getBarcodeId(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#serial_number").on("input", function(){
|
||||
let keyword = ($(this).val() || "").trim();
|
||||
|
||||
if(searchTimer){
|
||||
clearTimeout(searchTimer);
|
||||
}
|
||||
|
||||
if(keyword === ""){
|
||||
daftarBarang = [];
|
||||
renderTable();
|
||||
return;
|
||||
}
|
||||
|
||||
searchTimer = setTimeout(function(){
|
||||
if(!isSaving){
|
||||
getBarcodeId(false);
|
||||
}
|
||||
}, 300);
|
||||
});
|
||||
});
|
||||
|
||||
function getBarcodeId(){
|
||||
function getBarcodeId(isScanner = false){
|
||||
let barcode = ($("#serial_number").val() || "").trim();
|
||||
if(barcode==""){
|
||||
return;
|
||||
}
|
||||
|
||||
$.post(
|
||||
"<?=base_url('items/get_barcode_item');?>",
|
||||
{
|
||||
barcode:barcode
|
||||
},
|
||||
{ barcode: barcode },
|
||||
function(r){
|
||||
if(!r.status){
|
||||
Swal.fire({
|
||||
@@ -279,99 +305,174 @@ function getBarcodeId(){
|
||||
$("#serial_number").val("").focus();
|
||||
return;
|
||||
}
|
||||
let exist = daftarBarang.find(function(v){
|
||||
return v.barcode_id == r.data.barcode_id;
|
||||
});
|
||||
|
||||
if(exist){
|
||||
let rows = Array.isArray(r.data) ? r.data : [];
|
||||
if(rows.length === 0){
|
||||
Swal.fire({
|
||||
icon: "warning",
|
||||
title: "Barcode sudah discan",
|
||||
timer: 1000,
|
||||
showConfirmButton: false
|
||||
icon:"warning",
|
||||
title:"Data kosong",
|
||||
text:"Tidak ada barang yang cocok."
|
||||
});
|
||||
|
||||
$("#serial_number").val("").focus();
|
||||
return;
|
||||
}
|
||||
|
||||
daftarBarang.push(r.data);
|
||||
daftarBarang = rows;
|
||||
renderTable();
|
||||
$("#serial_number").val("").focus();
|
||||
|
||||
if(isScanner){
|
||||
$("#serial_number").val("").focus();
|
||||
}
|
||||
},
|
||||
"json"
|
||||
);
|
||||
}
|
||||
|
||||
function renderTable(){
|
||||
function renderTable() {
|
||||
|
||||
let html='';
|
||||
let html = '';
|
||||
|
||||
html+='<div class="table-responsive">';
|
||||
html+='<table class="table table-bordered table-hover table-sm mb-0">';
|
||||
html+='<thead>';
|
||||
html+='<tr>';
|
||||
html+='<th width="50">No</th>';
|
||||
html+='<th width="180">Barcode</th>';
|
||||
html+='<th width="150">Kode Barang</th>';
|
||||
html+='<th>Nama Barang</th>';
|
||||
html+='<th width="180">Serial Number</th>';
|
||||
html+='<th width="80" class="text-center">Action</th>';
|
||||
html+='</tr>';
|
||||
html+='</thead>';
|
||||
html+='<tbody>';
|
||||
html += '<div class="table-responsive">';
|
||||
html += '<table class="table table-bordered table-hover table-sm mb-0">';
|
||||
html += '<thead>';
|
||||
html += '<tr>';
|
||||
html += '<th width="50">No</th>';
|
||||
html += '<th width="180">Barcode</th>';
|
||||
html += '<th width="120">Kode Barang</th>';
|
||||
html += '<th>Nama Barang</th>';
|
||||
html += '<th width="180">Serial Number</th>';
|
||||
html += '<th width="70" class="text-center">Pilih</th>';
|
||||
html += '</tr>';
|
||||
html += '</thead>';
|
||||
html += '<tbody>';
|
||||
|
||||
if(daftarBarang.length==0){
|
||||
if (daftarBarang.length == 0) {
|
||||
|
||||
html+='<tr>';
|
||||
html+='<td colspan="6" class="text-center text-muted py-4">';
|
||||
html+='Belum ada barcode yang discan.';
|
||||
html+='</td>';
|
||||
html+='</tr>';
|
||||
html += `
|
||||
<tr>
|
||||
<td colspan="6" class="text-center text-muted py-4">
|
||||
Belum ada barang yang discan.
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
|
||||
}else{
|
||||
} else {
|
||||
|
||||
$.each(daftarBarang,function(i,v){
|
||||
$.each(daftarBarang, function (i, v) {
|
||||
|
||||
html+='<tr>';
|
||||
html+='<td>'+(i+1)+'</td>';
|
||||
html+='<td><strong>'+v.barcode+'</strong></td>';
|
||||
html+='<td>'+v.kode_detail+'</td>';
|
||||
html+='<td>'+v.nama_barang+'</td>';
|
||||
html+='<td>'+(v.serial_number?v.serial_number:'-')+'</td>';
|
||||
html+='<td class="text-center">';
|
||||
html+='<button class="btn btn-sm btn-outline-danger btnRemove" data-id="'+v.barcode_id+'">';
|
||||
html+='<i class="bi bi-trash"></i>';
|
||||
html+='</button>';
|
||||
html+='</td>';
|
||||
html+='</tr>';
|
||||
html += `
|
||||
<tr>
|
||||
<td>${i + 1}</td>
|
||||
<td><strong>${v.barcode}</strong></td>
|
||||
<td>${v.kode_detail}</td>
|
||||
<td>${v.nama_barang}</td>
|
||||
<td>${v.serial_number ? v.serial_number : '-'}</td>
|
||||
|
||||
<td class="text-center align-middle">
|
||||
<div class="form-check d-flex justify-content-center mb-0">
|
||||
<input
|
||||
class="form-check-input pilihBarang"
|
||||
type="checkbox"
|
||||
value="${v.barcode_id}"
|
||||
data-barcode="${v.barcode}">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
html+='</tbody>';
|
||||
html+='</table>';
|
||||
html+='</div>';
|
||||
html += '</tbody>';
|
||||
html += '</table>';
|
||||
html += '</div>';
|
||||
|
||||
$("#tableBarcode").html(html);
|
||||
$('#tableBarcode').html(html);
|
||||
|
||||
if (daftarBarang.length === 1) {
|
||||
$(".pilihBarang").prop("checked", false);
|
||||
$(".pilihBarang").first().prop("checked", true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$(document).on("click",".btnRemove",function(){
|
||||
// function renderTable(){
|
||||
|
||||
let id=$(this).data("id");
|
||||
// let html='';
|
||||
|
||||
daftarBarang=daftarBarang.filter(function(v){
|
||||
return v.barcode_id!=id;
|
||||
});
|
||||
// html+='<div class="table-responsive">';
|
||||
// html+='<table class="table table-bordered table-hover table-sm mb-0">';
|
||||
// html+='<thead>';
|
||||
// html+='<tr>';
|
||||
// html+='<th width="50">No</th>';
|
||||
// html+='<th width="180">Barcode</th>';
|
||||
// html+='<th width="150">Kode Barang</th>';
|
||||
// html+='<th>Nama Barang</th>';
|
||||
// html+='<th width="180">Serial Number</th>';
|
||||
// html+='<th width="80" class="text-center">Action</th>';
|
||||
// html+='</tr>';
|
||||
// html+='</thead>';
|
||||
// html+='<tbody>';
|
||||
|
||||
renderTable();
|
||||
// if(daftarBarang.length==0){
|
||||
|
||||
$("#serial_number").focus();
|
||||
// html+='<tr>';
|
||||
// html+='<td colspan="6" class="text-center text-muted py-4">';
|
||||
// html+='Belum ada barcode yang discan.';
|
||||
// html+='</td>';
|
||||
// html+='</tr>';
|
||||
|
||||
// }else{
|
||||
|
||||
// $.each(daftarBarang,function(i,v){
|
||||
|
||||
// html+='<tr>';
|
||||
// html+='<td>'+(i+1)+'</td>';
|
||||
// html+='<td><strong>'+v.barcode+'</strong></td>';
|
||||
// html+='<td>'+v.kode_detail+'</td>';
|
||||
// html+='<td>'+v.nama_barang+'</td>';
|
||||
// html+='<td>'+(v.serial_number?v.serial_number:'-')+'</td>';
|
||||
// html+='<td class="text-center">';
|
||||
// html+='<button class="btn btn-sm btn-outline-danger btnRemove" data-id="'+v.barcode_id+'">';
|
||||
// html+='<i class="bi bi-trash"></i>';
|
||||
// html+='</button>';
|
||||
// html+='</td>';
|
||||
// html+='</tr>';
|
||||
|
||||
// });
|
||||
|
||||
// }
|
||||
|
||||
// html+='</tbody>';
|
||||
// html+='</table>';
|
||||
// html+='</div>';
|
||||
|
||||
// $("#tableBarcode").html(html);
|
||||
|
||||
// }
|
||||
|
||||
|
||||
$(document).on("change", ".pilihBarang", function(){
|
||||
if($(this).is(":checked")){
|
||||
$(".pilihBarang").not(this).prop("checked", false);
|
||||
}
|
||||
});
|
||||
|
||||
function getSelectedBarcodeRows(){
|
||||
let selectedIds = $(".pilihBarang:checked").map(function(){
|
||||
return String($(this).val());
|
||||
}).get();
|
||||
|
||||
if(selectedIds.length === 0){
|
||||
return [];
|
||||
}
|
||||
|
||||
return daftarBarang.filter(function(v){
|
||||
return selectedIds.indexOf(String(v.barcode_id)) !== -1;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
let html5QrCode=null;
|
||||
|
||||
@@ -400,7 +501,7 @@ $("#btnCamera").click(function(){
|
||||
$("#serial_number")
|
||||
.val(decodedText);
|
||||
|
||||
saveSerial();
|
||||
getBarcodeId();
|
||||
|
||||
});
|
||||
|
||||
@@ -625,8 +726,9 @@ $('#btnSimpan').click(function(){
|
||||
// ================= RESET FORM KELUAR =================
|
||||
function resetFormKeluar(){
|
||||
$('#tanggal_keluar').val('');
|
||||
$('#qty_keluar').val('');
|
||||
$('#keterangan_keluar').val('');
|
||||
daftarBarang = [];
|
||||
renderTable();
|
||||
}
|
||||
|
||||
loadKasOut();
|
||||
@@ -683,28 +785,41 @@ function loadItems(warehouse_id){
|
||||
$('#btnKeluar').click(function(){
|
||||
|
||||
let btn = $(this);
|
||||
let selectedRows = getSelectedBarcodeRows();
|
||||
|
||||
if(selectedRows.length !== 1){
|
||||
Swal.fire({
|
||||
icon: 'warning',
|
||||
title: 'Pilih 1 barang',
|
||||
text: 'Pengeluaran hanya boleh 1 barcode item per proses.'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let selected = selectedRows[0];
|
||||
|
||||
let data = {
|
||||
account_biaya: $('#account_biaya').val(),
|
||||
tanggal_keluar: $('#tanggal_keluar').val(),
|
||||
warehouse_id_keluar: $('#warehouse_id_keluar').val(),
|
||||
barang_id: $('#barang_id').val(),
|
||||
qty_keluar: $('#qty_keluar').val(),
|
||||
keterangan_keluar: $('#keterangan_keluar').val()
|
||||
account_biaya: $('#account_biaya').val(),
|
||||
tanggal_keluar: $('#tanggal_keluar').val(),
|
||||
keterangan_keluar: $('#keterangan_keluar').val(),
|
||||
selected_barcode: selected.barcode_id
|
||||
};
|
||||
|
||||
let url = "<?= base_url('items/keluarkan'); ?>";
|
||||
|
||||
// 🔥 loading state
|
||||
btn.prop('disabled', true).html('Menyimpan...');
|
||||
|
||||
$.post(url, data, function(res){
|
||||
|
||||
if(res.status){
|
||||
|
||||
$('#modalItem').modal('hide');
|
||||
$('#modalKeluar').modal('hide');
|
||||
table.ajax.reload(null,false);
|
||||
|
||||
daftarBarang = [];
|
||||
renderTable();
|
||||
$("#serial_number").val("");
|
||||
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Berhasil',
|
||||
@@ -741,68 +856,68 @@ $('#btnKeluar').click(function(){
|
||||
// ================= END URUSAN KELUAR ===============
|
||||
// =====================================================
|
||||
|
||||
// ================= DELETE =================
|
||||
$(document).on('click','.btn-delete',function(){
|
||||
// // ================= DELETE =================
|
||||
// $(document).on('click','.btn-delete',function(){
|
||||
|
||||
let id = $(this).data('id');
|
||||
let btn = $(this);
|
||||
// let id = $(this).data('id');
|
||||
// let btn = $(this);
|
||||
|
||||
Swal.fire({
|
||||
title: 'Hapus data?',
|
||||
text: "Data tidak bisa dikembalikan!",
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#d33',
|
||||
cancelButtonColor: '#3085d6',
|
||||
confirmButtonText: 'Ya, hapus!',
|
||||
cancelButtonText: 'Batal'
|
||||
}).then((result) => {
|
||||
// Swal.fire({
|
||||
// title: 'Hapus data?',
|
||||
// text: "Data tidak bisa dikembalikan!",
|
||||
// icon: 'warning',
|
||||
// showCancelButton: true,
|
||||
// confirmButtonColor: '#d33',
|
||||
// cancelButtonColor: '#3085d6',
|
||||
// confirmButtonText: 'Ya, hapus!',
|
||||
// cancelButtonText: 'Batal'
|
||||
// }).then((result) => {
|
||||
|
||||
if(result.isConfirmed){
|
||||
// if(result.isConfirmed){
|
||||
|
||||
btn.prop('disabled', true).html('Menghapus...');
|
||||
// btn.prop('disabled', true).html('Menghapus...');
|
||||
|
||||
$.get("<?= base_url('items/delete/'); ?>"+id,function(res){
|
||||
// $.get("<?= base_url('items/delete/'); ?>"+id,function(res){
|
||||
|
||||
if(res.status){
|
||||
// if(res.status){
|
||||
|
||||
table.ajax.reload(null,false);
|
||||
// table.ajax.reload(null,false);
|
||||
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Berhasil',
|
||||
text: res.message || 'Data berhasil dihapus',
|
||||
timer: 1500,
|
||||
showConfirmButton: false
|
||||
});
|
||||
// Swal.fire({
|
||||
// icon: 'success',
|
||||
// title: 'Berhasil',
|
||||
// text: res.message || 'Data berhasil dihapus',
|
||||
// timer: 1500,
|
||||
// showConfirmButton: false
|
||||
// });
|
||||
|
||||
}else{
|
||||
// }else{
|
||||
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Gagal',
|
||||
text: res.message || 'Gagal menghapus data'
|
||||
});
|
||||
}
|
||||
// Swal.fire({
|
||||
// icon: 'error',
|
||||
// title: 'Gagal',
|
||||
// text: res.message || 'Gagal menghapus data'
|
||||
// });
|
||||
// }
|
||||
|
||||
},'json')
|
||||
.fail(function(){
|
||||
// },'json')
|
||||
// .fail(function(){
|
||||
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Error',
|
||||
text: 'Koneksi ke server gagal'
|
||||
});
|
||||
// Swal.fire({
|
||||
// icon: 'error',
|
||||
// title: 'Error',
|
||||
// text: 'Koneksi ke server gagal'
|
||||
// });
|
||||
|
||||
})
|
||||
.always(function(){
|
||||
btn.prop('disabled', false).html('Hapus');
|
||||
});
|
||||
// })
|
||||
// .always(function(){
|
||||
// btn.prop('disabled', false).html('Hapus');
|
||||
// });
|
||||
|
||||
}
|
||||
});
|
||||
// }
|
||||
// });
|
||||
|
||||
});
|
||||
// });
|
||||
|
||||
// ================= DETAIL =================
|
||||
$(document).on('click','.btn-detail',function(){
|
||||
@@ -920,5 +1035,73 @@ $('#btnAdjust').click(function(){
|
||||
|
||||
});
|
||||
|
||||
// ================= PRINT BARCODE =================
|
||||
$(document).on('click', '.btn-print', function () {
|
||||
|
||||
let id = $(this).data('id');
|
||||
|
||||
Swal.fire({
|
||||
title: 'Cetak Barcode',
|
||||
html: `
|
||||
<div class="text-left">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="print_column" class="font-weight-bold">
|
||||
Jumlah Kolom
|
||||
</label>
|
||||
<select id="print_column" class="form-control">
|
||||
<option value="1">1 Kolom</option>
|
||||
<option value="2">2 Kolom</option>
|
||||
<option value="3" selected>3 Kolom (Rekomendasi)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-0">
|
||||
<label for="duplicat" class="font-weight-bold">
|
||||
Jumlah Cetak per Barcode
|
||||
</label>
|
||||
<select id="duplicat" class="form-control">
|
||||
<option value="1" selected>1 Label</option>
|
||||
<option value="2">2 Label</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
`,
|
||||
icon: 'question',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Cetak',
|
||||
cancelButtonText: 'Batal',
|
||||
confirmButtonColor: '#f0ad4e',
|
||||
preConfirm: () => {
|
||||
|
||||
let column = $('#print_column').val();
|
||||
let duplicat = $('#duplicat').val();
|
||||
|
||||
return {
|
||||
column: column,
|
||||
duplicat: duplicat
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}).then((result) => {
|
||||
|
||||
if (!result.isConfirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.open(
|
||||
"<?= base_url('items/print_barcode/'); ?>" +
|
||||
id +
|
||||
"?column=" + result.value.column +
|
||||
"&duplicat=" + result.value.duplicat,
|
||||
"_blank"
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user