
<tr>
<?
	if($want_year =="")  $here = date("Y"); else $here = $want_year;
//평균 단가
$i=0;


	$query4 = "select avg(wr_3) as priceavg, max(wr_3)  as pricemax, min(wr_3)  as pricemin, wr_subject from $table  where left(wr_datetime, 4) = '$here'   group by wr_subject " ;
		$result4 = sql_query($query4);
		while($row  = sql_fetch_array($result4)) {
			$avg[$i] = $row[priceavg]; //구입처
			$max[$i] = $row[pricemax]; //제조사
			$min[$i] = $row[pricemin]; //물품명
			$goods[$i] = $row[wr_subject];
	//	echo $avg[$i];
			$i++;
		}
?>
	
<?
		
		$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($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;">


<?
		if($want_year =="")  $here = date("Y"); else $here = $want_year;

// 입출금 내역
$i=0;


		$query5 = "select    sum(wr_2) as sum_wr2, wr_subject,wr_datetime from $table where left(wr_datetime,4) = '$here' group by wr_subject, left(wr_datetime,7)    ";
		$result5 = sql_query($query5);
		while($row  = sql_fetch_array($result5)) {
			$ex_total[$i] = $row[sum_wr2];   //수량
			//$in_total[$i] = $row[sum_wr3];   // 금액, 파이를 위해
			$date[$i] = substr($row[wr_datetime], 5,2);
			$goods[$i] = $row[wr_subject];
			//echo $date[$i]."<br>";
			$b[$i] = "{ label: \"".$goods[$i]."\",";
			$m =0;$k =0;
		for($j=1; $j < 13; $j++) {
//$m++;
		if($j < 10) $m = "0".$j;
		else $m=$j;
		//echo $date[$i]."<br>";

		if($date[$i] == $m) $k = $ex_total[$i];
		else $k =0;
		//echo $date[$i]."<br>";

		$c[$i] .= "[".$j.",".$k."],";
		}
		
		$d = $n[$i].$c;
		$data .= "{ label: \"".$goods[$i]."\", data: [".substr($c[$i], 0, -1)."]},";
		
//		echo $data."<br>";


			$i++;
		}
		
		$data = substr($data,0,-1);
	
?>
<?
		

// 입출금 내역
$i=0;


		$query6 = "select    sum(wr_3) as sum_wr3, wr_subject from $table where left(wr_datetime,4) = '$here' group by wr_subject, left(wr_datetime,4)    ";
		$result6 = sql_query($query6);
		while($row  = sql_fetch_array($result6)) {
			//$ex_total[$i] = $row[sum_wr2];   //수량
			$in_total[$i] = $row[sum_wr3];   // 금액, 파이를 위해
			$goods_m[$i] = $row[wr_subject];
			$i++;
		
		}
?>

	<?
		

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

		$data1 .= "	{ label: \"".$goods_m[$i]."\",  data: ".$in_total[$i]."},";
		}

		$data1 = substr($data1, 0, -1);

			?>
<table class="t_ex2">
	<tr><th bgcolor=#E2F2D3 width=50>&nbsp;상품&nbsp;</th>
		<?

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

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


<tr><td  bgcolor=#CCFFFF align=center>&nbsp;평균단가&nbsp;</td>
<?

	for($i=0; $i < count($goods); $i++) {
	
			echo "<td   class='c2' width=7% align=right> ".number_format($avg[$i])."&nbsp;</td>";

			}
?>

</tr><tr><td  bgcolor=#FFFF00 align=center>&nbsp;최고단가&nbsp;</td>
<?

	for($i=0; $i < count($goods); $i++) {
	
		
echo "<th class='c4' width=7% align=right> <font size=2 color=black>".number_format($max[$i])."</font> </th>";
	}
?>
</tr>
<tr ><td bgcolor=#CB9696  align=center>&nbsp;최저단가&nbsp;</td>
<?
for($i=0; $i < count($goods); $i++) {

	echo "<td  class='c3' width=7% align=right> ".number_format($min[$i])."&nbsp;</td>";
			}
?>
</tr>
</table>



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

	<font size="5" color="red"><?=$here?> </font>
 </td>
</tr>
<tr><td>
		

<script type="text/javascript">

	$(function() {

		

		var data = [	<?=$data?>
			];



		var data1 = [
			<?=$data1?>
		];
		// 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 option = {
		  series: {
					    pie: {
							    show: true,
							     radius: 1,
					     label: {
						        show: true,
						        radius: 2/3,
						        formatter: labelFormatter,
							    threshold: 0.1
							  }
						 }
				  },
			 legend: {
		     show: false
			  }
		};

		var placeholder = $("#placeholder1");

		$.plot(placeholder, data, options);

		
		var placeholder = $("#placeholder2");

	$.plot(placeholder, data1, option);


		// 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="bar">
			<div id="placeholder1" class="bar-holder"></div>
			 </td>
</tr>
			<tr ><td height=50 align=center>

	<font size="5" color="red"><table>
	<tr>
		<td width=450 align=center><font size="5" color="red" colspan=3>품목 비율: <?=$here?></font></td>
		
		<td> 
		</td>
		
		<td> 
		</td>
	</tr>
	</table> </font>
 </td>
</tr>
<tr><td>
</div>
<div class="bar1">
<div id="placeholder2" class="bar-holder"></div></div>

			<!-----////////////////////// 2-->

    </td>
</tr>
