
<!-- Content Header (Page header) -->
<section class="content-header">
  <h1>
    <i class="fa fa-folder-o icon-title"></i> Data Biaya

    <a class="btn btn-primary btn-social pull-right" href="?module=form_biaya&form=add" title="Tambah Data" data-toggle="tooltip">
      <i class="fa fa-plus"></i> Tambah
    </a>
  </h1>

</section>

<!-- Main content -->
<section class="content">
  <div class="row">
    <div class="col-md-12">

    <?php  
    // fungsi untuk menampilkan pesan
    // jika alert = "" (kosong)
    // tampilkan pesan "" (kosong)
    if (empty($_GET['alert'])) {
      echo "";
    } 
    // jika alert = 1
    // tampilkan pesan Sukses "Data obat baru berhasil disimpan"
    elseif ($_GET['alert'] == 1) {
      echo "<div class='alert alert-success alert-dismissable'>
              <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
              <h4>  <i class='icon fa fa-check-circle'></i> Sukses!</h4>
              Data Biaya baru berhasil disimpan.
            </div>";
    }
    // jika alert = 2
    // tampilkan pesan Sukses "Data obat berhasil diubah"
    elseif ($_GET['alert'] == 2) {
      echo "<div class='alert alert-success alert-dismissable'>
              <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
              <h4>  <i class='icon fa fa-check-circle'></i> Sukses!</h4>
              Data Biaya berhasil diubah.
            </div>";
    }
    // jika alert = 3
    // tampilkan pesan Sukses "Data obat berhasil dihapus"
    elseif ($_GET['alert'] == 3) {
      echo "<div class='alert alert-success alert-dismissable'>
              <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
              <h4>  <i class='icon fa fa-check-circle'></i> Sukses!</h4>
              Data Biaya berhasil dihapus.
            </div>";
    }
    ?>

      <div class="box box-primary">
	  <?php
			$dt = strtotime('today GMT');
			$awal = $_GET['awal'];
			$akhir = $_GET['akhir'];
				
			if ($awal == ""){
				$awal = date('01-m-Y');
				$tglawal = date('Y-m-01');
			}else{
				$tanggal = substr($awal,0,2);
				$bulan = substr($awal,3,2);
				$tahun = substr($awal,6,4);
				$tglawal = $tahun.'-'.$bulan.'-'.$tanggal;
			}
			
			if ($akhir == ""){
				$akhir = date('t-m-Y'); 
				$tglakhir = date('Y-m-t'); 
			}else{
				$tanggal = substr($akhir,0,2);
				$bulan = substr($akhir,3,2);
				$tahun = substr($akhir,6,4);
				$tglakhir = $tahun.'-'.$bulan.'-'.$tanggal;
			}	
			
			
			

		?>
        <div class="box-body">
		
			<form role="form" class="form-horizontal" method="POST" action="modules/biaya/proses.php?act=reload">

            <div class="form-group">
              <label class="col-sm-1">Tanggal</label>
              <div class="col-sm-2">
                <input type="text" class="form-control date-picker" data-date-format="dd-mm-yyyy" name="tgl_awal" value = "<?php echo"$awal";?>" autocomplete="off" required>
              </div>

              <label class="col-sm-1">s.d.</label>
              <div class="col-sm-2">
                <input style="margin-left:-35px" type="text" class="form-control date-picker" data-date-format="dd-mm-yyyy" value = "<?php echo"$akhir";?>" name="tgl_akhir" autocomplete="off" required>
              </div>
			  
			  <div class="col-sm-2">
			   <button type="submit" class="btn btn-primary btn-social btn-submit">
                  <i class="fa fa-eye"></i> View
                </button>
			  </div>
            </div>
			
	
			
			
         
          
          
        </form>
		
		
          <!-- tampilan tabel obat -->
          <table id="dataTables1" class="table table-bordered table-striped table-hover">
            <!-- tampilan tabel header -->
            <thead>
              <tr>
                <th class="center">Tanggal</th>
				<th class="center">Kategori</th>
				<th class="center">Keterangan</th>
				<th class="center">Qty</th>
				<th class="center">Harga</th>
				<th class="center">Debet</th>
                <th class="center">Kredit</th>
                <th class="center">Action</th>
              </tr>
            </thead>
            <!-- tampilan tabel body -->
            <tbody>
            <?php  
            $no = 1;
            // fungsi query untuk menampilkan data dari tabel obat
            $query = mysqli_query($mysqli, "SELECT * ,(select category_name from categorybiaya where category_id = biaya.kategori) as category_name FROM biaya where (billdate >='$tglawal' and billdate <='$tglakhir') and del = 'N' ORDER BY billdate DESC")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

            // tampilkan data
            while ($data = mysqli_fetch_assoc($query)) { 
              //$harga_jual = format_rupiah($data['product_price']);
              // menampilkan isi tabel dari database ke tabel di aplikasi
			  
			  $tanggal         = $data['billdate'];
              $exp             = explode('-',$tanggal);
              $tanggal_masuk   = $exp[2]."-".$exp[1]."-".$exp[0];
			  
			  $debet = number_format($data['debet'],0);
			  $kredit = number_format($data['kredit'],0);
			  
			  $qty = number_format($data['qty'],0);
			  $harga = number_format($data['harga'],0);
			  
			  
			  if ($data['category_status'] == 'Y'){
				  $status = "<button class='btn btn-success' type='submit'><i
                                                        class='fa fa-check-square-o'></i> Active
                                            </button>";
			  }
			  else{
				  $status = "<button class='btn btn-danger' type='submit'><i class='fa fa-ban'></i> Not
                                                Active
                                            </button>";
			  }
              echo "<tr>
						<td ><p style='display:none;'>$data[billdate]</p>$tanggal_masuk</td>
						<td >$data[category_name]</td>
						<td >$data[ket]</td>
						<td align='center'>$qty</td>
						<td align='right'>$harga</td>
						<td align='right'>$debet</td>
						<td align='right'>$kredit</td>
                      <td class='center'>
                        <div>
                          <a data-toggle='tooltip' data-placement='top' title='Ubah' style='margin-right:5px' class='btn btn-primary btn-sm' href='?module=form_biaya&form=edit&id=$data[id]'>
                              <i style='color:#fff' class='glyphicon glyphicon-edit'></i>
                          </a>";
            ?>
                          <a data-toggle="tooltip" data-placement="top" title="Hapus" class="btn btn-danger btn-sm" href="modules/biaya/proses.php?act=delete&id=<?php echo $data['id'];?>" onclick="return confirm('Anda yakin ingin menghapus Biaya <?php echo $data['ket']; ?> ?');">
                              <i style="color:#fff" class="glyphicon glyphicon-trash"></i>
                          </a>
            <?php
              echo "    </div>
                      </td>
                    </tr>";
              $no++;
            }
            ?>
            </tbody>
          </table>
        </div><!-- /.box-body -->
      </div><!-- /.box -->
    </div><!--/.col -->
  </div>   <!-- /.row -->
</section><!-- /.content