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

    <a class="btn btn-primary btn-social pull-right" href="?module=form_ibadah&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 Ibadah 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 Ibadah 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 Ibadah berhasil dihapus.
            </div>";
    }elseif ($_GET['alert'] == 4) {
      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 Ibadah baru berhasil diapprove.
            </div>";
    }
    ?>

      <div class="box box-primary">
        <div class="box-body">
          <!-- tampilan tabel obat -->
          <table id="dataTables1" class="table table-bordered table-striped table-hover">
            <!-- tampilan tabel header -->
            <thead>
              <tr>
                <th class="center">No</th>
                <th class="center">Kategorial</th>
                <th class="center">Sektor</th>
                <th class="center">Tanggal</th>
                <th class="center">Dilaki</th>
                <th class="center">Diberu</th>
				<th class="center">Kolekte</th>
				<th class="center">Perpuluhen</th>
				<th class="center">Tanda Meriah Ukur</th>
                <th class="center">Action</th>
              </tr>
            </thead>
            <!-- tampilan tabel body -->
            <tbody>
            <?php  
            $no = 1;
            $user = $_SESSION['id_user'];
			$loc = $_SESSION['loc'];
			
			
			$pabrik = "lokasi in  (".$_SESSION['loc'].") and " ;

            $query = mysqli_query($mysqli, "SELECT *
													,(select nama from is_lokasi where id = ibadah.lokasi)as namalokasi 
													,(select nama from is_sektor where id=(select sektor from is_lokasi where id = ibadah.lokasi))as namasektor 
													,(select sum(total)  from dana where ibadah = ibadah.id and status <>'N' and jenis =1)as jlhkolekte
													,(select sum(total)  from dana where ibadah = ibadah.id and status <>'N' and jenis =2)as jlhperpuluhan
													,(select sum(total)  from dana where ibadah = ibadah.id and status <>'N' and jenis =3)as jlhsyukur
													from ibadah 
													where $pabrik status <> 'N'")
                                            or die('Ada kesalahan pada query tampil Data : '.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
              $id = $data['id'];
			  $kolekte = number_format($data['jlhkolekte'],0);
			  $perpuluhan = number_format($data['jlhperpuluhan'],0);
			  $syukur = number_format($data['jlhsyukur'],0);
			  
              echo "<tr>
                      <td class='center'>$data[id]</td>
                      <td class='center'>$data[namalokasi]</td>
                      <td class='center'>$data[namasektor]</td>
					  <td class='center'>$data[tanggal]</td>
					  <td class='center'>$data[lk]</td>
					  <td class='center'>$data[pr]</td>
					  <td class='center'>$kolekte</td>
					  <td class='center'>$perpuluhan</td>
					  <td class='center'>$syukur</td>
                      ";
            ?>           
                        <td> 
                        <?php if ($data['status'] == 'Y'): ?>
                            <a href="modules/ibadah/proses.php?act=approve&id=<?=$id?>" onclick="return confirm('Anda yakin ingin Approve Data Ibadah Ini # <?php echo $id; ?> ?')">
                                <button type="button" class="btn btn-success btn-sm"><i class="fa fa-thumbs-up"></i></button>
                            </a>
                            <a href='?module=form_ibadah&form=edit&id=<?=$id;?>'  class="btn btn-warning btn-sm" ><i class="fa fa-edit"></i></a>
                            <button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#delete<?=$id;?>"><i class="fa fa-trash"></i></button>
                        <?php else: ?>
                            <a href='?module=form_ibadah&form=edit&id=<?=$id;?>'  class="btn btn-warning btn-sm" ><i class="fa fa-eye"></i></a>
                            
                        <?php endif; ?>

                            
                        </td>
                       
            <?php
              echo " 
                      
                    </tr>";
              $no++;
            }
            ?>
            </tbody>
          </table>
        </div><!-- /.box-body -->
      </div><!-- /.box -->
    </div><!--/.col -->
    
  </div>   <!-- /.row -->
  <div class="modal fade" id="myModal">
    <div class="modal-dialog">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Tambah Data Ibadah</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
            <br>
            <form action="modules/ibadah/proses.php?act=tambahIbadah" name="formSaya" method="post">
                <label>Lokasi</label>
                <select name="lokasi" class="form-control">
                          <?php
                          $pilihpabrik = mysqli_query($mysqli, "SELECT *,(select nama from is_sektor where id = is_lokasi.sektor) as namasektor  
																from is_lokasi where id in ($_SESSION[loc]) and status = 'Y'");
                          while ($fetcharray = mysqli_fetch_array($pilihpabrik)) {
                            $lokasi = $fetcharray['nama']." - ".$fetcharray['namasektor'];
                            $id = $fetcharray['id'];
                            $selected = ($id == $lokasi) ? "selected" : "";
                            ?>
                            <option value="<?= $id; ?>" <?= $selected ?>>
                              <?= $lokasi; ?>
                            </option>
                            <?php
                          }
                          ?>
                </select>
                <br>
                <label>Tanggal</label>
                <div class="input-group">
                    <input type="date" class="form-control" name="tanggal" value="<?php echo date('Y-m-d'); ?>" >
                    <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>    
                    </div>
                </div> 
                <br>
                <label>Diaki</label>
                <div class="input-group">
                    <input type="number" class="form-control" name="lk" onkeyup="calc()">
                    <div class="input-group-addon">
                        <b>Org</b>   
                    </div>
                </div>
				<br>
                <label>Diberu</label>
                <div class="input-group">
                    <input type="number" class="form-control" name="pr" onkeyup="calc()">
                    <div class="input-group-addon">
                        <b>Org</b>   
                    </div>
                </div>
                <br>
				<label>Kolekte</label>
                <div class="input-group">
                    <div class="input-group-addon">
                        <b>Rp</b> 
                    </div>
                        <input type="text" class="form-control" name="kolekte">
                    </div>
				<br>
				<label>Perpuluhen</label>
                <div class="input-group">
                    <div class="input-group-addon">
                        <b>Rp</b> 
                    </div>
                        <input type="text" class="form-control" name="perpuluhan">
                    </div>
				<br>
				<label>Tanda Meriah Ukur</label>
                <div class="input-group">
                    <div class="input-group-addon">
                        <b>Rp</b> 
                    </div>
                        <input type="text" class="form-control" name="syukur">
                    </div>
				
				<br>
                <label>PJJ Senin Sireh</label>
                <div class="input-group">
                    <input type="date" class="form-control" name="tglnext" value="<?php echo date('Y-m-d'); ?>" >
                    <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>    
                    </div>
                </div> 
				<br>
                <label>Ingan Pulung I Rumah</label>
                    <input type="text" class="form-control" name="pic" >
				<br>
                <label>Alamat</label>
                    <input type="text" class="form-control" name="alamat" >
				<br>
				    <button type="button" class="btn btn-danger" style="float: left;" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary" name="submit" style="float: right;">Submit</button>
                <br>
                <br>
                <br>
            </form> 
        </div>
      </div>
    </div>
  </div>
  <?php
          $query2 = mysqli_query($mysqli, "SELECT * ,(select nama from is_lokasi where id = ibadah.lokasi)as namalokasi 
													,(select nama from is_sektor where id=(select sektor from is_lokasi where id = ibadah.lokasi))as namasektor 
													from ibadah 
													where status <> 'N'")
                                            or die('Ada kesalahan pada query tampil Data : '.mysqli_error($mysqli));
                                            
              // tampilkan data
            while ($data2 = mysqli_fetch_assoc($query2)) {  
              
              $id = $data2['id'];
              $lokasi = $data2['namalokasi'];
			  $sektor = $data2['namasektor'];
              $tanggal = $data2['tanggal'];
              $lk = $data2['lk'];
              $pr = $data2['pr'];
              $kolekte = $data2['kolekte'];
			  $perpuluhan = $data2['perpuluhan'];
			  $syukur = $data2['syukur'];
              $pic = $data2['pic'];  
			  $alamat = $data2['alamat'];  
			  $app = $data2['status'];  			  
            ?>
           
    <div class="modal fade" id="edit<?=$id;?>">
      <div class="modal-dialog modal-dialog-centered">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">View Ibadah</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
            <br>
            <form action="modules/ibadah/proses.php?act=editIbadah" name="formSaya2" method="post">
            <input type="hidden" class="form-control" name="id" value="<?=$id;?>">
            <label>Lokasi</label>
                <input type="text" class="form-control" value="<?=$lokasi;?>" readonly>
                <br>
                <label>Tanggal</label>
                <div class="input-group">
                    <input type="date" class="form-control" name="tanggal" value="<?php echo date('Y-m-d',strtotime($tanggal)); ?>" >
                    <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>    
                    </div>
                </div> 
                <br>
                <label>Dilaki</label>
                <div class="input-group">
                    <input type="text" class="form-control" value="<?=$lk;?>" name="lk" onkeyup="calc2()">
                    <div class="input-group-addon">
                        <b>Org</b>   
                    </div>
                </div>
                <br>
				<label>Diberu</label>
                <div class="input-group">
                    <input type="text" class="form-control" value="<?=$pr;?>" name="pr" onkeyup="calc2()">
                    <div class="input-group-addon">
                        <b>Org</b>   
                    </div>
                </div>
                <br>
				<label>Kolekte</label>
                <div class="input-group">
                    <div class="input-group-addon">
                        <b>Rp</b> 
                    </div>
                        <input type="text" class="form-control" value="<?=$kolekte;?>" name="kolekte">
                    </div>
				<br>
				<label>Perpuluhen</label>
                <div class="input-group">
                    <div class="input-group-addon">
                        <b>Rp</b> 
                    </div>
                        <input type="text" class="form-control" value="<?=$perpuluhan;?>" name="perpuluhan">
                    </div>
				<br>
				<label>Tanda Meriah Ukur</label>
                <div class="input-group">
                    <div class="input-group-addon">
                        <b>Rp</b> 
                    </div>
                        <input type="text" class="form-control" value="<?=$syukur;?>" name="syukur">
                    </div>
				<br>
                <label>PJJ Senin Sireh</label>
                <div class="input-group">
                    <input type="date" class="form-control" name="tglnext" value="<?php echo date('Y-m-d',strtotime($tanggal)); ?>" >
                    <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>    
                    </div>
                </div> 
				<br>
                <label>Ingan Pulung I Rumah</label>
					<input type="text" class="form-control" name="pic" value="<?=$pic;?>" >
				<br>
                <label>Alamat</label>
                    <input type="text" class="form-control" name="alamat"  value="<?=$alamat;?>">
            
               
                <br>
				    <button type="button" class="btn btn-danger" style="float: left;" data-dismiss="modal">Close</button>
					
					<?php
						if($app == "Y" ){
							echo"
							<button type='submit' class='btn btn-primary' name='submit' style='float: right;'>Submit</button>";
						}
					?>
                <br>
                <br>
                <br>
            </form> 
        </div>
      </div>
    </div>
  </div>
<!-- Delete Modal -->
<div class="modal fade" id="delete<?=$id;?>">
    <div class="modal-dialog modal-dialog-centered">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Hapus Data Ibadah</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
              Apakah anda ingin menghapus data ibadah ini ? # <?=$id?>
        </div>
        <!-- Modal footer -->
        <div class="modal-footer">
          <form action="modules/ibadah/proses.php?act=deleteIbadah" method="post">
            <input type="hidden" name="id" value="<?=$id;?>">
            <button type="submit" class="btn btn-primary" name="delete">Yes</button>
				    <button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
          </form> 
        </div>
      </div>
    </div>
  </div>
  <?php
            }
    ?>
</section>

<script>
      function calc(){
        var elm = document.forms["formSaya"];
        if (elm["netto"].value != "" && elm["potongan"].value != ""){
          var jlh = (parseInt(elm["netto"].value) - parseInt(elm["potongan"].value));
          elm["tarra"].value = jlh;
        }
      }
  </script>


<script>
      function calc2(){
        var elm = document.forms["formSaya2"];
        if (elm["netto"].value != "" && elm["potongan"].value != ""){
          var jlh = (parseInt(elm["netto"].value) - parseInt(elm["potongan"].value));
          elm["tarra2"].value = jlh;
        }
      }
  </script>


