<!-- DataTales Example -->
<div class="card shadow mb-4">
	<div class="card-header py-3">
		<h6 class="m-0 font-weight-bold text-primary">Data Pelayanan</h6>
	</div>
	<div class="card-body">
		<a href='javascript:void(0)' onclick="getpopup('popup/tambah_pelayanan','popupedit');" class="btn btn-primary btn-icon-split btn-sm mb-4">
			<span class="icon text-white-50">
				<i class="fas fa-plus"></i>
			</span>
			<span class="text">Tambah Data Pelayanan</span>
		</a>
		<div class="table-responsive">
			<table class="table table-bordered" id="tabel_data_pelayanan" width="100%" cellspacing="0">
				<thead>
					<tr>
						<th>No</th>
						<th>Jenis Pelayanan/Tugas</th>
						<th>Pelayan/Tugas</th>
						<th>Stipendium</th>
						<th>Stipendium Daring</th>
						<th>Keterangan</th>
						<th>Aksi</th>
					</tr>
				</thead>
				<tbody>
					<!-- Content -->
				</tbody>
			</table>
		</div>
	</div>
</div>

<script type="text/javascript">
	$(document).ready(function() {
		var base_url = "<?= base_url() ?>";
		var data_pka = function() {
			$('#tabel_produk').hide();
			$.ajax({
				url: base_url + 'pelayanan/data_pelayanan',
				type: "post",
				dataType: "json",
				async: 'false',
				success: function(result) {
					var data = [];
					for (var i = 0; i < result.length; i++) {
						var no = i + 1;
						var link_edit = `<a href="javascript:void(0)" title="Edit" onclick="getpopup('Popup/edit_pelayanan','popupedit','` + result[i].id_pelayanan + `');" class="btn btn-info btn-icon-split btn-sm">
                                        <span class="icon text-white-50">
                                          <i class="fas fa-edit"></i>
                                        </span>
                                      </a>`;
						var link_hapus = `<a href="javascript:void(0)" title="Hapus" onclick="hapus_pelayanan('` + result[i].id_pelayanan + `');" class="btn btn-danger btn-icon-split btn-sm">
                                        <span class="icon text-white-50">
                                          <i class="fas fa-trash-alt"></i>
                                        </span>
                                      </a>`;
						// data.push([no, result[i].jenis_pelayanan_id, result[i].nama, result[i].stipendium, result[i].stipendium_daring, result[i].keterangan, link_edit + " " + link_hapus]);
						data.push([no, result[i].nama_jenis_pelayanan, result[i].nama, result[i].stipendium, result[i].stipendium_daring, result[i].keterangan, link_edit + " " + link_hapus]);

					}
					$('#tabel_data_pelayanan').DataTable({
						//"bJQueryUI"     : true,
						data: data,
						deferRender: true,
						processing: true,
						ordering: true,
						retrieve: false,
						paging: true,
						deferLoading: 57,
						bDestroy: true,
						autoWidth: false,
						bFilter: true,
						iDisplayLength: 10,
						responsive: true,
						language: {
							searchPlaceholder: 'Cari',
							sSearch: '',
							lengthMenu: '_MENU_',
						},
					});
				},
				beforeSend: function() {},
				complete: function() {
					// $('#tabel_produk').show();
				}
			});
		}
		data_pka();

		hapus_pelayanan = function(id_pelayanan) {
			bootbox.confirm("Apakah Anda Yakin Akan Menghapus Data?", function(result) {
				if (result == true) {
					$.ajax({
						url: base_url + 'pelayanan/hapus_pelayanan',
						type: "POST",
						dataType: 'json',
						data: {
							id_pelayanan: id_pelayanan
						},
						success: function(response) {
							if (response == true) {
								Command: toastr["success"]("Data Pelayanan Berhasil Dihapus", "Berhasil");
								getcontens('page/data_pelayanan');
							}
							else {
								Command: toastr["error"]("Simpan error, data tidak berhasil disimpan", "Error");
							}
						},
						error: function(jqXHR, textStatus, errorThrown) {
							$('#loading').modal('hide');
							Command: toastr["error"](errorThrown, "Error");
						},
						beforeSend: function() {
							$('#loading').modal('show');
						},
						complete: function() {
							$('#loading').modal('hide');
						}
					})
				}
			});
		}
	});
</script>