<?php

    Getsecurity(26);
    $objAxpDB->ViewName("Daftar Group Penggajian");
    $objAxpDB->ViewTable("vHRPegawaiGroupPenggajian");
    $objAxpDB->ViewSQL("SELECT a.fnid, a.ftemployee_code, a.ftemployee_name,
                                a.ftgroup_pengajian_code,g.ftgroup_pengajian_name,
                                a.ftshift_code,f.ftshift_name,
                                a.ftdivision_code, d.ftdivision_name,
                                a.ftdepartment_code, c.ftdepartment_name,
                                a.ftposition_code,e.ftposition_name 
                        from tlemployee  a
                        left join tldivision d on a.ftdivision_code=d.ftdivision_code
                        left join tldepartment c on a.ftdepartment_code=c.ftdepartment_code
                        left join tlposition e on a.ftposition_code=e.ftposition_code
                        left join (SELECT distinct ftshift_code, ftshift_name FROM tlshift) f on a.ftshift_code=f.ftshift_code
                        left join tlgroup_pengajian g on a.ftgroup_pengajian_code=g.ftgroup_pengajian_code  
						where a.fntype=0 
                         order by a.fnstatus,a.ftemployee_code,a.fdstart_date 
                        ");

    $objAxpDB->ViewCaption("ID, Kode Pegawai, Nama Pegawai,Kode Group Penggajian,Nama Group Penggajian, Kode Shift, Nama Shift, Kode Devisi, Nama Divisi, Kode Departement,Nama Departement, Kode Jabatan, Nama Jabatan");

    $objAxpDB->FormName("Group Penggajian");


    $objAxpDB->FormSQL("SELECT  ftdivision_code,ftdepartment_code,ftposition_code, ftgroup_pengajian_code  FROM tlemployee");


    $objAxpDB->FormCaption("Devisi, Departement, Jabatan, Group Penggajian");
    $objAxpDB->FormPosition("TL,TL,TL,TL");

    $objAxpDB->FormLocked("0,0,0,0");

    $ajax1=" OnClick=\" ajax_do_grid0('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid&ftposition_code='+ document.getElementById('ftposition_code').value +'&ftdepartment_code='+ document.getElementById('ftdepartment_code').value +'&ftdivision_code='+ document.getElementById('ftdivision_code').value+'&ftgroup_pengajian_code='+ document.getElementById('ftgroup_pengajian_code').value);\"";
    $button="<input type='button' id='cmd_employee_list' name='cmd_employee_list' value='Lihat' {$ajax1}>";
    $objAxpDB->FormLayout(3,"{$button}");

	if($_REQUEST['id']) {

		$where.=" where a.fnid='{$_REQUEST['id']}'#";


	}

//    $objAxpDB->GridSQL(0, "SELECT fnid as fnindex, ftemployee_code, ftdivision_code,ftdepartment_code,ftposition_code, ftshift_code  FROM tlemployee $where ");

    $ssql="SELECT a.fnid as fnindex,  a.ftemployee_code,
                                concat( d.ftdivision_name,' * ', c.ftdepartment_name,' * ',e.ftposition_name) as fttemp,
                                ftgroup_pengajian_code
                        from tlemployee  a
                        left join tldivision d on a.ftdivision_code=d.ftdivision_code
                        left join tldepartment c on a.ftdepartment_code=c.ftdepartment_code
                        left join tlposition e on a.ftposition_code=e.ftposition_code
                        {$where} ";
    $objAxpDB->GridSQL(0,$ssql );

    $objAxpDB->GridCaption(0, "No.,Kode Pegawai, Divisi * Departement * Jabatan, Group Penggajian");
    $objAxpDB->GridLocked(0, "1, 1, 1,  0");

    $objAxpDB->Lookup("ftposition_code", "select 'SELURUH' AS ftposition_code,'SELURUH' AS ftposition_name UNION ALL (select ftposition_code, ftposition_name from tlposition) ", "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) ", "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) ", "ftdivision_code", "ftdivision_name", -1, False);
    $objAxpDB->Lookup("ftemployee_code", "select ftemployee_code, ftemployee_name from tlemployee ", "ftemployee_code", "ftemployee_name", -1, False);
    $objAxpDB->Lookup("ftshift_code", "select 'SELURUH' AS ftshift_code,'SELURUH' AS ftshift_name UNION ALL (SELECT distinct ftshift_code, ftshift_name FROM tlshift)", "ftshift_code", "ftshift_name", 0, True);
    $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", 0, True);

    $objAxpDB->LookupGrid(0,"ftposition_code", "select ftposition_code, ftposition_name from tlposition ", "ftposition_code", "ftposition_name", -1, False);
    $objAxpDB->LookupGrid(0,"ftdepartment_code", "select ftdepartment_code, ftdepartment_name from tldepartment ", "ftdepartment_code", "ftdepartment_name", -1, False);
    $objAxpDB->LookupGrid(0,"ftdivision_code", "select ftdivision_code, ftdivision_name from tldivision", "ftdivision_code", "ftdivision_name", -1, False);
    $objAxpDB->LookupGrid(0,"ftemployee_code", "select ftemployee_code, ftemployee_name from tlemployee ", "ftemployee_code", "ftemployee_name", -1, False);
    $objAxpDB->LookupGrid(0,"ftgroup_pengajian_code", "SELECT ftgroup_pengajian_code, ftgroup_pengajian_name FROM tlgroup_pengajian", "ftgroup_pengajian_code", "ftgroup_pengajian_name", 0, True);

    $objAxpDB->SetStatus("id");

    if ($objAxpDB->GetStatus("id") == "") {
            $objAxpDB->ButtonShow(" cetak_daftar, export_excel ,tutup");

    }

    elseif ($objAxpDB->GetStatus("id") != 0) {
            $objAxpDB->ButtonShow("update, tutup");

    }

       if($_REQUEST['ajax']) {
           switch($_REQUEST['code']) {
           case "grid":
               $_REQUEST['id']=0.5;
               if($_REQUEST['ftposition_code']!='SELURUH') {
                   $ftposition_code=" AND a.ftposition_code='{$_REQUEST['ftposition_code']}' ";
               }
                if($_REQUEST['ftdepartment_code']!='SELURUH') {
                   $ftdepartment_code=" AND a.ftdepartment_code='{$_REQUEST['ftdepartment_code']}' ";
               }
                if($_REQUEST['ftdivision_code']!='SELURUH') {
                   $ftdivision_code=" AND a.ftdivision_code='{$_REQUEST['ftdivision_code']}' ";
               }
                if($_REQUEST['ftgroup_pengajian_code']!='SELURUH') {
                   $ftgroup_pengajian_code=" AND a.ftgroup_pengajian_code='{$_REQUEST['ftgroup_pengajian_code']}' ";
               }
              $where=" WHERE 1=1 {$ftposition_code} {$ftdepartment_code} {$ftdivision_code} {$ftgroup_pengajian_code}";

               $ssql="SELECT a.fnid as fnindex,  a.ftemployee_code,
                                concat( d.ftdivision_name,' * ', c.ftdepartment_name,' * ',e.ftposition_name) as fttemp,
                                ftgroup_pengajian_code
                        from tlemployee  a
                        left join tldivision d on a.ftdivision_code=d.ftdivision_code
                        left join tldepartment c on a.ftdepartment_code=c.ftdepartment_code
                        left join tlposition e on a.ftposition_code=e.ftposition_code
                        {$where}
                         order by a.ftemployee_name ";
             # die($ssql);
               $objAxpDB->GridSQL(0, $ssql);
               ob_start();
               $objAxpDB->Process();
               $objAxpDB->setGrid2(0);
               $html = ob_get_contents();
               ob_end_clean();

               ?>
                    div = document.getElementById('txtHint0');
                    var m='<?php echo js_esc($html); ?>';
                    m= m.replace(/^\s*|\s*$/g,"");
                    div.innerHTML =m;

               <?
               break;

           }
           die("");
           exit;
    }

    $objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();
?>