Advertisement
cdsatrian

cetak absen

Jan 10th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.90 KB | None | 0 0
  1. <?php
  2. include("koneksi.php");
  3. include("tanggal.php");
  4. ?>
  5. <h3>ABSEN</h3>
  6. <?php
  7. // medapatkan tanggal yang dikirim kan oleh user
  8. $tgl_mulai = $_POST['tgl_mulai'];
  9. $bln_mulai = $_POST['bln_mulai'];
  10. $thn_mulai = $_POST['thn_mulai'];
  11. $mulai=$_POST['thn_mulai'].'-'.$_POST['bln_mulai'].'-'.$_POST['tgl_mulai'];
  12. $tgl_selesai = $_POST['tgl_selesai'];
  13. $bln_selesai = $_POST['bln_selesai'];
  14. $thn_selesai = $_POST['thn_selesai'];
  15. $selesai=$_POST['thn_selesai'].'-'.$_POST['bln_selesai'].'-'.$_POST['tgl_selesai'];
  16. echo "<h3>Mulai $mulai Sampai dengan $selesai</h3>";
  17. ?>
  18. <br>
  19. <table border=1>
  20. <tr>
  21. <th rowspan = "2">No</th>
  22. <th rowspan = "2">Nama</th>
  23. <th rowspan = "2">NIK</th>
  24. <th>Tgl</th>
  25. <?php
  26. // untuk mencari data yang terdapat pada tanggal sekian sampai tanggal sekian
  27. $sql = "
  28.         SELECT tanggal
  29.         FROM tabel_absen
  30.         WHERE
  31.             kd_proyek='{$_POST['kd_proyek']}'
  32.             AND tanggal BETWEEN '$mulai' AND '$selesai'
  33.         GROUP BY tanggal";
  34. $result = mysql_query($sql);
  35. $jml = mysql_num_rows($result);
  36. $jmlhari = tglakhirbulan($thn_mulai,$bln_mulai);
  37. $selisih = hari($selesai, $mulai);//cek selisih hari
  38. if($mulai > $selesai){// cek apa hari awal lebih besar dari lebih kecil
  39.     echo "<script>alert('Masukan Tanggal Mulai Laporan Dengan Benar'); window.location =' ../dashboard.php?modul=laporan' </script>";
  40. }
  41. elseif($mulai > $selesai AND $selisih >= 31 ){ // cek apa laporan dibuat dengan tanggal mulai terlebih dahulu apa
  42.     echo "<script>alert('Maximal Laporan adalah 31 hari'); window.location =' ../dashboard.php?modul=laporan' </script>";
  43. }
  44. elseif ($jml == 0 ){//cek jumlah row
  45.     $m=$_POST['tgl_mulai'].'-'.$_POST['bln_mulai'].'-'.$_POST['thn_mulai'];
  46.     $s=$_POST['tgl_selesai'].'-'.$_POST['bln_selesai'].'-'.$_POST['thn_selesai'];
  47.     echo "<script>alert('Tidak ada Absen pada Tanggal $m s/d $s'); window.location =' ../dashboard.php?modul=laporan' </script>";
  48. }
  49. else{
  50.     $hdr_tgl=array();
  51.     $list_tgl=array();
  52.     if($tgl_mulai>=$tgl_selesai){//cek apa tanggal selesai lebih besar dari tanggal mulai
  53.         for($i = $tgl_mulai; $i<=$jmlhari; $i++){
  54.             $hdr_tgl[]="<th>$i</th>";
  55.             $list_tgl[]=$_POST['bln_mulai']."/".$i;
  56.         }
  57.         for($i = 1; $i<=$tgl_selesai;$i++){
  58.             $hdr_tgl[]="<th>$i</th>";
  59.             $list_tgl[]=$_POST['bln_selesai']."/".$i;
  60.         }
  61.     }else{//kalau tanggal mulai kurang dati tanggal selesai
  62.         for($i=$tgl_mulai;$i<=$tgl_selesai;$i++){
  63.             $hdr_tgl[]="<th>$i</th>";
  64.             $list_tgl[]=$_POST['bln_mulai']."/".$i;
  65.         }
  66.     }
  67.     echo implode('',$hdr_tgl);
  68.     ?>
  69.     <th colspan="2">Total</th>
  70.     </tr>
  71.     <tr>
  72.     <th>Hari</th>
  73.     <?php
  74.     echo implode('',$hdr_tgl);
  75. }
  76. ?>
  77. <th>hk</th>
  78. <th>ot</th>
  79. </tr>
  80. <?php
  81. $no=0;
  82. $sql = "SELECT DATE_FORMAT(tanggal,'%m/%d') AS tgl,a.nama,a.nik,b.hk,b.ot
  83.             FROM
  84.                 karyawan a
  85.                 JOIN tabel_absen b USING(nik)
  86.             WHERE
  87.                 a.kd_proyek = '{$_POST['kd_proyek']}'
  88.                 AND b.tanggal BETWEEN '$mulai' AND '$selesai'
  89.             ORDER BY
  90.                 a.nik,b.tanggal
  91.             ";
  92. $result = mysql_query($sql);
  93. $nik='';
  94. while($row = mysql_fetch_assoc($result))
  95. {
  96.     if($nik!=$row['nik']){
  97.         $nik=$row['nik'];
  98.         if($no>0){
  99.             foreach($list_tgl AS $tgl){
  100.                 echo "<td>".(isset($hk[$tgl])?$hk[$tgl]:"-")."</td>";
  101.             }
  102.             echo "<td rowspan='2'>{$totalhk}</td><td rowspan='2'>{$totalot}</td></tr><tr>";
  103.             foreach($list_tgl AS $tgl){
  104.                 echo "<td>".(isset($ot[$tgl])?$ot[$tgl]:"-")."</td>";
  105.             }
  106.             echo "</tr>";
  107.         }
  108.         $totalhk=0;
  109.         $totalot=0;
  110.         $hk=array();
  111.         $ot=array();
  112.         echo "
  113.             <tr>
  114.             <td rowspan = 2>".(++$no)."</td>
  115.             <td rowspan = 2>{$row['nama']}</td>
  116.             <td rowspan = 2>{$row['nik']}</td>
  117.             <td>hk</td>";
  118.     }
  119.     $hk[$row['tgl']]=$row['hk'];
  120.     $hk[$row['ot']]=$row['ot'];
  121.     $totalhk+=$row['hk'];
  122.     $totalot+=$row['ot'];
  123. }
  124. foreach($list_tgl AS $tgl){
  125.     echo "<td>".(isset($hk[$tgl])?$hk[$tgl]:"-")."</td>";
  126. }
  127. echo "<td rowspan='2'>{$totalhk}</td><td rowspan='2'>{$totalot}</td></tr><tr>";
  128. foreach($list_tgl AS $tgl){
  129.     echo "<td>".(isset($ot[$tgl])?$ot[$tgl]:"-")."</td>";
  130. }
  131. echo "</tr>";
  132. ?>
  133. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement