<%@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"),"From&nbsp;",extjs);
ExtDateTextBox end_dateDTB=new ExtDateTextBox("rc_end_date",msbean.getSData("rc_end_date"),"To&nbsp;",extjs);

HtmlTable t=new HtmlTable(new int[]{130,110,160,270,170,120,100});
t.addTitleCell(0,0,msbean.getCur_menu_node().getName());
t.addLCell(3,0,Lang.set("Sub Type ")+subTypeSM.toHtml());
t.addLCell(4,0,start_dateDTB);
t.addLCell(5,0,end_dateDTB);
t.addRCell(6,0,new Button("Refresh","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,"Date");
	t.addHeaderCell(1,row,"ID");
	t.addHeaderCell(2,row,type_name);
	t.addHeaderCell(3,row,"Target");
	t.addHeaderCell(4,row,"Remark");
	t.addHeaderCell(5,row,"Amount");

	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+" Total Amount");
	t.addRCell(5,row,Arith.formatAmount(ttl));
	return t;
}
%>

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