{% extends 'template.html' %}
{% block title %}Edit Pembelian Obat{% endblock %}
{% block subcontent %}
	{% if session.flash.error != "" %}
		{{ session.flash.error | safe }}
	{% endif %}
	
	<h2>List Pembelian > Pembelian Baru</h2>
	<form method="post">
		<table cellpadding="5" cellspacing="0" border="0">
			<tr>
				<td>Nama Obat</td>
				<td>
					<select name="id_obat">
						{% for o in obat %}
						<option value="{{o.id}}" {% if data.id_obat == o.id %}selected="selected"{% endif %}>{{o.nama}}</option>
						{% endfor %}
					</select>
				</td>
			</tr>
			<tr>
				<td>Golongan</td>
				<td>
					<select name="jenis">
						<option value="u" {% if data.jenis == 'u' %}selected="selected"{% endif %}>Umum</option>
						<option value="s" {% if data.jenis == 's' %}selected="selected"{% endif %}>Subsidi</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>Tgl Beli</td>
				<td><input type="text" name="tgl_beli" id="date_picker1" value="{{ data.tgl_beli }}"/></td>
			</tr>
			<tr>
				<td>PBF</td>
				<td><input type="text" name="pbf" value="{{ data.pbf }}"/></td>
			</tr>
			<tr>
				<td>Batch</td>
				<td><input type="text" name="batch" value="{{ data.batch }}"/></td>
			</tr>
			<tr>
				<td>Harga Beli</td>
				<td><input type="text" name="harga_beli" value="{{ data.harga_beli }}"/></td>
			</tr>
			<tr>
				<td>Exp Date</td>
				<td><input type="text" name="exp" id="date_picker2" value="{{ data.exp }}"/></td>
			</tr>
			<tr>
				<td>Masuk</td>
				<td><input type="text" name="masuk" value="{{ data.masuk }}"/></td>
			</tr>
			<tr>
				<td>Keluar</td>
				<td><input type="text" name="keluar" value="{{ data.keluar }}"/></td>
			</tr>
			<tr>
				<td>Keterangan</td>
				<td><textarea name="keterangan" style="width:300px;height:100px">{{ data.keterangan }}</textarea></td>
			</tr>
		</table>
		<br/><input type="submit" class="btn btn-success" value="Simpan" /> <a class="btn btn-danger" href="{% nav apotik_stock %}">Batal</a>
	</form>
{% endblock %}
{% block script %}
<script type="text/javascript" src="{% nav public %}js/glDatePicker.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$("#date_picker1").glDatePicker({
			cssName: "android",
			selectedDate:new Date("{{tgl_js}}"),
			startDate: new Date("{{tgl_js}}"),
		    allowOld: true,
			onChange: function(target, newDate)
				{
					if (newDate.getDate() < 10) {
						tgl = "0" + newDate.getDate();
					} else {
						tgl = newDate.getDate();
					}
					var month= ["01","02","03","04","05","06","07","08","09","10","11","12"];
					target.val
					(
						tgl  + "-" +
						month[newDate.getMonth()] + "-" +
						newDate.getFullYear() 
					);
				}
		});
		$("#date_picker2").glDatePicker({
			cssName: "android",
			selectedDate:new Date("{{tgl_js}}"),
			startDate: new Date("{{tgl_js}}"),
		    allowOld: true,
			onChange: function(target, newDate)
				{
					if (newDate.getDate() < 10) {
						tgl = "0" + newDate.getDate();
					} else {
						tgl = newDate.getDate();
					}
					var month= ["01","02","03","04","05","06","07","08","09","10","11","12"];
					target.val
					(
						tgl  + "-" +
						month[newDate.getMonth()] + "-" +
						newDate.getFullYear() 
					);
				}
		});
	});
</script>
{% endblock %}