/******************************************************************* App. Name : INVENTORY AND SALES SYSTEMS Module : /apps/js/iss/po.js Desc. : JS - Transaksi Pembuatan Purchase Order Created By : Siau Pheng (siaupheng@3fonia.com). Created Date : May 22th, 2010. Last Modified : January 19th, 2026. (c) 2010 - 2026, 3FONIA Software; WWW.3FONIA.COM. *******************************************************************/ var POJS = { 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)); $('#butSimpan').click(function(){this.tx_simpan();}.bind(this)); $('#butBatal').click(function(){this.tx_batal();}.bind(this)); $('#butPrint').click(function(){this.tx_print();}.bind(this)); $('#butShare').click(function(){this.tx_share();}.bind(this)); this.data_query('master', 'view', ((typeof(q)!=='undefined') ? q : '')); }, tx_brow: function(){ var _isi = new String('
 
'); 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_PO').val(acell[0]); this.data_query('master', 'view'); }, tx_tambah: function(){ this.data_query('master', 'add'); }, tx_ubah: function(){ if (!$('#No_PO').val()){ FoniaJS.showError("Silakan masukkan Nomor Transaksi !"); return; } FoniaJS.showAuth(function(){this.data_query('master', 'edit')}.bind(this), this, 'EDIT '+$('#No_PO').val()); }, tx_hapus: function(){ if (!$('#No_PO').val()){ FoniaJS.showError("Silakan masukkan Nomor Transaksi !"); return; } FoniaJS.showConfirm('Konfirmasi', 'Yakin akan hapus '+$('#No_PO').val()+' ?', function(){ FoniaJS.showAuth(function(){ new Request.JSON({ url: this.PHP, sendParam: ['data=delete','No_PO'], onSuccess: function(adata){ if (adata.status==true){ $('#No_PO').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_PO').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; } this.data_query('master', 'save'); }, tx_batal: function(){ FoniaJS.showConfirm('Konfirmasi', 'Yakin akan membatalkan ?', function(){ this.data_query('master', 'cancel'); $('#No_PO').val(''); }.bind(this), 'danger'); }, tx_print: function(){ if ($('#No_PO').val()) { if (FoniaJS.WEB_MOBILE){ var dload = new cEXPORT({'url':FoniaJS.WEB_PATH+'apps/php/pdf/po.php'}); dload.add_param("data", "pdf-po"); dload.add_param("mode", "share"); dload.add_param("Nomor_Cetak", $('#No_PO').val()); dload.download(); } else { var cetak = new cPDF(FoniaJS.WEB_PATH+'apps/php/pdf/po.php'); cetak.add_param("data", "pdf-po"); cetak.add_param("Nomor_Cetak", $('#No_PO').val()); cetak.showPDF(); } return; } FoniaJS.showError("Silakan masukkan Nomor Transaksi !"); }, tx_share: function(){ if ($('#No_PO').val()) { var dload = new cSHARE({'url':FoniaJS.WEB_PATH+'apps/php/pdf/po.php'}); dload.add_param("data", "pdf-po"); dload.add_param("mode", "share"); dload.add_param("Nomor_Cetak", $('#No_PO').val()); dload.share(); return; } FoniaJS.showError("Silakan masukkan Nomor Transaksi !"); }, produk_brow: function(){ if ($('#SupID').val()==0){ FoniaJS.showError("Silakan pilih Nama Supplier !"); return; } var _isi = new String('
 
'); 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_PO','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_PO','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.StrToFloat($('#Jumlah').val())>0) this.detail_simpan(); }.bind(this)); if ($('#mode_detail').val() == 'insert' && $('#InvID').val() == 0) { FoniaJS.setFocus('#Nama_Produk'); } else { if ($('#mode_detail').val() != 'insert') this.Hitung_Detail(); this.Update_Items(); } }.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 "'+acell[4]+'" ?', function(){ new Request.JSONF({ url: this.PHP, sendParam: ['data=tabel-detail','mode','mode_detail=delete','No_PO','ID='+acell[0]] }).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_PO','ID','InvID','SatuanID','Qty','Harga_Beli','Harga_HPP'], onSuccess: function(){ if (_mdetail=='insert') { this.detail_tambah(); } else FoniaJS.closeWindow(this.winDetail); }.bind(this) }).send(); }, data_query: function(tipe, mode, kd_tx){ if (tipe=="master"){ mode = (mode) ? mode : ''; var sparam = ['data=master','mode='+mode,'No_PO'+((typeof(kd_tx)!=='undefined')?'='+kd_tx:'')]; if (-1 !== mode.search(/save/i)) sparam = ['data=master','mode='+mode,'No_PO','Tgl_PO','CabID','SupID','Total_Beli']; new Request.JSON({ url: this.PHP, sendParam: sparam, onSuccess: (ajson) => { $('#divTXMaster').html(ajson.html); $('#No_PO').keyup((e) => { if ((e.which || e.keyCode) == 13) { if (($("#No_PO")) && ($("#No_PO").val() !== '')) this.data_query('master'); } }); 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'); $('#butShare').addClass('d-none'); $('#butSimpan').removeClass('d-none'); $('#butBatal').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'); $('#butShare').removeClass('d-none'); $('#butSimpan').addClass('d-none'); $('#butBatal').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_PO'); } } }).send(); } else if (tipe=="tabel-detail"){ new Request.JSONF({ url: this.PHP, sendParam: ['data=tabel-detail','mode','No_PO'] }).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-produk"){ new Request.JSONF({ url: this.PHP, sendParam: ['data=brow-produk','Cari_Produk','Filter_Browse','SupID','No_PO'], 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_Satuan1').val(adata[1]); $('#Nama_Satuan2').val(adata[1]); $('#Harga_Beli').val(FoniaJS.FloatToStr(adata[3])); $('#Harga_HPP').val(FoniaJS.FloatToStr(adata[3])); POJS.Update_Items(); }, oc_SupID: function(ob){ if (ob.value == 0) return false; new Request.JSONF({ url: this.PHP, sendParam: ['data=tabel-detail','mode','mode_detail=sup-baru','No_PO','SupID'] }).send(); }, Update_Items: function(){ new Request.JSON({ url: this.PHP, sendParam: ['data=detail-item','InvID'], onSuccess: function(adata){ if (!adata.data) { $('#Stok').val(FoniaJS.FloatToStr(adata.Stok)); } FoniaJS.setFocus('#Qty'); }.bind(this) }).send(); }, Hitung_Detail: function(){ var dqty = FoniaJS.StrToFloat($('#Qty').val()); var dharga = FoniaJS.StrToFloat($('#Harga_Beli').val()); var dtot = dharga * dqty; $('#Jumlah').val(FoniaJS.FloatToStr(dtot,2)); } };