<!DOCTYPE html>
<html><head>
	<style>
		table {
		  border-collapse: collapse;
		}

		table, th, td {
		  border: 1px solid black;
		}
	</style>
		<title>Laporan Approval Reimburse</title>
	</head><body>
		<p align="left"><b>Laporan Approval Reimburse</b></p>
		<p align="left"><?php echo $perusahaan; ?></p>
		<p align="left">Periode tanggal <?php echo $awal; ?> s.d. <?php echo $akhir; ?></p>
		
		<table border="1" width="100%">
					        <thead style="background-color: #1062b1;color: #fff;font-weight: 600;">
					            <tr>
					                <th>No</th>
					                <th>Tanggal</th>
					                <th>No Pengajuan</th>
					                <th>Departemen</th>
					                <th>Karyawan</th>
					                <th>Jenis Reimburse</th>
					                <th>Keterangan</th>
					                <th>Platform Max</th>
					                <th>Nominal Diajukan</th>
					                <th>Nominal Disetujui</th>
					            </tr>
					        </thead>
					        <tbody>
					        	<?php
					        		if (isset($list_data)) {
					       
					                $no = 0;
					                foreach ($list_data as $val) {
					                $no++;
					               	$data_reimburse = $this->fungsi->data_reimburse($val->id_pengajuan);					               

					                $jumlah_row = $data_reimburse->num_rows()+1;
					            ?>            
					            <tr>
					                <td rowspan="<?= $jumlah_row  ?>" style="padding: 3px;"><?= $no ?></td>
					                <td rowspan="<?= $jumlah_row  ?>" style="padding: 3px;"><?= date('d-m-Y', strtotime($val->tgl_pengajuan));?></td>
					                <td rowspan="<?= $jumlah_row  ?>" style="padding: 3px;"><?= $val->no_pengajuan ?></td>
					                <td rowspan="<?= $jumlah_row  ?>" style="padding: 3px;"><?= $val->nama_departemen ?></td>
					                <td rowspan="<?= $jumlah_row  ?>" style="padding: 3px;"><?= $val->nama_karyawan ?></td>				                   
				                    <?php
				                        foreach ($data_reimburse->result() as $dat) {
				                    ?>
				                        <td style="padding: 3px;"><?= $dat->jenis_plafon; ?></td>
				                        <td style="padding: 3px;"><?= $dat->keterangan; ?></td>
				                        <td align="right" style="padding: 3px;"><?= number_format($dat->max_plafon,0,",","."); ?></td>
				                        <td align="right" style="padding: 3px;"><?= number_format($dat->nominal,0,",","."); ?></td>
				                        <td align="right" style="padding: 3px;"><?= number_format($dat->nominal_disetujui,0,",","."); ?></td>
					            </tr>
					            <?php
			                        }
			                    ?>
			                    <tr>
			                    	<td style="font-weight: bold; text-align: center;" colspan="3">Sub Total</td>
			                    	<td align="right" style="font-weight: bold; padding: 3px;"><?php
			                    		$jumlah_nominal = $this->fungsi->jumlah_nominal($val->id_pengajuan);

						                echo number_format($jumlah_nominal,0,",",".");
			                    	?></td>
			                    	<td align="right" style="font-weight: bold; padding: 3px;"><?php
			                    		$jumlah_disetujui = $this->fungsi->jumlah_disetujui($val->id_pengajuan);

						                echo number_format($jumlah_disetujui,0,",",".");
			                    	?></td>
			                    </tr>
					            <?php
					            		}
					            ?>

					             <?php
					            	if ($jumlah > 0) {
					            ?>
					            <tr style="font-weight: bold;">
					            	<td colspan="8" align="center">TOTAL</td>
					            	<td align="right" style="padding: 3px;">
					            		<?php
					            		    $pawal = ($awal == "0") ? date('Y-m-d')  : $this->fungsi->reverse_date2($awal);
   	 										$pakhir = ($akhir == "0") ? date('Y-m-d')  : $this->fungsi->reverse_date2($akhir);

					            			 $last = $this->fungsi->last_approval($karyawan);

					                        if ($last == '7') {
					                          $where_co = "reimbursement_pengajuan.apv_spv";
					                        }elseif ($last == '2') {
					                          $where_co = "reimbursement_pengajuan.apv_kedep";
					                        }elseif ($last == '5') {
					                          $where_co = "reimbursement_pengajuan.apv_kacap";
					                        }elseif ($last == '6') {
					                          $where_co = "reimbursement_pengajuan.apv_finance";
					                        }elseif ($last == '4') {
					                          $where_co = "reimbursement_pengajuan.apv_direksi";
					                        }elseif ($last == '1') {
					                          $where_co = "reimbursement_pengajuan.apv_finance";
					                        }

						            		$query = $this->fungsi->total_nominal_karyawan($karyawan,$pawal,$pakhir,$where_co);

					            				$total = 0;
					            				foreach ($query->result() as $val) {
					            					$total += $val->nominal;
					            				}
					            			echo number_format($total,0,",",".");
					            		?>
					            	</td>
					            	<td align="right" style="padding: 3px;">
					            		<?php
					            		    $pawal = ($awal == "0") ? date('Y-m-d')  : $this->fungsi->reverse_date2($awal);
   	 										$pakhir = ($akhir == "0") ? date('Y-m-d')  : $this->fungsi->reverse_date2($akhir);

					            			$last = $this->fungsi->last_approval($karyawan);

					                            if ($last == '7') {
					                              $where_co = "reimbursement_pengajuan.apv_spv";
					                            }elseif ($last == '2') {
					                              $where_co = "reimbursement_pengajuan.apv_kedep";
					                            }elseif ($last == '5') {
					                              $where_co = "reimbursement_pengajuan.apv_kacap";
					                            }elseif ($last == '6') {
					                              $where_co = "reimbursement_pengajuan.apv_finance";
					                            }elseif ($last == '4') {
					                              $where_co = "reimbursement_pengajuan.apv_direksi";
					                            }elseif ($last == '1') {
					                              $where_co = "reimbursement_pengajuan.apv_finance";
					                            }


					            			$query2 = $this->fungsi->total_disetujui_karyawan($karyawan,$pawal,$pakhir,$where_co);

					            				$total2 = 0;
					            				foreach ($query2->result() as $val) {
					            					$total2 += $val->nominal_setuju;
					            				}
					            			echo number_format($total2,0,",",".");
					            		?>
					            	</td>
					            </tr>
					            <?php
					            	}
					            ?>
					            <?php
						        	}else{
					                	echo "<center></center>";
					                }
						        ?>
					        </tbody>
		</table>
</body></html>