<%
	$: << File::dirname( ENV['PATH_TRANSLATED'] )
	load "#{File::dirname( ENV['PATH_TRANSLATED'] )}/waste.conf"
	require 'waste.rb'
	waste = Waste::new
	print waste.header
%><?xml version="1.0" encoding="EUC-JP"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
<html xml:lang="ja-JP">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" />
	<meta name="Author" content="TADA Tadashi" />
	<meta name="KeyWords" content="<%= @keywords %>" />
	<link rev="MADE" href="mailto:sho@spc.gr.jp" />
	<link rel="INDEX" href="./" />
	<title><%= @title_battle %></title>
	<meta http-equiv="content-style-type" content="text/css" />
	<link rel="stylesheet" href="waste.css" type="text/css" />
</head>
<body>
<h1><%= @title_battle %></h1>
<form method="get" action="battle.rhtml">
<p align="right">
<% if waste.user? %>[<a href="person.rhtml?person=<%= CGI::escape( waste.user ) %>;date=<%=waste.year%>">自分の記録を参照する</a>]<% end %>
[<a href="waste.rhtml">新しい<%= @sanzai %>を記録する</a>]
[<select name="date">
<% waste.each_year do |year| %>
	<option value="<%=year%>" <%=year == waste.year ? 'selected' : ''%>><%=year%>年</option>
<% end %>
</select>
<input type="submit" value="の<%= @sanzai %>を見る" />]
</p>
</form>

<hr />

<div align="right"><table><tr valign="top">
	<!-- Yearly total -->
	<td>
	<table class="total">
	<caption class="total"><%= waste.year %>年</caption>
	<%
		yt = 0
		waste.each_total do |name,total|
			yt += total
	%>
	<tr><td><a href="person.rhtml?person=<%= CGI::escape( name ) %>;date=<%=waste.year%>"><%= CGI::escapeHTML( name ) %></a></td><td align="right"><%= total.to_disp_str %><%= @currency %></td></tr>
	<%
		end
	%>
	<tr><th>Total</th><th><%= yt.to_disp_str %><%= @currency %></th></tr>
	</table>
	</td>

	<!-- Monthly total -->
	<%
		waste.each_month( 3 ) do |month|
	%>
	<td>
	<table class="monthlytotal">
	<caption class="total"><%= month %>月</caption>
	<%
			mt = 0
			waste.each_total( month ) do |name,total|
				mt += total
	%>
	<tr><td><a href="person.rhtml?person=<%= CGI::escape( name ) %>;date=<%=waste.year%>"><%= CGI::escapeHTML( name ) %></a></td><td align="right"><%= total.to_disp_str %><%= @currency %></td></tr>
	<%
			end
	%>
	<tr><th>Total</th><th><%= mt.to_disp_str %><%= @currency %></th></tr>
	</table>
	</td>
	<%
		end
	%>
</tr></table>
</div>
<hr />
<%
	waste.each_diary( nil, 30 ) do |diary|
%>
<h2>
<%= diary.date %> 
<a class="h2" href="person.rhtml?person=<%= CGI::escape( diary.name ) %>;date=<%=waste.year%>#<%= diary.date.sub( /^\d{4}\//, '').sub( /\//, '' ) %>"><%= CGI::escapeHTML( diary.name ) %></a>
<% if waste.user == diary.name then %><a class="h2" href="waste.rhtml?edit=<%= diary.date %>">[edit]</a><% end %>
</h2>
<p><%= diary.note.make_link %></p>
<table class="diary">
<%
		diary.each_item do |item|
%>
<tr>
	<td class="diary" width="40%"><%= CGI::escapeHTML( item.name ) %></td>
	<td class="diary" align="right" nowrap width="10%"><%= item.price.to_disp_str %><%= @currency %></td>
	<td class="diary"><%= item.note.make_link %></td>
</tr>
<%
		end
%>
<tr><th>Total</th><th nowrap align="right"><%= diary.total.to_disp_str %><%= @currency %></th><td></td></tr>
</table>
<%
	end
%>
<hr />
<p class="footer"><a href="http://www.spc.gr.jp/waste/">散財自慢システム</a> <%= waste.version %> by ただただし</p>
</body>
</html>

