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

	<section class="content">

		<div class="row">

			<div class="col-md-3 col-sm-6 col-xs-12">
				<div class="info-box bg-aqua">
					<span class="info-box-icon"><i class="fa fa-bookmark-o"></i></span>
					<div class="info-box-content">
						<span class="info-box-text">Perolehan</span>
						<span class="info-box-number"><?= $jumlah_perolehan?></span>
						<div class="progress">
							<div class="progress-bar" style="width: 70%"></div>
						</div>
						<span class="progress-description">
							Jumlah Perolehan
						</span>
					</div>
				</div>
			</div>

			<div class="col-md-3 col-sm-6 col-xs-12">
				<div class="info-box bg-purple">
					<span class="info-box-icon"><i class="fa fa-bookmark-o"></i></span>
					<div class="info-box-content">
						<span class="info-box-text">Luas</span>
						<span class="info-box-number"><?= $jumlah_luas.' Ha'?></span>
						<div class="progress">
							<div class="progress-bar" style="width: 70%"></div>
						</div>
						<span class="progress-description">
							Jumlah Luas
						</span>
					</div>
				</div>
			</div>

			<div class="col-md-3 col-sm-6 col-xs-12">
				<div class="info-box bg-green">
					<span class="info-box-icon"><i class="fa fa-bookmark-o"></i></span>
					<div class="info-box-content">
						<span class="info-box-text">Provinsi</span>
						<span class="info-box-number"><?= $jumlah_provinsi?></span>
						<div class="progress">
							<div class="progress-bar" style="width: 70%"></div>
						</div>
						<span class="progress-description">
							Jumlah Provinsi
						</span>
					</div>
				</div>
			</div>

			<div class="col-md-3 col-sm-6 col-xs-12">
				<div class="info-box bg-orange">
					<span class="info-box-icon"><i class="fa fa-bookmark-o"></i></span>
					<div class="info-box-content">
						<span class="info-box-text">Kabupaten/Kota</span>
						<span class="info-box-number"><?= $jumlah_kota?></span>
						<div class="progress">
							<div class="progress-bar" style="width: 70%"></div>
						</div>
						<span class="progress-description">
							Jumlah Kabupaten/Kota
						</span>
					</div>
				</div>
			</div>
		</div>

		<div class="row">
			<div class="col-lg-12">
				
				<div class="box box-primary" style="min-height: 530px;">
					<div class="box-header">
						<h3 class="box-title">Progres</h3>
					</div>
					<div class="box-body">
						<div class="table-responsive">
							<table class="table table-bordered" id="progres-datatable">
								<thead>
									<tr>
										<th>NO</th>
										<th>Lokasi</th>
                                        <th>Tahapan</th>
										<th>Kegiatan</th>								
									</tr>
								</thead>
								<tbody>
									<?php 
									$no=1;
									foreach ($perolehans as $y) {
									?>
										<tr>
											<td><?php echo $no++ ?></td>
											<td><?= '<p><strong>Kelurahan/Desa :</strong> '.$y->kelurahan_nama.'</p><p><strong>Kabupaten/Kota :</strong> '.$y->kota_nama.'</p><p><strong>Provinsi :</strong> '.$y->provinsi_nama.'</p><p><strong>Luas :</strong> '.$y->perolehan_luas.' Ha</p>';?></td>
											<td>
												<?php
													$tahapan = $this->db->select('*')
																->from('perolehan_progres as t1')
																->where('t1.perolehan_id', $y->perolehan_id)
																->join('master_perolehan_status as t6', 't1.perolehan_status_id = t6.perolehan_status_id', 'LEFT')
																->join('master_perolehan_kegiatan as t7', 't1.perolehan_kegiatan_id = t7.perolehan_kegiatan_id', 'LEFT')
																->order_by("t6.tahapan", "desc")
																->get()
																->first_row();
													if (!empty($tahapan->perolehan_status_nama)) {
												?>
												<div class="alert alert-<?=$tahapan->alert?>" style="opacity: 0.7;">
                                                        <strong><?= $tahapan->perolehan_status_nama;?></strong>
                                                </div>
												<?php
													}
												?>
											</td>
											<td>
												<?php
													$kegiatan = $this->db->select('*')
																->from('perolehan_progres as t1')
																->where('t1.perolehan_id', $y->perolehan_id)
																->join('master_perolehan_status as t6', 't1.perolehan_status_id = t6.perolehan_status_id', 'LEFT')
																->join('master_perolehan_kegiatan as t7', 't1.perolehan_kegiatan_id = t7.perolehan_kegiatan_id', 'LEFT')
																->order_by("t6.tahapan", "desc")
																->order_by("t1.tgl_awal", "desc")
																->get()
																->first_row();
													if (!empty($kegiatan->perolehan_status_nama)) {
														$tgl_awal = date("d-m-Y", strtotime($kegiatan->tgl_awal));

                                                        if ($kegiatan->tgl_akhir) {
                                                            $tgl_akhir = date("d-m-Y", strtotime($kegiatan->tgl_akhir));
                                                        }else {
                                                            $tgl_akhir = "Belum Selesai";
                                                        }
												?>
													<p><?=$kegiatan->perolehan_kegiatan_desc;?></p>
													<p><?= 'Mulai : '.$tgl_awal.' | Selesai : '.$tgl_akhir; ?></p>
												<?php
													}
												?>
											</td>
										</tr>
									<?php
									}
									?>
								</tbody>														
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="row">
			<div class="col-lg-4">
				
				<div class="box box-primary" style="min-height: 530px;">
					<div class="box-header">
						<h3 class="box-title">Perolehan</h3>
					</div>
					<div class="box-body">
						<div class="table-responsive">
							<table class="table table-bordered" id="perolehan-datatable">
								<thead>
									<tr>
										<th>NO</th>
										<th>Kelurahan/Desa</th>
                                        <th>Luas</th>								
									</tr>
								</thead>
								<tbody>
									<?php 
									$no=1;
									foreach ($perolehans as $p) {
									?>
										<tr>
											<td><?php echo $no++ ?></td>
											<td><?= $p->kelurahan_nama;?></td>
											<td><?= $p->perolehan_luas.' Ha';?></td>
										</tr>
									<?php
									}
									?>
								</tbody>														
							</table>
						</div>
					</div>
				</div>
			</div>

            <div class="col-lg-4">
				
				<div class="box box-primary" style="min-height: 530px;">
					<div class="box-header">
						<h3 class="box-title">Provinsi</h3>
					</div>
					<div class="box-body">
						<div class="table-responsive">
							<table class="table table-bordered" id="provinsi-datatable">
								<thead>
									<tr>
										<th>NO</th>
										<th>Provinsi</th>
                                        <th>Perolehan</th>							
									</tr>
								</thead>
								<tbody>
									<?php 
									$no=1;
									foreach ($provinsis as $p) {
									?>
										<tr>
											<td><?php echo $no++ ?></td>
											<td><?= $p->provinsi_nama;?></td>
											<td><?php 
                                                    $pero_prov = $this->db->query("SELECT COUNT(perolehan_id) AS prov FROM perolehan WHERE provinsi_id = '$p->provinsi_id'")->row()->prov;
                                                    echo "$pero_prov"." Lokasi";
                                                ?>
                                            </td>
										</tr>
									<?php
									}
									?>
								</tbody>														
							</table>
						</div>
					</div>
				</div>
			</div>

            <div class="col-lg-4">
				
				<div class="box box-primary" style="min-height: 530px;">
					<div class="box-header">
						<h3 class="box-title">Kabupaten/Kota</h3>
					</div>
					<div class="box-body">
						<div class="table-responsive">
							<table class="table table-bordered" id="kota-datatable">
								<thead>
									<tr>
										<th>NO</th>
										<th>Kabupaten/Kota</th>
                                        <th>Perolehan</th>							
									</tr>
								</thead>
								<tbody>
									<?php 
									$no=1;
									foreach ($kotas as $p) {
									?>
										<tr>
											<td><?php echo $no++ ?></td>
											<td><?= $p->kota_nama;?></td>
											<td>
                                                <?php
                                                    $pero_kota = $this->db->query("SELECT COUNT(perolehan_id) AS kota FROM perolehan WHERE kota_id = '$p->kota_id'")->row()->kota;
                                                    echo "$pero_kota"." Lokasi";
                                                ?>
                                            </td>
										</tr>
									<?php
									}
									?>
								</tbody>														
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="row">
			<div class="col-md-8">
				<div class="box box-solid" style="position: relative;">					
					<div class="box-body">															
						<div class="chart-container">
							<center><b>DASAR PEROLEHAN</b></center>
							<center><canvas id="bar_dasar"></canvas></center>
						</div>						
					</div>
				</div>
			</div>	

			<div class="col-md-4">
				<div class="box box-solid" style="position: relative;">					
					<div class="box-body">															
						<div class="chart-container">
							<center><b>RKAT</b></center>
							<center><canvas id="pie_rkat"></canvas></center>
						</div>						
					</div>
				</div>
			</div>	
		</div>

	</section>

</div>