<%@page contentType="text/plain; charset=UTF-8"%>
<%@page import="com.csc.library.utilities.GetDataMailmerge,com.csc.library.utilities.UProfile"%>
<%@page import="org.apache.commons.lang.StringUtils,com.csc.library.utilities.CscCalendar"%>
<jsp:useBean id="checkmodule" class="com.csc.library.system.Task" scope="page"/><%
	final StringBuilder buffer = new StringBuilder();
	UProfile uprofile = null;
	try {
		session.invalidate();	
		checkmodule.setChannel( request, response );
		checkmodule.checkProfile();
		uprofile = checkmodule.getUProfile();
		if( uprofile == null ) {
			throw new NullPointerException("User Profile must not be null.");
		}

		final GetDataMailmerge tag = new GetDataMailmerge(uprofile);
		tag.setDbXml("CODIM002");
		tag.setSimField("memployee","fullname,companyname,empages_short");	// พนักงาน
		tag.setSimField("v1memployee","fullname,positionname");	 // ผู้ลงนาม
		tag.setSimField("mempl_promisework","duration_of_employ");

		String filter = String.format(" EXISTS ( "
				+"	select * from ( "
				+"		select employeeid,max(startdate) AS startdate "
				+"		from mempl_promisework "
				+"		group by employeeid "
				+"	) p$ where mempl_promisework.employeeid=p$.employeeid "
				+"		and mempl_promisework.startdate=p$.startdate "
				+") and (startdate between '%s' and '%s' ) and isprint='0' "
				
				, new CscCalendar().decDate(90).getYYYYMMDD()	// today - 90day
				, new CscCalendar().incDate(90).getYYYYMMDD()		// today + 90day
			);

		String userFilter = StringUtils.trimToEmpty(request.getParameter("__filter"));

		if( StringUtils.isNotBlank( userFilter )) {
			filter = filter +" and "+userFilter;
		}
		
		tag.setFilter( filter );

		// set child filter
		tag.setChildFilter( "mempl_addr", "addr_current='1' ");

		tag.read();

		buffer.append("<STATUS>\"TRUE\"</STATUS>\n");
		buffer.append(tag.getAllTag());
		out.print(buffer.toString());

	} catch (Exception e) {
		out.print("<STATUS>FALSE</STATUS>\n");
		throw e;
	}
%>