<?
include_once("./_common.php");
if($excel == "y") {
 $title = "Report";
 header( "Content-type: application/vnd.ms-excel" );  
 header( "Content-Disposition: attachment; filename=".date("dmYmsh").".xls");  
// $title 변수명으로 저장됩니다. 원하는 이름으로 바꾸세요
 header( "Content-Description: PHP4 Generated Data" );
}
?>
<style type="text/css">
<!--
body {
font: small Verdana, Geneva, Arial, Helvetica, sans-serif;
color: #666666;
background-color: #ffffff;
border: 1px solid #999999;
}
td {font-size: 8pt;}
th {font-size: 8pt;}
-->
</style>
<script language=javascript>
  function win_print() {
              self.print();
  }
</script> 
<?
$query4 = "select * from g4_write_payroll  ";
$result4 = sql_query($query4);
while($row  = sql_fetch_array($result4)) {
	
//	$in[$i] = $row[wr_1]; //in
	$use_item[$i] = str_replace("use_", "", $row[wr_3]); //out
	$model[$i] = $row[wr_2]; //model
	$rule[$i] = $row[wr_subject]; //parts
//	$content[$i] = $row[wr_subject]; //parts
//echo $use_item[$i];
	$i++;
}

function evaluate($str)
{

$pt1 = "/x/i";
$str = preg_replace($pt1, "*", $str);

$pt2 = "/([a-z])+/i";
$str = preg_replace($pt2, "\$$0", $str);

$pt3 = "/([0-9])+%/";
$str = preg_replace($pt3, "($0/100)", $str);

$pt4 = "/%/";
$str = preg_replace($pt4, "", $str);

$e = "\$comm = $str;";
eval($e);
//echo $e . "<br>";
return $comm; 


	}
?>
<body onload="javascript:win_print()" oncontextmenu="return false" onselectstart="return false" ondragstart="return false"> 
<table cellpadding="5" cellspacing="0" border="1" align="center" style="border-collapse:collapse; border:1px gray solid;">
<col width="30" />

    <col  />
    <col width="5%" />
    <col width="5%" />
    <col width="5%" />
    <col width="5%" />

    <col width="5%" />
    <col width="5%" />
    <col width="5%" />
    <col width="5%" />
    <col width="5%" />
    <col width="5%" />
    <col width="5%" />
    <col width="5%" />
    <col width="5%" />
    <col width="5%" />
<col width="5%" />
    <col width="100" />
	<tr>
        <th colspan=18  align=center>
	<table >
	<tr>
		<td  align=center><a href="print.php"> Print </a>
</td><td width=200  align=center><a href="print.php?excel=y">Export to excel</a></td>
	</tr>
	</table>
	</td>
	</tr>
	<tr bgcolor=#CCFFCC>
        <th><img src="./img/list_no.gif" border='0'></th>

        <th>Name </th>
		        <th>Number</th>
        <th>Department </th>
        <th>Position</th>
        <th>Basic</th>
        <th>Housing</th>
        <th>Medical</th>
        <th>Pension</th>
        <th>Absent</th>
        <th>100%<br>attend</th>
        <th>Food</th>
        <th >Overtime</th>
        <th>Holiday</th>
        <th>Tax</th>
        <th>Bonus</th>
        <th>Etc</th>
		<th><b><font size="2" color="red">Salary</font></b></th> 
    </tr>
<tr>
	<td>
<?
$i=1;
$query5 = "select * from g4_write_payroll  ";
$result5 = sql_query($query5);
while($row  = sql_fetch_array($result5)) {
	?>
<?
				$wr_4 = $row[wr_4];
				$query3 = "select * from g4_write_payrule where wr_subject = '$wr_4' ";
				$result3 = sql_query($query3);
				while($row1  = sql_fetch_array($result3)) {
	
					$type = $row1[wr_1]; //model

				}
				//항목 계산식 가져오기

 //echo $list[$i][wr_4]; 
		$temp ="";	
		for($j=0; $j < count($rule) ; $j++) {
			$use_item[$j] = substr($use_item[$j], 0 ,-1);
			if($row[wr_4] == $rule[$j]) $item = explode(",", $use_item[$j]);
			//echo $use_item[$j]."<br>";
		}
			$m=0;
			$query6 = "select * from g4_write_payitem where wr_subject ='$type'; ";
			$result6 = sql_query($query6);
			while($row2  = sql_fetch_array($result6)) {
				
				for($j=0; $j < count($item) ; $j++) {
				//	$it[$j] = ${"item".$j};
					
					if($item[$j] != 10) {
					$itrow[j] = "wr_".$item[$j];
					$it[$j] = array($item[$j], $row2[$itrow[j]]);
					}
					if($item[$j] == 11) $it[$j] = array($item[$j], $row2[wr_link1]);
			//var_dump($item[10]);
					//echo $row[$itrow[j]];
				}
					
//					echo 

			}
			$item_sep =  explode(",", $row[wr_content]);
//var_dump($it);
			?>
<tr>
	<td align=center><?=$i?></td>
	<td><?=$row[wr_subject]?></td>
	<td  align=right><?=$row[wr_1]?></td>
	<td ><?=$row[wr_2]?></td>
	<td ><?=$row[wr_3]?></td>
	<td  align=right><?=$row[wr_5]?></td>
	<td  align=right><?=$item_sep[0]?></td>
	<td  align=right><?=$item_sep[1]?></td>
	<td  align=right><?=$item_sep[2]?></td>
	<td  align=right><?=$row[wr_6]?>/hours</td>
	<td  align=right><? if($row[wr_6] !=0) echo "No"; else echo "Yes";?></td>
	<td  align=right><?=$item_sep[3]?></td>
	<td  align=right><?=$row[wr_8]?>/hours</td>
	<td  align=right><?=$row[wr_9]?>/hours</td>
	<td  align=right><?=$item_sep[4]?></td>
	<td  align=right><?=$item_sep[5]?></td>
	<td  align=right><?=$item_sep[6]?></td>
	<td  align=right><?=$item_sep[7]?></td>

</tr>

	<?
	$i++;
}
?></td>
	
</tr>
</table>

