<?php
     
    // Deklarasi UctVw
    $objAxpDB->ViewName("Daftar Rekapitulasi Hak Cuti");

   


  $ssql_1 = "SELECT b.fnid, DATE_FORMAT(now(),'%b') AS ftmonth ,
                    DATE_FORMAT(now(),'%Y') as ftYear ,
                    a.ftemployee_code, b.ftemployee_name, b.fdstart_Date, " ;


  $ssql="SELECT * FROM tlleave_type WHERE fnleave_status = 0";
  $rs=mysql_query($ssql) or die($ssql);
  while ($r=mysql_fetch_assoc($rs)) {
         $ssql_1 = $ssql_1 ." SUM(CASE a.ftleave_type_code WHEN '".$r['ftleave_type_code']."' THEN fnleave_days ELSE 0 END) AS `".$r['ftleave_type_code']."`, ";
  }

  $ssql_1 = $ssql_1 . " sum(fnleave_days) AS fnleave_days, ifnull(c.fnleavelastyear, 0) as fnleavelastyear
                    from txleave a 
                    inner join tlemployee b on a.ftemployee_code = b.ftemployee_code
                    left join ( 
                      select b.ftemployee_code, sum(fnleave_days) as fnleavelastyear 
                      from thleave a 
                      left join tlemployee b on a.ftemployee_code = b.ftemployee_code 
                      where year(fdleave_period) < year(now()) - 1
                      group by fdleave_period, b.ftemployee_code 
                    ) c on a.ftemployee_code = c.ftemployee_code 
                    where year(fdtrans_date) = year(now())
                    group by b.fnid, a.ftbranch_code, a.fdtrans_date, a.ftemployee_code, b.ftemployee_name, b.fdstart_date, c.fnleavelastyear 
                    order by a.ftemployee_code";

   #die($ssql_1) ;
//    $objAxpDB->ViewSQL("SELECT b.fnid,b.ftemployee_code,b.ftemployee_name,SUM(a.fnleave_days) as fnleave_days
//                        FROM txleave a,tlemployee b
//                        WHERE a.ftemployee_code=b.ftemployee_code
//                        GROUP BY b.fnid,b.ftemployee_code,b.ftemployee_name");
						
$objAxpDB->ViewSQL($ssql_1);
  $ssql_2=" ID, Bulan, Tahun, Kode Pegawai, Nama Pegawai, Tgl. Kerja ";
  $ssql="SELECT * FROM tlleave_type WHERE fnleave_status = 0";
  $rs=mysql_query($ssql) or die($ssql);
  while ($r=mysql_fetch_assoc($rs)) {
         $ssql_2 = $ssql_2 .",".$r['ftleave_type_name'];
  }
  $ssql_2=$ssql_2.",Hari Cuti, Total Cuti Tahun Lalu";
  
    $objAxpDB->ViewCaption($ssql_2);
	//$objAxpDB->ViewPeriod(TRUE);
	

              $strAutoNumber0=" 
                           var jj =document.getElementsByName('fnindexD0[]').length;
                            for(var ii=1;ii<jj;ii++) {
                               document.getElementsByName('fnindexD0[]')[ii].value=ii;
                            }
                       

                                 
                                ";

            $objAxpDB->FormJS($strAutoNumber0);

	 
    // Deklarasi Header & Footer
    $objAxpDB->FormName("Rekapitulasi Hak Cuti");
    $objAxpDB->FormSQL("select ftemployee_code from tlemployee");
    $objAxpDB->FormCaption("Pegawai");
    $objAxpDB->FormPosition("TL");

	$ftemployee_code=RetRstField("select ftemployee_code from tlemployee where fnid='{$_REQUEST['id']}'");
    // Deklarasi Detail
    $objAxpDB->GridSQL(0, "select a.fnid as fnindex,a.ftleave_type_code,ifnull(sum(b.fnleave_days),0) as fnleave_days
                        from tlleave_type a
                                left join txleave b on a.ftleave_type_code=b.ftleave_type_code and b.ftemployee_code='{$ftemployee_code}'
                                left join txovertime_det c on 1=0 
                        group by a.ftleave_type_code
                        order by a.fnid#");
    $objAxpDB->GridCaption(0, "No.,Type Cuti, Jumlah");

     $objAxpDB->Lookup("ftleave_type_code", "SELECT ftleave_type_code, ftleave_type_name FROM tlleave_type", "ftleave_type_code", "ftleave_type_name", 0, False);
    $objAxpDB->Lookup("ftemployee_code", "SELECT ftemployee_code, ftemployee_name FROM tlemployee", "ftemployee_code", "ftemployee_name", -1, False);
  
    $objAxpDB->FormLocked("1");
    $objAxpDB->GridLocked(0, "1, 1, 1, 1");
	$objAxpDB->ButtonShow("tutup , export_excel ,cetak_daftar");
	
    $objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();


?>
