<?php
	$now = @$this->uri->segment(3);
?>
<div class="panel panel-default">
	<div class="panel-heading">
		<div class="row">
			<div class='col-sm-6'><?php echo $judul;?></div>
			<div class='col-sm-6' align='right'>

			</div>
		</div>
	</div>
	<?php
	if(isset($_GET['s'])){
		switch($_GET['s']){
			case "true" : $c="success"; break;
			case "false": $c="danger"; break;
		}
			echo"
			<br>
			<div class='container' style='width:100%;'><div class='row'><div class='col-md-12'>
			<div class='alert alert-$c' role='alert'>
				<span class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></span>
				<span class='sr-only'>Error:</span>
				$_GET[m]
			</div></div></div>
			</div>
			";
	}
	?>	
	<form action="<?=base_url()?>cms/logic/barangProses" method="post" data-parsley-validate enctype="multipart/form-data">
		<div class="panel-body"> 
			<?php if(isset($data['id_barang']) && $data['id_barang'] != ''): ?>
				<input type="hidden" name="_id" value="<?=$data['id_barang']?>" /> 
				<input type="hidden" name="action" value="edit" /> 
			<?php endif; ?> 

			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Kode Obat<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-7"> 
						<input type='text' class='form-control'  name='kode' value='<?=(isset($data['kode']) ? $data['kode'] : '')?>' required>
					</div>
				</div>
			</div>   
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Nama<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-7"> 
						<input type='text' class='form-control' id='nama' name='nama' value='<?=(isset($data['nama']) ? $data['nama'] : '')?>' required>
					</div>
				</div>
			</div>   
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Satuan<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-4"> 
						<select class='form-control' name='id_satuan'>
							<option value=''> - </option>
							<?php
							if(isset($satuan) && count($satuan) > 0): foreach($satuan as $row ):?>
								<option value="<?=$row['id_satuan']?>" <?=(isset($data['id_satuan']) && $data['id_satuan'] == $row['id_satuan']) ? 'selected' : ''?>><?=$row['nama']?></option>  
							<?php endforeach; endif;  ?>
						</select>
					</div>
				</div>
			</div>  
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Kategori<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-4"> 
						<select class='form-control' name='id_kategori'>
							<option value=''> - </option>
							<?php
							if(isset($kategori) && count($kategori) > 0): foreach($kategori as $row ):?>
								<option value="<?=$row['id_kategori']?>" <?=(isset($data['id_kategori']) && $data['id_kategori'] == $row['id_kategori']) ? 'selected' : ''?>><?=$row['nama']?></option>  
							<?php endforeach; endif;  ?>
						</select>
					</div>
				</div>
			</div>  
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Distributor<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-4"> 
						<select class='form-control' name='id_supplier'>
							<option value=''> - </option>
							<?php
							if(isset($supplier) && count($supplier) > 0): foreach($supplier as $row ):?>
								<option value="<?=$row['id_supplier']?>" <?=(isset($data['id_supplier']) && $data['id_supplier'] == $row['id_supplier']) ? 'selected' : ''?>><?=$row['nama']?></option>  
							<?php endforeach; endif;  ?>
						</select>
					</div>
				</div>
			</div>  
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Harga Beli<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-3"> 
						<input type='number' class='form-control'  name='harga_beli' id='harga_beli' value='<?=(isset($data['harga_beli']) ? $data['harga_beli'] : '')?>' required>
					</div>
				</div>
			</div>   
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Harga Resep<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-3"> 
						<input type='number' class='form-control'  name='harga_resep' value='<?=(isset($data['harga_resep']) ? $data['harga_resep'] : '')?>' required>
					</div>
				</div>
			</div>
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Harga Satuan<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-3"> 
						<input type='number' class='form-control'  name='harga_satuan' id='harga_satuan' value='<?=(isset($data['harga_satuan']) ? $data['harga_satuan'] : '')?>' required>
					</div>
				</div>
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Margin Satuan<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-3"> 
						<span id='persen'></span> %
					</div>
				</div>
			</div>   
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Harga Box<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-3"> 
						<input type='number' class='form-control' id='harga_box'  name='harga_box' value='<?=(isset($data['harga_box']) ? $data['harga_box'] : '')?>' required>
					</div>
				</div>
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Margin Box<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-3"> 
						<span id='persenbox'></span> %
					</div>
				</div></div>
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Isi<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-2"> 
						<input type='number' class='form-control'  name='isi' value='<?=(isset($data['isi']) ? $data['isi'] : '')?>' required>
					</div>
				</div>
			</div>   
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Stok<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-2"> 
						<input type='number' class='form-control'  name='stok' value='<?=(isset($data['stok']) ? $data['stok'] : '')?>' required>
					</div>
				</div>
			</div>   
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Tgl Masuk<span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-2"> 
						<?php
							$tm = "";
							if(isset($data['tgl_masuk'])){
								if($data['tgl_masuk']!=""){
									$ex = explode(" ",$data['tgl_masuk']);
									$tm = $ex[0];
								}
							}
						?>
						<input type='text' class='form-control datepicker' data-date-format='yyyy-mm-dd'  name='tgl_masuk' value='<?=$tm?>' required>
					</div>
				</div>
			</div>   
			<div class="form-group">
				<div class="row">
					<div class="col-sm-2">
						<label class="control-label">Status <span class="text-danger">*</span></label>
					</div>
					<div class="col-sm-3"> 
						<select name="status" class="form-control" required>
							<option value="">Select</option>
							<?php  foreach ($status as $key => $value) { ?>
								<option value="<?=$key?>" <?=(isset($data['status']) && $data['status'] == $key) ? 'selected' : ''?>><?=$value?></option>  
							<?php } ?>
						</select>
					</div>
				</div>
			</div> 	
		</div> 
		
		<div class="panel-footer">
			<button type="submit" onclick=" " class="btn btn-primary">Submit</button>
			<a href='<?=$url?>barang' class='btn btn-default'>Back</a>
			<button type="reset" class="btn btn-inverse">Clear</button>
		</div>
	</form>
</div>