<div class="content-wrapper">
	<section class="content-header">
		<h1>
			Perolehan
			<small>Rencana Perolehan Tanah</small>
		</h1>
	</section>

	<section class="content">

		<div class="row">
			<div class="col-lg-12">


				


				<div class="box box-primary">
					<div class="box-header">
                        <h3 class="box-title">Data Perolehan</h3>
                        <div class="pull-right">
                            <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#addKategori"><i class="fa fa-plus"></i>  &nbsp Tambah</button>
                        </div>

						<div id="addKategori" class="modal fade" role="dialog">
							<div class="modal-dialog">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal">&times;</button>
										<center><h4 class="modal-title"> Tambah Data Perolehan</h4></center>
									</div>
									<div class="modal-body">

										<form action="<?= base_url('perolehan/perolehan_act');?>" method="post" enctype="multipart/form-data">											

											<div class="form-group" style="width:100%">
												<label style="width: 100%;"> Provinsi</label>		
												<!-- <input type="text" name="provinsi" required class="form-control" style="width:100%"> -->
                                                <?php $idProv = 0; ?>
                                                <select class="form-control" name="provinsi" id="provinsi<?=$idProv;?>" onchange="changeKota(<?=$idProv;?>)" required style="width: 100%;">
													<option value="">--Pilih Provinsi--</option>
													<?php 
													$pr = $this->db->query("SELECT * FROM master_provinsi ORDER BY provinsi_nama")->result();
													foreach ($pr as $d) {
														?>
														<option value="<?php echo $d->provinsi_id ?>"><?php echo $d->provinsi_nama ?></option>
														<?php
													}
													?>													
												</select>
                                            </div>

                                            <div class="form-group" style="width:100%">
												<label style="width: 100%;"> Kabupaten/Kota</label>		
												<!-- <input type="text" name="kota" required class="form-control" style="width:100%"> -->
                                                <select class="form-control" id="kota<?=$idProv;?>" name="kota" onchange="changeKecamatan(<?=$idProv;?>)" required style="width: 100%;">
													<option>No Selected</option>
												</select>
											</div>

                                            <div class="form-group" style="width:100%">
												<label style="width: 100%;"> Kecamatan</label>		
                                                <select class="form-control" id="kecamatan<?=$idProv;?>" name="kecamatan" onchange="changeKelurahan(<?=$idProv;?>)" required style="width: 100%;">
													<option>No Selected</option>
												</select>
											</div>

                                            <div class="form-group" style="width:100%">
												<label style="width: 100%;"> Kelurahan/Desa</label>		
                                                <select class="form-control" id="kelurahan<?=$idProv;?>" name="kelurahan" required style="width: 100%;">
													<option>No Selected</option>
												</select>
											</div>

                                            <div class="form-group" style="width:100%">
												<label style="width: 100%;"> Status RKAT</label>		
												<select class="form-control" name="rkat" required style="width: 100%;">
													<option>--Pilih Status--</option>
                                                    <option value="rkat">RKAT</option>
                                                    <option value="non">NON RKAT</option>
												</select>
											</div>

                                            <div class="form-group" style="width:100%">
												<label style="width: 100%;"> Luas (Ha)</label>		
												<input type="number" name="luas" required class="form-control" style="width:100%">
											</div>

                                            <div class="form-group" style="width:100%">
												<label style="width: 100%;"> Bekas Pemegang Hak</label>		
												<input type="text" name="ex_hak" required class="form-control" style="width:100%">
											</div>

                                            <div class="form-group" style="width:100%">
												<label style="width: 100%;"> Dasar Perolehan</label>		
												<select class="form-control" id="dasar_perolehan" name="dasar_perolehan" required style="width: 100%;">
													<option value="">--Pilih Dasar Perolehan--</option>
													<?php 
													$mdp = $this->db->query("select * from master_dasar_perolehan")->result();
													foreach ($mdp as $dp) {
														?>
														<option value="<?php echo $dp->dasar_perolehan_desc ?>"><?php echo $dp->dasar_perolehan_desc ?></option>
														<?php
													}
													?>													
												</select>
											</div>

                                            <div class="form-group" style="width:100%">
												<label style="width: 100%;"> P.I.C.</label>		
												<input type="text" name="pic" required class="form-control" style="width:100%">
											</div>
										
											<br>
											<input type="submit" value="Simpan" class="btn btn-primary">
										</form>
									</div>											
								</div>
							</div>
						</div>		
					</div>

					<div class="box-body">
                        <div class="table-responsive">
                            <!-- Create the drop down filter -->
                            <!-- <div class="category-filter">
                                <select id="provinsiFilter" class="form-control" style="display: inline; margin-left: 25px; width: 200px; height: 30px;">
                                    <option value="">--Provinsi--</option>
                                    <?php 
										// $fprovs = $this->db->query("select * from master_provinsi order by provinsi_nama")->result();
										// foreach ($fprovs as $fp) {
									?>
										<option value="<?php // $fp->provinsi_nama; ?>"><?php // $fp->provinsi_nama; ?></option>
									<?php
										//}
									?>	
                                </select>
                            </div> -->

                            <table class="table table-bordered" id="table-datatable">
                                <thead>
                                    <tr>
                                        <th width="1%">NO</th>
                                        <th>Provinsi</th>
                                        <th>Kabupaten/Kota</th>
                                        <th>Status</th>
                                        <th>Luas</th>
                                        <th>Dasar Perolehan</th>
                                        <th>P.I.C.</th>
                                        <th>Tahapan Perolehan</th>
                                        <th width="15%">OPSI</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php 
                                    $no = 1;
                                    foreach($perolehans as $p){ 									
                                        ?>
                                        <tr>
                                            <td><?php echo $no++; ?></td>
                                            <td><?= $p->provinsi_nama;?></td>
                                            <td><?= $p->kota_nama;?></td>
                                            <td>
                                                <?php
                                                    if ($p->is_rkat) {
                                                        echo "RKAT";
                                                    }else {
                                                        echo "NON RKAT";
                                                    }
                                                ?>
                                            </td>
                                            <td><?= $p->perolehan_luas.' Ha';?></td>
                                            <td><?= $p->perolehan_dasar;?></td>
                                            <td><?= $p->perolehan_pic;?></td>
                                            <td>
                                                <?php
                                                    $tahapan = $this->db->query("SELECT COUNT(DISTINCT perolehan_status_id) AS tahapan FROM perolehan_progres WHERE perolehan_id = '$p->perolehan_id'")->row()->tahapan;

                                                    if($tahapan >= 13){
                                                ?>

                                                    <div class="alert alert-success" style="opacity: 0.7;">
                                                        <strong><?= $tahapan.' dari 13 tahapan.'?></strong>
                                                    </div>

                                                <?php     
                                                    }elseif($tahapan < 13 && $tahapan > 2){
                                                ?>

                                                    <div class="alert alert-info" style="opacity: 0.7;">
                                                        <strong><?= $tahapan.' dari 13 tahapan.'?></strong>
                                                    </div>

                                                <?php
                                                    }elseif($tahapan == 1 || $tahapan == 2){
                                                ?>

                                                    <div class="alert alert-warning" style="opacity: 0.7;">
                                                        <strong><?= $tahapan.' dari 13 tahapan.'?></strong>
                                                    </div>

                                                <?php
                                                    }else{
                                                ?>
                                                    <div class="alert" style="opacity: 0.5; background-color: lightgrey;">
                                                        <strong><?= $tahapan.' dari 13 tahapan.'?></strong>
                                                    </div>
                                                <?php
                                                    }
                                                ?>
                                            </td>
                                            <td>

                                                <button type="button" class="btn btn-primary btn-sm" title="Progres" data-toggle="modal" data-target="#progres<?php echo $p->perolehan_id ?>"><i class="fa fa-history"></i> </button>
                                                <button type="button" class="btn btn-success btn-sm" title="Edit Perolehan" data-toggle="modal" data-target="#edit<?php echo $p->perolehan_id ?>"><i class="fa fa-pencil"></i> </button>
                                                <button type="button" class="btn btn-warning btn-sm" title="Tambah Progres" data-toggle="modal" data-target="#addProgres<?=$p->perolehan_id;?>"><i class="fa fa-arrow-up"></i> </button>
                                                <button type="button" class="btn btn-danger btn-sm" title="Hapus" data-toggle="modal" data-target="#hapusData<?php echo $p->perolehan_id ?>"><i class="fa fa-trash"></i> </button>	


                                                <!-- Progres Perolehan -->
                                                <div id="progres<?php echo $p->perolehan_id ?>" class="modal fade" role="dialog">
                                                    <div class="modal-dialog">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                                <center>
                                                                    <h4 class="modal-title"> Aktivitas Terakhir</h4>
                                                                </center>
                                                                <center>
                                                                    <small><?=$p->kota_nama;?>, <?=$p->provinsi_nama;?>, <?=$p->perolehan_luas;?> Ha</small>
                                                                </center>
                                                            </div>
                                                            <div class="modal-body" style="height: 360px; overflow-y: scroll;">
                                                                    <?php
                                                                        $i = 0;
                                                                        foreach ($progres as $q) {
                                                                            if ($q->perolehan_id == $p->perolehan_id) {
                                                                    ?>
                                                                        <?php
                                                                            $i++;
                                                                            $tgl_awal = date("d-m-Y", strtotime($q->tgl_awal));

                                                                            if ($q->tgl_akhir) {
                                                                                $tgl_akhir = date("d-m-Y", strtotime($q->tgl_akhir));
                                                                            }else {
                                                                                $tgl_akhir = "Belum Selesai";
                                                                            }
                                                                            
                                                                        ?>
                                                                        <h4><?= $q->perolehan_status_nama;?></h4>
                                                                        <p><?= $q->perolehan_kegiatan_desc;?></p>
                                                                        <p><?= 'Mulai : '.$tgl_awal.' | Selesai : '.$tgl_akhir; ?></p>
                                                                        <hr>

                                                                    <?php
                                                                            }
                                                                        }

                                                                        if ($i == 0) {
                                                                            echo "<p>Belum ada progres</p>";
                                                                        }
                                                                    ?>
                                                            </div>		
                                                            <div class="modal-footer">
                                                                <div class="pull-right">
                                                                    <a href="<?= base_url('Perolehan/progres_perolehan/'.$p->perolehan_id)?>" type="button" class="btn btn-success btn-sm"><i class="fa fa-eye"></i> Detail</a>
                                                                </div>
                                                            </div>									
                                                        </div>
                                                    </div>
                                                </div>

                                                <!-- Add Progres -->
                                                <div id="addProgres<?=$p->perolehan_id;?>" class="modal fade" role="dialog">
                                                    <div class="modal-dialog">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                                <center><h4 class="modal-title"> Tambah Progres</h4></center>
                                                                <center>
                                                                    <small><?=$p->kota_nama;?>, <?=$p->provinsi_nama;?>, <?=$p->perolehan_luas;?> Ha</small>
                                                                </center>
                                                            </div>

                                                            <div class="modal-body">
                                                                <form action="<?= base_url('perolehan/progres_act');?>" method="post" enctype="multipart/form-data">		
                                                                    <div class="form-group" style="width:100%; margin-bottom:10px;">
                                                                        <label style="width: 100%;">Tahapan Perolehan</label>		
                                                                        <select class="form-control" id="status_perolehan<?=$p->perolehan_id;?>" onchange="changeKegiatan(<?=$p->perolehan_id;?>)" name="status" required style="width: 100%;">
                                                                            <option value="">--Pilih Tahapan Perolehan--</option>
                                                                            <?php 
                                                                            $statuse = $this->db->query("select * from master_perolehan_status")->result();
                                                                            foreach ($statuse as $stpe) {
                                                                                ?>
                                                                                <option value="<?php echo $stpe->perolehan_status_id;?>" <?php //if($stpe->perolehan_status_id == $p->perolehan_status_id){echo "selected";} ?>><?php echo $stpe->perolehan_status_nama; ?></option>
                                                                                <?php
                                                                            }
                                                                            ?>													
                                                                        </select>
                                                                    </div>

                                                                    <div class="form-group" style="width:100%; margin-bottom:10px;">
                                                                        <label style="width: 100%;">Kegiatan</label>		
                                                                        <select class="form-control" id="kegiatan_perolehan<?=$p->perolehan_id;?>" name="kegiatan" required style="width: 100%;">
                                                                            <option value="">No Selection</option>												
                                                                        </select>
                                                                    </div>

                                                                    <!-- <div class="form-group" style="width:100%; margin-bottom:10px;">
                                                                        <label style="width: 100%;"> Progres</label>		
                                                                        <input type="hidden" name="perolehan_id" value="<?php //$p->perolehan_id?>">
                                                                        <select class="form-control" id="upd_progres<?php //$p->perolehan_id;?>" name="nama" required style="width: 100%;">
                                                                            <option value="">--Pilih Progres--</option>
                                                                            <?php 
                                                                            // $pr = $this->db->query("select * from master_progres_status")->result();
                                                                            // foreach ($pr as $d) {
                                                                                ?>
                                                                                <option value="<?php //echo $d->progres_status_desc ?>"><?php //echo $d->progres_status_desc ?></option>
                                                                                <?php
                                                                            //}
                                                                            ?>													
                                                                        </select>
                                                                    </div> -->
                                                                    
                                                                    <div class="form-group" style="width:100%; margin-bottom:10px;">
                                                                        <label style="width: 100%;"> Kondisi</label>	
                                                                        <select class="form-control" name="kondisi" id="kondisi<?=$p->perolehan_id;?>" onchange="changeKondisi(<?=$p->perolehan_id;?>)" required style="width: 100%;">
                                                                            <option value="">--Pilih Kondisi--</option>
                                                                            <option value="selesai">Sudah Selesai</option>
                                                                            <option value="belum">Belum Selesai</option>
                                                                        </select>
                                                                    </div>

                                                                    <div class="form-group" style="width:100%; margin-bottom:20px;">
                                                                        <div class="col-sm-6">
                                                                            <label style="width: 100%;"> Tanggal Mulai</label>		
                                                                            <input type="date" name="tgl_awal" required class="form-control" style="width:100%">
                                                                        </div>

                                                                        <div class="col-sm-6" id="tgl_akhir<?=$p->perolehan_id;?>">
                                                                            <label style="width: 100%;"> Tanggal Selesai</label>		
                                                                            <input type="date" name="tgl_akhir" class="form-control" style="width:100%">
                                                                        </div>
                                                                    </div>

                                                                    <div class="form-group" style="width:100%; margin-bottom:10px;">
                                                                        <label style="width: 100%;"> Keterangan</label>	
                                                                        <input type="hidden" name="perolehan_id" value="<?=$p->perolehan_id?>">	
                                                                        <textarea name="ket_progres" class="form-control" cols="84" rows="5" required></textarea>
                                                                    </div>
                                                                                            
                                                                    <input type="submit" value="Simpan" class="btn btn-primary">
                                                                </form>
                                                            </div>											
                                                        </div>
                                                    </div>
                                                </div>
                                                
                                                <!-- Edit Perolehan -->
                                                <div id="edit<?php echo $p->perolehan_id; ?>" class="modal fade" role="dialog">
                                                    <div class="modal-dialog">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                                <center><h4 class="modal-title"> Edit Perolehan Tanah</h4></center>
                                                            </div>
                                                            <div class="modal-body">
                                                                <form action="<?= base_url('perolehan/perolehan_update');?>" method="post" enctype="multipart/form-data">											
                                                                    <div class="form-group" style="width:100%">
                                                                        <label style="width: 100%;"> Provinsi</label>		
                                                                        <input type="hidden" name="id" value="<?=$p->perolehan_id;?>">
                                                                        <select class="form-control" name="provinsi" id="provinsi<?=$p->perolehan_id;?>" onchange="changeKota(<?=$p->perolehan_id;?>)" required style="width: 100%;">
                                                                            <option value="">--Pilih Provinsi--</option>
                                                                            <?php 
                                                                            $provs = $this->db->query("select * from master_provinsi")->result();
                                                                            foreach ($provs as $pro) {
                                                                                ?>
                                                                                <option value="<?php echo $pro->provinsi_id ?>" <?php if($pro->provinsi_id == $p->provinsi_id){echo "selected";} ?>><?php echo $pro->provinsi_nama ?></option>
                                                                                <?php
                                                                            }
                                                                            ?>													
                                                                        </select>
                                                                    </div>
                                                                    <div style="height:10px;"></div>

                                                                    <div class="form-group" style="width:100%">
                                                                        <label style="width: 100%;"> Kabupaten/Kota</label>		
                                                                        <!-- <input type="text" name="kota" required class="form-control" style="width:100%"> -->
                                                                        <select class="form-control" id="kota<?=$p->perolehan_id;?>" name="kota" onchange="changeKecamatan(<?=$p->perolehan_id;?>)" required style="width: 100%;">

                                                                            <option value="">--Pilih Kabupaten/Kota--</option>
                                                                            <?php 
                                                                                $kotas = $this->db->query("select * from master_kota where provinsi_id = '$p->provinsi_id'")->result();
                                                                                foreach ($kotas as $kot) {
                                                                                    ?>
                                                                                    <option value="<?php echo $kot->kota_id ?>" <?php if($kot->kota_id == $p->kota_id){echo "selected";} ?>><?php echo $kot->kota_nama ?></option>
                                                                                    <?php
                                                                                }
                                                                            ?>
                                                                        </select>
                                                                    </div>
                                                                    <div style="height:10px;"></div>

                                                                    <div class="form-group" style="width:100%">
                                                                        <label style="width: 100%;"> Kecamatan</label>		
                                                                        <select class="form-control" id="kecamatan<?=$p->perolehan_id;?>" name="kecamatan" onchange="changeKelurahan(<?=$p->perolehan_id;?>)" required style="width: 100%;">
                                                                            <option value="">--Pilih Kecamatan--</option>
                                                                            <?php 
                                                                                $kecs = $this->db->query("select * from master_kecamatan where kota_id = '$p->kota_id'")->result();
                                                                                foreach ($kecs as $kec) {
                                                                                    ?>
                                                                                    <option value="<?php echo $kec->kecamatan_id ?>" <?php if($kec->kecamatan_id == $p->kecamatan_id){echo "selected";} ?>><?php echo $kec->kecamatan_nama ?></option>
                                                                                    <?php
                                                                                }
                                                                            ?>
                                                                        </select>
                                                                    </div>
                                                                    <div style="height:10px;"></div>

                                                                    <div class="form-group" style="width:100%">
                                                                        <label style="width: 100%;"> Kelurahan/Desa</label>		
                                                                        <select class="form-control" id="kelurahan<?=$p->perolehan_id;?>" name="kelurahan" required style="width: 100%;">
                                                                            <option value="">--Pilih Kelurahan/Desa--</option>
                                                                            <?php 
                                                                                $kels = $this->db->query("select * from master_kelurahan where kecamatan_id = '$p->kecamatan_id'")->result();
                                                                                foreach ($kels as $kel) {
                                                                                    ?>
                                                                                    <option value="<?php echo $kel->kelurahan_id ?>" <?php if($kel->kelurahan_id == $p->kelurahan_id){echo "selected";} ?>><?php echo $kel->kelurahan_nama ?></option>
                                                                                    <?php
                                                                                }
                                                                            ?>
                                                                        </select>
                                                                    </div>
                                                                    <div style="height:10px;"></div>

                                                                    <div class="form-group" style="width:100%">
                                                                        <label style="width: 100%;"> Status RKAT</label>		
                                                                        <select class="form-control" name="rkat" required style="width: 100%;">
                                                                            <option>--Pilih Status--</option>
                                                                            <option value="rkat" <?php if($p->is_rkat){echo "selected";} ?>>RKAT</option>
                                                                            <option value="non" <?php if(!$p->is_rkat){echo "selected";} ?>>NON RKAT</option>
                                                                        </select>
                                                                    </div>

                                                                    <div class="form-group" style="width:100%">
                                                                        <label style="width: 100%;"> Luas (Ha)</label>		
                                                                        <input type="number" name="luas" value="<?= $p->perolehan_luas; ?>" required class="form-control" style="width:100%">
                                                                    </div>
                                                                    <div style="height:10px;"></div>

                                                                    <div class="form-group" style="width:100%">
                                                                        <label style="width: 100%;"> Bekas Pemegang Hak</label>		
                                                                        <input type="text" name="ex_hak" value="<?= $p->bekas_pemegang_hak; ?>" required class="form-control" style="width:100%">
                                                                    </div>

                                                                    <div class="form-group" style="width:100%">
                                                                        <label style="width: 100%;"> Dasar Perolehan</label>		
                                                                        <select class="form-control" id="dasar_perolehan<?=$p->perolehan_id;?>" name="dasar_perolehan" required style="width: 100%;">
                                                                            <option value="">--Pilih Dasar Perolehan--</option>
                                                                            <?php 
                                                                            $dsr_p = $this->db->query("select * from master_dasar_perolehan")->result();
                                                                            foreach ($dsr_p as $dsp) {
                                                                                ?>
                                                                                <option value="<?= $dsp->dasar_perolehan_desc ?>" <?php if($dsp->dasar_perolehan_desc == $p->perolehan_dasar){echo "selected";}?> ><?= $dsp->dasar_perolehan_desc ?></option>
                                                                                <?php
                                                                            }
                                                                            ?>													
                                                                        </select>
                                                                    </div>
                                                                    <div style="height:10px;"></div>

                                                                    <div class="form-group" style="width:100%">
                                                                        <label style="width: 100%;"> P.I.C.</label>		
                                                                        <input type="text" name="pic" value="<?= $p->perolehan_pic ?>" required class="form-control" style="width:100%">
                                                                    </div>
                                                                
                                                                    <div style="height:20px;"></div>

                                                                    <input type="submit" value="Simpan" class="btn btn-primary">
                                                                </form>
                                                            </div>											
                                                        </div>
                                                    </div>
                                                </div>

                                                <!-- Hapus data perolehan -->
                                                <div id="hapusData<?php echo $p->perolehan_id ?>" class="modal fade" role="dialog">
                                                    <div class="modal-dialog">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                    <span aria-hidden="true">&times;</span>
                                                                </button>
                                                                <h5 class="modal-title" id="exampleModalLabel">Peringatan!</h5>
                                                                

                                                            </div>
                                                            <div class="modal-body">
                                                                <p>Yakin ingin menghapus data ini ?</p>
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
                                                                <a href="<?php echo base_url().'Perolehan/perolehan_hapus/'.$p->perolehan_id; ?>" class="btn btn-primary">Hapus</a>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                
                                            </td>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                        </div>
					</div>
				</div>

			</div>
		</div>

	</section>

</div>