449 lines
21 KiB
JavaScript
449 lines
21 KiB
JavaScript
/*******************************************************************
|
|
|
|
App. Name : INVENTORY AND SALES SYSTEMS
|
|
Module : /apps/js/iss/beli.js
|
|
Desc. : JS - Transaksi Pembelian
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : May 22th, 2010.
|
|
Last Modified : October 19th, 2025.
|
|
|
|
(c) 2010 - 2025, 3FONIA Software; WWW.3FONIA.COM.
|
|
|
|
*******************************************************************/
|
|
|
|
var BeliJS = {
|
|
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));
|
|
$('#butPendingBrow').click(function(){this.pending_brow();}.bind(this));
|
|
$('#butPendingSimpan').click(function(){this.tx_simpan('pending');}.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));
|
|
$('#winBTX').find('#butSearch').click(function(e){
|
|
this.data_query('brow-tx');
|
|
}.bind(this));
|
|
$('#winBTX').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_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;
|
|
}
|
|
if (-1 !== $('#No_Beli').val().search(/BELI/i)){
|
|
this.data_query('master', 'pending-edit')
|
|
return;
|
|
}
|
|
FoniaJS.showAuth(function(){this.data_query('master', 'edit')}.bind(this), 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 <strong>'+$('#No_Beli').val()+'</strong> ?', function(){
|
|
FoniaJS.showAuth(function(){
|
|
new Request.JSON({
|
|
url: this.PHP,
|
|
sendParam: ['data=delete','No_Beli'],
|
|
onSuccess: function(adata){
|
|
if (adata.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!');
|
|
}
|
|
}.bind(this)
|
|
}).send();
|
|
}.bind(this), this, 'DELETE '+$('#No_Beli').val());
|
|
}.bind(this), 'danger');
|
|
},
|
|
|
|
tx_simpan: function(mode){
|
|
if ($('#CabID').val()==0){
|
|
FoniaJS.showError("Silakan pilih Nama Cabang !");
|
|
return;
|
|
}
|
|
if ($('#SupID').val()==0){
|
|
FoniaJS.showError("Silakan pilih Nama Supplier !");
|
|
return;
|
|
}
|
|
if (mode == 'pending'){
|
|
this.data_query('master', 'pending-save');
|
|
return;
|
|
}
|
|
if (parseFloat($('#Total_Hutang').val())==0){
|
|
this.total_show();
|
|
return;
|
|
}
|
|
this.data_query('master', 'save');
|
|
},
|
|
|
|
tx_batal: function(){
|
|
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan membatalkan ?', function(){
|
|
this.data_query('master', 'cancel');
|
|
$('#No_Beli').val('');
|
|
}.bind(this), 'danger');
|
|
},
|
|
|
|
tx_print: function(prt){
|
|
if ($('#No_Beli').val()) {
|
|
var cetak = new cPRINTER(FoniaJS.WEB_PATH+'apps/php/repo/nota.php');
|
|
cetak.add_param("data", "nota-beli");
|
|
cetak.add_param("Nomor_Cetak", $('#No_Beli').val());
|
|
if (prt) cetak.doPrint(); else cetak.doPreview();
|
|
return;
|
|
}
|
|
FoniaJS.showError("Silakan masukkan Nomor Transaksi !");
|
|
},
|
|
|
|
pending_brow: function(){
|
|
var _isi = new String('<div id="divBrowPending"> </div>');
|
|
this.winBPending = FoniaJS.showWindow('BPending', 'Daftar Pending Pembelian', _isi, 900, '', function(){
|
|
this.data_query('brow-pending');
|
|
}.bind(this));
|
|
},
|
|
|
|
pending_select: function(acell){
|
|
FoniaJS.closeWindow(this.winBPending);
|
|
$('#No_Beli').val(acell[0]);
|
|
this.data_query('master', 'pending-edit');
|
|
},
|
|
|
|
pending_delete: function(acell){
|
|
FoniaJS.closeWindow(this.winBPending);
|
|
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan hapus Transaksi Pending "'+acell[0]+'" ?', function(){
|
|
$('#No_Beli').val(acell[0]);
|
|
this.data_query('master', 'pending-delete');
|
|
}.bind(this), 'danger');
|
|
},
|
|
|
|
produk_brow: function(){
|
|
if ($('#SupID').val()==0){
|
|
FoniaJS.showError("Silakan pilih Nama Supplier !");
|
|
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><input type="hidden" id="Filter_Browse" value="all" /></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));
|
|
$('#winBProduk').find('#butSearch').click(function(e){
|
|
this.data_query('brow-produk');
|
|
}.bind(this));
|
|
$('#winBProduk').find('#butAll').click(function(){
|
|
if ($('#Filter_Browse').val()=='filter') {
|
|
$('#Filter_Browse').val('all');
|
|
$('#butAll').html('Semua');
|
|
} else {
|
|
$('#Filter_Browse').val('filter');
|
|
$('#butAll').html('Supplier');
|
|
}
|
|
$('#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]);
|
|
},
|
|
|
|
detail_produk: function(mode, ID, InvID, SatuanID){
|
|
new Request.JSON({
|
|
url: this.PHP,
|
|
sendParam: ['data=detail-produk','No_Beli','mode','mode_detail='+mode,'ID='+ID,'InvID='+InvID,'SatuanID='+SatuanID],
|
|
onSuccess: function(a){
|
|
this.winDetail = FoniaJS.showWindow('Detail', 'Detail Barang', a.html, 700, [{},{i:'butTutup'},{i:'butWSimpan',v:'Simpan',c:'success'}], function(){
|
|
FoniaJS.AutoComplete('#Nama_Produk', this.PHP, ['data=auto-produk','No_Beli','CabID','SupID'], this.Produk_Comp);
|
|
$('#winDetail')
|
|
.find('#butWSimpan').click(function(){this.detail_simpan();}.bind(this)).end()
|
|
.find('#Nama_Produk').on('click', function(){
|
|
$('#Nama_Produk').select();
|
|
}).end()
|
|
.find('#Qty').keyup(function(e) {
|
|
this.Hitung_Detail();
|
|
if (e.which==13 && parseInt(e.target.value)>0) FoniaJS.setFocus('#Harga_Beli');
|
|
}.bind(this)).end()
|
|
.find('#Harga_Beli').keyup(function(e) {
|
|
this.Hitung_Detail();
|
|
if (e.which==13) FoniaJS.setFocus('#Disk_Rupiah');
|
|
}.bind(this)).end()
|
|
.find('#Disk_Rupiah').keyup(function(e) {
|
|
this.Hitung_Detail();
|
|
if (e.which==13) FoniaJS.setFocus('#Disk_Persen1');
|
|
}.bind(this)).end()
|
|
.find('#Disk_Persen1').keyup(function(e) {
|
|
this.Hitung_Detail();
|
|
if (e.which==13) FoniaJS.setFocus('#Disk_Persen2');
|
|
}.bind(this)).end()
|
|
.find('#Disk_Persen2').keyup(function(e) {
|
|
this.Hitung_Detail();
|
|
if (e.which==13) FoniaJS.setFocus('#Disk_Persen3');
|
|
}.bind(this)).end()
|
|
.find('#Disk_Persen3').keyup(function(e) {
|
|
this.Hitung_Detail();
|
|
if (e.which==13) FoniaJS.setFocus('#Disk_Persen4');
|
|
}.bind(this)).end()
|
|
.find('#Disk_Persen4').keyup(function(e) {
|
|
this.Hitung_Detail();
|
|
if (e.which==13) FoniaJS.setFocus('#Disk_Persen5');
|
|
}.bind(this)).end()
|
|
.find('#Disk_Persen5').keyup(function(e) {
|
|
this.Hitung_Detail();
|
|
if (e.which==13 && FoniaJS.StrToFloat($('#Jumlah').val())>0) this.detail_simpan();
|
|
}.bind(this));
|
|
if ($('#mode_detail').val() == 'insert' && $('#InvID').val() == 0) {
|
|
FoniaJS.setFocus('#Nama_Produk');
|
|
} else {
|
|
this.Hitung_Detail();
|
|
FoniaJS.setFocus('#Qty');
|
|
}
|
|
}.bind(this), false);
|
|
}.bind(this)
|
|
}).send();
|
|
},
|
|
|
|
detail_tambah: function(){
|
|
if ($('#SupID').val()==0){
|
|
FoniaJS.showError("Silakan pilih Nama Supplier !");
|
|
return;
|
|
}
|
|
this.detail_produk('insert', 0, 0, 0);
|
|
},
|
|
|
|
detail_ubah: function(acell){
|
|
this.detail_produk('update', acell[0], acell[1], acell[2]);
|
|
},
|
|
|
|
detail_hapus: function(acell){
|
|
FoniaJS.showConfirm('Konfirmasi', 'Hapus item <strong>"'+acell[4]+'"</strong> ?', function(){
|
|
new Request.JSONF({
|
|
url: this.PHP,
|
|
sendParam: ['data=tabel-detail','mode','mode_detail=delete','No_Beli','ID='+acell[0]],
|
|
onSuccess: function(){
|
|
var _obtn = $('button:contains("Total")');
|
|
if (_obtn) _obtn.removeClass('btn-info').addClass('btn-secondary').attr('id','tombolTotal').html('Hutang : '+FoniaJS.FloatToStr($('#Total_Hutang').val(),2));
|
|
}
|
|
}).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_Beli','ID','InvID','SatuanID','Qty','Harga_Beli','Disk_Rupiah','Disk_Persen1','Disk_Persen2','Disk_Persen3','Disk_Persen4','Disk_Persen5'],
|
|
onSuccess: function(){
|
|
var _obtn = $('button:contains("Total")');
|
|
if (_obtn) _obtn.removeClass('btn-info').addClass('btn-secondary').attr('id','tombolTotal').html('Hutang : '+FoniaJS.FloatToStr($('#Total_Hutang').val(),2));
|
|
if (_mdetail=='insert') { this.detail_tambah(); } else FoniaJS.closeWindow(this.winDetail);
|
|
}.bind(this)
|
|
}).send();
|
|
},
|
|
|
|
total_show: function(){
|
|
if (['add','edit'].indexOf($('#mode').val()) == -1) return false;
|
|
new Request.JSON({
|
|
url: this.PHP,
|
|
sendParam: ['data=detail-total'],
|
|
onSuccess: function(a){
|
|
this.winTotal = FoniaJS.showWindow('Total', 'Informasi Transaksi', a.html, 500, [{},{i:'butTutup'},{i:'butWSimpan',v:'Simpan',c:'success'}], function(){
|
|
var dhutang = parseFloat($('#Total_Hutang').val());
|
|
if (dhutang==0) dhutang = parseFloat($('#Total_Beli').val());
|
|
$('#winTotal')
|
|
.find('#butWSimpan').click(function(){this.total_simpan();}.bind(this)).end()
|
|
.find('#popTotal_Bulat').keyup(function(e) {
|
|
this.Hitung_Total();
|
|
if (e.which==13) $('#butWSimpan').focus();
|
|
}.bind(this)).end()
|
|
.find('#popTotal_Bulat').val($('#Total_Bulat').val()).end()
|
|
.find('#popTotal_Hutang').val(dhutang);
|
|
FoniaJS.setFocus('#popTotal_Bulat');
|
|
}.bind(this), false);
|
|
}.bind(this)
|
|
}).send();
|
|
},
|
|
|
|
total_simpan: function(){
|
|
$('#Total_Bulat').val(FoniaJS.StrToFloat($('#popTotal_Bulat').val()));
|
|
$('#Total_Hutang').val(FoniaJS.StrToFloat($('#popTotal_Hutang').val()));
|
|
$('#tombolTotal').html('<i class="bi-wallet2 me-1"></i>Hutang : '+FoniaJS.FloatToStr($('#Total_Hutang').val(),2));
|
|
FoniaJS.closeWindow(this.winTotal);
|
|
},
|
|
|
|
data_query: function(tipe, mode, kd_tx){
|
|
if (tipe=="master"){
|
|
mode = (mode) ? mode : '';
|
|
var sparam = ['data=master','mode='+mode,'No_Beli'+((typeof(kd_tx)!=='undefined')?'='+kd_tx:'')];
|
|
if (-1 !== mode.search(/save/i)) sparam = ['data=master','mode='+mode,'No_Beli','Tgl_Beli','Tgl_Faktur','No_Faktur','CabID','SupID','Total_Bulat='+FoniaJS.StrToFloat($('#Total_Bulat').val()),'Total_Hutang='+FoniaJS.StrToFloat($('#Total_Hutang').val())];
|
|
new Request.JSON({
|
|
url: this.PHP,
|
|
sendParam: sparam,
|
|
onSuccess: function(ajson){
|
|
$('#divTXMaster').html(ajson.html);
|
|
$('#No_Beli').keyup(function(e){
|
|
if ((e.which || e.keyCode) == 13) {
|
|
if (($("#No_Beli")) && ($("#No_Beli").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');
|
|
$('#butPendingBrow').addClass('d-none');
|
|
$('#butPendingSimpan').addClass('d-none');
|
|
if (-1 !== $('#No_Beli').val().search(/BELI/i)) $('#butPendingSimpan').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');
|
|
$('#butPendingBrow').removeClass('d-none');
|
|
$('#butPendingSimpan').addClass('d-none');
|
|
}
|
|
$('#butUbah').prop('disabled', ($('#Lunas').val()==1 ? true : false));
|
|
$('#butHapus').prop('disabled', ($('#Lunas').val()==1 ? true : false));
|
|
if (ajson.error) {
|
|
FoniaJS.showError(ajson.error);
|
|
FoniaJS.setFocus('#No_Beli');
|
|
}
|
|
}.bind(this)
|
|
}).send();
|
|
} else if (tipe=="tabel-detail"){
|
|
new Request.JSONF({
|
|
url: this.PHP,
|
|
sendParam: ['data=tabel-detail','mode','No_Beli'],
|
|
onSuccess: function(){
|
|
var _obtn = $('button:contains("Total")');
|
|
if (_obtn) _obtn.removeClass('btn-info').addClass('btn-secondary').attr('id','tombolTotal').html('<i class="bi-wallet2 me-1"></i>Hutang : '+FoniaJS.FloatToStr($('#Total_Hutang').val(),2));
|
|
}
|
|
}).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-pending"){
|
|
new Request.JSONF({
|
|
url: this.PHP,
|
|
sendParam: ['data=brow-pending','Cari_Pending'],
|
|
onSuccess: function(){
|
|
FoniaJS.setFocus('#Cari_Pending');
|
|
}
|
|
}).send();
|
|
} else if (tipe=="brow-produk"){
|
|
new Request.JSONF({
|
|
url: this.PHP,
|
|
sendParam: ['data=brow-produk','Cari_Produk','Filter_Browse','SupID'],
|
|
onSuccess: function(){
|
|
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[1]);
|
|
$('#Harga_Jual').val(FoniaJS.FloatToStr(adata[3]));
|
|
BeliJS.update_Items();
|
|
},
|
|
|
|
update_Items: function(){
|
|
new Request.JSON({
|
|
url: this.PHP,
|
|
sendParam: ['data=detail-item','InvID','SatuanID','SupID'],
|
|
onSuccess: function(adata){
|
|
if (!adata.data) {
|
|
$('#Harga_Beli').val(FoniaJS.FloatToStr(adata.Harga_Beli));
|
|
$('#Disk_Rupiah').val(adata.Disk_Rupiah);
|
|
$('#Disk_Persen1').val(adata.Disk_Persen1);
|
|
$('#Disk_Persen2').val(adata.Disk_Persen2);
|
|
$('#Disk_Persen3').val(adata.Disk_Persen3);
|
|
$('#Disk_Persen4').val(adata.Disk_Persen4);
|
|
$('#Disk_Persen5').val(adata.Disk_Persen5);
|
|
this.Hitung_Detail();
|
|
}
|
|
FoniaJS.setFocus('#Qty');
|
|
}.bind(this)
|
|
}).send();
|
|
},
|
|
|
|
Hitung_Detail: function(){
|
|
var dqty = FoniaJS.StrToFloat($('#Qty').val());
|
|
var dharga = FoniaJS.StrToFloat($('#Harga_Beli').val());
|
|
var ddiskrp = FoniaJS.StrToFloat($('#Disk_Rupiah').val());
|
|
var ddiskp1 = (100.0-FoniaJS.StrToFloat($('#Disk_Persen1').val())) / 100;
|
|
var ddiskp2 = (100.0-FoniaJS.StrToFloat($('#Disk_Persen2').val())) / 100;
|
|
var ddiskp3 = (100.0-FoniaJS.StrToFloat($('#Disk_Persen3').val())) / 100;
|
|
var ddiskp4 = (100.0-FoniaJS.StrToFloat($('#Disk_Persen4').val())) / 100;
|
|
var ddiskp5 = (100.0-FoniaJS.StrToFloat($('#Disk_Persen5').val())) / 100;
|
|
var dtot = ((dharga - ddiskrp) * ddiskp1 * ddiskp2 * ddiskp3 * ddiskp4 * ddiskp5) * dqty;
|
|
var ddis = (dharga * dqty) - dtot;
|
|
$('#Total_Diskon').val(FoniaJS.FloatToStr(ddis,2));
|
|
$('#Jumlah').val(FoniaJS.FloatToStr(dtot,2));
|
|
},
|
|
|
|
Hitung_Total: function(){
|
|
var dbeli = FoniaJS.StrToFloat($('#Total_Beli').val());
|
|
var dbulat = FoniaJS.StrToFloat($('#popTotal_Bulat').val());
|
|
$('#popTotal_Hutang').val(FoniaJS.FloatToStr(dbeli-dbulat,2));
|
|
}
|
|
|
|
};
|