<?php
    $fnsalary_type="0";
	if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "grid":
				$ssqlm="SELECT MAX(a.fdend_date) AS fdend_date
                        FROM txpayroll_slip_hdr a
                        WHERE a.ftpayroll_type_code='{$_REQUEST['ftpayroll_type_code']}'
                        ";
				if(RetRstField("SELECT fnid FROM txpayroll_slip_hdr WHERE ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."'")&&($_REQUEST['x']!='1')) {
					?>
						alert('No. transaksi sudah dipakai...\n System akan mengenerate No. transaksi kembali ...\n Silahkan ulangi proses penyimpanan...  ');
						OnChangeDate_fdattendance_date();
					<?php
					die("");
				}
				?>
					document.getElementById('txtHint0').innerHTML = '<img src=images/loading.gif>';
				<?php
            break;
			case "save_employee":
                $ssql=" UPDATE txpayroll_slip_emp
						SET
                            fcincome_amount='{$_REQUEST['fcincome_amount']}',
                            fcdeduction_amount='{$_REQUEST['fcdeduction_amount']}',
                            fcamount='{$_REQUEST['fcamount']}',
                            fnattendance_days='{$_REQUEST['fnattendance_days']}',
                            fnleave_days='{$_REQUEST['fnleave_days']}'
                        WHERE ftemployee_code='{$_REQUEST['ftemployee_code']}' AND
                            ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}'
                        ";
                $strSQL["Insert txpayroll_slip_emp"][]=$ssql;
                $arr1=explode("*",base64_decode($_REQUEST['strgrid1']));
                for($j=0; $j<count($arr1); $j++) {
                    if($arr1[$j]!="") {
                        $arr2=explode("|",$arr1[$j]);
                        $ssql="UPDATE txpayroll_slip_inc
                                SET
                                    fnindex='{$arr2[0]}',fcamount='{$arr2[2]}'
                               WHERE  ftemployee_code='{$_REQUEST['ftemployee_code']}' AND
                                        ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}' AND
                                       ftsalary_code='{$arr2[1]}'";
                         $strSQL["Insert txpayroll_slip_inc"][]=$ssql;
                    }
                }

				$arr1=explode("*",base64_decode($_REQUEST['strgrid2']));
                for($j=0; $j<count($arr1); $j++) {
                    if($arr1[$j]!="") {
                        $arr2=explode("|",$arr1[$j]);
                        $ssql="UPDATE txpayroll_slip_dec
                                SET
                                    fnindex='{$arr2[0]}',fcamount='{$arr2[2]}'
                               WHERE  ftemployee_code='{$_REQUEST['ftemployee_code']}' AND
                                        ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}' AND
                                       ftsalary_code='{$arr2[1]}'";
                       $strSQL["Insert txpayroll_slip_dec"][]=$ssql;
                    }
                }
                $ssql="UPDATE txpayroll_slip_hdr ,(SELECT ftpayroll_slip_no,
                                                SUM(fcincome_amount) AS  fcincome_amount,
                                                SUM(fcdeduction_amount) AS fcdeduction_amount,
                                                SUM(fcamount) AS fcamount
                                                FROM txpayroll_slip_emp
                                                WHERE ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}'
                                                GROUP BY ftpayroll_slip_no
                                                ) txpayroll_slip_emp
                        SET txpayroll_slip_hdr.fcgrand_income_amount=txpayroll_slip_emp.fcincome_amount,
                                txpayroll_slip_hdr.fcgrand_deduction_amount=txpayroll_slip_emp.fcdeduction_amount,
                                        txpayroll_slip_hdr.fcgrand_total=txpayroll_slip_emp.fcamount
                        WHERE txpayroll_slip_hdr.ftpayroll_slip_no=txpayroll_slip_emp.ftpayroll_slip_no AND
                                   txpayroll_slip_hdr.ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}'
                                                ";
				$strSQL["Update txpayroll_slip_hdr"][]=$ssql;
				Query_SqlArr($strSQL);
				$ssql="SELECT fcgrand_income_amount,
                            fcgrand_deduction_amount,
                               fcgrand_total
                        FROM txpayroll_slip_hdr
                        WHERE ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}'  ";
				$rs=mysql_query($ssql);
				$r=mysql_fetch_assoc($rs);
				?>
					document.getElementById('fcgrand_income_amount').value='<?php echo $r['fcgrand_income_amount']; ?>';
					document.getElementById('fcgrand_deduction_amount').value='<?php echo $r['fcgrand_deduction_amount']; ?>';
					document.getElementById('fcgrand_total').value='<?php echo $r['fcgrand_total']; ?>';
				<?php
				die("");
			break;
            case "delete_employee":
                $ssql="DELETE FROM txpayroll_slip_emp
                        WHERE ftemployee_code='{$_REQUEST['ftemployee_code']}' AND
                            ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}'
                        ";
                $strSQL["Delete txpayroll_slip_emp"][]=$ssql;

				$ssql="DELETE FROM txpayroll_slip_inc
                        WHERE ftemployee_code='{$_REQUEST['ftemployee_code']}' AND
                            ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}'
                        ";
                $strSQL["Delete txpayroll_slip_inc"][]=$ssql;

				$ssql="DELETE FROM txpayroll_slip_dec
                        WHERE ftemployee_code='{$_REQUEST['ftemployee_code']}' AND
                            ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}'
                        ";
                $strSQL["Delete txpayroll_slip_dec"][]=$ssql;
                Query_SqlArr($strSQL);
                $ssql=" SELECT fcgrand_income_amount,fcgrand_deduction_amount,fcgrand_total
							FROM txpayroll_slip_hdr
                        WHERE ftpayroll_slip_no='{$_REQUEST['ftpayroll_slip_no']}'  ";
                $rs=mysql_query($ssql);
                $r=mysql_fetch_assoc($rs);
                ?>
					document.getElementById('fcgrand_income_amount').value='<?php echo $r['fcgrand_income_amount']; ?>';
					document.getElementById('fcgrand_deduction_amount').value='<?php echo $r['fcgrand_deduction_amount']; ?>';
					document.getElementById('fcgrand_total').value='<?php echo $r['fcgrand_total']; ?>';
					var index_delete=0;
					var obj=document.getElementById("fcamountD0<?php echo $_REQUEST['index']; ?>").parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
					index_delete=obj.rowIndex;
					document.getElementById("TransactionDetail0").deleteRow(index_delete);
					for (var ix=3; ix <  document.getElementById("TransactionDetail1").rows.length; i++) {
						document.getElementById("TransactionDetail1").deleteRow(ix);
					}
					for ( ix=3; ix <  document.getElementById("TransactionDetail2").rows.length; i++) {
						 document.getElementById("TransactionDetail2").deleteRow(ix);
					}
					RowIndex0();
					reSize();
                <?php
				die("");
            break;
        }
    }
    if(!$_REQUEST['id']) {
		$strAutoNumber1="ajax_do('query2.php?code=2&ftmodule_code=hrd009&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftpayroll_slip_no&no_trans=ftpayroll_slip_no&table_name=txpayroll_slip_hdr');";
		$strAutoNumber0="function ValInclude() {
							if(document.getElementById('chk_include').checked == true) {
								document.getElementById('hd_include').value='1';
							}
							else {
								document.getElementById('hd_include').value='0';
							}
						}
						function ValInclude_tunjangan() {
							if(document.getElementById('chk_include_tunjangan').checked == true) {
								document.getElementById('hd_include_tunjangan').value='1';
							}
							else {
								document.getElementById('hd_include_tunjangan').value='0';
							}
						}
						function OnChangeDate_fdtrans_date() {
							{$strAutoNumber1}
						}
						OnChangeDate_fdtrans_date();
						var i=document.getElementsByName('fnindexD0[]').length;
							document.getElementById(\"TransactionDetail0\").deleteRow(3);
						";
	}
	else {
		$strAutoNumber0="// var i=document.getElementsByName('fnindexD0[]').length;
                                        //document.getElementById(\"TransactionDetail0\").deleteRow(3);
						function ValInclude() {
							if(document.getElementById('chk_include').checked == true) {
								document.getElementById('hd_include').value='1';
							}
							else {
								document.getElementById('hd_include').value='0';
							}
						}
						function ValInclude_tunjangan() {
							if(document.getElementById('chk_include_tunjangan').checked == true) {
								document.getElementById('hd_include_tunjangan').value='1';
							}
							else {
								document.getElementById('hd_include_tunjangan').value='0';
							}
						}
						RowIndex0();";
	}
    $objAxpDB->FormJS($strAutoNumber0);
	$objAxpDB->ViewName("Daftar Slip Gaji Tipe 1");
	$objAxpDB->ViewTable("vHRSlipGaji1");
	$objAxpDB->ViewSQL("SELECT a.fnid, a.ftpayroll_slip_no, a.fdtrans_date,
							ifnull(d.ftdivision_name,'SELURUH') AS ftdivision_name,IFNULL(e.ftdepartment_name,'SELURUH') AS ftdepartment_name, IFNULL(f.ftposition_name,'SELURUH') AS ftposition_name,ftgroup_pengajian_code,
							c.fttrans_status_name AS ftpayroll_type_code,  a.fdstart_date, a.fdend_date,
							a.fdstart_date_overtime, a.fdend_date_overtime,
							a.ftnotes, b.fttrans_status_name AS fnstatus
						FROM txpayroll_slip_hdr a
							LEFT JOIN tstransaction_status b ON b.fntrans_status_code=a.fnstatus AND b.fntrans_group_code = 2
							LEFT JOIN tstransaction_status c ON a.ftpayroll_type_code=c.fntrans_status_code  AND c.fntrans_group_code = 25
							LEFT join tldivision d on a.ftdivision_code=d.ftdivision_code
							LEFT join tldepartment e on a.ftdepartment_code=e.ftdepartment_code
							LEFT join tlposition f on a.ftposition_code=f.ftposition_code
						WHERE a.fnsalary_type={$fnsalary_type} 
                            ORDER by a.ftpayroll_slip_no desc, a.fdtrans_date desc");

	$objAxpDB->ViewCaption("ID, No. Slip Gaji,Tgl. Transaksi,Divisi, Departement, Jabatan, Group Penggajian,
							Type Pengajian, Periode Absensi 1, Periode Absensi 2,
							Periode Lembur 1, Periode Lembur 2,  Catatan, Status");
	$objAxpDB->ViewPeriod(TRUE);
	$objAxpDB->FormName("Slip Gaji Tipe 1");
	$objAxpDB->FormSQL("SELECT ftpayroll_slip_no, fdtrans_date,ftdivision_code, ftdepartment_code, ftposition_code,ftgroup_pengajian_code, fntrainning, 
						ftpayroll_type_code, fdstart_date, fdend_date,fdstart_date_overtime, fdend_date_overtime,fdtunjangan_date,fdjht_date,
						ftnotes, fcgrand_income_amount, fcgrand_deduction_amount,fcgrand_total, fnstatus FROM txpayroll_slip_hdr");
	$objAxpDB->FormCaption("No. Slip Gaji, Tgl. Transaksi,Divisi, Departement, Jabatan, Group Penggajian, Training, Type Gaji, Periode Absensi 1, Periode Absensi 2, Periode Lembur 1, Periode Lembur 2,  Periode Tunjangan, Periode JHT,Catatan, Grand Total Pendapatan, Grand Total Potongan, Grand Total Gaji, Status");
	$objAxpDB->FormPosition("TL, TL,TR, TR,TR,TR, TR,TR, TR,TR,TR,TR,TR,TR, BL, BR, BR, BR, BR");
	$objAxpDB->SetStatus("id,fnstatus");
	if(!$_REQUEST['id']) {
//		$ajax1=" OnClick=\"if(ValDaftarPegawai()==false) { return false; } ajax_do_grid0('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid&ftdivision_code='+ document.getElementById('ftdivision_code').value +'&ftdepartment_code='+ document.getElementById('ftdepartment_code').value +'&ftposition_code='+ document.getElementById('ftposition_code').value +'&ftpayroll_type_code='+ document.getElementById('ftpayroll_type_code').value +'&fdstart_date='+ document.getElementById('fdstart_date').value +'&fdend_date='+ document.getElementById('fdend_date').value+'&fdstart_date_overtime='+ document.getElementById('fdstart_date_overtime').value +'&fdend_date_overtime='+ document.getElementById('fdend_date_overtime').value+'&fdjht_date='+ document.getElementById('fdjht_date').value+'&hd_include='+ document.getElementById('hd_include').value+'&hd_include_tunjangan='+ document.getElementById('hd_include_tunjangan').value+'&fdtunjangan_date='+ document.getElementById('fdtunjangan_date').value+ValStrSlipGajiUrlHdr());\"";
		$ajax1=" OnClick=\"if(ValDaftarPegawai()==false) { return false; } ajax_do_grid0('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid&fntrainning='+ document.getElementById('fntrainning').value +'&ftdivision_code='+ document.getElementById('ftdivision_code').value +'&ftdepartment_code='+ document.getElementById('ftdepartment_code').value +'&ftposition_code='+ document.getElementById('ftposition_code').value+'&ftgroup_pengajian_code='+ document.getElementById('ftgroup_pengajian_code').value+'&ftpayroll_type_code='+ document.getElementById('ftpayroll_type_code').value +'&fdstart_date='+ document.getElementById('fdstart_date').value +'&fdend_date='+ document.getElementById('fdend_date').value+'&fdstart_date_overtime='+ document.getElementById('fdstart_date_overtime').value +'&fdend_date_overtime='+ document.getElementById('fdend_date_overtime').value+'&fdjht_date='+ document.getElementById('fdjht_date').value+'&hd_include='+ document.getElementById('hd_include').value+'&hd_include_tunjangan='+ document.getElementById('hd_include_tunjangan').value+'&fdtunjangan_date='+ document.getElementById('fdtunjangan_date').value+ValStrSlipGajiUrlHdr());\"";
		$button="<input type='button' id='cmd_employee_list' name='cmd_employee_list' value='Daftar Pegawai' {$ajax1}>";
		$check="&nbsp;<input type='hidden' id='hd_include' name='hd_include' value='0'> <input type='checkbox'  id='chk_include' name='chk_include' onclick='ValInclude();'> Plus JHT";
		$check1.="&nbsp;<input type='hidden' id='hd_include_tunjangan' name='hd_include_tunjangan' value='0'> <input type='checkbox'  id='chk_include_tunjangan' name='chk_include_tunjangan' onclick='ValInclude_tunjangan();'> Plus Tunjangan Bulanan";
	}
	else {
		$ssql=" SELECT fnstatus
					FROM txpayroll_slip_hdr
				WHERE fnid='{$_REQUEST['id']}'";
		if(RetRstField($ssql)==0) {
			$ajax1=" OnClick=\"if(ValDaftarPegawai()==false) { return false; } ajax_do_grid0('hrd.php?x=1&form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&fntrainning='+ document.getElementById('fntrainning').value +'&code=grid&ftdivision_code='+ document.getElementById('ftdivision_code').value +'&ftdepartment_code='+ document.getElementById('ftdepartment_code').value +'&ftposition_code='+ document.getElementById('ftposition_code').value+'&ftgroup_pengajian_code='+ document.getElementById('ftgroup_pengajian_code').value+'&ftpayroll_type_code='+ document.getElementById('ftpayroll_type_code').value +'&fdstart_date='+ document.getElementById('fdstart_date').value +'&fdend_date='+ document.getElementById('fdend_date').value+'&fdstart_date_overtime='+ document.getElementById('fdstart_date_overtime').value +'&fdend_date_overtime='+ document.getElementById('fdend_date_overtime').value+'&fdjht_date='+ document.getElementById('fdjht_date').value+'&hd_include='+ document.getElementById('hd_include').value+'&hd_include_tunjangan='+ document.getElementById('hd_include_tunjangan').value+'&fdtunjangan_date='+ document.getElementById('fdtunjangan_date').value+ValStrSlipGajiUrlHdr());\"";
			$button="<input type='button' id='cmd_employee_list' name='cmd_employee_list' value='Daftar Pegawai' {$ajax1}>";
			$check="&nbsp;<input type='hidden' id='hd_include' name='hd_include' value='0'> <input type='checkbox'  id='chk_include' name='chk_include' onclick='ValInclude();'> Plus JHT";
			$check1.="&nbsp;<input type='hidden' id='hd_include_tunjangan' name='hd_include_tunjangan' value='0'> <input type='checkbox'  id='chk_include_tunjangan' name='chk_include_tunjangan' onclick='ValInclude_tunjangan();'> Plus Tunjangan Bulanan";
		}
	}
	$objAxpDB->FormLayout(12,$check1);
	$objAxpDB->FormLayout(13,"{$check}<input type='hidden' id='fnindex_grid1' name='fnindex_grid1'> <input type='hidden' id='fnindex_grid0' name='fnindex_grid0'> {$button}");
    $objAxpDB->GridName(0, "Daftar Pegawai");
    $objAxpDB->GridSQL(0, "select fnindex, ftemployee_code, fnstatus_tunda, fcincome_amount, fcdeduction_amount,fcamount,fnattendance_days,fnalfaizin_days, fnleave_days,fnsick_days from txpayroll_slip_emp ");
    $objAxpDB->GridCaption(0, "No., Pegawai, Waktu Pengajian, Total Pendapatan, Total Potongan, Total, Absensi(hr),Alfa/Izin(hr), Cuti (hr), Sakit/Srt.Dr ");
    $ajax1="&ftpayroll_slip_no='+ document.getElementById('ftpayroll_slip_no').value +'&ftemployee_code='+ document.getElementById('ftemployee_codeD0_N_').value";
    $ajax1="document.getElementById('fnindex_grid0').value='_N_';open('?form=slip_gaji_x&mode=edit&id=0{$ajax1},'mywindow','width=900,height=800,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,screenX=100,screenY=2')";
    $ajax1=" OnClick=\"{$ajax1}\"";
    $objAxpDB->GridLayout(0,1,"
				<table colspacing=0 colpadding=0>
					<tr>
						<td>
							<input type='button' id='cmd_grid_list' name='cmd_grid_list' value='DETAIL' {$ajax1}>
						</td>
						{$simpan}
						{$hapus}
					</tr>
				</table>
				");
	$objAxpDB->GridAllowDelete(0,true);
	$objAxpDB->GridName(1, "Daftar Pendapatan");
	if($_REQUEST['id']) {
		$m=" where 1=0 #";
	}
	$objAxpDB->Lookup("ftemployee_code", "SELECT ftemployee_code, ftemployee_name FROM tlemployee", "ftemployee_code", "ftemployee_name", -1, False);
	$objAxpDB->Lookup("fnstatus", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 2", "fntrans_status_code", "fttrans_status_name", 0, True);
	$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", 2, True);
	$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->Lookup("fnstatus_tunda", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 37", "fntrans_status_code", "fttrans_status_name", 0, True);
	$objAxpDB->Lookup("fntrainning", "SELECT 0 AS A,'NON TRAINING' AS B UNION ALL SELECT 1 AS A,'TRAINING' AS B", "A", "B", 1,true);
	$objAxpDB->GridScroll(0,true,"200");
	if ($objAxpDB->GetStatus("id") == "") {
		$objAxpDB->ButtonShow("baru, cetak_daftar,cetak, export_excel ,  tutup");
	}
	elseif ($objAxpDB->GetStatus("id") == 0) {
		$objAxpDB->ButtonShow("reset, simpan, tutup");
		$objAxpDB->FormLocked("0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,1 1, 1");
		$objAxpDB->GridLocked(0, "1,1,1,1,1,1,1,1,1,1");
        $objAxpDB->GridAllowDelete(0,false);
	}
	elseif ($objAxpDB->GetStatus("fnstatus") == 0) {
		$objAxpDB->ButtonShow("cetak,cetak_slip_crosstab,cetak_slip_lembur,update, final, batal, tutup");
		$objAxpDB->FormLocked("1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1, 1");
		$objAxpDB->GridLocked(0, "1,1,1,1,1,1,1,1,1,1");
        $objAxpDB->GridAllowDelete(0,false);
	} 
	elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
		$objAxpDB->ButtonShow("cetak,cetak_slip_crosstab,cetak_slip_lembur,cetak_slip_lembur_tertunda,update_waktu_pengajian,  batal, tutup");
		$objAxpDB->FormLocked("1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1");
		$objAxpDB->GridLocked(0, "1,1,0,1,1,1,1,1,1");
		$objAxpDB->GridAllowAddNew(0,false);
		$objAxpDB->GridAllowDelete(0,false);
		$objAxpDB->GridAllowAddNew(1,false);
		$objAxpDB->GridAllowDelete(1,false);
		$objAxpDB->GridAllowAddNew(2,false);
		$objAxpDB->GridAllowDelete(2,false);
	} 
	elseif ($objAxpDB->GetStatus("fnstatus") == 9) {
		$objAxpDB->ButtonShow("tutup");
		$objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1,1, 1,1, 1, 1,1");
		$objAxpDB->GridLocked(0, "1, 1, 1, 1,1,1,1,1,1,1");
		$objAxpDB->GridAllowAddNew(0,false);
        $objAxpDB->GridAllowDelete(0,false);
	}
	if(($_REQUEST['fnstatus']=='1')||($_REQUEST['fnstatus']=='9')) {
		
	}
	if($_REQUEST['ajax']) {
		switch($_REQUEST['code']) {
			case "grid":
				if($_REQUEST['ftdivision_code']!="SELURUH") {
					$ftdivision_code=" AND a1.ftdivision_code='{$_REQUEST['ftdivision_code']}'";
					$ftdivision_code_attendance_overtime=" AND b.ftdivision_code='{$_REQUEST['ftdivision_code']}'";
				}
				if($_REQUEST['ftdepartment_code']!="SELURUH") {
					$ftdepartment_code=" AND a1.ftdepartment_code='{$_REQUEST['ftdepartment_code']}'";
					$ftdepartment_code_attendance_overtime=" AND b.ftdepartment_code='{$_REQUEST['ftdepartment_code']}'";
				}
				if($_REQUEST['ftposition_code']!="SELURUH") {
					$ftposition_code=" AND a1.ftposition_code='{$_REQUEST['ftposition_code']}'";
					$ftposition_code_attendance_overtime=" AND b.ftposition_code='{$_REQUEST['ftposition_code']}'";
				}
				if($_REQUEST['ftgroup_pengajian_code']!="SELURUH") {
					$ftgroup_pengajian_code=" AND a1.ftgroup_pengajian_code='{$_REQUEST['ftgroup_pengajian_code']}'";
				}
				if((isset($_REQUEST['fntrainning']))&&($_REQUEST['fntrainning']==1)) {
					$where_fntrainning="  a1.fnstatus=3 AND ";
				}
				else {
					$where_fntrainning="";
				}
                $ftpayroll_type_codex=" WHERE {$where_fntrainning} ifnull(a1.fntype,0)=0 and  a1.fnstatus<>4 AND a1.fnsalary_type={$fnsalary_type} AND  a1.ftpayroll_type_code='{$_REQUEST['ftpayroll_type_code']}' {$ftdivision_code} {$ftdepartment_code} {$ftposition_code} {$ftgroup_pengajian_code}";
                    if($_REQUEST['hd_include']==0) {
						$include_jhtx=" AND c1.ftsalary_category_code<>'B01' ";
                    }
                    if((isset($_REQUEST['fntrainning']))&&($_REQUEST['fntrainning']==1)) {
                        $include_tunjanganx="  AND a1.fnstatus=3  ";
                    }
                    else {
                        $include_tunjanganx="";
                    }
				if($_REQUEST['hd_include_tunjangan']!=0) {
					$include_tunjanganx.=" AND NOT( b1.fnsalary_period=3 AND b1.ftsalary_category_code='A07') ";
					$include_tunjanganx.=" AND NOT( b1.fnsalary_period=3 AND b1.ftsalary_category_code='A06') ";
					$include_tunjanganx.=" AND NOT( b1.fnsalary_period=3 AND b1.ftsalary_category_code='A03') ";
					$include_tunjanganx.=" AND NOT( b1.fnsalary_period=3 AND b1.ftsalary_category_code='A02') ";
				}
				$salary_plus2x=" WHERE  1=1  {$ftdivision_code} {$ftdepartment_code} {$ftposition_code}";
				$attendance_overtime.="{$ftdivision_code_attendance_overtime}{$ftdepartment_code_attendance_overtime}{$ftposition_code_attendance_overtime}";
				$attendance_overtime.=" AND (b.fnsalary_type2=1 or b.fnsalary_type='{$fnsalary_type}') ";
                    
				$ssql_1=ListEmployee($ftpayroll_type_codex,$include_jhtx,$include_tunjanganx,$salary_plus2x);
				$ssql_1_CoatingInjection=ListEmployeeCoatingInjection($ftpayroll_type_codex,$include_jhtx,$include_tunjanganx,$salary_plus2x);
				$ssql_2=ListInc($ftpayroll_type_codex,$include_jhtx,$include_tunjanganx, $salary_plus2x);
				$ssql_2plus=ListIncPlus($ftpayroll_type_codex,$include_jhtx,$include_tunjanganx,$salary_plus2x);
				$ssql_3=ListDec($ftpayroll_type_codex,$include_jhtx,$include_tunjanganx, $salary_plus2x);
				$ssql_3_CoatingInjection=ListDecCoatingInjection($ftpayroll_type_codex,$include_jhtx,$include_tunjanganx, $salary_plus2x);

				ob_start();
				mysql_query("BEGIN");
				
				$ssql=" UPDATE tlemployee_salary_inc,tlsalary 
							SET tlemployee_salary_inc.ftsalary_category_code=tlsalary.ftsalary_category_code
						WHERE tlemployee_salary_inc.ftsalary_code=tlsalary.ftsalary_code";
				$strSQL["Insert txpayroll_slip_hdr"][]=$ssql;
				mysql_query($ssql);
				$ssql=" UPDATE tlemployee_salary_dec,tlsalary
							SET tlemployee_salary_dec.ftsalary_category_code=tlsalary.ftsalary_category_code
                        WHERE tlemployee_salary_dec.ftsalary_code=tlsalary.ftsalary_code";
				$strSQL["Insert txpayroll_slip_hdr"][]=$ssql;
				mysql_query($ssql);
				$ssql=" SELECT ftpayroll_slip_no 
							FROM txpayroll_slip_hdr
						WHERE ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."'
                                                    AND fdstart_date='".CDate($_REQUEST['fdstart_date'])."' AND fdend_date='".CDate($_REQUEST['fdend_date'])."'";

				if(RetRstField($ssql)=="") {
                    $ssql=" INSERT INTO  txpayroll_slip_hdr
							(
								ftpayroll_slip_no,fdtrans_date,fdstart_date,
								fdend_date,ftpayroll_type,ftpayroll_type_code,
								ftnotes,fnstatus,fcgrand_income_amount,
								fcgrand_deduction_amount,fcgrand_total,
								ftcreated_user,fdcreated_date,
								ftmodified_user,fdmodified_date,
								ftdepartment_code,
								ftdivision_code,
								ftposition_code,
								ftgroup_pengajian_code,
								fdstart_date_overtime,
								fdend_date_overtime,
								fdjht_date,
								fnsalary_type,
								fdtunjangan_date,
								fntrainning 
							)
							SELECT
								'".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' AS ftpayroll_slip_no, '".CDate(base64_decode($_REQUEST['fdtrans_datex']))."' AS fdtrans_date, '".CDate(base64_decode($_REQUEST['fdstart_datex']))."' AS fdstart_date,
								'".CDate(base64_decode($_REQUEST['fdend_datex']))."' AS fdend_date,'".base64_decode($_REQUEST['ftpayroll_typex'])."'  AS ftpayroll_type, '".base64_decode($_REQUEST['ftpayroll_type_codex'])."' AS ftpayroll_type_code,
								'".($_REQUEST['ftnotesx'])."' AS ftnotes, '".base64_decode($_REQUEST['fnstatusx'])."' AS fnstatus,'".CCur(base64_decode($_REQUEST['fcgrand_income_amountx']))."'  AS fcgrand_income_amount,
								'".CCur(base64_decode($_REQUEST['fcgrand_deduction_amountx']))."' AS fcgrand_deduction_amount,'".CCur(base64_decode($_REQUEST['fcgrand_totalx']))."' as fcgrand_total,
								'{$_SESSION['username']}' AS ftcreated_user,now() AS  fdcreated_date,
								'{$_SESSION['username']}' AS ftmodified_user,now() as fdmodified_date,
								'{$_REQUEST['ftdepartment_code']}',
								'{$_REQUEST['ftdivision_code']}',
								'{$_REQUEST['ftposition_code']}',
								'{$_REQUEST['ftgroup_pengajian_code']}',
								'".CDate($_REQUEST['fdstart_date_overtime'])."' AS fdstart_date_overtime,
								'".CDate($_REQUEST['fdend_date_overtime'])."'  AS fdend_date_overtime,
								'".CDate($_REQUEST['fdjht_date'])."'  AS fdjht_date,
								{$fnsalary_type} as fnsalary_type,
								'".CDate($_REQUEST['fdtunjangan_date'])."'  AS fdtunjangan_date,
								'{$_REQUEST['fntrainning']}'
								";
					$strSQL["Insert txpayroll_slip_hdr"][]=$ssql;
					mysql_query($ssql);
				}
				else {
					$ssql="DELETE FROM txpayroll_slip_emp WHERE ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' ";
					$strSQL["Insert txpayroll_slip_hdr"][]=$ssql;
					mysql_query($ssql);
					$ssql="DELETE FROM txpayroll_slip_inc WHERE ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' ";
					$strSQL["Insert txpayroll_slip_hdr"][]=$ssql;
					mysql_query($ssql);
					$ssql="DELETE FROM txpayroll_slip_inc_plus WHERE ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' ";
					$strSQL["Insert txpayroll_slip_hdr"][]=$ssql;
					mysql_query($ssql);
					$ssql="DELETE FROM txpayroll_slip_dec WHERE ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' ";
					$strSQL["Insert txpayroll_slip_hdr"][]=$ssql;
					mysql_query($ssql);
				}
				if(($_REQUEST['ftdivision_code']=='INJ') || ($_REQUEST['ftdivision_code']=='CTG')){
					$ssql="INSERT INTO  txpayroll_slip_emp
							(
								fnindex,ftemployee_code,
								fcincome_amount,fcdeduction_amount,fcamount,
								fnattendance_days,fnleave_days,fnsick_days,fnalfaizin_days,
								ftpayroll_slip_no,
								fnstatus_tunda
							)
							SELECT fnindex,ftemployee_code,
								fcincome_amount,fcdeduction_amount,fcamount,
								fnattendance_days,fnleave_days,fnsick_days, fnalfaizin_days,
								'".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' AS ftpayroll_slip_no,
								0 as fnstatus_tunda 
							FROM ($ssql_1_CoatingInjection) XX";
					$strSQL["Insert txpayroll_slip_hdr"][]=$ssql;
					mysql_query($ssql);
				}
				else{
					$ssql="INSERT INTO  txpayroll_slip_emp
							(
								fnindex,ftemployee_code,
								fcincome_amount,fcdeduction_amount,fcamount,
								fnattendance_days,fnleave_days,fnsick_days,fnalfaizin_days,
								ftpayroll_slip_no,
								fnstatus_tunda
							)
							SELECT fnindex,ftemployee_code,
								fcincome_amount,fcdeduction_amount,fcamount,
								fnattendance_days,fnleave_days,fnsick_days, fnalfaizin_days,
								'".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' AS ftpayroll_slip_no,
								0 as fnstatus_tunda 
							FROM ($ssql_1) XX";
					$strSQL["Insert txpayroll_slip_hdr"][]=$ssql;
					mysql_query($ssql);
				}
				
				$ssql="INSERT INTO  txpayroll_slip_inc
						(
							fnindex, ftsalary_code,fcamount,ftemployee_code,ftpayroll_slip_no
						)
						SELECT fnindex, ftsalary_code,fcamount,ftemployee_code,
							'".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' AS ftpayroll_slip_no
						FROM ($ssql_2) XX";

				$strSQL["Insert txpayroll_slip_inc"][]=$ssql;
				mysql_query($ssql);
				
				$ssql="INSERT INTO  txpayroll_slip_inc_plus
						(
							fnindex, ftsalary_code,fcamount,ftemployee_code,ftpayroll_slip_no
						)
						SELECT fnindex, ftsalary_code,fcamount,ftemployee_code,
							'".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' AS ftpayroll_slip_no
						FROM ($ssql_2plus) XX";
                $strSQL["Insert txpayroll_slip_inc_plus"][]=$ssql;
				mysql_query($ssql);
				
				if(($_REQUEST['ftdivision_code']=='INJ') || ($_REQUEST['ftdivision_code']=='CTG')){
					$ssql="INSERT INTO  txpayroll_slip_dec
							(
								fnindex, ftsalary_code,fcamount,ftemployee_code,ftpayroll_slip_no
							)
							SELECT fnindex, ftsalary_code,fcamount,ftemployee_code,
								'".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' AS ftpayroll_slip_no
							FROM ($ssql_3_CoatingInjection) XX";
					$strSQL["Insert txpayroll_slip_dec"][]=$ssql;
					mysql_query($ssql);
				}
				else{
					$ssql="INSERT INTO  txpayroll_slip_dec
							(
								fnindex, ftsalary_code,fcamount,ftemployee_code,ftpayroll_slip_no
							)
							SELECT fnindex, ftsalary_code,fcamount,ftemployee_code,
								'".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' AS ftpayroll_slip_no
							FROM ($ssql_3) XX";
					$strSQL["Insert txpayroll_slip_dec"][]=$ssql;
					mysql_query($ssql);
				}
				
				$ssql="UPDATE txpayroll_slip_emp a,
						(
							SELECT c.fnid,
								(
									SELECT IFNULL(COUNT(d.fnid),0)+1
										FROM txpayroll_slip_emp d
									WHERE d.fnid<c.fnid 
									AND d.ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."'
								) AS m
							FROM  txpayroll_slip_emp c
							WHERE c.ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."'
						) b
							SET a.fnindex=b.m
						WHERE a.ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."'  
						AND a.fnid=b.fnid";
				$strSQL["Update txpayroll_slip_emp"][]=$ssql;
				mysql_query($ssql);
				$ssql=" SELECT ftpayroll_slip_no,ftemployee_code
                            FROM txpayroll_slip_emp
						WHERE  ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."'";
				$rs=mysql_query($ssql);
				while($r=mysql_fetch_assoc($rs)) {
					$ssql=" UPDATE txpayroll_slip_inc a,
								(
									SELECT c.fnid,
										(
											SELECT IFNULL(COUNT(d.fnid),0)+1
												FROM txpayroll_slip_inc d
											WHERE d.fnid<c.fnid 
											AND d.ftpayroll_slip_no='{$r['ftpayroll_slip_no']}' 
											AND d.ftemployee_code='{$r['ftemployee_code']}'
										) AS m
									FROM  txpayroll_slip_inc c
									WHERE c.ftpayroll_slip_no='{$r['ftpayroll_slip_no']}'  
									AND c.ftemployee_code='{$r['ftemployee_code']}'
								) b
							SET a.fnindex=b.m
							WHERE a.ftpayroll_slip_no='{$r['ftpayroll_slip_no']}'  
							AND a.ftemployee_code='{$r['ftemployee_code']}' 
							AND a.fnid=b.fnid";
					$strSQL["Update index txpayroll_slip_inc"][]=$ssql;
					mysql_query($ssql);
					$ssql=" UPDATE txpayroll_slip_dec a,
								(
									SELECT c.fnid,
										(
											SELECT IFNULL(COUNT(d.fnid),0)+1
												FROM txpayroll_slip_dec d
											WHERE d.fnid<c.fnid 
											AND d.ftpayroll_slip_no='{$r['ftpayroll_slip_no']}' 
											AND d.ftemployee_code='{$r['ftemployee_code']}'
										) AS m
									FROM  txpayroll_slip_dec c
									WHERE c.ftpayroll_slip_no='{$r['ftpayroll_slip_no']}'  
									AND c.ftemployee_code='{$r['ftemployee_code']}'
								) b
							SET a.fnindex=b.m
							WHERE a.ftpayroll_slip_no='{$r['ftpayroll_slip_no']}'  
							AND a.ftemployee_code='{$r['ftemployee_code']}' 
							AND a.fnid=b.fnid";
					$strSQL["Update index txpayroll_slip_dec"][]=$ssql;
					mysql_query($ssql);
				}
				$ssql=" UPDATE 
							txpayroll_slip_hdr ,
								(
									SELECT ftpayroll_slip_no,SUM(fcincome_amount) AS fcincome_amount,
										SUM(fcdeduction_amount) AS fcdeduction_amount,
										SUM(fcamount) AS fcamount
									FROM txpayroll_slip_emp
									WHERE ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."'
									GROUP BY ftpayroll_slip_no
								) txpayroll_slip_emp
                        SET txpayroll_slip_hdr.fcgrand_income_amount=txpayroll_slip_emp.fcincome_amount,
							txpayroll_slip_hdr.fcgrand_deduction_amount=txpayroll_slip_emp.fcdeduction_amount,
							txpayroll_slip_hdr.fcgrand_total=txpayroll_slip_emp.fcamount
                        WHERE txpayroll_slip_hdr.ftpayroll_slip_no=txpayroll_slip_emp.ftpayroll_slip_no AND
							txpayroll_slip_hdr.ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."'
						";
				mysql_query($ssql);
                $where=" WHERE ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' ";
				$ssql=" UPDATE  txpayroll_slip_emp a,
							(
								SELECT ftpayroll_slip_no,ftemployee_code,SUM(fcamount) AS fcamount
									FROM txpayroll_slip_inc
								{$where}
								GROUP BY ftpayroll_slip_no,ftemployee_code
							) b
						SET a.fcincome_amount=b.fcamount
						WHERE a.ftpayroll_slip_no=b.ftpayroll_slip_no and
							a.ftemployee_code=b.ftemployee_code and
							a.ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' ";

				$strSQL['txpayroll_slip_hdr'][]=$ssql;
				mysql_query($ssql);
				$ssql=" UPDATE  txpayroll_slip_emp a,
							(
								SELECT ftpayroll_slip_no,ftemployee_code,SUM(fcamount) AS fcamount
									FROM txpayroll_slip_dec
								{$where}
								GROUP BY ftpayroll_slip_no,ftemployee_code
							) c
						SET a.fcdeduction_amount=c.fcamount
						WHERE a.ftpayroll_slip_no=c.ftpayroll_slip_no and
							a.ftemployee_code=c.ftemployee_code  and
							a.ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."'";
				$strSQL['txpayroll_slip_hdr'][]=$ssql;
				mysql_query($ssql);
				$ssql=" UPDATE  txpayroll_slip_emp
							SET fcamount=fcincome_amount-fcdeduction_amount
						WHERE ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' ";
				$strSQL['txpayroll_slip_hdr'][]=$ssql;
				mysql_query($ssql);
				$ssql=" UPDATE txpayroll_slip_hdr ,
								(
									SELECT ftpayroll_slip_no,
										SUM(fcincome_amount) AS  fcincome_amount,
										SUM(fcdeduction_amount) AS fcdeduction_amount,
										SUM(fcamount) AS fcamount
									FROM txpayroll_slip_emp
									WHERE ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."'
									GROUP BY ftpayroll_slip_no
								) txpayroll_slip_emp
                        SET txpayroll_slip_hdr.fcgrand_income_amount=txpayroll_slip_emp.fcincome_amount,
							txpayroll_slip_hdr.fcgrand_deduction_amount=txpayroll_slip_emp.fcdeduction_amount,
							txpayroll_slip_hdr.fcgrand_total=txpayroll_slip_emp.fcamount
                        WHERE txpayroll_slip_hdr.ftpayroll_slip_no=txpayroll_slip_emp.ftpayroll_slip_no AND
							txpayroll_slip_hdr.ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."'
						";
				$strSQL['txpayroll_slip_hdr'][]=$ssql;
				mysql_query($ssql);
				mysql_query("COMMIT");
				$id=RetRstField("SELECT fnid FROM txpayroll_slip_hdr WHERE ftpayroll_slip_no='".base64_decode($_REQUEST['ftpayroll_slip_nox'])."' ");
				?>
					window.location= 'hrd.php?form=slip_gaji&mode=edit&id=<?php echo $id; ?>';
				<?php
			break;
			case "grid0":
				$ssql1x="select sum(fcamount) as fcamount from txpayroll_slip_inc where ftemployee_code='".($_REQUEST['ftemployee_code'])."' AND  ftpayroll_slip_no='".($_REQUEST['ftpayroll_slip_no'])."'";
                $ssql2x="select sum(fcamount) as fcamount from txpayroll_slip_dec where ftemployee_code='".($_REQUEST['ftemployee_code'])."' AND  ftpayroll_slip_no='".($_REQUEST['ftpayroll_slip_no'])."'";
                $fcincome_amountD0=RetRstField($ssql1x);
                $fcdeduction_amountD0=RetRstField($ssql2x);
                $fcamountD0=$fcincome_amountD0-$fcdeduction_amountD0;
				?>
                   document.getElementById('fcincome_amountD0<?php echo $_REQUEST['index'];?>').value='<?php echo $fcincome_amountD0;?>';
                   document.getElementById('fcdeduction_amountD0<?php echo $_REQUEST['index'];?>').value='<?php echo $fcdeduction_amountD0;?>';
                   document.getElementById('fcamountD0<?php echo $_REQUEST['index'];?>').value='<?php echo $fcamountD0;?>';
                   ElementCurrencyOnBlur(document.getElementById('fcincome_amountD0<?php echo $_REQUEST['index'];?>'));
                   ElementCurrencyOnBlur(document.getElementById('fcdeduction_amountD0<?php echo $_REQUEST['index'];?>'));
                   ElementCurrencyOnBlur(document.getElementById('fcamountD0<?php echo $_REQUEST['index'];?>'));
				<?
			break;
			case "grid1":
				ob_start();
				$ssql_2="select fnindex, ftsalary_code,fcamount from txpayroll_slip_inc where ftemployee_code='".($_REQUEST['ftemployee_code'])."' AND  ftpayroll_slip_no='".($_REQUEST['ftpayroll_slip_no'])."'";
				$objAxpDB->GridSQL(1,$ssql_2."#");
                $objAxpDB->Process();
                $objAxpDB->setGrid2(1);
                $html = ob_get_contents();
                ob_end_clean();
                ?>
                    div = document.getElementById('txtHint1');
                    var m='<?php echo js_esc($html); ?>';
                    m= m.replace(/^\s*|\s*$/g,"");
                    div.innerHTML =m;
				<?php
				if(!RetRstField($ssql_2)) {
					?>
					   document.getElementById("TransactionDetail1").deleteRow(3);
					<?php
				}
				?>
					RowIndex1();
					reSize();
				<?php
			break;
			case "grid2":
				ob_start();
				$ssql_3="select fnindex, ftsalary_code,fcamount from txpayroll_slip_dec where ftemployee_code='".($_REQUEST['ftemployee_code'])."' AND  ftpayroll_slip_no='".($_REQUEST['ftpayroll_slip_no'])."'";
				$objAxpDB->GridSQL(2,$ssql_3."#");
				$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;
                    <?php
                    if(!RetRstField($ssql_3)) {
						?>
							document.getElementById("TransactionDetail2").deleteRow(3);
						<?
                    }
                    ?>
                    RowIndex2();
                    reSize();
				<?php
			break;
		}
		die("");
		exit;
    }
	$objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();
?>