<?php  
    $objAxpDB->ViewName("Daftar laporan hrd");
    $objAxpDB->ViewSQL("SELECT fnid,ftreport_code,  ftreport_name FROM tlreport WHERE ftreport_group = 'hrd' order by ftreport_code");
    $objAxpDB->ViewCaption("ID,Kode Laporan, Nama laporan");
    
    $objAxpDB->FormName(" laporan hrd");
    $objAxpDB->FormSQL("SELECT ftreport_name
                      FROM tlreport");
    $objAxpDB->FormCaption("Nama laporan");
    $objAxpDB->FormPosition("TL");
    $objAxpDB->lengt_object=false;

    if($_REQUEST['id']) {
        $ssql="select * from tlreport where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $code=$r['ftreport_code'];
        $report_name=" :: ".$r['ftreport_name'];
        switch ($code) {
       
           case "h001":
              $objAxpDB->Lookup("pfnsni", "SELECT 0 AS A,'ALL' AS B UNION ALL SELECT 1 AS A,'SNI' AS B", "A", "B", 1,true);

             $objAxpDB->FormSQL("SELECT '0' as pfnsni
                      FROM tlreport");
              $objAxpDB->FormCaption("Tipe");
            $objAxpDB->FormPosition("TL");
          break;
          case "h001_1":

             $objAxpDB->Lookup("pfnsni", "SELECT 0 AS A,'ALL' AS B UNION ALL SELECT 1 AS A,'SNI' AS B", "A", "B", 1,true);

             $objAxpDB->FormSQL("SELECT '0' as pfnsni
                      FROM tlreport");
              $objAxpDB->FormCaption("Tipe");
            $objAxpDB->FormPosition("TL");
          break;
         case "h002": //date_from,date_end
               $objAxpDB->Lookup("pfnsni", "SELECT 0 AS A,'ALL' AS B UNION ALL SELECT 1 AS A,'SNI' AS B", "A", "B", 1,true);

             $objAxpDB->FormSQL("SELECT '0' as pfnsni
                      FROM tlreport");
              $objAxpDB->FormCaption("Tipe");
            $objAxpDB->FormPosition("TL");
             break;
         case "h002_1":
            $objAxpDB->Lookup("pfnsni", "SELECT 0 AS A,'ALL' AS B UNION ALL SELECT 1 AS A,'SNI' AS B", "A", "B", 1,true);

             $objAxpDB->FormSQL("SELECT '0' as pfnsni, 
                            CONVERT(null,date) as pdate  
                            
                            FROM tlreport");
            $objAxpDB->FormCaption("Tipe,Bulan");
            $objAxpDB->FormPosition("TL,TL");
            break;
         case "h002_3":
              $objAxpDB->Lookup("pfnsni", "SELECT 0 AS A,'ALL' AS B UNION ALL SELECT 1 AS A,'SNI' AS B", "A", "B", 1,true);

             $objAxpDB->FormSQL("SELECT '0' as pfnsni, 
                            CONVERT(null,date) as pdate

                            FROM tlreport");
            $objAxpDB->FormCaption("Tipe,Bulan");
            $objAxpDB->FormPosition("TL,TL");
            break;
       case "h003": //date_from,date_end
             $objAxpDB->Lookup("pfnsni", "SELECT 0 AS A,'ALL' AS B UNION ALL SELECT 1 AS A,'SNI' AS B", "A", "B", 1,true);

             $objAxpDB->FormSQL("SELECT '0' as pfnsni

                            FROM tlreport");
            $objAxpDB->FormCaption("Tipe");
            $objAxpDB->FormPosition("TL");
            break;
            
        case "h004": //date_from,date_end
             $objAxpDB->Lookup("ftdivision_code", "select 'SELURUH' AS ftdivision_code,'SELURUH' AS ftdivision_name UNION ALL (select ftdivision_code, ftdivision_name from tldivision order by ftdivision_code) ", "ftdivision_code", "ftdivision_name", -1, False);
   
            $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as pdate,
                            '' as ftdivision_code
                            FROM tlreport");
            $objAxpDB->FormCaption("Bulan, Divisi");
            $objAxpDB->FormPosition("TL, TL");
            break;
         case "h004_1": //date_from,date_end
            $objAxpDB->Lookup("ftdepartment_code", "select 'SELURUH' AS ftdepartment_code,'SELURUH' AS ftdepartment_name UNION ALL (select ftdepartment_code, ftdepartment_name from tldepartment order by ftdepartment_code) ", "ftdepartment_code", "ftdepartment_name", -1, False);

            $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as pdate,
                            '' as ftdepartment_code
                            FROM tlreport");
            $objAxpDB->FormCaption("Bulan, Department");
            $objAxpDB->FormPosition("TL, TL");
            break;
      case "h005": //date_from,date_end
            $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as pdate

                            FROM tlreport");
            $objAxpDB->FormCaption("Bulan");
            $objAxpDB->FormPosition("TL");
            break;
        case "h007_1": //date_from,date_end
	      $objAxpDB->Lookup("ftdepartment_code", "select 'SELURUH' AS ftdepartment_code,'SELURUH' AS ftdepartment_name UNION ALL (select ftdepartment_code, ftdepartment_name from tldepartment order by ftdepartment_code) ", "ftdepartment_code", "ftdepartment_name", -1, False);
            $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as pdate_from ,
                            '' as ftdepartment_code
                            FROM tlreport");
            $objAxpDB->FormCaption("Tgl. THR, Department");
            $objAxpDB->FormPosition("TL,TL");
            break;
          case "h008": //date_from,date_end
            $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as pdate_from ,
                            CONVERT(null,date) as pdate_end
                            FROM tlreport");
            $objAxpDB->FormCaption("Bulan 1, Bulan 2");
            $objAxpDB->FormPosition("TL,TL");
            break;
        case "h009": //date_from,date_end
            $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as pdate_from ,
                            CONVERT(null,date) as pdate_end
                            FROM tlreport");
            $objAxpDB->FormCaption("Bulan 1, Bulan 2");
            $objAxpDB->FormPosition("TL,TL");
            break;
       case "h010": //date_from,date_end
            $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as pdate

                            FROM tlreport");
            $objAxpDB->FormCaption("Bulan");
            $objAxpDB->FormPosition("HD");
            break;
         case "h011": //date_from,date_end
//            $objAxpDB->FormSQL("SELECT
//                            CONVERT(null,date) as pdate_from ,
//                            CONVERT(null,date) as pdate_end
//                            FROM tlreport");
//            $objAxpDB->FormCaption("Bulan 1, Bulan 2");
//            $objAxpDB->FormPosition("TL,TL");
//            break;

            $objAxpDB->Lookup("ftposition_code", "select 'SELURUH' AS ftposition_code,'SELURUH' AS ftposition_name UNION ALL (SELECT ftposition_code, ftposition_name FROM tlposition   order by ftposition_code) ", "ftposition_code", "ftposition_name", -1, False);
            $objAxpDB->Lookup("ftdepartment_code", "select 'SELURUH' AS ftdepartment_code,'SELURUH' AS ftdepartment_name UNION ALL (select ftdepartment_code, ftdepartment_name from tldepartment order by ftdepartment_code) ", "ftdepartment_code", "ftdepartment_name", -1, False);
            $objAxpDB->Lookup("ftdivision_code", "select 'SELURUH' AS ftdivision_code,'SELURUH' AS ftdivision_name UNION ALL (select ftdivision_code, ftdivision_name from tldivision order by ftdivision_code) ", "ftdivision_code", "ftdivision_name", -1, False);
            $objAxpDB->Lookup("ftgroup_pengajian_code", "select 'SELURUH' AS ftgroup_pengajian_code,'SELURUH' AS ftgroup_pengajian_name UNION ALL (select ftgroup_pengajian_code, ftgroup_pengajian_name from tlgroup_pengajian order by  ftgroup_pengajian_code)", "ftgroup_pengajian_code", "ftgroup_pengajian_name", -1, False);

            $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as pdate_from ,
                            CONVERT(null,date) as pdate_end,

                            '' as ftdivision_code, '' as ftdepartment_code, '' as ftposition_code ,
                            '' as ftgroup_pengajian_code
                            FROM tlreport");
            $objAxpDB->FormCaption("Tgl 1, Tgl 2, Divisi, Departement, Jabatan, Group Pengajian");
            $objAxpDB->FormPosition("TL,TL,TL,TL,TL,TL");
            break;
        case "h012": //date_from,date_end
            #$objAxpDB->Lookup("ftemployee_code", "'SELURUH' AS ftemployee_code,'SELURUH' AS ftemployee_name UNION ALL (SELECT ftemployee_code, ftemployee_name FROM tlemployee)", "ftemployee_code", "ftemployee_name", -1, False);
            $ftemployee="SELECT ";
            $ftemployee.=" DISTINCT a.ftemployee_code,b.ftemployee_name ";
            $ftemployee.=" FROM txloan a ";
            $ftemployee.=" INNER JOIN tlemployee b ON a.ftemployee_code=b.ftemployee_code ";
            $ftemployee.=" WHERE a.fnstatus<>9 AND a.fnstatus<>3  ";
            
	    $objAxpDB->Lookup("pftemployee_code", "select 'SELURUH' AS ftemployee_code,'SELURUH' AS ftemployee_name UNION ALL ($ftemployee) ", "ftemployee_code", "ftemployee_name", -1, False);
            $objAxpDB->Lookup("pftbankpym_no", "select 'SELURUH' AS ftbankpym_no,'SELURUH' AS ftjournal_no UNION ALL (SELECT ftbankpym_no,ftjournal_no FROM txloan WHERE fnstatus<>9 AND fnstatus<>3 ORDER BY ftbankpym_no DESC) ", "ftbankpym_no", "ftjournal_no", -1, False);
            $objAxpDB->Lookup("pLunas", "select 'SELURUH' AS A,'SELURUH' AS B UNION ALL select '0' AS A,'BELUM LUNAS' AS B  UNION ALL select '1' AS A,'LUNAS' AS B  ", "A", "B", -1, TRUE);

            
            $objAxpDB->FormSQL("SELECT
                            '' as pftemployee_code,
                            '' as pftbankpym_no,
                            '' as pLunas 
                            FROM tlreport");
            $objAxpDB->FormCaption("Pegawai, No. PV, Status Pinjaman ");
            $objAxpDB->FormPosition("TL,TL,TL");
            break;
         case "h013": //date_from,date_end
            $objAxpDB->Lookup("ftposition_code", "select 'SELURUH' AS ftposition_code,'SELURUH' AS ftposition_name UNION ALL (SELECT ftposition_code, ftposition_name FROM tlposition   order by ftposition_code) ", "ftposition_code", "ftposition_name", -1, False);
            $objAxpDB->Lookup("ftdepartment_code", "select 'SELURUH' AS ftdepartment_code,'SELURUH' AS ftdepartment_name UNION ALL (select ftdepartment_code, ftdepartment_name from tldepartment order by ftdepartment_code) ", "ftdepartment_code", "ftdepartment_name", -1, False);
            $objAxpDB->Lookup("ftdivision_code", "select 'SELURUH' AS ftdivision_code,'SELURUH' AS ftdivision_name UNION ALL (select ftdivision_code, ftdivision_name from tldivision order by ftdivision_code) ", "ftdivision_code", "ftdivision_name", -1, False);
            $objAxpDB->Lookup("ftgroup_pengajian_code", "select 'SELURUH' AS ftgroup_pengajian_code,'SELURUH' AS ftgroup_pengajian_name UNION ALL (select ftgroup_pengajian_code, ftgroup_pengajian_name from tlgroup_pengajian order by  ftgroup_pengajian_code)", "ftgroup_pengajian_code", "ftgroup_pengajian_name", -1, False);

            $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as pdate_from ,
                            CONVERT(null,date) as pdate_end,

                            '' as ftdivision_code, '' as ftdepartment_code, '' as ftposition_code ,
                            '' as ftgroup_pengajian_code
                            FROM tlreport");
            $objAxpDB->FormCaption("Tgl 1, Tgl 2, Divisi, Departement, Jabatan, Group Pengajian");
            $objAxpDB->FormPosition("TL,TL,TL,TL,TL,TL");
            break;
        case "h014": //date_from,date_end
	      $objAxpDB->Lookup("ftdepartment_code", "select 'SELURUH' AS ftdepartment_code,'SELURUH' AS ftdepartment_name UNION ALL (select ftdepartment_code, ftdepartment_name from tldepartment order by ftdepartment_code) ", "ftdepartment_code", "ftdepartment_name", -1, False);
            $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as pdate_from ,
                            '' as ftdepartment_code
                            FROM tlreport");
            $objAxpDB->FormCaption("Tgl. THR, Department");
            $objAxpDB->FormPosition("TL,TL");
            break;
        }
    }
    
   
     
    $objAxpDB->Process();
    if(!$_REQUEST['id']) {       
        $objAxpDB->WriteHtmlTable();
    }
    else {
         $objAxpDB->FormName("laporan hrd".$report_name);
         $objAxpDB->ButtonShow("generate_report,print_report");
         $objAxpDB->reportData();
    }