
<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 g4_write_project    ";
		$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 ='open'  ";  
		$result4 = sql_query($query4);
		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>";
			$i++;
		}
?>




<table class="t_ex2">
<tr><td colspan=10 bgcolor=white align=center height=50> <b>Opened Project</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>

	<th  class='c1'  >Delayed</th>

		<?

	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);
		for($j=0; $j < count($item); $j++) {
			if($project[$i] == $item[$j]) $shipping[$j] = $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' >";
		if($end[$i] != "") 
		echo number_format(floor($remaining_diff/3600/24))." days";
		else echo "0";
		echo "</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";
		echo "</td>";
		
		echo "</tr>";
	}

?>
</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 ='pending'  ";  
		$result4 = sql_query($query4);
		while($row  = sql_fetch_array($result4)) {

			
			$poutput[$i] = $row[wr_10];
//			$shipping[$i] = $row[sunwr1];
			$ptarget[$i] = $row[wr_1];
			$pproject[$i] = $row[wr_subject];
			$pcustomer[$i] = $row[wr_4];
			$pstart[$i] = $row[wr_2];
			$pend[$i] = $row[wr_3];
			$preal[$i] = $row[wr_link1];
			$pdelay[$i] = $row[wr_link1];

			
		
		//echo $output[$i] = $project[$i] = $row[wr_subject].$row[wr_10].$target[$i]."<br>";
			$i++;
		}
?>



<table class="t_ex2">
<tr><td colspan=10 bgcolor=white align=center height=50> <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>
	

		<?

	for($i=0; $i < count($pproject); $i++) {
	

		$d1 = strtotime($pstart[$i]);
		$d2 = strtotime($preal[$i]);
		$d3 = strtotime($pend[$i]);
		//echo $end."//".$d3;
		$seconds_diff = $d2 - $d1;
		$remaining_diff = $d3 - $d1;
		//$delay = date_diff($start, $end);

		for($j=0; $j < count($item); $j++) {
			//echo $pproject[$i]."//".$item[$j]."//".$ship[$j];
			if(trim($pproject[$i]) == trim($item[$j])) { $pshipping[$i] = $ship[$j];	echo "aa"; }
			
		}
        @$b = round($poutput[$i]/$ptarget[$i]*100);
        @$c = round($pshipping[$i]/$ptarget[$i]*100);
		echo "<tr><td class='c2' width=7% align=center> ".$pproject[$i]." </td>";
		echo "<td  class='c2' width=7% align=right> ".number_format($poutput[$i])."(".$b.")&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".number_format($pshipping[$i])."(".$c.")&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".number_format($ptarget[$i])."&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".$pcustomer[$i]."&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".$pstart[$i]."&nbsp;</td>";
		echo "<td  class='c2' width=7% align=right> ".$pend[$i]."&nbsp;</td>";
		
		
		
		echo "</tr>";
	}

?>
</tr>

</table>



    </td>
</tr>

<tr><td>
		

<script type="text/javascript">

	$(function() {

		
	var data = [

		{ label: "notebook", data: [[1, 0],[2, 0],[3, 0],[4, 0],[5, 0],[6, 0],[7, 0],[8, 0],[9, 0],[10, 0],[11, 0],[12, 0],[13, 0],[14, 0],[15, 0],[16, 0],[17, 0],[18, 0],[19, 0],[20, 0],[21, 0],[22, 1],[23, 1],[24, 0],[25, 0],[26, 0],[27, 0],[28, 0],[29, 0],[30, 0]]},
			
		{ label: "printer", data: [[1, 0],[2, 0],[3, 0],[4, 0],[5, 0],[6, 0],[7, 0],[8, 0],[9, 0],[10, 0],[11, 0],[12, 0],[13, 0],[14, 0],[15, 0],[16, 0],[17, 0],[18, 0],[19, 0],[20, 0],[21, 0],[22, 0],[23, 0],[24, 0],[25, 0],[26, 1],[27, 0],[28, 0],[29, 0],[30, 0]]},
			
		{ label: "Sewing machine", data: [[1, 0],[2, 0],[3, 0],[4, 0],[5, 0],[6, 0],[7, 0],[8, 0],[9, 0],[10, 0],[11, 0],[12, 0],[13, 0],[14, 0],[15, 0],[16, 0],[17, 0],[18, 0],[19, 0],[20, 5],[21, 0],[22, 0],[23, 1],[24, 0],[25, 0],[26, 0],[27, 0],[28, 0],[29, 0],[30, 0]]}

		// A null signifies separate line segments

	];
			var options = {
			series: {
				lines: {
					show: true
				},
				points: {
					show: true
				}
			},
			legend: {
				noColumns: 2
			},
			xaxis: {
				tickDecimals: 0
			},
			yaxis: {
				min: 0
			},
			selection: {
				mode: "x"
			}
		};
		
		

		var placeholder = $("#placeholder1");

		$.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/>" + Math.round(series.percent) + "%</div>";
	}
	</script>
		
			 </td>
</tr>
			