text: var save_method,table;function add_menu(){reset_modal_form(),save_method="add",$("#modal_stok_form").modal("show"),$("#modal_title").text("Tambah Stok Barang")}function edit_stok(a){reset_modal_form(),save_method="update",$.ajax({url:base_url+"stok_barang/edit_stok",type:"POST",dataType:"JSON",data:{id:a},success:function(a){$('[name="id_stok"]').val(a.old_data.id_stok),$('[name="id_barang"]').val(a.old_data.id_barang).trigger("change"),$('[name="id_gudang"]').val(a.old_data.id_gudang).trigger("change"),$('[name="sawal"]').val(a.old_data.qty),$('[name="smin"]').val(a.old_data.qty_min),$('[name="hpp"]').val(a.old_data.hpp),$("#modal_stok_form").modal("show"),$("#modal_title").text("Edit Stok Barang")},error:function(a,e,t){alert("Error get data from ajax")}})}function reload_table(){table.ajax.reload(null,!1)}function save(){var e,t="add"==save_method?(e=base_url+"stok_barang/add_stok_barang","Tambah Stok Barang"):(e=base_url+"stok_barang/update_stok_barang","Edit Stok Barang"),a=$("#form-user")[0],r=new FormData(a);$("#btnSave").prop("disabled",!0),$("#btnSave").text("Menyimpan Data"),swalConfirm.fire({title:"Simpan Data Stok Baru ?",text:"Apakah Anda Yakin ?",type:"warning",showCancelButton:!0,confirmButtonText:"Ya !",cancelButtonText:"Tidak !",reverseButtons:!0}).then(a=>{a.value?$.ajax({type:"POST",enctype:"multipart/form-data",url:e,data:r,dataType:"JSON",processData:!1,contentType:!1,cache:!1,timeout:6e5,success:function(a){if(a.status)swal.fire("Sukses!!","Aksi "+t+" Berhasil","success"),$("#btnSave").prop("disabled",!1),$("#btnSave").text("Simpan"),reset_modal_form(),$(".modal").modal("hide"),reload_table();else if(0==a.status)swal.fire("Gagal!!",a.pesan,"error"),reset_modal_form(),$(".modal").modal("hide");else{for(var e=0;e<a.inputerror.length;e++)"pegawai"!=a.inputerror[e]?($('[name="'+a.inputerror[e]+'"]').addClass("is-invalid"),$('[name="'+a.inputerror[e]+'"]').next().text(a.error_string[e]).addClass("invalid-feedback")):$('[name="'+a.inputerror[e]+'"]').next().next().text(a.error_string[e]).addClass("invalid-feedback-select");$("#btnSave").prop("disabled",!1),$("#btnSave").text("Simpan")}},error:function(a){console.log("ERROR : ",a),$("#btnSave").prop("disabled",!1),$("#btnSave").text("Simpan"),reset_modal_form(),$(".modal").modal("hide")}}):a.dismiss===Swal.DismissReason.cancel&&swalConfirm.fire("Dibatalkan","Aksi Dibatalakan","error")})}function delete_stok(e){swalConfirmDelete.fire({title:"Hapus Data ?",text:"Data Akan dihapus permanen ?",type:"warning",showCancelButton:!0,confirmButtonText:"Ya, Hapus Data !",cancelButtonText:"Tidak, Batalkan!",reverseButtons:!0}).then(a=>{a.value?$.ajax({url:base_url+"stok_barang/delete_stok",type:"POST",dataType:"JSON",data:{id:e},success:function(a){swalConfirm.fire("Berhasil Hapus Stok!",a.pesan,"success"),table.ajax.reload()},error:function(a,e,t){Swal.fire("Terjadi Kesalahan")}}):a.dismiss===Swal.DismissReason.cancel&&swalConfirm.fire("Dibatalkan","Aksi Dibatalakan","error")})}function reset_modal_form(){$("#form-user")[0].reset(),$(".append-opt").remove(),$("div.form-group").children().removeClass("is-invalid invalid-feedback"),$("span.help-block").text(""),$(".select2").val("0").trigger("change")}function reset_modal_form_import(){$("#form_import_excel")[0].reset(),$("#label_file_excel").text("Pilih file excel yang akan diupload")}function import_excel(){$("#modal_import_excel").modal("show"),$("#modal_import_title").text("Import data user")}function import_data_excel(){var a=$("#form_import_excel")[0],a=new FormData(a);$("#btnSaveImport").prop("disabled",!0),$("#btnSaveImport").text("Import Data"),$.ajax({type:"POST",enctype:"multipart/form-data",url:base_url+"master_user/import_data_master",data:a,dataType:"JSON",processData:!1,contentType:!1,success:function(a){a.status?swal.fire("Sukses!!",a.pesan,"success"):swal.fire("Gagal!!",a.pesan,"error"),$("#btnSaveImport").prop("disabled",!1),$("#btnSaveImport").text("Simpan"),reset_modal_form_import(),$(".modal").modal("hide"),table.ajax.reload()},error:function(a){console.log("ERROR : ",a),$("#btnSaveImport").prop("disabled",!1),$("#btnSaveImport").text("Simpan"),reset_modal_form_import(),$(".modal").modal("hide"),table.ajax.reload()}})}$(document).ready(function(){$("input.numberinput").bind("keypress",function(a){return 8==a.which||0==a.which||!(a.which<48||57<a.which)||46==a.which}),table=$("#tabel_user").DataTable({responsive:!0,processing:!0,serverside:!0,ajax:{url:base_url+"stok_barang/list_stok_barang",type:"POST"},language:{decimal:",",thousands:"."}}),$(document).on("click",".btn_edit_status",function(){var e=$(this).attr("id"),t=$(this).val();swalConfirm.fire({title:"Ubah Status Data User ?",text:"Apakah Anda Yakin ?",icon:"warning",showCancelButton:!0,confirmButtonText:"Ya, Ubah Status!",cancelButtonText:"Tidak, Batalkan!",reverseButtons:!0}).then(a=>{a.value?$.ajax({url:base_url+"master_user/edit_status_user/"+e,type:"POST",dataType:"JSON",data:{status:t},success:function(a){swalConfirm.fire("Berhasil Ubah Status User!",a.pesan,"success"),table.ajax.reload()},error:function(a,e,t){Swal.fire("Terjadi Kesalahan")}}):a.dismiss===Swal.DismissReason.cancel&&swalConfirm.fire("Dibatalkan","Aksi Dibatalakan","error")})}),$(".modal").on("hidden.bs.modal",function(){reset_modal_form(),reset_modal_form_import()})});