Perubahan barcode dan inventory
This commit is contained in:
@@ -122,10 +122,12 @@
|
||||
</div>
|
||||
|
||||
<div class="mb-2 d-none" id="wrap_barcode_select">
|
||||
<label for="barcode_select" class="form-label">Barcode ID</label>
|
||||
<label for="barcode_select" class="form-label">Barcode / QR ID</label>
|
||||
<select id="barcode_select" class="form-control select-search"></select>
|
||||
</div>
|
||||
|
||||
<div id="stokSisaQty"></div>
|
||||
|
||||
<div class="mb-2" id="wrap_qty_item">
|
||||
<label for="qty" class="form-label">Qty</label>
|
||||
<input type="number" id="qty" class="form-control" min="0">
|
||||
@@ -232,6 +234,7 @@ $(function(){
|
||||
$('#wrap_item_select').addClass('d-none');
|
||||
$('#wrap_nama_item').removeClass('d-none');
|
||||
$('#wrap_qty_item').removeClass('d-none');
|
||||
$('#wrap_barcode_select').addClass('d-none');
|
||||
|
||||
$('#warehouse_id').html('<option value="">Pilih Gudang</option>');
|
||||
$('#item_select').html('<option value="">Pilih Item</option>');
|
||||
@@ -241,10 +244,12 @@ $(function(){
|
||||
$('#qty').val('');
|
||||
$('#harga').val('');
|
||||
$('#keterangan').val('');
|
||||
$('#barcode_select').val('');
|
||||
|
||||
$('#is_cicilan').prop('checked', false);
|
||||
$('#wrap_cicilan').addClass('d-none');
|
||||
$('#tenor').val('');
|
||||
$('#stokSisaQty').html('');
|
||||
|
||||
setMode('manual');
|
||||
}
|
||||
@@ -359,33 +364,91 @@ $(function(){
|
||||
return;
|
||||
}
|
||||
|
||||
loadItemBarcodes(item_id);
|
||||
// loadItemBarcodes(item_id);
|
||||
loadItemBarcodes(
|
||||
item_id,
|
||||
isEditing ? editData.barcode_id : null
|
||||
);
|
||||
});
|
||||
|
||||
$('#barcode_select').on('change', function(){
|
||||
|
||||
let barcode_id = $(this).val();
|
||||
|
||||
let selected = $(this).find(':selected');
|
||||
let qty_sisa = parseFloat(selected.data('qty_sisa')) || 0;
|
||||
|
||||
// console.log("QTY : " + qty_sisa);
|
||||
if (qty_sisa > 1 ) {
|
||||
$('#stokSisaQty').html('<h6 class="text-success ml-4">Stok : ' + qty_sisa + '</h6><hr>');
|
||||
$('#qty').val('');
|
||||
$('#wrap_qty_item').removeClass('d-none');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// $(document).on('keyup','#qty',function(){
|
||||
// hitungTotal();
|
||||
// });
|
||||
|
||||
// function hitungTotal(){
|
||||
// let qty_sisa = 1000;
|
||||
// $('#stokSisaQty').html('<h6 class="text-success ml-4">Stok : ' + qty_sisa + '</h6><hr>');
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// ================= LOAD BARCODE ITEMS =================
|
||||
function loadItemBarcodes(item_id){
|
||||
// function loadItemBarcodes(item_id){
|
||||
// return $.get("<?= base_url('items/get_list_barcode_id/'); ?>" + item_id, function(res){
|
||||
// if(res && res.length){
|
||||
// let opt = '<option value="">Pilih Item</option>';
|
||||
// res.forEach(i=>{
|
||||
// opt += `<option value="${i.barcode_id}">
|
||||
// ${i.nama_barang} - ${i.barcode} - ${i.serial_number}
|
||||
// </option>`;
|
||||
// });
|
||||
// $('#barcode_select').html(opt);
|
||||
// $('#wrap_barcode_select').removeClass('d-none');
|
||||
|
||||
// // set QTY jadi 1
|
||||
// let qty = Number($('#qty').val());
|
||||
// $('#qty').val(qty + 1);
|
||||
|
||||
// setMode('item');
|
||||
// } else {
|
||||
// $('#wrap_barcode_select').addClass('d-none');
|
||||
// // $('#wrap_barcode_select').removeClass('d-none');
|
||||
// setMode('manual');
|
||||
// }
|
||||
// }, 'json');
|
||||
// }
|
||||
|
||||
function loadItemBarcodes(item_id, selectedBarcode = null){
|
||||
return $.get("<?= base_url('items/get_list_barcode_id/'); ?>" + item_id, function(res){
|
||||
if(res && res.length){
|
||||
let opt = '<option value="">Pilih Item</option>';
|
||||
let opt = '<option value="">Pilih Barcode</option>';
|
||||
res.forEach(i=>{
|
||||
opt += `<option value="${i.barcode_id}">
|
||||
${i.nama_barang} - ${i.barcode} - ${i.serial_number}
|
||||
</option>`;
|
||||
opt += `
|
||||
<option value="${i.barcode_id}" data-qty_sisa="${i.qty_sisa}">
|
||||
${i.nama_barang} - ${i.barcode} - ${i.serial_number}
|
||||
</option>
|
||||
`;
|
||||
});
|
||||
$('#barcode_select').html(opt);
|
||||
if(selectedBarcode){
|
||||
$('#barcode_select').val(selectedBarcode);
|
||||
}
|
||||
$('#wrap_barcode_select').removeClass('d-none');
|
||||
|
||||
// set QTY jadi 1
|
||||
let qty = Number($('#qty').val());
|
||||
$('#qty').val(qty + 1);
|
||||
|
||||
if(!isEditing){
|
||||
$('#qty').val(1);
|
||||
}
|
||||
setMode('item');
|
||||
} else {
|
||||
}else{
|
||||
$('#wrap_barcode_select').addClass('d-none');
|
||||
// $('#wrap_barcode_select').removeClass('d-none');
|
||||
setMode('manual');
|
||||
}
|
||||
}, 'json');
|
||||
},'json');
|
||||
}
|
||||
|
||||
// ================= AUTO HARGA =================
|
||||
@@ -398,8 +461,8 @@ $(function(){
|
||||
// ================= STOK CHECK =================
|
||||
$('#qty').on('input', function(){
|
||||
let qty = parseFloat($(this).val()) || 0;
|
||||
let selected = $('#item_select option:selected');
|
||||
let stok = selected.length ? parseFloat(selected.data('stok')) || 0 : 0;
|
||||
let selected = $('#barcode_select option:selected');
|
||||
let stok = selected.length ? parseFloat(selected.data('qty_sisa')) || 0 : 0;
|
||||
|
||||
if(stok > 0 && qty > stok){
|
||||
Swal.fire('Warning','Stok tidak cukup! Max: ' + stok,'warning');
|
||||
@@ -527,25 +590,7 @@ $(function(){
|
||||
let btnAction = '';
|
||||
if(v.status == 'draft'){
|
||||
|
||||
let btnEditTable = '';
|
||||
if(v.is_cicilan == 0) {
|
||||
btnEditTable = `
|
||||
<button class="btn btn-sm btn-secondary btn-editItem"
|
||||
data-id="${v.id}"
|
||||
data-tanggal_input="${v.tanggal}"
|
||||
data-account="${v.account_id}"
|
||||
data-item="${v.nama_item}"
|
||||
data-qty="${v.qty}"
|
||||
data-harga="${v.harga}"
|
||||
data-warehouse="${v.warehouse_id || ''}"
|
||||
data-item_id="${v.items_id || ''}"
|
||||
data-keterangan="${v.keterangan || ''}"
|
||||
data-is_cicilan="${v.is_cicilan || 0}">
|
||||
Edit
|
||||
</button>`;
|
||||
}
|
||||
btnAction = `
|
||||
${btnEditTable}
|
||||
<button class="btn btn-sm btn-danger btn-delete" data-id="${v.id}">
|
||||
Hapus
|
||||
</button>
|
||||
@@ -614,53 +659,6 @@ $(function(){
|
||||
modal.show();
|
||||
});
|
||||
|
||||
// ================= EDIT =================
|
||||
$(document).on('click','.btn-editItem', function(){
|
||||
action = "edit";
|
||||
edit_id = $(this).data('id');
|
||||
isEditing = true;
|
||||
editData = $(this).data();
|
||||
|
||||
$('#modalTitle').text('Edit Item');
|
||||
resetForm();
|
||||
|
||||
// Set basic fields first
|
||||
$('#account_id').val(editData.account).trigger('change');
|
||||
|
||||
// Wait for account change to complete, then set other fields
|
||||
setTimeout(() => {
|
||||
if(editData.warehouse){
|
||||
$('#warehouse_id').val(editData.warehouse).trigger('change');
|
||||
|
||||
// gak ada checkbox cicilan
|
||||
$('#is_cicilan_group').addClass('d-none');
|
||||
|
||||
// Wait for warehouse items to load
|
||||
setTimeout(() => {
|
||||
$('#item_select').val(editData.item_id).trigger('change');
|
||||
}, 500);
|
||||
} else {
|
||||
$('#nama_item').val(editData.item);
|
||||
}
|
||||
|
||||
|
||||
$('#qty').val(editData.qty);
|
||||
$('#harga').val(editData.harga);
|
||||
$('#tanggal_input').val(editData.tanggal_input);
|
||||
$('#keterangan').val(editData.keterangan);
|
||||
|
||||
}, 500);
|
||||
|
||||
// if(editData.is_cicilan == 1){
|
||||
// $('#qty').prop('disabled', true);
|
||||
// $('#harga').prop('disabled', true);
|
||||
// $('#is_cicilan').prop('disabled', true);
|
||||
// $('#tenor').prop('disabled', true);
|
||||
// }
|
||||
|
||||
modal.show();
|
||||
});
|
||||
|
||||
// ================= SAVE =================
|
||||
|
||||
// ================= SAVE - FIXED SESUAI STYLE ANDA =================
|
||||
@@ -693,6 +691,7 @@ $(function(){
|
||||
qty: parseFloat($('#qty').val()) || 0,
|
||||
harga: parseFloat($('#harga').val()) || 0,
|
||||
keterangan: $('#keterangan').val().trim(),
|
||||
barcode_id: $('#barcode_select').val() || 0,
|
||||
|
||||
is_cicilan: $('#is_cicilan').is(':checked') ? 1 : 0,
|
||||
tenor: parseInt($('#tenor').val()) || 0,
|
||||
@@ -757,7 +756,7 @@ $(function(){
|
||||
btn.prop('disabled', true).html('Menghapus...');
|
||||
|
||||
$.get({
|
||||
url: "<?= base_url('invoices/delete_item/'); ?>" + id,
|
||||
url: "<?= base_url('invoices/delete_item/'); ?>" + id + "/" + `<?= $no_invoice ?>`,
|
||||
dataType: 'json' // ✅ FIXED
|
||||
})
|
||||
.done(function(res){
|
||||
|
||||
Reference in New Issue
Block a user