
<tr>
<?
	$i=0;	
	$query5 = "select   sum(wr_1) as total,wr_subject from g4_write_delivery  group by wr_subject  ";
		$result5 = sql_query($query5);
		while($row  = sql_fetch_array($result5)) {
		
			$ship[$i] = $row[total];
			$item[$i] = $row[wr_subject];
		//	echo $ship[$i]."//".$item[$i]."<br>";
			$i++;
		}
		/// shipping data
			
?>		
<?
		
	$query5 = "select   wr_3 from ".$table."    ";
		$result5 = sql_query($query5);
		while($row  = sql_fetch_array($result5)) {
		
			$year[$i] = substr($row[wr_3], 6, 4);
	
			$i++;
		}
		/// 년도 뽑아오기
			if($i != 0) { $year = array_unique($year); 
	foreach($year as $v) {
		if( date("Y") == $v) 		echo "<td align=center> <b><a href=".$g4[path]."/bbs/board.php?bo_table=static&wr_id=".$view[wr_id]."&want_year=$v>".$v."</b> </td>";
		else echo "<td align=center> ".$v." </td>";
	
		}}
?>


</tr>
</table>



    </td>
</tr>
<tr>
    <td height=30 style="color:#888;">
<?
//현재 재고
$i=0;

	if($want_year =="") $want_year = date("Y");

	$query4 = "select  *  from g4_write_project  where wr_9 ='close'  ";  
		$result4 = sql_query($query4);
		//$aaa  = mysql_num_rows($result4);
		while($row  = sql_fetch_array($result4)) {

			
			$output[$i] = $row[wr_10];
//			$shipping[$i] = $row[sunwr1];
			$target[$i] = $row[wr_1];
			$project[$i] = $row[wr_subject];
			$customer[$i] = $row[wr_4];
			$start[$i] = $row[wr_2];
			$end[$i] = $row[wr_3];
			$real[$i] = $row[wr_link1];
			$delay[$i] = $row[wr_link1];

			
		//echo $output[$i] = $project[$i] = $row[wr_subject].$row[wr_10].$target[$i]."<br>";
		$all_close = $i;
			$i++;
		}
		//echo $aaa;
		$query5 = "select  *  from g4_write_project  where wr_9 ='pending'  ";  
		$result5 = sql_query($query5);
		$pending  = mysql_num_rows($result5);

				$query6 = "select  *  from g4_write_project  where wr_9 ='open'  ";  
		$result6 = sql_query($query6);
		$opened  = mysql_num_rows($result6);
		//echo $pending;
?>



<table class="t_ex2">
<tr><td colspan=10 bgcolor=white align=center> <b>종료된 프로젝트</b></td></tr>
	<tr><th  class='c1'  >프로젝트</th>
	<th  class='c1'  >생산(%)</th>
	<th  class='c1'  >배송(%)</th>
	<th  class='c1'  >주문량</th>
	<th  class='c1'  >고객</th>
	<th  class='c1'  >시작일</th>
	<th  class='c1'  >계획일</th>
	<th  class='c1'  >실제종료</th>

	<th  class='c1'  >지연일</th>

		<?
$over =0;
$intime = 0;
	for($i=0; $i < count($project); $i++) {
	

		$d1 = strtotime($start[$i]);
		$d2 = strtotime($real[$i]);
		$d3 = strtotime($end[$i]);
		//echo $end."//".$d3;
		$seconds_diff = $d2 - $d1;
		$remaining_diff = $d3 - $d1;
		//$delay = date_diff($start, $end);
		if($d2 > $d3) $over++; 
		for($j=0; $j < count($item); $j++) {
			if($project[$i] == $item[$j]) $shipping[$i] = $ship[$j];
		}		
        @$b = round($output[$i]/$target[$i]*100);
        @$c = round($shipping[$i]/$target[$i]*100);
		echo "<tr><td class='c1' width=7% align=center> ".$project[$i]." </td>";
		echo "<td  class='c2' width=7% align=right> ".number_format($output[$i])."(".$b.")&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".number_format($shipping[$i])."(".$c.")&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".number_format($target[$i])."&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".$customer[$i]."&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".$start[$i]."&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".$end[$i]."&nbsp;</td>";
		
		echo "<td  class='c2' width=7% align=right> ".$real[$i]."&nbsp;</td>";
		echo "<td class='c2' >";
		if($end[$i] != "" && $d2 > $d3) 
		echo "<font color=red><b>".number_format(floor($seconds_diff/3600/24))."<b></font> days";
		else { echo "0"; $intime++; }
		echo "</td>";
		
		echo "</tr>";
	}



?>





</table>



    </td>
</tr>
<tr><td>

<table class="t_ex2">
<tr><td colspan=10 bgcolor=white align=center> <b>프로젝트 현황</b></td></tr>
	<tr>
	<th  class='c1'  >총계</th>
	<th  class='c1'  >진행중</th>
	<th  class='c1'  >종료</th>
	<th  class='c1'  >시간 내 종료</th>
	<th  class='c1'  >지연</th>
	<th  class='c1'  >중지</th>


		<?

$all_project = count($project) + $pending;
$total = $all_project + $opened;

		echo "<tr>";
		echo "<td  class='c3' width=7% align=right> ".number_format($total)."&nbsp;</td>";
		echo "<td  class='c4' width=7% align=right> ".number_format($opened)."&nbsp;</td>";
		echo "<td  class='c4' width=7% align=right> ".number_format($all_project)."&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".number_format($intime)."&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".number_format($over)."&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".number_format($pending)."&nbsp;</td>";

		
		
		echo "</tr>";
	

?>


</table>



    </td>
</tr>
<tr><td align=center> &nbsp;</td>
</tr>


<tr><td align=center>
	<b>비율</b> 	

			
<script type="text/javascript">

	$(function() {
	

	var data = [
			{ label: "Pending",  data: <?=$pending?>},
			{ label: "In time",  data: <?=$intime?>},
			{ label: "Delayed days",  data: <?=$over?>}
		];

			var options = {
        series: {
            pie: {
                show: true,
                radius: 1,
                label: {
                    show: true,
                    radius: 3/4,
                    formatter: function(label, series){
                        return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
                    },
                    background: { opacity: 0.5 }
                }
            }
        },
        legend: {
            show: false
        }
};
		
			

		

		
		var placeholder = $("#placeholder2");

		$.plot(placeholder, data, options);


		// Add the Flot version string to the footer

		$("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
	});

		// A custom label formatter used by several of the plots

	function labelFormatter(label, series) {
		return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>" + label + "<br/>" + "5" + "%</div>";
	}
	</script>
		
	<div class="bar1">
			<div id="placeholder2" class="bar-holder"></div>
			 
</td>
</tr>