first commit
This commit is contained in:
@@ -0,0 +1,444 @@
|
||||
/*******************************************************************
|
||||
|
||||
PHP Class : /Controller/Inv/BeliController
|
||||
Description : Transaksi Pembelian
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : May 22th, 2010.
|
||||
Last Modified : September 20th, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
var BeliJS = {
|
||||
PHP: '',
|
||||
KODE: '',
|
||||
|
||||
index: function(q){
|
||||
$('#butTambah').click(() => this.tx_tambah());
|
||||
$('#butUbah').click(() => this.tx_ubah());
|
||||
$('#butHapus').click(() => this.tx_hapus());
|
||||
$('#butPendingBrow').click(() => this.pending_brow());
|
||||
$('#butPendingSimpan').click(() => this.tx_simpan('pending'));
|
||||
$('#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('<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, '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;
|
||||
}
|
||||
if (-1 !== $('#No_Beli').val().search(/BELI/i)){
|
||||
this.data_query('master', 'pending-edit')
|
||||
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 <strong>'+$('#No_Beli').val()+'</strong> ?', () => {
|
||||
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(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($('#Real_Beli').val())==0){
|
||||
this.total_show();
|
||||
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');
|
||||
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, 'xl', '', () => this.data_query('brow-pending'));
|
||||
},
|
||||
|
||||
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]+'" ?', () => {
|
||||
$('#No_Beli').val(acell[0]);
|
||||
this.data_query('master', 'pending-delete');
|
||||
}, '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, '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(() => {
|
||||
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');
|
||||
});
|
||||
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('#Nama_Produk').click(() => $('#Nama_Produk').select()).end()
|
||||
.find('#Qty').keyup((e) => {
|
||||
this.Hitung_Detail();
|
||||
if (e.which==13 && parseInt(e.target.value)>0) FoniaJS.setFocus('#Harga_Beli');
|
||||
}).end()
|
||||
.find('#Harga_Beli').keyup((e) => {
|
||||
this.Hitung_Detail();
|
||||
if (e.which==13) FoniaJS.setFocus('#Disk_Rupiah');
|
||||
}).end()
|
||||
.find('#Disk_Rupiah').keyup((e) => {
|
||||
this.Hitung_Detail();
|
||||
if (e.which==13) FoniaJS.setFocus('#Disk_Persen1');
|
||||
}).end()
|
||||
.find('#Disk_Persen1').keyup((e) => {
|
||||
this.Hitung_Detail();
|
||||
if (e.which==13) FoniaJS.setFocus('#Disk_Persen2');
|
||||
}).end()
|
||||
.find('#Disk_Persen2').keyup((e) => {
|
||||
this.Hitung_Detail();
|
||||
if (e.which==13) FoniaJS.setFocus('#Disk_Persen3');
|
||||
}).end()
|
||||
.find('#Disk_Persen3').keyup((e) => {
|
||||
this.Hitung_Detail();
|
||||
if (e.which==13) FoniaJS.setFocus('#Disk_Persen4');
|
||||
}).end()
|
||||
.find('#Disk_Persen4').keyup((e) => {
|
||||
this.Hitung_Detail();
|
||||
if (e.which==13) FoniaJS.setFocus('#Disk_Persen5');
|
||||
}).end()
|
||||
.find('#Disk_Persen5').keyup((e) => {
|
||||
this.Hitung_Detail();
|
||||
if (e.which==13 && FoniaJS.StrToFloat($('#Jumlah').val())>0) this.detail_simpan();
|
||||
});
|
||||
if ($('#mode_detail').val() == 'insert') {
|
||||
if ($('#InvID').val() == 0) {
|
||||
FoniaJS.setFocus('#Nama_Produk');
|
||||
} else {
|
||||
this.update_Items();
|
||||
}
|
||||
} 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 <strong>"'+acell[5]+'"</strong> ?', () => {
|
||||
new Request.JSONF({
|
||||
url: this.PHP + '/table_detail',
|
||||
sendParam: ['mode','mode_detail=delete','No_Beli','ID='+acell[0]],
|
||||
onSuccess: () => {
|
||||
var _obtn = $('button:contains("Total")');
|
||||
if (_obtn) _obtn.removeClass('btn-info').addClass('btn-secondary').attr('id','tombolTotal').html('Hutang : '+FoniaJS.FloatToStr($('#Real_Beli').val(),2));
|
||||
}
|
||||
}).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','Disk_Rupiah','Disk_Persen1','Disk_Persen2','Disk_Persen3','Disk_Persen4','Disk_Persen5'],
|
||||
onSuccess: () => {
|
||||
var _obtn = $('button:contains("Total")');
|
||||
if (_obtn) _obtn.removeClass('btn-info').addClass('btn-secondary').attr('id','tombolTotal').html('Hutang : '+FoniaJS.FloatToStr($('#Real_Beli').val(),2));
|
||||
if (_mdetail=='insert') { this.detail_tambah(); } else FoniaJS.closeWindow(this.winDetail);
|
||||
}
|
||||
}).send();
|
||||
},
|
||||
|
||||
total_show: function(){
|
||||
if (['add','edit'].indexOf($('#mode').val()) == -1) return false;
|
||||
new Request({
|
||||
url: this.PHP + '/form_total',
|
||||
onSuccess: (ajson) => {
|
||||
this.winTotal = FoniaJS.showWindow('Total', 'Informasi Transaksi', ajson.html, 'md', [{},{i:'butTutup'},{i:'butWSimpan',v:'Simpan',c:'success'}], () => {
|
||||
var dhutang = parseFloat($('#Real_Beli').val());
|
||||
if (dhutang == 0) dhutang = parseFloat($('#Total_Beli').val());
|
||||
$('#winTotal')
|
||||
.find('#butWSimpan').click(() => this.total_simpan()).end()
|
||||
.find('#popTotal_Diskon').keyup((e) => {
|
||||
if (e.which==13) FoniaJS.setFocus('#popTotal_Beli');
|
||||
}).end()
|
||||
.find('#popTotal_Beli').keyup((e) => {
|
||||
if (e.which==13) $('#butWSimpan').focus();
|
||||
}).end()
|
||||
.find('#popTotal_Diskon').val($('#Real_Diskon').val()).end()
|
||||
.find('#popTotal_Beli').val(dhutang);
|
||||
FoniaJS.setFocus('#popTotal_Diskon');
|
||||
}, false);
|
||||
}
|
||||
}).send();
|
||||
},
|
||||
|
||||
total_simpan: function(){
|
||||
$('#Real_Diskon').val(FoniaJS.StrToFloat($('#popTotal_Diskon').val()));
|
||||
$('#Real_Beli').val(FoniaJS.StrToFloat($('#popTotal_Beli').val()));
|
||||
$('#tombolTotal').html('<i class="bi-wallet2 me-1"></i>Hutang : '+FoniaJS.FloatToStr($('#Real_Beli').val(),2));
|
||||
FoniaJS.closeWindow(this.winTotal);
|
||||
},
|
||||
|
||||
data_query: function(tipe, mode, kd_tx){
|
||||
if (tipe=="master"){
|
||||
mode = (mode) ? mode : '';
|
||||
var sparam = ['mode='+mode,'No_Beli'+((typeof(kd_tx)!=='undefined')?'='+kd_tx:'')];
|
||||
if (-1 !== mode.search(/save/i)) sparam = ['mode='+mode,'No_Beli','Tgl_Beli','Tgl_Faktur','No_Faktur','CabID','SupID','Real_Diskon','Real_Beli','PPN'];
|
||||
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());
|
||||
$('#No_Faktur').addClass('w-auto');
|
||||
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');
|
||||
}
|
||||
}
|
||||
}).send();
|
||||
} else if (tipe=="tabel-detail"){
|
||||
new Request.JSONF({
|
||||
url: this.PHP + '/table_detail',
|
||||
sendParam: ['mode','No_Beli'],
|
||||
onSuccess: () => {
|
||||
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($('#Real_Beli').val(),2));
|
||||
}
|
||||
}).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-pending"){
|
||||
new Request.JSONF({
|
||||
url: this.PHP + '/brow_pending',
|
||||
sendParam: ['Cari_Pending']
|
||||
}).send();
|
||||
} else if (tipe=="brow-produk"){
|
||||
new Request.JSONF({
|
||||
url: this.PHP + '/brow_produk',
|
||||
sendParam: ['Cari_Produk','Filter_Browse','SupID'],
|
||||
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($('<option>', { value: adata[1], label: adata[1] }));
|
||||
_vari.val(adata[1]).trigger('change');
|
||||
BeliJS.update_Varian();
|
||||
BeliJS.update_Items();
|
||||
},
|
||||
|
||||
update_Items: function(){
|
||||
new Request({
|
||||
url: this.PHP + '/item_detail',
|
||||
sendParam: ['InvID','SatuanID','SupID'],
|
||||
onSuccess: (adata) => {
|
||||
if (adata.data) {
|
||||
var _data = adata.data;
|
||||
$('#Harga_Beli').val(FoniaJS.FloatToStr(_data.Harga_Beli));
|
||||
$('#Disk_Rupiah').val(_data.Disk_Rupiah);
|
||||
$('#Disk_Persen1').val(_data.Disk_Persen1);
|
||||
$('#Disk_Persen2').val(_data.Disk_Persen2);
|
||||
$('#Disk_Persen3').val(_data.Disk_Persen3);
|
||||
$('#Disk_Persen4').val(_data.Disk_Persen4);
|
||||
$('#Disk_Persen5').val(_data.Disk_Persen5);
|
||||
this.Hitung_Detail();
|
||||
}
|
||||
FoniaJS.setFocus('#Qty');
|
||||
}
|
||||
}).send();
|
||||
},
|
||||
|
||||
update_Varian: function(){
|
||||
new Request.JSONF({
|
||||
url: this.PHP + '/option_varian',
|
||||
sendParam: ['InvID','SatuanID','VarianID']
|
||||
}).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));
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user