/******************************************************************* PHP Class : /Controller/Inv/OpnameController Description : Transaksi Opname Stok Created By : Siau Pheng (siaupheng@3fonia.com). Created Date : May 24th, 2010. Last Modified : September 28th, 2026. (c) 3FONIA Software; WWW.3FONIA.COM. *******************************************************************/ var OpnameJS = { PHP: '', KODE: '', index: function(q){ $('#butTambah').click(() => this.tx_tambah()); $('#butUbah').click(() => this.tx_ubah()); $('#butHapus').click(() => this.tx_hapus()); $('#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('
 
'); 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_Opname').val(acell[0]); this.data_query('master', 'view'); }, tx_tambah: function(){ this.data_query('master', 'add'); }, tx_ubah: function(){ if (!$('#No_Opname').val()){ FoniaJS.showError("Silakan masukkan Nomor Transaksi !"); return; } FoniaJS.showAuth(() => this.data_query('master', 'edit'), this, 'EDIT '+$('#No_Opname').val()); }, tx_hapus: function(){ if (!$('#No_Opname').val()){ FoniaJS.showError("Silakan masukkan Nomor Transaksi !"); return; } FoniaJS.showConfirm('Konfirmasi', 'Yakin akan hapus '+$('#No_Opname').val()+' ?', () => { FoniaJS.showAuth(() => { new Request({ url: this.PHP + '/proses_delete', sendParam: ['No_Opname'], onSuccess: (ajson) => { if (ajson.status === true){ $('#No_Opname').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_Opname').val()); }, 'danger'); }, tx_simpan: function(){ if ($('#CabID').val()==0){ FoniaJS.showError("Silakan pilih Nama Cabang !"); return; } this.data_query('master', 'save'); }, tx_batal: function(){ FoniaJS.showConfirm('Konfirmasi', 'Yakin akan membatalkan ?', () => { this.data_query('master', 'cancel'); $('#No_Opname').val(''); }, 'danger'); }, tx_print: function(prt){ if ($('#No_Opname').val()) { var cetak = new Printer('report/nota/opname'); cetak.add_param("Nomor_Cetak", $('#No_Opname').val()); if (prt) cetak.doPrint(); else cetak.doPreview(); return; } FoniaJS.showError("Silakan masukkan Nomor Transaksi !"); }, produk_brow: function(){ if ($('#CabID').val()==0){ FoniaJS.showError("Silakan pilih Nama Cabang !"); return; } var _isi = new String('
 
'); 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(() => { $('#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_Opname','ID='+ID,'InvID='+InvID,'SatuanID='+SatuanID,'VarianIID='+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_Opname','CabID'], {'selectFunc': this.Produk_Comp}); $('#winDetail') .find('#butWSimpan').click(() => this.detail_simpan()).end() .find('#Qty').keyup((e) => { if (parseFloat(e.target.value) == 0) return false; if (-1!==$.inArray(e.which, [13,9])) this.detail_simpan(); }); if ($('#mode_detail').val() == 'insert' && $('#InvID').val() == 0) { FoniaJS.setFocus('#Nama_Produk'); } else { FoniaJS.setFocus('#Qty'); } }, false); } }).send(); }, detail_tambah: function(){ if ($('#CabID').val()==0){ FoniaJS.showError("Silakan pilih Nama Cabang !"); 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 "'+acell[2]+'" ?', () => { new Request.JSONF({ url: this.PHP + '/table_detail', sendParam: ['mode','mode_detail=delete','No_Opname','ID='+acell[0]] }).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_Opname','CabID','ID','InvID','SatuanID','VarianID','Qty','Harga_Beli'], onSuccess: () => { if (_mdetail=='insert') { this.detail_tambah(); } else FoniaJS.closeWindow(this.winDetail); } }).send(); }, data_query: function(tipe, mode, kd_tx){ if (tipe=="master"){ var sparam = ['mode='+mode,'No_Opname'+((typeof(kd_tx)!=='undefined')?'='+kd_tx:'')]; if ((mode ?? '')=='save') sparam = ['mode='+mode,'No_Opname','Tgl_Opname','CabID','Catatan']; new Request({ url: this.PHP + '/form_master', sendParam: sparam, onSuccess: (ajson) => { $('#divTXMaster').html(ajson.html); $('#No_Opname').keyup((e) => { if ((e.which || e.keyCode) == 13) { if (($("#No_Opname")) && ($("#No_Opname").val() !== '')) this.data_query('master'); } }); $('#butBrow').click(() => this.tx_brow()); 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'); FoniaJS.setFocus('#No_Opname'); } 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'); } if (ajson.error) FoniaJS.showError(ajson.error); } }).send(); } else if (tipe=="tabel-detail"){ new Request.JSONF({ url: this.PHP + '/table_detail', sendParam: ['mode','No_Opname'] }).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-produk"){ new Request.JSONF({ url: this.PHP + '/brow_produk', sendParam: ['CabID','Cari_Produk'], onSuccess: () => FoniaJS.setFocus('#Cari_Produk') }).send(); } }, Produk_Comp: function(item){ var adata = item.data.split(':'); // Satuan : Varian : Harga_Pokok : Satuan : Stok $('#InvID').val(item.value); $('#SatuanID').val(adata[0]); $('#VarianID').val(adata[1]); $('#Harga_Beli').val(adata[2]); $('#Nama_Satuan1').val(adata[3]); $('#Nama_Satuan2').val(adata[3]); $('#Stok').val(adata[4]); FoniaJS.setFocus('#Qty'); } };