{% extends 'template.html' %}
{% block style %}
	<link href="{% nav public %}css/infomodal.css" rel="stylesheet">
{% endblock %}
{% block subcontent %}
<div style="margin-left:10px;">
	<h2>Periksa Pasien</h2>
	<h3 style="margin:5px 0px;">-- Data Pasien --</h3>
	<table class="data" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td style="width:90px;">No. RM</td>
			<td style="width:492px;">{{ pasien.no_rekmed }}</td>
		</tr>
		<tr>
			<td><b>Nama</b></td>
			<td><b>{{ pasien.nama }}</b>
			</td>
		</tr>
		<tr>
			<td>Alamat</td>
			<td>{{ pasien.alamat }}</td>
		</tr>
		<tr>
			<td>Usia</td>
			<td>{{ pasien.usia }} Tahun</td>
		</tr>
		<tr>
			<td>Jns Kel.</td>
			<td>{{ pasien.sex }}</td>
		</tr>
		<tr>
			<td>Golongan</td>
			<td>{{ data.golongan }}</td>
		</tr>
		<tr>
			<td>Kunjungan Lalu</td>
			<td>
				{% if histori != null %}
					{% for h in histori %}
						<div class="btn-info btn btnModal" style="margin-bottom:5px" onclick="loadHistori({{h.id}})">{{h.tglh}}</div>
					{% endfor %}
				{% else %}
					Tidak Ada
				{% endif %}
			</td>
		</tr>
	</table>
	<br/><br/>
	<h3 style="margin:5px 0px;">-- TTV --</h3>
	<table class="data" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td style="width:90px;">Suhu</td>
			<td style="width:492px;">{{ ttv.suhu }}</td>
		</tr>
		<tr>
			<td>Denyut</td>
			<td><b>{{ ttv.denyut }}</b>
			</td>
		</tr>
		<tr>
			<td>Tekanan Darah</td>
			<td>{{ ttv.tekanan_darah }}</td>
		</tr>
		<tr>
			<td>Pernapasan</td>
			<td>{{ ttv.pernapasan }}</td>
		</tr>
	</table>
	<br/><br/>
	<form class="items"  method="post">
		{% if session.flash.error != "" %}
			<div class="error">
				<b>Ada Kesalahan:</b><br/> 
				{{ session.flash.error | safe }}
			</div>
		{% endif %}
		<br/>
		<h3 style="margin:5px 0px;display:none">-- Tindakan --</h3>
		<div class="tindakan" style="display:none">
			<div class="clearfix"></div>
			<center><br/><br/><h3>Loading Data...</h3></center>
			<div class="plus plust btn-success"><i class="fas fa-plus"></i></div>
		</div>
		<br/><br/><br/>
		<h3 style="margin:5px 0px;">-- Obat --</h3>
		<div class="obat">
			<div class="clearfix"></div>
			<center><br/><br/><h3>Loading Data...</h3></center>
			<div class="plus pluso btn-success btn"><i class="fas fa-plus"></i></div>
		</div>
		<br/><br/><br/>
		<table>
			<tr>
				<td style="width:60px;"><h2>Total </h2></td>
				<td style="width:20px;padding-left:10px;color:#666;"></td>
				<td style="width:120px;"><h2>Rp  <span class="total_sum">0</span></h2></td>
			</tr>
		</table>
		<br/><br/><br/>
		<button class="submit btn btn-primary" type="submit" >Selesai</button>
		<div class="batal btn btn-danger" style="margin-left:15px">Batal</div>
		<br/><br/>
	</form>
</div>
<div class="tindakan_item_master" style="display:none">
	<div class="option">
		<div class="minus minust btn-danger btn"><i class="fas fa-minus"></i></div>
	</div>
	<table style="margin-left:30px;width:600px;">
		<tr>
			<td>
				<select class="form-control menu1" name="tindakan[]">
				{% for t in tindakan %}
					<option kode="{{t.kode}}" id_tindakan="{{t.id}}" value="{{t.id}};{{t.harga_jual}}">{{t.nama | safe}}</option>
				{% endfor %}
				</select>
			</td>
			<td style="padding-left:10px;">
				Jml: <input class="jml form-control" value="1" name="jmlt[]" type="text" style="width:50px;" />
			</td>
			<td>
				<span class="total" style="width:100%;">Rp <span class="total_price">0</span></span>
			</td>
		</tr>
	</table>
