295 lines
13 KiB
JavaScript
295 lines
13 KiB
JavaScript
/*******************************************************************
|
|
|
|
App. Name : INVENTORY AND SALES SYSTEMS
|
|
Module : /apps/js/iss/mutasi.js
|
|
Desc. : JS - Transaksi Mutasi Stok Cabang
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : February 28th, 2011.
|
|
Last Modified : December 10th, 2025.
|
|
|
|
(c) 2011 - 2025, 3FONIA Software; WWW.3FONIA.COM.
|
|
|
|
*******************************************************************/
|
|
|
|
var MutasiJS = {
|
|
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_Mutasi').val(acell[0]);
|
|
this.data_query('master', 'view');
|
|
},
|
|
|
|
tx_tambah: function(){
|
|
this.data_query('master', 'add');
|
|
},
|
|
|
|
tx_ubah: function(){
|
|
if (!$('#No_Mutasi').val()){
|
|
FoniaJS.showError("Silakan masukkan Nomor Transaksi !");
|
|
return;
|
|
}
|
|
FoniaJS.showAuth(function(){this.data_query('master', 'edit')}.bind(this), this, 'EDIT '+$('#No_Mutasi').val());
|
|
},
|
|
|
|
tx_hapus: function(){
|
|
if (!$('#No_Mutasi').val()){
|
|
FoniaJS.showError("Silakan masukkan Nomor Transaksi !");
|
|
return;
|
|
}
|
|
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan hapus <strong>'+$('#No_Mutasi').val()+'</strong> ?', function(){
|
|
FoniaJS.showAuth(function(){
|
|
new Request.JSON({
|
|
url: this.PHP,
|
|
sendParam: ['data=delete','No_Mutasi'],
|
|
onSuccess: function(adata){
|
|
if (adata.status==true){
|
|
$('#No_Mutasi').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_Mutasi').val());
|
|
}.bind(this), 'danger');
|
|
},
|
|
|
|
tx_simpan: function(){
|
|
this.data_query('master', 'save');
|
|
},
|
|
|
|
tx_batal: function(){
|
|
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan membatalkan ?', function(){
|
|
this.data_query('master', 'cancel');
|
|
$('#No_Mutasi').val('');
|
|
}.bind(this), 'danger');
|
|
},
|
|
|
|
tx_print: function(prt){
|
|
if ($('#No_Mutasi').val()) {
|
|
var cetak = new cPRINTER(FoniaJS.WEB_PATH+'apps/php/repo/nota.php');
|
|
cetak.add_param("data", "nota-mutasi");
|
|
cetak.add_param("Nomor_Cetak", $('#No_Mutasi').val());
|
|
if (prt) cetak.doPrint(); else cetak.doPreview();
|
|
return;
|
|
}
|
|
FoniaJS.showError("Silakan masukkan Nomor Transaksi !");
|
|
},
|
|
|
|
produk_brow: function(){
|
|
if ($('#Dari_CabID').val()==0){
|
|
FoniaJS.showError("Silakan pilih Dari Cabang !");
|
|
return;
|
|
}
|
|
if ($('#Ke_CabID').val()==0){
|
|
FoniaJS.showError("Silakan pilih Ke Cabang !");
|
|
return;
|
|
}
|
|
if ($('#Dari_CabID').val()==$('#Ke_CabID').val()){
|
|
FoniaJS.showError("Dari Cabang dan Ke Cabang tidak boleh sama !");
|
|
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_Mutasi','ID='+ID,'InvID='+InvID,'SatuanID='+SatuanID,'HPP='+HPP],
|
|
onSuccess: function(a){
|
|
this.winDetail = FoniaJS.showWindow('Detail', 'Detail Barang', a.html, 600, [{},{i:'butTutup'},{i:'butWSimpan',v:'Simpan',c:'success'}], function(){
|
|
FoniaJS.AutoComplete('#Nama_Produk', this.PHP, ['data=auto-produk','No_Mutasi','Dari_CabID'], {'selectFunc': MutasiJS.Produk_Comp});
|
|
$('#winDetail')
|
|
.find('#butWSimpan').click(function(){this.detail_simpan();}.bind(this)).end()
|
|
.find('#Qty').keyup(function(e){
|
|
this.Hitung_Detail();
|
|
if (parseFloat(e.target.value) == 0) return false;
|
|
if (-1!==$.inArray(e.which, [13,9])) this.detail_simpan();
|
|
}.bind(this));
|
|
if (mode == 'insert' && InvID == 0) {
|
|
FoniaJS.setFocus('#Nama_Produk');
|
|
} else {
|
|
this.Hitung_Detail();
|
|
FoniaJS.setFocus('#Qty');
|
|
}
|
|
}.bind(this), null, false);
|
|
}.bind(this)
|
|
}).send();
|
|
},
|
|
|
|
detail_tambah: function(){
|
|
if ($('#Dari_CabID').val()==0){
|
|
FoniaJS.showError("Silakan pilih Dari Cabang !");
|
|
return;
|
|
}
|
|
if ($('#Ke_CabID').val()==0){
|
|
FoniaJS.showError("Silakan pilih Ke Cabang !");
|
|
return;
|
|
}
|
|
if ($('#Dari_CabID').val()==$('#Ke_CabID').val()){
|
|
FoniaJS.showError("Dari Cabang dan Ke Cabang tidak boleh sama !");
|
|
return;
|
|
}
|
|
this.detail_produk('insert', 0, 0, 0, 0);
|
|
},
|
|
|
|
detail_ubah: function(acell){
|
|
this.detail_produk('update', acell[0], acell[1], acell[2], acell[3]);
|
|
},
|
|
|
|
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_Mutasi','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_Mutasi','Dari_CabID','Ke_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_Mutasi'+((typeof(kd_tx)!=='undefined')?'='+kd_tx:'')];
|
|
if ((mode ?? '')=='save') sparam = ['data=master','mode=save','No_Mutasi','Tgl_Mutasi','Dari_CabID','Ke_CabID','Catatan'];
|
|
new Request.JSON({
|
|
url: this.PHP,
|
|
sendParam: sparam,
|
|
onSuccess: function(ajson){
|
|
$('#divTXMaster').html(ajson.html);
|
|
$('#No_Mutasi').keyup(function(e){
|
|
if ((e.which || e.keyCode) == 13) {
|
|
if (($("#No_Mutasi")) && ($("#No_Mutasi").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_Mutasi');
|
|
}
|
|
}.bind(this)
|
|
}).send();
|
|
} else if (tipe=="tabel-detail"){
|
|
new Request.JSONF({
|
|
url: this.PHP,
|
|
sendParam: ['data=tabel-detail','mode','No_Mutasi']
|
|
}).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','Dari_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]);
|
|
FoniaJS.setFocus('#Qty');
|
|
},
|
|
|
|
Hitung_Detail: function(){
|
|
$('#Jumlah').val(FoniaJS.FloatToStr(FoniaJS.StrToFloat($('#Qty').val()) * FoniaJS.StrToFloat($('#Harga_Beli').val()), 2));
|
|
}
|
|
|
|
};
|