<link rel="stylesheet" type="text/css" href="plugins/datatables/jquery.dataTables.css"/>
<link rel="stylesheet" type="text/css" href="plugins/datatables/dataTables.bootstrap.css"/>
<link rel="stylesheet" href="themes/base/jquery.ui.all.css">
<link rel="stylesheet" href="css/chosen.css">
<script src="plugins/datepicker/js/jquery-1.7.2.js"></script>
<script src="plugins/datepicker/ui/jquery.ui.core.js"></script>
<script src="plugins/datepicker/ui/jquery.ui.widget.js"></script>
<script src="plugins/datepicker/ui/jquery.ui.datepicker.js"></script>

<script>
	$(function() {
		$( "#datepicker" ).datepicker({
			format:'yyyy-mm-dd'
		});
	});
</script>
<script>
	$(function() {
		$( "#datepicker1" ).datepicker({
			format:'yyyy-mm-dd'
		});
	});
</script>
<script>
	$(function() {
		$( "#datepicker2" ).datepicker({
			format:'yyyy-mm-dd'
		});
	});
</script> 
<div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            DATA OBAT
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">

          <div class="row">
              
              <!-- TABS ------------------------------------------------------------------------------------- -->
            <div class="col-md-12">
              <div class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                  <li class="active"><a href="#data" data-toggle="tab">Data Obat</a></li>
                  <li><a href="#tambah" data-toggle="tab">Tambah Data</a></li>
                </ul>
                <div class="tab-content">
                  <div class="active tab-pane" id="data">
                    <!-- Post -->
                    <div class="post">
                      <div class="box">
                        <div class="box-header">
                            <h3 class="box-title"></h3>
                        </div><!-- /.box-header -->
                            <div class="box-body table-responsive">
                                <table id="example1" class="table table-bordered table-hover table-striped">
                                    <thead>
                                        <tr>
                                            <th style="width:px;">Tanggal Masuk</th>
                                            <th style="width:px;">Jenis Obat</th>
                                            <th style="width:px;">Nama Obat</th>
                                            <th style="width:px;">Jumlah Awal</th>
                                            
                                            <th style="width:px;">Terpakai</th>
                                            <th style="width:px;">Sisa Obat</th>
                                            <th style="width:px;">Opsi</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    $query = mysql_query("SELECT * FROM inventaris");
                                    while ($data = mysql_fetch_array($query)) {
                                    ?>
                                        <tr>           
                                            <td><?php echo $data['TglPeroleh']; ?></td>
                                            <td><?php echo $data['JenisBarang']; ?></td>
                                            <td><?php echo $data['NamaBarang']; ?></td>
                                            <td><?php echo $data['BeliSendiri']; ?></td>
                                            
                                            <td><?php echo $data['Baik']; ?></td>
                                            <td><?php echo $data['Rusak']; ?></td>
                                            <td align="center">
                                              <a href="#" data-toggle="modal" data-target="#editinventaris<?php echo $data['id']; ?>"> <i class="glyphicon glyphicon-edit"></i></a>  
                                            </td>
                                        </tr>
										
<!-- Modal Edit-->                                                
<div class="modal fade" id="editinventaris<?php echo $data['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="editinventaris<?php echo $data['id']; ?>" aria-hidden="true"> 
    <div class="modal-dialog modal-lg" >
        <div class="modal-content" >
            <form id="form-data" role="form" action="" method="post" enctype="multipart/form-data">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="editinventaris<?php echo $data['id']; ?>">Edit Data</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="" class="col-sm-5 control-label">Tanggal Di Terima</label>
                            <div class="col-sm-6">
                                <input type="date" id="datepicker" name="ETglPeroleh" class="form-control" value="<?php echo $data['TglPeroleh']; ?>">
                                <input type="hidden" id="id" name="id" class="form-control" value="<?php echo $data['id']; ?>">
                            </div>
                        </div>
                        <br><br>
                        <div class="form-group">
                            <label for="" class="col-sm-5 control-label">Jenis Obat</label>
                            <div class="col-sm-6">
                                <input type="text" id="EJenisBarang" name="EJenisBarang" class="form-control" value="<?php echo $data['JenisBarang']; ?>">
                            </div>
                        </div>
                        <br><br>
                        <div class="form-group">
                            <label for="" class="col-sm-5 control-label">Kode Obat</label>
                            <div class="col-sm-6">
                                <input type="text" id="EKodeBarang" name="EKodeBarang" class="form-control" value="<?php echo $data['KodeBarang']; ?>">
                            </div>
                        </div>
                        <br><br>
                        <div class="form-group">
                            <label for="" class="col-sm-5 control-label">Nama Obat</label>
                            <div class="col-sm-6">
                                <input type="text" id="ENamaBarang" name="ENamaBarang" class="form-control" value="<?php echo $data['NamaBarang']; ?>">
                            </div>
                        </div>
                        <br><br>
                        <div class="form-group">
                            <label for="" class="col-sm-5 control-label">Jumlah</label>
                            <div class="col-sm-6">
                                <input type="text" id="EBeliSendiri" name="EBeliSendiri" class="form-control" value="<?php echo $data['BeliSendiri']; ?>">
                            </div>
                        
                    
                        </div>
                        <br><br>
                        <div class="form-group">
                            <label for="" class="col-sm-5 control-label">Terpakai</label>
                            <div class="col-sm-6">
                                <input type="text" id="EBaik" name="EBaik" class="form-control" value="<?php echo $data['Baik']; ?>">
                            </div>
                        </div>
                        <br><br>
                        <div class="form-group">
                            <label for="" class="col-sm-5 control-label">Sisa Obat</label>
                            <div class="col-sm-6">
                                <input type="text" id="ERusak" name="ERusak" class="form-control" value="<?php echo $data['Rusak']; ?>">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-info btn-submit" name="EditInventaris"><i class="fa fa-save"></i> Simpan</button>
                <button class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"></i> Batal</button>                                        
           
				<?php
				if (isset($_POST['EditInventaris'])) 
				{
				include 'koneksi.php';
				$id = $_POST['id'];				
				$ETglPeroleh			= $_POST['ETglPeroleh'];
				$EJenisBarang			= $_POST['EJenisBarang'];
				$EKodeBarang			= $_POST['EKodeBarang'];
				$ENamaBarang			= $_POST['ENamaBarang'];
				$EBeliSendiri			= $_POST['EBeliSendiri'];
				$EBantuanPemerintah			= $_POST['EBantuanPemerintah'];
				$EBantuanProv			= $_POST['EBantuanProv'];
				$EBantuanKab			= $_POST['EBantuanKab'];
				$EBantuanSumbangan			= $_POST['EBantuanSumbangan'];
				$EBaik			= $_POST['EBaik'];
				$ERusak			= $_POST['ERusak'];
				
				$query2=mysql_query("Update inventaris set TglPeroleh='$ETglPeroleh',JenisBarang='$EJenisBarang',KodeBarang='$EKodeBarang',NamaBarang='$ENamaBarang',BeliSendiri='$EBeliSendiri',BantuanPemerintah='$EBantuanPemerintah',BantuanProv='$EBantuanProv',BantuanKab='$EBantuanKab',BantuanSumbangan='$EBantuanSumbangan',Baik='$EBaik',Rusak='$ERusak' where id='$id'")or die(mysql_error());  
				echo "<script>window.location='indexadmin.php?p=UksDataObat';</script>";
				}
				?>	
            </form>    
			 </div>
         </div>
    </div>
</div>
<!--End Modal Edit-->
                                                
                                        
                                     
                                    
                             <?php
                                      }
                                      ?>
                             </tbody>
                                  </table>  
								  </div>
                        </div>
                    </div><!-- /.post -->
                  </div><!-- /.tab-pane -->

                  <div class="tab-pane" id="tambah">
                    <form id="form-data" role="form" action="" method="post" enctype="multipart/form-data">
                    <div class="row">
                    <div class="col-md-6">
                      <div class="form-group">
                        <label for="inputName" class="col-sm-5 control-label">Tanggal DiTerima</label>
                        <div class="col-sm-6">
                          <input type="date" class="form-control" id="datepicker1" placeholder="" name="TglPeroleh">
                        </div>
                      </div>
					  <br><br>
                      <div class="form-group">
                        <label for="inputExperience" class="col-sm-5 control-label">Jenis Obat</label>
                        <div class="col-sm-7">
                          <input type="text" class="form-control" id="JenisBarang" placeholder="Jenis Barang" name="JenisBarang">
                        </div>
                      </div>
					  <br><br>
					  <div class="form-group">
                        <label for="inputSkills" class="col-sm-5 control-label">Kode Obat</label>
                        <div class="col-sm-7">
                          <input type="text" class="form-control" id="KodeBarang" placeholder="Kode Barang" name="KodeBarang">
                        </div>
                      </div>
					  <br><br>
                      <div class="form-group">
                        <label for="inputSkills" class="col-sm-5 control-label">Nama Obat</label>
                        <div class="col-sm-7">
                          <input type="text" class="form-control" id="NamaBarang" placeholder="Nama Barang" name="NamaBarang">
                        </div>
                      </div>
					  <br><br>
                      <div class="form-group">
                        <label for="inputExperience" class="col-sm-5 control-label">Jumlah </label>
                        <div class="col-sm-7">
                          <input type="text" class="form-control" id="BeliSendiri" placeholder="Beli Sendiri" name="BeliSendiri">
                        </div>
                      </div>
                       
                    
                      </div>
                        <br><br>
                      <div class="modal-footer">
                        <div class="col-sm-offset-2 col-sm-10">
                          <button type="submit" name="TambahInventaris" class="btn btn-danger btn-lg">Simpan</button>
						   <?php
				if (isset($_POST['TambahInventaris'])) 
				{
				include 'koneksi.php';					
				$TglPeroleh			= $_POST['TglPeroleh'];
				$JenisBarang			= $_POST['JenisBarang'];
				$KodeBarang			= $_POST['KodeBarang'];
				$NamaBarang			= $_POST['NamaBarang'];
				$BeliSendiri			= $_POST['BeliSendiri'];
				$BantuanPemerintah			= $_POST['BantuanPemerintah'];
				$BantuanProv			= $_POST['BantuanProv'];
				$BantuanKab			= $_POST['BantuanKab'];
				$BantuanSumbangan			= $_POST['BantuanSumbangan'];
				$Baik			= $_POST['Baik'];
				$Rusak			= $_POST['Rusak'];
				$query3=mysql_query("INSERT INTO inventaris(id,TglPeroleh,JenisBarang,KodeBarang,NamaBarang,BeliSendiri,BantuanPemerintah,BantuanProv,BantuanKab,BantuanSumbangan,Baik,Rusak) VALUES ('','$TglPeroleh','$JenisBarang','$KodeBarang','$NamaBarang','$BeliSendiri','$BantuanPemerintah','$BantuanProv','$BantuanKab','$BantuanSumbangan','$Baik','$Rusak')")or die(mysql_error());  
				echo "<script>window.location='indexadmin.php?p=UksDataObat';</script>";
				}
				?>
                        </div>
                      </div>
					 
                    </form>
                  </div><!-- /.tab-pane -->
                </div><!-- /.tab-content -->
              </div><!-- /.nav-tabs-custom -->
            </div><!-- /.col -->
          </div><!-- /.row -->

        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->

<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script type="text/javascript" charset="utf8" src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.js"></script>
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
  <script>
  $(function(){
    $("#example1").dataTable();
  })
  </script>