</div>
<div class="obat_item_master" style="display:none">
	<div class="option">
		<div class="minus btn-danger btn"><i class="fas fa-minus"></i></div>
	</div>
	<table style="margin-left:30px;width:600px;">
		<tr>
			<td>
				<select class="form-control menu1" name="obat[]">
				{% for o in obat %}
					<option kode="{{o.kode}}" id_obat="{{o.id}}" value="{{o.id}};{{o.harga_jual}}">{{o.nama | safe}}</option>
				{% endfor %}
				</select>
			</td>
			<td style="padding-left:10px;">
				Jml: <input class="jml form-control" value="1" name="jmlo[]" type="text" style="width:50px;" />
			</td>
			<td>
				<span class="total" style="width:100%;">Rp <span class="total_price">0</span></span>
			</td>
		</tr>
	</table>
</div>
<!-- iModal -->
<div id="infoModal" class="imodal" style="display:none">
  <!-- iModal content -->
	<div class="imodal-content">
		<span class="close">&times;</span>
		<div class="detail-content">
		</div>
	</div>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript">
	var reg = 0;
	var baru = "{{ data.baru }}";
	$(document).ready(function() {
		if (baru == 'y') {
			reg = 10000;
			$(".total_sum").text(currency(reg));
		}
		$(".plust").on("click",function() {
			newItemT();
		});
		$(".pluso").on("click",function() {
			newItemO();
		});
		$(".minus").on("click",function() {
			$(this).parent().parent().remove();
			$(this).parent().parent().find(".jml").keyup();
		});
		$(".batal").on("click",function() {
			location.href = "{% nav poli_kunjungan %}";
		});
		$(".obat_item select").on('change',function() {
			$menu = $(this).parent().parent();
			$menu.find('.jml').keyup();
		});
		$(".tindakan_item select").on('change',function() {
			$menu = $(this).parent().parent();
			$menu.find('.jml').keyup();
		});
		$(".jml").on("keyup",function() {
			$parent = $(this).parent().parent()
			$super_parent = $parent.parent().parent().parent();
			jml =  $super_parent.find('.jml').val();
			total_price = currency(parseInt(jml * $super_parent.find('select').val().split(';')[1]));
			$super_parent.find('.total_price').text(total_price);
			
			var total = 0;
			$(".total_price").each(function() {
				total += $(this).text().replace(/\./g,'') *1;
			});
			$(".total_sum").text(currency(total + reg));
		});
		$(".items").submit(function() {
			$(".submit").attr('disabled','disabled');
		});
		$(".tindakan center").remove();
		$(".obat center").remove();
	});
	<!-- newItemT(); -->
	<!-- newItemO(); -->
	function newItemT() {
		$menu = $(".tindakan_item_master").clone().removeClass("tindakan_item_master").addClass("tindakan_item").show();
		$menu.insertBefore($('.plust')).find('.jml').keyup();
	}
	function newItemO() {
		$menu = $(".obat_item_master").clone().removeClass("obat_item_master").addClass("obat_item").show();
		$menu.insertBefore($('.pluso')).find('.jml').keyup();
	}
	function loadHistori(id) {
		modal.style.display = "block";
		$('.detail-content').html('Sedang memproses...');
		$('.detail-content').load('{% nav poli_histori %}?idk='+id);
	}
	function currency(angka){
		var rupiah = '';		
		var angkarev = angka.toString().split('').reverse().join('');
		for(var i = 0; i < angkarev.length; i++) if(i%3 == 0) rupiah += angkarev.substr(i,3)+'.';
		return rupiah.split('',rupiah.length-1).reverse().join('');
	}
</script>
<script src="{% nav public %}js/infomodal.js" type="text/javascript"></script>
{% endblock %}