<?php
     if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              if(RetRstField("SELECT fnid FROM tlemployee WHERE ftemployee_code='{$_REQUEST['fttrans_no']}'")) {
                  ?>
                  alert('Kode Pegawai sudah dipakai...\n System akan mengenerate Kode Pegawai kembali ...\n Silahkan ulangi proses penyimpanan...  ');

                  OnChangeDate_fdstart_date()
            <?php
              }
              else {
                    ?> 
                  submitbutton('Simpan','','','','');                   
            <?php
              }
			    die("");
            break;
			case "ftsalary_code2":
				$ssql="SELECT fnpayroll_slip,fnsalary_period,fcsalary_amount 
						FROM tlsalary 
						WHERE fnsalary_type=0 AND 
							ftsalary_code='{$_REQUEST['ftsalary_code']}'";
				$rs=mysql_query($ssql);
				$r=mysql_fetch_assoc($rs);
				?>
				document.getElementById('fcamountD2<?php echo $_REQUEST['index']; ?>').value='<?php echo $r['fcsalary_amount']; ?>';
				ElementCurrencyOnBlur(document.getElementById('fcamountD2<?php echo $_REQUEST['index']; ?>'));
				var ObjSelect=document.getElementById('fnsalary_periodD2<?php echo $_REQUEST['index']; ?>');
                    var len = ObjSelect.length;

                    for (var idx=0; idx < len; idx++)
                    {
                            if (ObjSelect.options[idx].value=='<?php echo $r['fnsalary_period']; ?>') {
                                ObjSelect.selectedIndex=idx;
                                break;
                            }
                    }
					
					 ObjSelect=document.getElementById('fnpayroll_slipD2<?php echo $_REQUEST['index']; ?>');
                     len = ObjSelect.length;

                    for ( idx=0; idx < len; idx++)
                    {
                            if (ObjSelect.options[idx].value=='<?php echo $r['fnpayroll_slip']; ?>') {
                                ObjSelect.selectedIndex=idx;
                                break;
                            }
                    }
					
				<?php
			  die("");
            break;
			case "ftsalary_code3":
			 $ssql="SELECT fnpayroll_slip,fnsalary_period,fcsalary_amount 
						FROM tlsalary 
						WHERE fnsalary_type=1 AND 
							ftsalary_code='{$_REQUEST['ftsalary_code']}'";
				$rs=mysql_query($ssql);
				$r=mysql_fetch_assoc($rs);
				?>
				document.getElementById('fcamountD3<?php echo $_REQUEST['index']; ?>').value='<?php echo $r['fcsalary_amount']; ?>';
				ElementCurrencyOnBlur(document.getElementById('fcamountD3<?php echo $_REQUEST['index']; ?>'));
				var ObjSelect=document.getElementById('fnsalary_periodD3<?php echo $_REQUEST['index']; ?>');
                    var len = ObjSelect.length;

                    for (var idx=0; idx < len; idx++)
                    {
                            if (ObjSelect.options[idx].value=='<?php echo $r['fnsalary_period']; ?>') {
                                ObjSelect.selectedIndex=idx;
                                break;
                            }
                    }
					
					 ObjSelect=document.getElementById('fnpayroll_slipD3<?php echo $_REQUEST['index']; ?>');
                     len = ObjSelect.length;

                    for ( idx=0; idx < len; idx++)
                    {
                            if (ObjSelect.options[idx].value=='<?php echo $r['fnpayroll_slip']; ?>') {
                                ObjSelect.selectedIndex=idx;
                                break;
                            }
                    }
					
				<?php
			  die("");
            break;
			
        }       
      
    }

    
	  if(!$_REQUEST['id']) {
           
            $strAutoNumber0="   
                                 document.getElementById(\"TransactionDetail0\").deleteRow(3);
                                 document.getElementById(\"TransactionDetail1\").deleteRow(3);
                                 ajax_do_grid2('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid_salary2'); 
                                 ajax_do_grid3('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid_salary3');
								 document.getElementById('ftreligion').selectedIndex=1;

                                 function OnChangeDate_fdstart_date() {
                                           ajax_do('query2.php?code=2&ftmodule_code=hrd008&fnstatus=' + document.getElementById(\"fnstatus\").value + '&thbln=' + document.getElementById(\"fdstart_date\").value + '&field_name=ftemployee_code&no_trans=ftemployee_code&table_name=tlemployee');
                                   }
                                   OnChangeDate_fdstart_date();
                                document.getElementById('frmMain').enctype=\"multipart/form-data\";
                                 document.getElementById('DivCtl_ftphoto').innerHTML=\"<table colspacing=0 colpadding=0><tr><td><img src='employee_photo/"."blank".".jpg' width='180' height='200'></td></tr><tr><td><input type='file' name='ftphoto1' id='ftphoto1' size='60'></td></tr></table>\";

								 ";
                               

            $objAxpDB->FormJS($strAutoNumber0);
             }
            else {

                $employee_code=RetRstField("SELECT ftemployee_code FROM tlemployee WHERE fnid='{$_REQUEST['id']}'");
                if(file_exists("employee_photo/".$employee_code.".jpg")) {
                    $employee_code=$employee_code;
                }
                else {
                    $employee_code="blank";
                }

                $strAutoNumber0="
                                 document.getElementById('frmMain').enctype=\"multipart/form-data\";
                                 document.getElementById('DivCtl_ftphoto').innerHTML=\"<table colspacing=0 colpadding=0><tr><td><img src='employee_photo/".$employee_code.".jpg' width='160' height='200'></td></tr><tr><td><input type='file' name='ftphoto1' id='ftphoto1' size='60'></td></tr></table>\";

								 ";


            $objAxpDB->FormJS($strAutoNumber0);
             
           
     }

    $objAxpDB->ViewName("Daftar Pegawai Habis Kontrak");
    $objAxpDB->ViewTable("");
    $objAxpDB->ViewSQL("SELECT 	a.fnid,  a.ftemployee_code, a.ftemployee_name,a.fdstart_date,a.fdstart_contract_date,a.fdend_contract_date,d.ftdivision_name,c.ftdepartment_name,
				e.ftposition_name,ifnull(a.ftparent_name,'') as ftparent_name,a.ftaddress,
				f.ftshift_name,b.fttrans_status_name
                        from tlemployee  a
				left join tstransaction_status b on a.fnstatus=b.fntrans_status_code and b.fntrans_group_code = 29
				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
			WHERE a.fnstatus <> 0 and a.fnstatus <> 4 AND  NOW() >=a.fdend_contract_date AND a.fntype=0 
                        order by a.fnstatus,a.ftemployee_code,a.fdstart_date

                         ");
    $objAxpDB->ViewCaption("ID, Kode Pegawai, Nama Pegawai,Tgl. Masuk,Tgl. Mulai Kontrak, Tgl. Akhir Kontrak, Devisi,Departemen,Jabatan,Nama Orang Tua, Alamat, Shift, Status");
   
    $objAxpDB->FormName("Pegawai");
    $objAxpDB->FormSQL("select ftemployee_code, ftemployee_name, ftnickname, fiphoto, fdbirth_date, ftbirth_place,
								ftreligion, fnsex, fttelephone, fthandphone, ftktp_no, ftaddress,
								ftcity, ftzip_code, ftstate, ftcountry, fteducation_code, ftjurusan, ftphoto, fdstart_date,
								fdleave_date, ftdivision_code,ftdepartment_code, ftposition_code ,fnstatus, fdappointed_date, fdstart_contract_date, fncontract, fdend_contract_date, ftpph21_code,
								fnmarried_status, ftspouse_name,ftparent_name, ftnotes, ftemergency_contact, ftemergency_affiliation, ftemergency_telephone,
								ftpermanent_address, ftpermanent_city, ftpermanent_state, ftpermanent_zip_code, ftpermanent_telephone,ftpayroll_type_code,ftgroup_pengajian_code, 
								fcbasic_salary, fcfood_money, fctransport_money, fcovertime_money, fcmaximum_loan, ftshift_code,
								fnpayment_status_code, ftbank_name, ftbank_account, ftpayroll_notes 
								from tlemployee");
    $objAxpDB->FormCaption(" Kode Pegawai, Nama Pegawai, Nama Panggilan, Foto, Tgl. Lahir,
                                Tempat Lahir, Agama, Jenis Kelamin, Telepon, Handphone, No. KTP, Alamat,
                                 Kota, Kode Pos, Propinsi, Negara, Pendidikan, Jurusan, Foto, Tgl. Mulai Kerja,
                                        Tgl. Akumulasi Cuti,Divisi, Departemen, Jabatan, Status,Tgl. Pengangkatan,Tgl. Mulai Kontrak,Lama Kontrak (Bulan), Tgl. Akhir Kontrak, PPH 21,
                                    Status Menikah, Nama Suami/Istri, Nama Orang Tua, Catatan, Nama Kontak Darurat, Status Hubungan, Telepon Kontak Darurat, Alamat Permanen, Kota Permanen, Propinsi Permanen, Kode Pos Permanen, Telepon Permanen, Tipe Gaji,Group Pengajian,
                                     Gaji Pokok, Uang Makan, Uang Transport, Uang Lembur, Maksimum Pinjaman, Shift, Metode Pembayaran, Nama Bank, No. Rekening, Catatan Gaji");
    $objAxpDB->FormPosition("TL, TL, TL, HD, TL, TL, 
                                TL, TL, TL, TL, TL, TL,
                                    TL, TL, TL,  TL, TL,TL,TR, TR,
                                         TR, TR, TR, TR, TR,TR, TR, TR, TR,TR,
                                            TL, TL, TL, TR, BL, BL, BL, BL, BL, BL, BL, BL,BR, BR, HD, HD, HD, HD, BR, BR, BR, BR, BR, BR");
    $objAxpDB->FormScript(24, "OnChange=\"OnChangeDate_fdstart_date();\"");
   
    
    $objAxpDB->GridName(0, "Tanggungan");
    $objAxpDB->GridSQL(0, "select fnindex, ftload_name, fdload_birthday, ftload_status from tlemployee_load");
    $objAxpDB->GridCaption(0, "No., Nama Tanggungan, Tgl. Lahir Tanggungan, Status Tangungan");

    $objAxpDB->GridName(1, "Catatan");
    $objAxpDB->GridSQL(1, "select fnindex, fdnotes_date, ftnotes_type_code,  ftnotes_content from tlemployee_notes");
    $objAxpDB->GridCaption(1, "No., Tgl. Catatan, Tipe Catatan, Isi Catatan");

    $objAxpDB->SetStatus("id");
    if ($objAxpDB->GetStatus("id") == "") {

    }  elseif ($objAxpDB->GetStatus("id") == 0) {       
        $objAxpDB->GridName(2, "Pendapatan");
        $objAxpDB->GridSQL(2, "select fnindex, ftsalary_code, fcamount,fnsalary_period,fnpayroll_slip from tlemployee_salary_inc");
        $objAxpDB->GridCaption(2, "No., Kode Gaji, Jumlah Gaji, Periode, Pengajian");
        $ajaxGrid="ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=ftsalary_code2&ftsalary_code='+ this.value +'&index=_N_');";
        $objAxpDB->GridScript(2,1,"OnChange=\"$ajaxGrid\"");

        $objAxpDB->GridName(3, "Potongan");
        $objAxpDB->GridSQL(3, "select fnindex, ftsalary_code, fcamount,fnsalary_period,fnpayroll_slip from tlemployee_salary_dec");
        $objAxpDB->GridCaption(3, "No., Kode Gaji, Jumlah Gaji, Periode, Pengajian");
        $ajaxGrid="ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=ftsalary_code3&ftsalary_code='+ this.value +'&index=_N_');";
        $objAxpDB->GridScript(3,1,"OnChange=\"$ajaxGrid\"");
       
    } elseif ($objAxpDB->GetStatus("id") != 0) {
        $fnsalary_type=RetRstField("SELECT fnsalary_type FROM tlemployee WHERE fnid='".$objAxpDB->GetStatus("id")."'");
        if($fnsalary_type==0) {
           if(Getsecurity("slip_gaji")) {
                $objAxpDB->GridName(2, "Pendapatan");
                $objAxpDB->GridSQL(2, "select fnindex, ftsalary_code, fcamount,fnsalary_period,fnpayroll_slip from tlemployee_salary_inc");
                $objAxpDB->GridCaption(2, "No., Kode Gaji, Jumlah Gaji, Periode, Pengajian");
                $ajaxGrid="ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=ftsalary_code2&ftsalary_code='+ this.value +'&index=_N_');";
                $objAxpDB->GridScript(2,1,"OnChange=\"$ajaxGrid\"");

                $objAxpDB->GridName(3, "Potongan");
                $objAxpDB->GridSQL(3, "select fnindex, ftsalary_code, fcamount,fnsalary_period,fnpayroll_slip from tlemployee_salary_dec");
                $objAxpDB->GridCaption(3, "No., Kode Gaji, Jumlah Gaji, Periode, Pengajian");
                $ajaxGrid="ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=ftsalary_code3&ftsalary_code='+ this.value +'&index=_N_');";
                $objAxpDB->GridScript(3,1,"OnChange=\"$ajaxGrid\"");
           }
        }
        elseif($fnsalary_type==1) {
            if(Getsecurity("slip_gaji2")) {
                $objAxpDB->GridName(2, "Pendapatan");
                $objAxpDB->GridSQL(2, "select fnindex, ftsalary_code, fcamount,fnsalary_period,fnpayroll_slip from tlemployee_salary_inc");
                $objAxpDB->GridCaption(2, "No., Kode Gaji, Jumlah Gaji, Periode, Pengajian");
                $ajaxGrid="ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=ftsalary_code2&ftsalary_code='+ this.value +'&index=_N_');";
                $objAxpDB->GridScript(2,1,"OnChange=\"$ajaxGrid\"");

                $objAxpDB->GridName(3, "Potongan");
                $objAxpDB->GridSQL(3, "select fnindex, ftsalary_code, fcamount,fnsalary_period,fnpayroll_slip from tlemployee_salary_dec");
                $objAxpDB->GridCaption(3, "No., Kode Gaji, Jumlah Gaji, Periode, Pengajian");
                $ajaxGrid="ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=ftsalary_code3&ftsalary_code='+ this.value +'&index=_N_');";
                $objAxpDB->GridScript(3,1,"OnChange=\"$ajaxGrid\"");
           }
        }
         elseif($fnsalary_type==2) {
            if(Getsecurity("slip_gaji3")) {
                $objAxpDB->GridName(2, "Pendapatan");
                $objAxpDB->GridSQL(2, "select fnindex, ftsalary_code, fcamount,fnsalary_period,fnpayroll_slip from tlemployee_salary_inc");
                $objAxpDB->GridCaption(2, "No., Kode Gaji, Jumlah Gaji, Periode, Pengajian");
                $ajaxGrid="ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=ftsalary_code2&ftsalary_code='+ this.value +'&index=_N_');";
                $objAxpDB->GridScript(2,1,"OnChange=\"$ajaxGrid\"");

                $objAxpDB->GridName(3, "Potongan");
                $objAxpDB->GridSQL(3, "select fnindex, ftsalary_code, fcamount,fnsalary_period,fnpayroll_slip from tlemployee_salary_dec");
                $objAxpDB->GridCaption(3, "No., Kode Gaji, Jumlah Gaji, Periode, Pengajian");
                $ajaxGrid="ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=ftsalary_code3&ftsalary_code='+ this.value +'&index=_N_');";
                $objAxpDB->GridScript(3,1,"OnChange=\"$ajaxGrid\"");
           }
        }
            
    }
    
   
    
    $objAxpDB->Lookup("fnsex", "select fntrans_status_code, fttrans_status_name from tstransaction_status where fntrans_group_code = 23", "fntrans_status_code", "fttrans_status_name", -1, True);
    $objAxpDB->Lookup("ftreligion", "select ftreligion_code, ftreligion_name from tlreligion order by fnid ", "ftreligion_code", "ftreligion_name", -1, True);
    $objAxpDB->Lookup("fnstatus", "select fntrans_status_code, fttrans_status_name from tstransaction_status where fntrans_group_code = 29", "fntrans_status_code", "fttrans_status_name", 1, True);
    $objAxpDB->Lookup("ftpph21_code", "select ftpph21_code, ftpph21_name from tlpph21 ", "ftpph21_code", "ftpph21_name", 0, True);
    $objAxpDB->Lookup("fnmarried_status", "select fntrans_status_code, fttrans_status_name from tstransaction_status where fntrans_group_code = 24", "fntrans_status_code", "fttrans_status_name", 0, True);
    $objAxpDB->Lookup("ftposition_code", "select ftposition_code, ftposition_name from tlposition ", "ftposition_code", "ftposition_name", -1, True);
    $objAxpDB->Lookup("ftdepartment_code", "select ftdepartment_code, ftdepartment_name from tldepartment ", "ftdepartment_code", "ftdepartment_name", -1, True);
    $objAxpDB->Lookup("ftdivision_code", "select ftdivision_code, ftdivision_name from tldivision ", "ftdivision_code", "ftdivision_name", -1, True);
    $objAxpDB->Lookup("ftgroup_pengajian_code", "select ftgroup_pengajian_code, ftgroup_pengajian_name from tlgroup_pengajian ", "ftgroup_pengajian_code", "ftgroup_pengajian_name", -1, True);

   
   
    $objAxpDB->Lookup('ftload_status', 'SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status where fntrans_group_code=9', 'fntrans_status_code', 'fttrans_status_name', 1,true);
    $objAxpDB->Lookup("ftnotes_type_code", "select ftnotes_type_code, ftnotes_type_name from tlnotes_type ", "ftnotes_type_code", "ftnotes_type_name", -1, True);
    $objAxpDB->Lookup("ftallowance_type_code", "select ftallowance_type_code, ftallowance_type_name from tlallowance_type ", "ftallowance_type_code", "ftnotes_type_name", -1, True);
    $objAxpDB->Lookup("ftsalary_code", "select ftsalary_code, ftsalary_name from tlsalary", "ftsalary_code", "ftsalary_name", -1, False);
    $objAxpDB->Lookup("fteducation_code", "select fteducation_code, fteducation_name from tleducation", "fteducation_code", "fteducation_name", -1, True);

    $objAxpDB->LookupGrid(2,"ftsalary_code", "select ftsalary_code, ftsalary_name from tlsalary WHERE fnsalary_type=0", "ftsalary_code", "ftsalary_name", -1, False);
    $objAxpDB->LookupGrid(3,"ftsalary_code", "select ftsalary_code, ftsalary_name from tlsalary WHERE fnsalary_type=1", "ftsalary_code", "ftsalary_name", -1, False);
    
    $objAxpDB->Lookup("ftpayroll_type_code", "select fntrans_status_code, fttrans_status_name from tstransaction_status where fntrans_group_code = 25", "fntrans_status_code", "fttrans_status_name", 1, true);
    $objAxpDB->Lookup("ftshift_code", "SELECT distinct ftshift_code, ftshift_name FROM tlshift", "ftshift_code", "ftshift_name", 0, True);
    $objAxpDB->Lookup('fnpayment_status_code', 'SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status where fntrans_group_code=26', 'fntrans_status_code', 'fttrans_status_name', 1,true);
    $objAxpDB->Lookup("fnsalary_period", "select fntrans_status_code, fttrans_status_name from tstransaction_status where fntrans_group_code = 25", "fntrans_status_code", "fttrans_status_name", 1, True);
    $objAxpDB->Lookup("fnpayroll_slip", "select fntrans_status_code, fttrans_status_name from tstransaction_status where fntrans_group_code = 28", "fntrans_status_code", "fttrans_status_name", 1, True);

 
 
   
    $objAxpDB->GridAllowAddNew(0, TRUE);
    $objAxpDB->GridAllowDelete(0, TRUE);
    $objAxpDB->GridAllowAddNew(1, TRUE);
    $objAxpDB->GridAllowDelete(1, TRUE);
    $objAxpDB->GridAllowAddNew(2, TRUE);
    $objAxpDB->GridAllowDelete(2, TRUE);
    $objAxpDB->GridAllowAddNew(3, TRUE);
    $objAxpDB->GridAllowDelete(3, TRUE);


    $objAxpDB->GridLocked(0, "1, 0, 0, 0");
    $objAxpDB->GridLocked(1, "1, 0, 0, 0");
    $objAxpDB->GridLocked(2, "1, 0, 0, 0");
	$objAxpDB->GridLocked(3, "1, 0, 0, 0");
    
    
    
    if ($objAxpDB->GetStatus("id") == "")
            $objAxpDB->ButtonShow("cetak_daftar,  export_excel ,  tutup");
    elseif ($objAxpDB->GetStatus("id") == 0) {
            $objAxpDB->FormLocked("0, 0, 0");
            $objAxpDB->ButtonShow("reset,  tutup");
    } elseif ($objAxpDB->GetStatus("id") != 0) {
            $objAxpDB->FormLocked(" 1, 0");
            $objAxpDB->ButtonShow("tutup");
    }

	 if($_REQUEST['ajax']) {
           switch($_REQUEST['code']) {
           case "grid_salary2":
				
               ob_start();
				$ssql="SELECT fnindex, ftsalary_code, fcsalary_amount AS fcamount,fnsalary_period, fnpayroll_slip 
						FROM tlsalary
						WHERE fnsalary_type=0   #   ";
				$_REQUEST["id"]=0.5;
				
				$objAxpDB->GridSQL(2,$ssql);
				$objAxpDB->GridCaption(2, "No., Kode Gaji, Jumlah Gaji, Periode, Pengajian");
				$objAxpDB->Process();
				$objAxpDB->setGrid2(2);
				$html = ob_get_contents();
				ob_end_clean();
               ?>

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

                    div.innerHTML =m;
                     TransactionDetailRowID2 =document.getElementsByName('fnindexD2[]').length;
                    RowIndex2();
                   // reSize();
                   
               <?
			  case "grid_salary3":
				 ob_start();
				$ssql="SELECT fnindex,ftsalary_code, fcsalary_amount AS fcamount,fnsalary_period, fnpayroll_slip 
						FROM tlsalary
						WHERE fnsalary_type=1 #   ";
				$_REQUEST["id"]=0.5;
				$objAxpDB->GridSQL(3,$ssql);
				$objAxpDB->GridCaption(3, "No., Kode Gaji, Jumlah Gaji, Periode, Pengajian");
				$objAxpDB->Process();
				$objAxpDB->setGrid2(3);
				$html = ob_get_contents();
				ob_end_clean();
               ?>

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

                    div.innerHTML =m;
                    TransactionDetailRowID3 =document.getElementsByName('fnindexD3[]').length;
                    RowIndex3();
                    reSize();
                   
               <?
			   
               break;

           }
           die("");
           exit;
    }
	
    $objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();
	   
       
?>
