
<tr>
	
<?
		
		$query5 = "select   wr_datetime from ".$table."    ";
		$result5 = sql_query($query5);
		while($row  = sql_fetch_array($result5)) {
		
			$year[$i] = substr($row[wr_datetime], 0, 4);
	
			$i++;
		}
		/// 년도 뽑아오기
			if($year[0] != "") { $year = array_unique($year); 
		if($want_month == "") $t=date("m");
	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&want_month=$t>".$v."</b> </td>";
		else echo "<td align=center> ".$v." </td>";

		}}
?>


</tr>
</table>



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


	$query4 = "select  wr_4, wr_3  from g4_write_setup     ";
		$result4 = sql_query($query4);
		while($row  = sql_fetch_array($result4)) {

			$part_a[$i] = $row[wr_4];
			$current[$i] = $row[wr_3];
		
			$i++;
		}
?>

<?
//현재 재고
$i=0;


	$query4 = "select  wr_datetime  from $table     ";
		$result4 = sql_query($query4);
		while($row  = sql_fetch_array($result4)) {

			$date_first[$i] = substr($row[wr_datetime], 5,2);		
			//$current[$i] = $row[wr_3];
			//echo $date_first[$i];
		
			$i++;
		}
?>
<?
	if($want_year =="")  $want_year = date("Y"); 
		
		
			if($want_month == "") { $want_month=date("m"); $here =$want_year."-".$want_month; }
			else $here =$want_year."-".$want_month;
			

		$end_day = date("t", mktime(0, 0, 0, substr($here, 0,2), 1, substr($here, 3,4)));
		//echo $end_day;
?>
<?

//월별 고장 내역

$temp ="";
$i=0;
$k=0;
		$query6 = "select  wr_4, wr_3,wr_datetime, count(*)  from (select wr_datetime,wr_4, wr_3 from $table  where left(wr_datetime,7) = '$here' order by wr_datetime desc) as whatever  group by  wr_4, left(wr_datetime,10)";
		$result6 = sql_query($query6);
		while($row  = sql_fetch_array($result6)) {
			//$total[$i] = $row['count(*)'];
			$stock[$i] = $row[wr_3];		
			$part[$i] = $row[wr_4];			
			$date[$i] = substr($row[wr_datetime], 8,2);			
			
			if(trim($temp) != trim($part[$i]))
			{
				
				$all .= "##".$part[$i]."#/".$date[$i]."//".$stock[$i]."#/";
				//if($k == 1) $all[$i] .= "&&"; 
				//$k =0;
			}
			else				{ 	$all .=  $date[$i]."//".$stock[$i]."#/"; $k = 1;}



				$temp = $part[$i];

			
			$i++;
		}
	//	echo $all."<br>";


?>
<?
	
	$bypart = explode("##", $all); 
		
	
	array_splice($bypart, 0, 1);
	
	for($i=0; $i < count($bypart); $i++) { //항목별로 분류
		$bypart[$i] = substr($bypart[$i], 0, -2);
	
	//echo $bypart[$i]."<br>";

		$bypart_sep[$i] = explode("#/", $bypart[$i]); 
		
		
	
		$m=0;
		for($j=1; $j < count($bypart_sep[$i]); $j++) {  // 항목별로 분류

					//echo $bypart_sep[$i][$j]."<br>";
		
			$field = explode("//", $bypart_sep[$i][$j]);
		

			$fileld[$i][0] .= $field[0].",";
			$fileld[$i][1] .= $field[1].",";;
			$m++;
		}

		//echo $fileld[$i][0]."<br>";
		//echo $fileld[$i][1]."<br>";
			//${"fileld".$j} .= "(".$field[0].",".$field[1]."),"; 
		$field_sep1[$i] = explode(",",$fileld[$i][0]);
		$field_sep2[$i] = explode(",",$fileld[$i][1]);
		//$bypart = "";
	//var_dump($field_sep[$i])."<br>";

		
					//echo count($fileld[$l])."<br>";

					$m =0;$d =0;$a =0;
					for($j=0; $j < $end_day; $j++) {   // 없는 날짜 0로 채우기
						$m++;

						if($j < 9) $day = "0".$m;
						else $day = $m;
						 //$a = 0 
						for($k=0; $k < count($field_sep1[$i]); $k++) {  // 항목별로 분류
						
							if(trim($day) == trim($field_sep1[$i][$k])) { $a = $field_sep2[$i][$k]; $e = $i; $d = $a; }
							//$a[$i] .= "[".$m.", ".$field_sep2[$i][$k]."],";
							else if($e = $i)  $a = $d;
							//echo $i."-".$day."#".$a."<br>";
							
						}
						//echo $want_month;
								
						if($a == 0) {
							for($k=0; $k < count($part_a); $k++) { 
//echo $want_month;
								if($part_a[$k] == $bypart_sep[$i][0] && $date_first[0] < $want_month ) $a = $current[$k];
							}
						}

						$b[$i] .= "[".$m.", ".$a."],";
					}
						$b[$i] = substr($b[$i], 0, -1);
						
						$b[$i] = "{ label: \"".$bypart_sep[$i][0]."\", data: [".$b[$i]."]},";
						$c .= $b[$i]; 
						
	}
	$c = substr($c, 0, -1);
						
					//	echo $c."<br>";
		
?>


<table class="t_ex2">
	<tr><th  class='c1'  >&nbsp;품목&nbsp;</th>
		<?

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

		echo "<th class='c1' width=7% align=center> ".$part_a[$i]." </th>";
	}
?>


<tr ><td   class='c1'>&nbsp;현재&nbsp;</td>
<?
	for($i=0; $i <count($part_a); $i++) {
	
		
if($current[$i] == "") $current[$i] =0;
		echo "<td  class='c4' width=7% align=right> ".number_format($current[$i])."&nbsp;</td>";
			}
?>
</tr>
</table>



    </td>
</tr>
<tr ><td height=40 align=center valign=bottom>

	<font size="5" color="red"><?=$here?> </font>
 </td>
</tr>
<tr ><td height=30 align=center valign=bottom>

<? for($i=1; $i < 13; $i++) {
		if(strlen($i) < 2) $q = "0".$i;
		else $q = $i;
		$want_month = $q;
		echo "<a href='".$g4[path]."/bbs/board.php?bo_table=static&wr_id=".$view[wr_id]."&want_year=".$want_year."&want_month=".$want_month."'>".$i."</a>&nbsp;&nbsp;&nbsp;";
	}
?> 

 </td>
</tr>

<tr><td>
		

<script type="text/javascript">

	$(function() {

		

		var data = [

		<?=$c?>

		// A null signifies separate line segments

	];


		
		// 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>
		<div class="bar1">
			<div id="placeholder1" class="bar-holder"></div>
			 </td>
</tr>
			