<%@page contentType="text/html; charset=utf-8"%>
<%@page import="org.acts.common.*" %>
<%@page import="org.acts.common.html.*" %>
<%@page import="org.acts.account.*" %>
<%@page import="org.acts.member.*" %>
<%@include file="../include/check_login.jsp" %>

<%@include file="../include/header.jsp" %>
<%msbean.setCur_menu_node(MenuItem.MEMBER__RECEIPT);%>
<link rel="stylesheet" type="text/css" href="../script/ext/resources/css/ext-all.css">
<script type="text/javascript" src="../script/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../script/ext/ext-all.js"></script>
<%@include file="../include/body.jsp" %>
<%
RecordList subTypes=Member.getActiveReceiptSubTypes();
SelectMenu subTypeSM=new SelectMenu("rc_sub_type",subTypes,"name","code",msbean.getSData("rc_sub_type"));
subTypeSM.setNilItem(Lang.set("--全部--"),"");

SelectMenu typeSM=new SelectMenu("rc_type",SelectMenu.buildItemsByMap(Receipt.TYPE_MAP),"name","code",msbean.getSData("rc_type"));
typeSM.setNilItem(Lang.set("--全部--"),"");

ExtJs extjs=new ExtJs();
ExtDateTextBox start_dateDTB=new ExtDateTextBox("rc_start_date",msbean.getSData("rc_start_date"),"日期",extjs);
ExtDateTextBox end_dateDTB=new ExtDateTextBox("rc_end_date",msbean.getSData("rc_end_date"),"至",extjs);

HtmlTable t=new HtmlTable(new int[]{130,150,160,160,140,120,100});
t.addTitleCell(0,0,msbean.getCur_menu_node().getName());
t.addLCell(3,0,Lang.set("項目 ")+subTypeSM.toHtml());
t.addLCell(4,0,start_dateDTB);
t.addLCell(5,0,end_dateDTB);
t.addRCell(6,0,new Button("重新整理","javascript:opSubmit('member.MemberModuleAction.receipt.read')"));
t.toHtml(out);

int row=0;
createTable(msbean,Receipt.TYPE__OFFERING).toHtml(out);
(new EmptySpace(10,35)).toHtml(out);
createTable(msbean,Receipt.TYPE__CHARGE).toHtml(out);

extjs.toHtml(out);
%>

<%!
private HtmlTable createTable(MemberSessionBean msbean,String receipt_type){
	HtmlTable t=new HtmlTable(new int[]{100,120,220,100,310,100});
	String type_name=Tools.getStatusName(Receipt.TYPE_MAP,receipt_type);
	
	int row=0;
	t.addHeaderCell(0,row,"日期");
	t.addHeaderCell(1,row,"收據編號");
	t.addHeaderCell(2,row,type_name+"項目");
	t.addHeaderCell(3,row,"指定期");
	t.addHeaderCell(4,row,"摘要");
	t.addHeaderCell(5,row,"金額");

	RecordList r=Member.getReceipts(
		msbean.getMember_seq()
		,receipt_type
		,msbean.getSData("rc_sub_type")
		,msbean.getTData("rc_start_date")
		,msbean.getTData("rc_end_date")
		);

	double ttl=0;	
	for(int i=0;i<r.size();i++){
		r.setCurrentRow(i);
		row++;
		t.addLCell(0,row,TimeUtil.getStringByDate(r.getT("date")));
		t.addLCell(1,row,r.getS("id"));
		t.addLCell(2,row,r.getS("sub_type"));
		t.addLCell(3,row,TimeUtil.getStringByDate(r.getT("target_date")));
		t.addLCell(4,row,r.getS("note"));
		t.addRCell(5,row,Arith.formatAmount(r.getD("amount")));
		ttl=Arith.add(ttl,r.getD("amount"));
	}
	row++;
	t.addRCell(4,row,type_name+"合共");
	t.addRCell(5,row,Arith.formatAmount(ttl));
	return t;
}
%>

<%@include file="../include/footer.jsp" %>