288 lines
12 KiB
JavaScript
288 lines
12 KiB
JavaScript
/*******************************************************************
|
|
|
|
App. Name : INVENTORY AND SALES SYSTEMS
|
|
Module : /apps/js/iss/opname.js
|
|
Desc. : JS - Transaksi Opname Stok Barang
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : May 24th, 2010.
|
|
Last Modified : April 10th, 2026.
|
|
|
|
(c) 2010 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
|
|
|
*******************************************************************/
|
|
|
|
var OpnameJS = {
|
|
PHP: '',
|
|
KODE: '',
|
|
|
|
loading: function(q){
|
|
$('#butTambah').click(function(){this.tx_tambah();}.bind(this));
|
|
$('#butUbah').click(function(){this.tx_ubah();}.bind(this));
|
|
$('#butHapus').click(function(){this.tx_hapus();}.bind(this));
|
|
$('#butSimpan').click(function(){this.tx_simpan();}.bind(this));
|
|
$('#butBatal').click(function(){this.tx_batal();}.bind(this));
|
|
$('#butPrint').click(function(){this.tx_print();}.bind(this));
|
|
this.data_query('master', 'view', ((typeof(q)!=='undefined') ? q : ''));
|
|
},
|
|
|
|
tx_brow: function(){
|
|
var _isi = new String('<div class="row mb-1"><div class="col"><div class="input-group"><input class="form-control" id="Cari_TX" placeholder="Kunci Pencarian" type="text"><button class="btn btn-info shadow-none" type="button" id="butSearch">Cari</button><button class="btn btn-secondary shadow-none" type="button" id="butAll">Semua</button></div></div></div><div id="divBrowTX"> </div>');
|
|
this.winBTX = FoniaJS.showWindow('BTX', 'Daftar Transaksi', _isi, 900, '', function(){
|
|
$('#winBTX')
|
|
.find('#Cari_TX').keydown(function(e){
|
|
var key = e.keyCode || e.which || 0;
|
|
if (key==13 && e.target.value!='') this.data_query('brow-tx');
|
|
}.bind(this)).end()
|
|
.find('#butSearch').click(function(e){
|
|
this.data_query('brow-tx');
|
|
}.bind(this)).end()
|
|
.find('#butAll').click(function(){
|
|
$('#winBTX').find('#Cari_TX').val('');
|
|
this.data_query('brow-tx');
|
|
}.bind(this));
|
|
this.data_query('brow-tx');
|
|
FoniaJS.setFocus('#Cari_TX');
|
|
}.bind(this));
|
|
},
|
|
|
|
tx_select: function(acell){
|
|
FoniaJS.closeWindow(this.winBTX);
|
|
$('#No_Opname').val(acell[0]);
|
|
this.data_query('master', 'view');
|
|
},
|
|
|
|
tx_tambah: function(){
|
|
this.data_query('master', 'add');
|
|
},
|
|
|
|
tx_ubah: function(){
|
|
if (!$('#No_Opname').val()){
|
|
FoniaJS.showError("Silakan masukkan Nomor Transaksi !");
|
|
return;
|
|
}
|
|
FoniaJS.showAuth(function(){this.data_query('master', 'edit')}.bind(this), this, 'EDIT '+$('#No_Opname').val());
|
|
},
|
|
|
|
tx_hapus: function(){
|
|
if (!$('#No_Opname').val()){
|
|
FoniaJS.showError("Silakan masukkan Nomor Transaksi !");
|
|
return;
|
|
}
|
|
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan hapus <strong>'+$('#No_Opname').val()+'</strong> ?', function(){
|
|
FoniaJS.showAuth(function(){
|
|
new Request.JSON({
|
|
url: this.PHP,
|
|
sendParam: ['data=delete','No_Opname'],
|
|
onSuccess: function(adata){
|
|
if (adata.status==true){
|
|
$('#No_Opname').val('');
|
|
this.data_query('master', 'view');
|
|
FoniaJS.showInfo('Proses hapus data sukses!');
|
|
}else{
|
|
FoniaJS.showInfo('Ada masalah dalam proses hapus data!');
|
|
}
|
|
}.bind(this)
|
|
}).send();
|
|
}.bind(this), this, 'DELETE '+$('#No_Opname').val());
|
|
}.bind(this), 'danger');
|
|
},
|
|
|
|
tx_simpan: function(){
|
|
if ($('#CabID').val()==0){
|
|
FoniaJS.showError("Silakan pilih Nama Cabang !");
|
|
return;
|
|
}
|
|
this.data_query('master', 'save');
|
|
},
|
|
|
|
tx_batal: function(){
|
|
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan membatalkan ?', function(){
|
|
this.data_query('master', 'cancel');
|
|
$('#No_Opname').val('');
|
|
}.bind(this), 'danger');
|
|
},
|
|
|
|
tx_print: function(prt){
|
|
if ($('#No_Opname').val()) {
|
|
var cetak = new cPRINTER(FoniaJS.WEB_PATH+'apps/php/repo/nota.php');
|
|
cetak.add_param("data", "nota-opname");
|
|
cetak.add_param("Nomor_Cetak", $('#No_Opname').val());
|
|
if (prt) cetak.doPrint(); else cetak.doPreview();
|
|
return;
|
|
}
|
|
FoniaJS.showError("Silakan masukkan Nomor Transaksi !");
|
|
},
|
|
|
|
produk_brow: function(){
|
|
if ($('#CabID').val()==0){
|
|
FoniaJS.showError("Silakan pilih Nama Cabang !");
|
|
return;
|
|
}
|
|
var _isi = new String('<div class="row mb-1"><div class="col"><div class="input-group"><input class="form-control" id="Cari_Produk" placeholder="Kunci Pencarian" type="text"><button class="btn btn-info shadow-none" type="button" id="butSearch">Cari</button><button class="btn btn-secondary shadow-none" type="button" id="butAll">Semua</button></div></div></div><div id="divBrowProduk"> </div>');
|
|
this.winBProduk = FoniaJS.showWindow('BProduk', 'Daftar Barang', _isi, 900, '', function(){
|
|
$('#winBProduk')
|
|
.find('#Cari_Produk').keydown(function(e){
|
|
var key = e.keyCode || e.which || 0;
|
|
if (key==13 && e.target.value!='') this.data_query('brow-produk');
|
|
}.bind(this)).end()
|
|
.find('#butSearch').click(function(e){
|
|
this.data_query('brow-produk');
|
|
}.bind(this)).end()
|
|
.find('#butAll').click(function(){
|
|
$('#winBProduk').find('#Cari_Produk').val('');
|
|
this.data_query('brow-produk');
|
|
}.bind(this));
|
|
this.data_query('brow-produk');
|
|
FoniaJS.setFocus('#Cari_Produk');
|
|
}.bind(this));
|
|
},
|
|
|
|
produk_select: function(acell){
|
|
FoniaJS.closeWindow(this.winBProduk);
|
|
this.detail_produk('insert', 0, acell[0], acell[1], acell[2]);
|
|
},
|
|
|
|
detail_produk: function(mode, ID, InvID, SatuanID, HPP){
|
|
new Request.JSON({
|
|
url: this.PHP,
|
|
sendParam: ['data=detail-produk','mode','mode_detail='+mode,'No_Opname','ID='+ID,'InvID='+InvID,'SatuanID='+SatuanID,'HPP='+HPP],
|
|
onSuccess: (a) => {
|
|
this.winDetail = FoniaJS.showWindow('Detail', 'Detail Barang', a.html, 600, [{},{i:'butTutup'},{i:'butWSimpan',v:'Simpan',c:'success'}], () => {
|
|
FoniaJS.AutoComplete('#Nama_Produk', this.PHP, ['data=auto-produk','No_Opname','Tgl_Opname','CabID'], {'selectFunc': OpnameJS.Produk_Comp});
|
|
$('#winDetail')
|
|
.find('#butWSimpan').click(() => this.detail_simpan()).end()
|
|
.find('#Qty').keyup((e) => {
|
|
if (parseFloat(e.target.value) == 0) return false;
|
|
if (-1!==$.inArray(e.which, [13,9])) this.detail_simpan();
|
|
});
|
|
if (mode == 'insert' && InvID == 0) {
|
|
FoniaJS.setFocus('#Nama_Produk');
|
|
} else {
|
|
FoniaJS.setFocus('#Qty');
|
|
}
|
|
this.update_stok();
|
|
}, null, false);
|
|
}
|
|
}).send();
|
|
},
|
|
|
|
detail_tambah: function(){
|
|
if ($('#CabID').val()==0){
|
|
FoniaJS.showError("Silakan pilih Nama Cabang !");
|
|
return;
|
|
}
|
|
this.detail_produk('insert', 0, 0, 0, 0);
|
|
},
|
|
|
|
detail_ubah: function(acell){
|
|
this.detail_produk('update', acell[0], 0, 0, 0);
|
|
},
|
|
|
|
detail_hapus: function(acell){
|
|
FoniaJS.showConfirm('Konfirmasi', 'Hapus item <strong>"'+acell[2]+'"</strong> ?', function(){
|
|
new Request.JSONF({
|
|
url: this.PHP,
|
|
sendParam: ['data=tabel-detail','mode','mode_detail=delete','No_Opname','ID='+acell[0]]
|
|
}).send();
|
|
}.bind(this), 'danger');
|
|
},
|
|
|
|
detail_simpan: function(){
|
|
if (parseInt($('#InvID').val())==0) {
|
|
FoniaJS.showError('Silakan masukkan Nama Barang !');
|
|
return;
|
|
}
|
|
var _mdetail = $('#mode_detail').val();
|
|
new Request.JSONF({
|
|
url: this.PHP,
|
|
sendParam: ['data=tabel-detail','mode','mode_detail','No_Opname','CabID','ID','InvID','SatuanID','Qty','Harga_Beli'],
|
|
onSuccess: function(){
|
|
if (_mdetail=='insert') { this.detail_tambah(); } else FoniaJS.closeWindow(this.winDetail);
|
|
}.bind(this)
|
|
}).send();
|
|
},
|
|
|
|
data_query: function(tipe, mode, kd_tx){
|
|
if (tipe=="master"){
|
|
var sparam = ['data=master','mode='+mode,'No_Opname'+((typeof(kd_tx)!=='undefined')?'='+kd_tx:'')];
|
|
if ((mode ?? '')=='save') sparam = ['data=master','mode=save','No_Opname','Tgl_Opname','CabID','Catatan'];
|
|
new Request.JSON({
|
|
url: this.PHP,
|
|
sendParam: sparam,
|
|
onSuccess: function(ajson){
|
|
$('#divTXMaster').html(ajson.html);
|
|
$('#No_Opname').keyup(function(e){
|
|
if ((e.which || e.keyCode) == 13) {
|
|
if (($("#No_Opname")) && ($("#No_Opname").val() !== '')) this.data_query('master');
|
|
}
|
|
}.bind(this));
|
|
this.data_query('tabel-detail');
|
|
if ($.inArray($("#mode").val(),['add','edit']) !== -1) {
|
|
$('#butBrow').prop('disabled', true).removeClass('btn-info').addClass('btn-secondary');
|
|
$('#butTambah').addClass('d-none');
|
|
$('#butUbah').addClass('d-none');
|
|
$('#butHapus').addClass('d-none');
|
|
$('#butPrint').addClass('d-none');
|
|
$('#butSimpan').removeClass('d-none');
|
|
$('#butBatal').removeClass('d-none');
|
|
} else {
|
|
$('#butBrow').prop('disabled', false).removeClass('btn-secondary').addClass('btn-info');
|
|
$('#butTambah').removeClass('d-none');
|
|
$('#butUbah').removeClass('d-none');
|
|
$('#butHapus').removeClass('d-none');
|
|
$('#butPrint').removeClass('d-none');
|
|
$('#butSimpan').addClass('d-none');
|
|
$('#butBatal').addClass('d-none');
|
|
}
|
|
if (ajson.error) {
|
|
FoniaJS.showError(ajson.error);
|
|
FoniaJS.setFocus('#No_Opname');
|
|
}
|
|
if ($('#mode').val()=='print') this.tx_print(true);
|
|
}.bind(this)
|
|
}).send();
|
|
} else if (tipe=="tabel-detail"){
|
|
new Request.JSONF({
|
|
url: this.PHP,
|
|
sendParam: ['data=tabel-detail','mode','No_Opname']
|
|
}).send();
|
|
} else if (tipe=="brow-tx"){
|
|
new Request.JSONF({
|
|
url: this.PHP,
|
|
sendParam: ['data=brow-tx','Cari_TX'],
|
|
onSuccess: function(){
|
|
FoniaJS.setFocus('#Cari_TX');
|
|
}
|
|
}).send();
|
|
} else if (tipe=="brow-produk"){
|
|
new Request.JSONF({
|
|
url: this.PHP,
|
|
sendParam: ['data=brow-produk','CabID','Cari_Produk'],
|
|
onSuccess: function(){
|
|
FoniaJS.setFocus('#Cari_Produk');
|
|
}
|
|
}).send();
|
|
}
|
|
},
|
|
|
|
Produk_Comp: function(item){
|
|
var adata = item.data.split(':');
|
|
$('#InvID').val(item.value);
|
|
$('#SatuanID').val(adata[3]);
|
|
$('#Kode_Barang').val(adata[0]);
|
|
$('#Nama_Satuan').val(adata[2]);
|
|
$('#Harga_Beli').val(adata[4]);
|
|
$('#Kali').val(adata[5]);
|
|
OpnameJS.update_stok();
|
|
FoniaJS.setFocus('#Qty');
|
|
},
|
|
|
|
update_stok: function(){
|
|
new Request.JSONF({
|
|
url: this.PHP,
|
|
sendParam: ['data=cek_stok','Tgl_Opname','CabID','InvID','Kali']
|
|
}).send();
|
|
}
|
|
|
|
};
|