/*******************************************************************
PHP Class : /Controller/Inv/BelireturController
Description : Transaksi Retur Pembelian
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : May 22th, 2010.
Last Modified : September 21st, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
var BeliReturJS = {
PHP: '',
KODE: '',
index: function(q){
$('#butTambah').click(() => this.tx_tambah());
$('#butUbah').click(() => this.tx_ubah());
$('#butHapus').click(() => this.tx_hapus());
$('#butSimpan').click(() => this.tx_simpan());
$('#butBatal').click(() => this.tx_batal());
$('#butPrint').click(() => this.tx_print());
this.data_query('master', 'view', ((typeof(q)!=='undefined') ? q : ''));
},
tx_brow: function(){
var _isi = new String('
');
this.winBTX = FoniaJS.showWindow('BTX', 'Daftar Transaksi', _isi, 'xl', '', () => {
$('#winBTX')
.find('#Cari_TX').keydown((e) => {
var key = e.keyCode || e.which || 0;
if (key==13 && e.target.value!='') this.data_query('brow-tx');
}).end()
.find('#butSearch').click(() => this.data_query('brow-tx')).end()
.find('#butAll').click(() => {
$('#winBTX').find('#Cari_TX').val('');
this.data_query('brow-tx');
});
this.data_query('brow-tx');
});
},
tx_select: function(acell){
FoniaJS.closeWindow(this.winBTX);
$('#No_Beli').val(acell[0]);
this.data_query('master', 'view');
},
tx_tambah: function(){
this.data_query('master', 'add');
},
tx_ubah: function(){
if (!$('#No_Beli').val()){
FoniaJS.showError("Silakan masukkan Nomor Transaksi !");
return;
}
FoniaJS.showAuth(() => this.data_query('master', 'edit'), this, 'EDIT '+$('#No_Beli').val());
},
tx_hapus: function(){
if (!$('#No_Beli').val()){
FoniaJS.showError("Silakan masukkan Nomor Transaksi !");
return;
}
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan hapus '+$('#No_Beli').val()+' ?', () => {
FoniaJS.showAuth(() => {
new Request({
url: this.PHP + '/proses_delete',
sendParam: ['No_Beli'],
onSuccess: (ajson) => {
if (ajson.status === true){
$('#No_Beli').val('');
this.data_query('master', 'view');
FoniaJS.showInfo('Proses hapus data sukses!');
} else {
FoniaJS.showInfo('Ada masalah dalam proses hapus data!');
}
}
}).send();
}, this, 'DELETE '+$('#No_Beli').val());
}, 'danger');
},
tx_simpan: function(){
if ($('#CabID').val()==0){
FoniaJS.showError("Silakan pilih Nama Cabang !");
return;
}
if ($('#SupID').val()==0){
FoniaJS.showError("Silakan pilih Nama Supplier !");
return;
}
this.data_query('master', 'save');
},
tx_batal: function(){
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan membatalkan ?', () => {
this.data_query('master', 'cancel');
$('#No_Beli').val('');
}, 'danger');
},
tx_print: function(prt){
if ($('#No_Beli').val()) {
var cetak = new Printer('report/nota/beli_retur');
cetak.add_param("Nomor_Cetak", $('#No_Beli').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('
');
this.winBProduk = FoniaJS.showWindow('BProduk', 'Daftar Barang', _isi, 'xl', '', () => {
$('#winBProduk')
.find('#Cari_Produk').keydown((e) => {
var key = e.keyCode || e.which || 0;
if (key == 13 && e.target.value != '') this.data_query('brow-produk');
}).end()
.find('#butSearch').click(() => this.data_query('brow-produk')).end()
.find('#butAll').click(() => {
$('#winBProduk').find('#Cari_Produk').val('');
this.data_query('brow-produk');
});
this.data_query('brow-produk');
});
},
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, VarianID){
new Request({
url: this.PHP + '/form_produk',
sendParam: ['mode','mode_detail='+mode,'No_Beli','ID='+ID,'InvID='+InvID,'SatuanID='+SatuanID,'VarianID='+VarianID],
onSuccess: (ajson) => {
this.winDetail = FoniaJS.showWindow('Detail', 'Detail Barang', ajson.html, 'lg', [{},{i:'butTutup'},{i:'butWSimpan',v:'Simpan',c:'success'}], () => {
FoniaJS.AutoComplete('#Nama_Produk', this.PHP + '/auto_produk', ['No_Beli','CabID','SupID'], {'selectFunc': this.Produk_Comp});
$('#winDetail')
.find('#butWSimpan').click(() => this.detail_simpan()).end()
.find('#Qty').keyup((e) => {
this.Hitung_Detail();
if (parseFloat(e.target.value) == 0) return false;
if (-1!==$.inArray(e.which, [13,9])) FoniaJS.setFocus('#Harga_Beli');
}).end()
.find('#Harga_Beli').keyup((e) => {
this.Hitung_Detail();
if (e.which==13 && FoniaJS.StrToFloat($('#Jumlah').val())>0) this.detail_simpan();
});
if ($('#mode_detail').val() == 'insert' && $('#InvID').val() == 0) {
FoniaJS.setFocus('#Nama_Produk');
} else {
this.Hitung_Detail();
this.update_Varian();
FoniaJS.setFocus('#Qty');
}
}, false);
}
}).send();
},
detail_tambah: function(){
if ($('#SupID').val()==0){
FoniaJS.showError("Silakan pilih Nama Supplier !");
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 "'+acell[5]+'" ?', () => {
new Request.JSONF({
url: this.PHP + '/table_detail',
sendParam: ['mode','mode_detail=delete','No_Beli','ID='+acell[0]]
}).send();
}, '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 + '/table_detail',
sendParam: ['mode','mode_detail','No_Beli','ID','InvID','SatuanID','VarianID','Qty','Harga_Beli'],
onSuccess: () => {
if (_mdetail=='insert') { this.detail_tambah(); } else FoniaJS.closeWindow(this.winDetail);
}
}).send();
},
data_query: function(tipe, mode, kd_tx){
if (tipe=="master"){
var sparam = ['mode='+mode,'No_Beli'+((typeof(kd_tx)!=='undefined')?'='+kd_tx:'')];
if ((mode ?? '')=='save') sparam = ['mode='+mode,'No_Beli','Tgl_Beli','No_Faktur','CabID','SupID'];
new Request({
url: this.PHP + '/form_master',
sendParam: sparam,
onSuccess: (ajson) => {
$('#divTXMaster').html(ajson.html);
$('#No_Beli').keyup((e) => {
if ((e.which || e.keyCode) == 13) {
if (($("#No_Beli")) && ($("#No_Beli").val() !== '')) this.data_query('master');
}
});
$('#butBrow').click(() => this.tx_brow());
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');
FoniaJS.setFocus('#No_Beli');
} 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);
}
}).send();
} else if (tipe=="tabel-detail"){
new Request.JSONF({
url: this.PHP + '/table_detail',
sendParam: ['mode','No_Beli']
}).send();
} else if (tipe=="brow-tx"){
new Request.JSONF({
url: this.PHP + '/brow_tx',
sendParam: ['Cari_TX'],
onSuccess: () => FoniaJS.setFocus('#Cari_TX')
}).send();
} else if (tipe=="brow-produk"){
new Request.JSONF({
url: this.PHP + '/brow_produk',
sendParam: ['CabID','Cari_Produk'],
onSuccess: () => FoniaJS.setFocus('#Cari_Produk')
}).send();
}
},
Produk_Comp: function(item){
var adata = item.data.split(':');
$('#InvID').val(item.value);
$('#SatuanID').val(adata[0]);
$('#Nama_Satuan').val(adata[2]);
var _vari = $('#VarianID');
_vari.append($('