/*******************************************************************
App. Name : INVENTORY AND SALES SYSTEMS
Module : /apps/js/iss/beli_lunas_sup.js
Desc. : JS - Transaksi Pelunasan Pembelian / Supplier
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : March 7th, 2011.
Last Modified : December 11th, 2025.
(c) 2011 - 2025, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
var BeliLunasSupJS = {
PHP: '',
KODE: '',
loading: function(q){
$('#butSimpan').click(function(){this.tx_simpan();}.bind(this));
$('#butBatal').click(function(){this.tx_batal();}.bind(this));
this.data_query('master', 'view', ((typeof(q)!=='undefined') ? q : ''));
},
tx_simpan: function(mode){
FoniaJS.showConfirm("Konfirmasi", "Yakin akan proses Pelunasan ?", function(){
new Request({
url: this.PHP,
sendParam: ['data=proses-bayar','SupID','Tgl_Bayar'],
onSuccess: function(){
this.data_query('tabel-nota');
}.bind(this)
}).send();
}.bind(this), 'warning');
},
tx_batal: function(){
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan membatalkan ?', function(){
this.data_query('master', 'cancel');
$('#SupID').val(0);
}.bind(this), 'danger');
},
sup_brow: function(){
var _isi = new String('
');
this.winBSup = FoniaJS.showWindow('BSup', 'Daftar Supplier', _isi, 900, '', function(){
$('#winBSup').find('#Cari_Sup').keydown(function(e){
var key = e.keyCode || e.which || 0;
if (key==13 && e.target.value!='') this.data_query('brow-sup');
}.bind(this));
$('#winBSup').find('#butSearch').click(function(e){
this.data_query('brow-sup');
}.bind(this));
$('#winBSup').find('#butAll').click(function(){
$('#winBSup').find('#Cari_Sup').val('');
this.data_query('brow-sup');
}.bind(this));
this.data_query('brow-sup');
FoniaJS.setFocus('#Cari_Sup');
}.bind(this));
},
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');
},
bayar_tampil: function(acell){
new Request.JSON({
url: this.PHP,
sendParam: ['data=detail-bayar'],
onSuccess: function(ajson){
this.winBayar = FoniaJS.showWindow('Bayar', 'Detail Pembayaran', ajson.html, 600, [{},{i:'butTutup'},{i:'butWSimpan',v:'Simpan',c:'success'}], function(){
$('#winBayar')
.find('#butWSimpan').click(function(){this.bayar_simpan();}.bind(this)).end()
.find('#Jumlah_Bayar').keyup(function(e) {this.Hitung_Bayar();}.bind(this)).end()
.find('#Jumlah_Potong').keyup(function(e) {this.Hitung_Bayar();}.bind(this)).end()
.find('#No_Beli').val(acell[0]).end()
.find('#No_Faktur').val(acell[1]).end()
.find('#Tgl_Faktur').val(acell[2]).end()
.find('#Faktur').val(this.IDR_to_USD(acell[3])).end()
.find('#SBayar').val(this.IDR_to_USD(acell[4])).end()
.find('#Jumlah_Faktur').val(this.IDR_to_USD(acell[5])).end()
.find('#Jumlah_Bayar').val(this.IDR_to_USD((acell[6]==0?acell[5]:acell[6]))).end()
.find('#Jumlah_Potong').val(this.IDR_to_USD(acell[7]));
this.Hitung_Bayar();
FoniaJS.setFocus('#Jumlah_Bayar');
}.bind(this), false);
}.bind(this)
}).send();
},
bayar_simpan: function(){
var djumlah = FoniaJS.StrToFloat($('#Jumlah_Faktur').val());
var dbayar = FoniaJS.StrToFloat($('#Jumlah_Bayar').val());
var dpot = FoniaJS.StrToFloat($('#Jumlah_Potong').val());
if (djumlah<(dbayar+dpot)) {
FoniaJS.showError('Jumlah Pembayaran melebihi Jumlah Faktur !');
return;
}
new Request.JSONF({
url: this.PHP,
sendParam: ['data=tabel-nota','mode_detail','SupID','No_Beli','Jumlah_Bayar','Jumlah_Potong'],
onSuccess: function(){
FoniaJS.closeWindow(this.winBayar);
}.bind(this)
}).send();
},
data_query: function(tipe, mode, kd_tx){
if (tipe=="master"){
new Request.JSON({
url: this.PHP,
sendParam: ['data=master','mode='+mode,'SupID'+((typeof(kd_tx)!=='undefined')?'='+kd_tx:'')],
onSuccess: function(ajson){
$('#divTXMaster').html(ajson.html);
FoniaJS.AutoComplete('#Nama_Sup', this.PHP, ['data=auto-sup'], this.Sup_Comp);
$('#Nama_Sup').on('click', function(){
$('#Nama_Sup').select();
});
$('#Disp_Bayar').addClass('border-success');
if (ajson.error) {
FoniaJS.showError(ajson.error);
}
this.data_query('tabel-nota');
FoniaJS.setFocus('#Nama_Sup');
}.bind(this)
}).send();
} else if (tipe=="tabel-nota"){
new Request.JSONF({
url: this.PHP,
sendParam: ['data=tabel-nota','SupID']
}).send();
} else if (tipe=="brow-sup"){
new Request.JSONF({
url: this.PHP,
sendParam: ['data=brow-sup','Cari_Sup'],
onSuccess: function(){
FoniaJS.setFocus('#Cari_Sup');
}
}).send();
}
},
Sup_Comp: function(item){
$('#SupID').val(item.value);
$('#Alamat_Sup').val(item.data);
BeliLunasSupJS.data_query('tabel-nota');
},
Hitung_Bayar: function(){
var djumlah = FoniaJS.StrToFloat($('#Jumlah_Faktur').val());
var dbayar = FoniaJS.StrToFloat($('#Jumlah_Bayar').val());
var dpot = FoniaJS.StrToFloat($('#Jumlah_Potong').val());
$('#Sisa_Bayar').val(FoniaJS.FloatToStr(djumlah-dbayar-dpot, 2));
},
IDR_to_USD: function(value){
var nilai = value.replace(/\./g,'').replace(',','.');
return FoniaJS.FloatToStr(parseFloat(nilai));
}
};