<section class="content-header">
	<div class="container-fluid">
		<div id="flash" data-flash="<?= $this->session->flashdata('success'); ?>"></div>
		<div class="row ">
			<div class="col-sm-6">
				<h1>HARGA JASA </h1>

			</div>
		</div>
	</div>
</section>
<section class="content">

	<!-- start pencarian -->
	<div class="container-fluid">
		<form action="" method="get">
			<div class="row mb-2 ">
				<div class="col-12">
					<?php if (isset($_GET['Jasa'])) {
						$in = $_GET['Jasa'];
					} else {
						$in = null;
					} ?>
					<div class="input-group align-center">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="fas fa-cog"></i></span>
						</div>
						<select name="Jasa" class="custom-select text-dark text-uppercase">
							<option value="0" selected>Pilih Katalog Jasa </option>
							<?php foreach ($katbrg->result() as $key => $data) { ?>
								<option value="<?= $data->id_katalogjasa  ?>" <?= $in == $data->id_katalogjasa  ? "selected" : null ?>> <?= $data->nama_katjasa ?></option>
							<?php } ?>
						</select>
						<div style="width: 100px" class="input-group-prepend">
							<button type="submit" class="btn btn-outline-secondary w-100">Pilih</button>
						</div>
					</div>
				</div>
		</form>
	</div>
	<!-- ending pencarian -->

	<div class="card card-outline card-secondary mt-3">
		<div class="card-header ">
			<h3 class="card-title">Daftar Harga Sparepart
			</h3>

			<div class="card-tools">
				<button type="button" class="btn btn-tool" data-card-widget="collapse" data-toggle="tooltip" title="Collapse">
					<i class="fas fa-minus"></i></button>
				<button type="button" class="btn btn-tool" data-card-widget="remove" data-toggle="tooltip" title="Remove">
					<i class="fas fa-times"></i></button>
			</div>
		</div>
		<div class="card-body">
			<table id="example1" class="table  table-hover table-sm ">
				<thead>
					<tr class="text-center">
						<th class="text-left">Nama Jasa</th>
						<th class="text-left">Harga</th>

						<th>Status</th>

					</tr>
				</thead>
				<tbody>
					<?php
					if ($Part->num_rows() > 0) {
						foreach ($Part->result() as $am => $data) {
					?>
							<tr class="text-center">
								<td class="text-left text-uppercase"><?= $data->nama_jasa ?></td>
								<td class="text-left text-uppercase"><?= $data->hargam_jasa ?></td>
								<td class=" w-25">
									<button id="select" data-toggle="modal" data-nama_jasa="<?= $data->nama_jasa ?>" data-toggle="modal" data-datetime="<?= $data->datetime ?>" data-id_katjasastok="<?= $data->id_katjasastok ?>" data-id_katjasastok="<?= $data->id_katjasastok ?>" data-hargam_jasa="<?= $data->hargam_jasa ?>" data-hargac_jasa="<?= $data->hargac_jasa ?>" data-target="#upjasa" class="btn btn-sm btn-warning">
										Update harga
									</button>
								</td>
							</tr>
					<?php
						}
					} else {
						echo '<tr>
                                <td colspan="8" class="text-center"> Tidak Ada Data Sparepart Yang Tersedia </td>
                                </tr>';
					}
					?>
				</tbody>
			</table>
		</div>
	</div>
</section>

<!-- Start modal harga -->
<form action="<?= base_url('kmjasa/editharga'); ?>" method="post">
	<div class="modal fade bd-example-modal-lg" id="upjasa" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-lg modal-dialog-centered">
			<div class="modal-content">
				<div class="modal-body">

					<div class="row">

						<div class="col-12 col-lg-12 ">
							<input autocomplete="off" name="id_katjasastok" type="hidden" id="idkatjasastok" class="form-control" readonly="on">

							<div class="input-group mt-2 ">
								<div class="input-group-prepend">
									<span class="input-group-text text-bold">Update&nbsp;</span>
								</div>
								<input autocomplete="off" type="text" id="datetimeok" class="form-control" readonly="on">
								<input autocomplete="off" type="text" value="<?= date('Y-m-d h:i:s') ?>" name="datetime" class="form-control text-bold" readonly="on">

							</div>

							<div class="input-group mt-2 ">
								<div class="input-group-prepend">
									<span class="input-group-text text-bold">Jasa&nbsp; &nbsp; &nbsp;&nbsp;</span>
								</div>
								<input autocomplete="off" name="nama_jasa" type="text" id="namajasa" class="form-control" readonly="on">
							</div>

							<div class="input-group mt-2">
								<div class="input-group-prepend">
									<span class="input-group-text text-bold">Modal &nbsp;</span>
								</div>
								<input autocomplete="off" type="text" id="hargamjasa2" class="form-control  " readonly="on">
								<input autocomplete="off" required type="text" id="hargajasa" name="hargam_jasa" class="form-control text-bold" placeholder="Cth: 10000">
							</div>

							<div class="input-group mt-2">
								<div class="input-group-prepend">
									<span class="input-group-text text-bold">Corp&nbsp; &nbsp; &nbsp;</span>
								</div>
								<input autocomplete="off" name="hargac_jasa" type="text" id="hargacjasa" class="form-control" readonly="on">
								<input autocomplete="off" type="text" id="hargajasa1" class="form-control text-bold" readonly="on">


							</div>


							<button type="submit" class="btn btn-secondary w-100 mt-2">Simpan Harga Terbaru</button>
						</div>
					</div>

				</div>
			</div>
		</div>
	</div>

</form>
<!-- ending modal Keterangan absen -->

<script src="<?= base_url() ?>/assets/dist/js/jquery-2.1.1.js"></script>

<script>
	$(document).ready(function() {
		$(document).on('click', '#select', function() {
			var id_katjasastok = $(this).data('id_katjasastok');
			var nama_jasa = $(this).data('nama_jasa');
			var hargam_jasa = $(this).data('hargam_jasa');
			var hargac_jasa = $(this).data('hargac_jasa');
			var datetime = $(this).data('datetime');
			$('#idkatjasastok').val(id_katjasastok);
			$('#namajasa').val(nama_jasa);
			$('#hargamjasa').val(hargam_jasa);
			$('#hargamjasa2').val(hargam_jasa);
			$('#hargacjasa').val(hargac_jasa);
			$('#datetimeok').val(datetime);
		})
	})

	$("#hargajasa").change(function() {
		var Jasa = eval($("#hargajasa").val());

		var persen = (20 / 100) * Jasa;
		jasa1 = Jasa - persen;

		var x = document.getElementById('hargajasa1').value = jasa1;

		document.getElementById("hargajasa1").innerHTML = x;

	})
</script>