/*******************************************************************
PHP Class : /Controller/Gel/HutangController
Description : Transaksi Pembayaran Hutang Supplier
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : March 7th, 2011.
Last Modified : September 10th, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
var GELHutangJS = {
PHP: '',
KODE: '',
index: function(q){
$('#butMode').click(() => this.tx_mode());
$('#butBatal').click(() => this.tx_batal());
if (FoniaJS.User.Level>0) $('#butMode').hide();
this.data_query('master', 'view', ((typeof(q)!=='undefined') ? q : ''));
},
tx_mode: function(){
var mode = ($('#Mode_Tampil').val()==1) ? 0 : 1;
$('#Mode_Tampil').val(mode);
$('#butMode').html(''+(mode==1?'Semua':'Normal'));
this.data_query('tabel-nota');
},
tx_batal: function(){
$('#divTXNota').removeClass('d-none');
$('#divDetailNota').addClass('d-none');
$('#divDetailBayar').addClass('d-none');
if (FoniaJS.User.Level==0) $('#butMode').removeClass('d-none');
$('#butBatal').addClass('d-none');
$('#butBrow').prop('disabled', false).removeClass('btn-secondary').addClass('btn-info');
$('#Nama_Sup').prop('disabled', false).removeClass('disabled').addClass('enabled');
this.data_query('tabel-nota');
},
sup_brow: function(){
var _isi = new String('
');
this.winBSup = FoniaJS.showWindow('BSup', 'Daftar Supplier', _isi, 'xl', '', () => {
$('#winBSup')
.find('#Cari_Sup').keydown((e) => {
var key = e.keyCode || e.which || 0;
if (key==13 && e.target.value!='') this.data_query('brow-sup');
}).end()
.find('#butSearch').click(() => this.data_query('brow-sup')).end()
.find('#butAll').click(() => {
$('#winBSup').find('#Cari_Sup').val('');
this.data_query('brow-sup');
});
this.data_query('brow-sup');
FoniaJS.setFocus('#Cari_Sup');
});
},
sup_select: function(acell){
FoniaJS.closeWindow(this.winBSup);
$('#SupID').val(acell[0]);
$('#Nama_Sup').val(acell[2]);
$('#Alamat_Sup').val(acell[4]);
this.data_query('tabel-nota');
},
nota_select: function(acell){
new Request({
url: this.PHP + '/form_nota',
sendParam: ['No_Beli='+acell[1],'Tipe_Nota='+acell[0]],
onSuccess: (ajson) => {
$('#divDetailNota').html(ajson.html);
$('#divTXNota').addClass('d-none');
$('#divDetailNota').removeClass('d-none');
$('#divDetailBayar').removeClass('d-none');
if (FoniaJS.User.Level==0) $('#butMode').addClass('d-none');
$('#butBatal').removeClass('d-none');
$('#butBrow').prop('disabled', true).removeClass('btn-info').addClass('btn-secondary');
$('#Nama_Sup').prop('disabled', true).removeClass('enabled').addClass('disabled');
this.data_query('tabel-bayar');
}
}).send();
},
bayar_show: function(){
new Request({
url: this.PHP + '/form_bayar',
sendParam: ['No_Beli','Total_Sisa'],
onSuccess: (ajson) => {
this.winBayar = FoniaJS.showWindow('Bayar', 'Detail Pembayaran', ajson.html, 'lg', [{},{i:'butTutup'},{i:'butWSimpan',v:'Simpan',c:'success'}], () => {
$('#winBayar').find('#butWSimpan').click(() => this.bayar_simpan());
FoniaJS.setFocus('#Total_Bayar');
}, false);
}
}).send();
},
bayar_hapus: function(acell){
FoniaJS.showConfirm('Konfirmasi', 'Hapus item "'+acell[1]+'" ?', () => {
new Request.JSONF({
url: this.PHP + '/table_bayar',
sendParam: ['mode_detail=delete','No_Beli','ID='+acell[0]]
}).send();
}, 'danger');
},
bayar_simpan: function(){
if ((FoniaJS.StrToFloat($('#Total_Bayar').val()) + FoniaJS.StrToFloat($('#Total_Potong').val())) > $('#Total_Sisa').val()){
FoniaJS.showError("Jumlah pelunasan melebihi jumlah faktur!");
return;
}
new Request.JSONF({
url: this.PHP + '/table_bayar',
sendParam: ['mode_detail=insert','SupID','No_Beli','Tgl_Bayar','Kode_Rek','Total_Bayar','Total_Potong','Tipe_Nota','Nama_Sup'],
onSuccess: () => FoniaJS.closeWindow(this.winBayar)
}).send();
},
data_query: function(tipe, mode, kd_tx){
if (tipe=="master"){
new Request({
url: this.PHP + '/form_master',
sendParam: ['SupID'+((typeof(kd_tx)!=='undefined')?'='+kd_tx:'')],
onSuccess: (ajson) => {
$('#divTXMaster').html(ajson.html);
this.tx_batal();
FoniaJS.AutoComplete('#Nama_Sup', this.PHP + '/auto_sup', [], {'selectFunc': this.Sup_Comp});
$('#Nama_Sup').click(() => $('#Nama_Sup').select());
$('#butBrow').click(() => this.sup_brow());
if (ajson.error) {
FoniaJS.showError(ajson.error);
}
FoniaJS.setFocus('#Nama_Sup');
}
}).send();
} else if (tipe=="tabel-nota"){
new Request.JSONF({
url: this.PHP + '/table_nota',
sendParam: ['SupID','Mode_Tampil']
}).send();
} else if (tipe=="tabel-bayar"){
new Request.JSONF({
url: this.PHP + '/table_bayar',
sendParam: ['No_Beli','Lunas','Mode_Tampil']
}).send();
} else if (tipe=="brow-sup"){
new Request.JSONF({
url: this.PHP + '/brow_sup',
sendParam: ['Cari_Sup'],
onSuccess: () => FoniaJS.setFocus('#Cari_Sup')
}).send();
}
},
Sup_Comp: function(item){
$('#SupID').val(item.value);
$('#Alamat_Sup').val(item.data);
GELHutangJS.data_query('tabel-nota');
}
};