Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("koneksi.php");
- include("tanggal.php");
- ?>
- <h3>ABSEN</h3>
- <?php
- // medapatkan tanggal yang dikirim kan oleh user
- $tgl_mulai = $_POST['tgl_mulai'];
- $bln_mulai = $_POST['bln_mulai'];
- $thn_mulai = $_POST['thn_mulai'];
- $mulai=$_POST['thn_mulai'].'-'.$_POST['bln_mulai'].'-'.$_POST['tgl_mulai'];
- $tgl_selesai = $_POST['tgl_selesai'];
- $bln_selesai = $_POST['bln_selesai'];
- $thn_selesai = $_POST['thn_selesai'];
- $selesai=$_POST['thn_selesai'].'-'.$_POST['bln_selesai'].'-'.$_POST['tgl_selesai'];
- echo "<h3>Mulai $mulai Sampai dengan $selesai</h3>";
- ?>
- <br>
- <table border=1>
- <tr>
- <th rowspan = "2">No</th>
- <th rowspan = "2">Nama</th>
- <th rowspan = "2">NIK</th>
- <th>Tgl</th>
- <?php
- // untuk mencari data yang terdapat pada tanggal sekian sampai tanggal sekian
- $sql = "
- SELECT tanggal
- FROM tabel_absen
- WHERE
- kd_proyek='{$_POST['kd_proyek']}'
- AND tanggal BETWEEN '$mulai' AND '$selesai'
- GROUP BY tanggal";
- $result = mysql_query($sql);
- $jml = mysql_num_rows($result);
- $jmlhari = tglakhirbulan($thn_mulai,$bln_mulai);
- $selisih = hari($selesai, $mulai);//cek selisih hari
- if($mulai > $selesai){// cek apa hari awal lebih besar dari lebih kecil
- echo "<script>alert('Masukan Tanggal Mulai Laporan Dengan Benar'); window.location =' ../dashboard.php?modul=laporan' </script>";
- }
- elseif($mulai > $selesai AND $selisih >= 31 ){ // cek apa laporan dibuat dengan tanggal mulai terlebih dahulu apa
- echo "<script>alert('Maximal Laporan adalah 31 hari'); window.location =' ../dashboard.php?modul=laporan' </script>";
- }
- elseif ($jml == 0 ){//cek jumlah row
- $m=$_POST['tgl_mulai'].'-'.$_POST['bln_mulai'].'-'.$_POST['thn_mulai'];
- $s=$_POST['tgl_selesai'].'-'.$_POST['bln_selesai'].'-'.$_POST['thn_selesai'];
- echo "<script>alert('Tidak ada Absen pada Tanggal $m s/d $s'); window.location =' ../dashboard.php?modul=laporan' </script>";
- }
- else{
- $hdr_tgl=array();
- $list_tgl=array();
- if($tgl_mulai>=$tgl_selesai){//cek apa tanggal selesai lebih besar dari tanggal mulai
- for($i = $tgl_mulai; $i<=$jmlhari; $i++){
- $hdr_tgl[]="<th>$i</th>";
- $list_tgl[]=$_POST['bln_mulai']."/".$i;
- }
- for($i = 1; $i<=$tgl_selesai;$i++){
- $hdr_tgl[]="<th>$i</th>";
- $list_tgl[]=$_POST['bln_selesai']."/".$i;
- }
- }else{//kalau tanggal mulai kurang dati tanggal selesai
- for($i=$tgl_mulai;$i<=$tgl_selesai;$i++){
- $hdr_tgl[]="<th>$i</th>";
- $list_tgl[]=$_POST['bln_mulai']."/".$i;
- }
- }
- echo implode('',$hdr_tgl);
- ?>
- <th colspan="2">Total</th>
- </tr>
- <tr>
- <th>Hari</th>
- <?php
- echo implode('',$hdr_tgl);
- }
- ?>
- <th>hk</th>
- <th>ot</th>
- </tr>
- <?php
- $no=0;
- $sql = "SELECT DATE_FORMAT(tanggal,'%m/%d') AS tgl,a.nama,a.nik,b.hk,b.ot
- FROM
- karyawan a
- JOIN tabel_absen b USING(nik)
- WHERE
- a.kd_proyek = '{$_POST['kd_proyek']}'
- AND b.tanggal BETWEEN '$mulai' AND '$selesai'
- ORDER BY
- a.nik,b.tanggal
- ";
- $result = mysql_query($sql);
- $nik='';
- while($row = mysql_fetch_assoc($result))
- {
- if($nik!=$row['nik']){
- $nik=$row['nik'];
- if($no>0){
- foreach($list_tgl AS $tgl){
- echo "<td>".(isset($hk[$tgl])?$hk[$tgl]:"-")."</td>";
- }
- echo "<td rowspan='2'>{$totalhk}</td><td rowspan='2'>{$totalot}</td></tr><tr>";
- foreach($list_tgl AS $tgl){
- echo "<td>".(isset($ot[$tgl])?$ot[$tgl]:"-")."</td>";
- }
- echo "</tr>";
- }
- $totalhk=0;
- $totalot=0;
- $hk=array();
- $ot=array();
- echo "
- <tr>
- <td rowspan = 2>".(++$no)."</td>
- <td rowspan = 2>{$row['nama']}</td>
- <td rowspan = 2>{$row['nik']}</td>
- <td>hk</td>";
- }
- $hk[$row['tgl']]=$row['hk'];
- $hk[$row['ot']]=$row['ot'];
- $totalhk+=$row['hk'];
- $totalot+=$row['ot'];
- }
- foreach($list_tgl AS $tgl){
- echo "<td>".(isset($hk[$tgl])?$hk[$tgl]:"-")."</td>";
- }
- echo "<td rowspan='2'>{$totalhk}</td><td rowspan='2'>{$totalot}</td></tr><tr>";
- foreach($list_tgl AS $tgl){
- echo "<td>".(isset($ot[$tgl])?$ot[$tgl]:"-")."</td>";
- }
- echo "</tr>";
- ?>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement