
<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[$i] != "") { $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  wr_datetime, sum(wr_1) as sum_wr1, sum(wr_2) as sum_wr2 from g4_write_finance where left(wr_datetime,4) = '$here' group by left(wr_datetime,7)    ";
		$result5 = sql_query($query5);
		while($row  = sql_fetch_array($result5)) {
			$ex_total[$i] = $row[sum_wr1];
			$in_total[$i] = $row[sum_wr2];
			$date[$i] = substr($row[wr_datetime], 0, 7);
			//echo $in_total[$i]."<br>";
			$i++;
		}
?>
<?
//비용 
$i=0;
		$query6 = "select  wr_subject, sum(wr_1) as sum_wr1, sum(wr_2) as sum_wr2  from g4_write_finance where left(wr_datetime,4) = '$here' group by  wr_subject    ";
		$result6 = sql_query($query6);
		while($row  = sql_fetch_array($result6)) {
			$pa_total[$i] = $row[sum_wr1];
			$pain_total[$i] = $row[sum_wr2];
			$pa_name[$i] = $row[wr_subject];
			
			$i++;

		}
?>

	<?
		//$count_part = count($pa_total);

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

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

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

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

	for($i=1; $i < 13; $i++) {

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


	//echo count($date);
	for($j=0; $j < count($date); $j++) {
			$check[$j] = substr($date[$j], 5, 2);
			$m =0;
		for($i=0; $i < 12; $i++) {
			
	
	//	$check = $check -1;
		$m++;
		if($i < 9) $mo = "0".$m;
		else $mo = $m;
		//echo  $check[$j]."//".$mo."//".$in_total[$j]."<br>";
		if($check[$j] == $mo) { $expen[$i] = $ex_total[$j]; $incom[$i] = $in_total[$j]; }
	//	else {  $expen[$i] = 0; $income[$i] = 0;  }
//		$expen[$check] = $ex_total[$i];
//		$incom[$check] = $in_total[$i]; 
		$expen_year = $expen[$i] + $expen_year;
		$incom_year = $incom[$i] + $incom_year;
//echo $i."//".$expen[$i]."//". $income[$i]."<br>";
	}

		}
?>

<tr><td bgcolor=#CCFFFF  align=center>&nbsp;지출&nbsp;</td>
<?

	for($i=0; $i < 12; $i++) {
	
	
		echo "<td  class='c2' width=7% align=right> ".number_format($expen[$i])."&nbsp;</td>";
			}
?>
<td class='c2'  width=7%>    <?=number_format($expen_year)?>           </td>
</tr><tr><td bgcolor=#FFFF00 align=center>&nbsp;수입&nbsp;</td>
<?

	for($i=0; $i < 12; $i++) {
	
		//echo $income[7]."<br>";
//if($incom[$i] == "") $incom[$i] =0;
		echo "<td  class='c4' width=7% align=right> ".number_format($incom[$i])."&nbsp;</td>";
			}
?><td width=7% class='c4'>    <?=number_format($incom_year)?>           </td>
</tr>
<tr ><td bgcolor=#CB9696  align=center>&nbsp;잔고&nbsp;</td>
<?

	for($i=0; $i < 12; $i++) {
		$balance[$i] = $balance[$i-1] + $incom[$i] + $expen[$i];
	echo "<td  class='c3' width=7% align=right> ".number_format($balance[$i])."&nbsp;</td>";
			}
?><td width=7% class='c3'>  <?    $balance_year = $incom_year +   $expen_year ; echo  number_format($balance_year);  ?></td>
</tr>
</table>



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

	<font size="5" color="red"><?=$here?> </font>
 </td>
</tr>
<tr><td>
		<? for($i=0; $i < 12; $i++) {
		$expen[$i] =str_replace("-", "", $expen[$i]);

			}

		

			?>

<script type="text/javascript">

	$(function() {

		

		var data = [{
			label: "Income",
			data: [[1, <?=$incom[0]?>], [2, <?=$incom[1]?>], [3, <?=$incom[2]?>], [4, <?=$incom[3]?>], [5, <?=$incom[4]?>], [6, <?=$incom[5]?>], [7,<?=$incom[6]?>], [8, <?=$incom[7]?>], [9, <?=$incom[8]?>], [10, <?=$incom[9]?>], [11, <?=$incom[10]?>], [12, <?=$incom[11]?>] ]

		// A null signifies separate line segments

			}, {
			
			label: "Expense",
			data: [ [1, <?=$expen[0]?>], [2, <?=$expen[1]?>], [3, <?=$expen[2]?>], [4, <?=$expen[3]?>], [5, <?=$expen[4]?>], [6, <?=$expen[5]?>], [7,<?=$expen[6]?>], [8, <?=$expen[7]?>], [9, <?=$expen[8]?>], [10, <?=$expen[9]?>], [11, <?=$expen[10]?>], [12, <?=$expen[11]?>] ]

			}, {
					label: "balance",
			data: [ [1, <?=$balance[0]?>], [2, <?=$balance[1]?>], [3, <?=$balance[2]?>], [4, <?=$balance[3]?>], [5, <?=$balance[4]?>], [6, <?=$balance[5]?>], [7,<?=$balance[6]?>], [8, <?=$balance[7]?>], [9, <?=$balance[8]?>], [10, <?=$balance[9]?>], [11, <?=$balance[10]?>], [12, <?=$balance[11]?>] ]
		}];



		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: 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 = $("#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=150><font size="5" color="red">비율</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>
