package com.kingdee.eas.custom.gggl.app;

import org.apache.log4j.Logger;
import com.kingdee.bos.*;



import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.framework.report.util.RptParams;
import com.kingdee.eas.framework.report.util.RptRowSet;
import com.kingdee.eas.framework.report.util.RptTableColumn;
import com.kingdee.eas.framework.report.util.RptTableHeader;
import com.kingdee.util.StringUtils;

public class GgRPaymentReportFacadeControllerBean extends AbstractGgRPaymentReportFacadeControllerBean
{
    private static Logger logger =
        Logger.getLogger("com.kingdee.eas.custom.gggl.app.GgRPaymentReportFacadeControllerBean");
    
      
    /**
     * 创建表
     */ 
    protected RptParams _createTempTable(Context ctx, RptParams params)
    		throws BOSException, EASBizException {
    	RptTableHeader header = new RptTableHeader();
    	RptTableColumn col = null;
    	initColumn(header, col, "Number", 130, false);
    	initColumn(header, col, "CompnayName", 220, false);
    	initColumn(header, col, "BizDate", 140, false);
    	initColumn(header, col, "Customer", 240, false);
    	initColumn(header, col, "SkAmount", 120, false);    //广告合同：收款计划分录：应收金额（实收）	
    	initColumn(header, col, "RecAmount", 100, false);  //广告合同：收款计划分录：收款金额
    	initColumn(header, col, "ActualAmt", 100, false);   //付款单：分录实付金额      付款金额   	
    	String[] fixedHead1 =  new String[]{
    			"广告合同制作费的收付情况表","广告合同制作费的收付情况表","广告合同制作费的收付情况表","广告合同制作费的收付情况表","广告合同制作费的收付情况表","广告合同制作费的收付情况表","广告合同制作费的收付情况表"
    	};
    	String[] fixedHead2 = new String[] {
    			"合同号","公司","签约日期","客户","应收金额","收款金额","付款金额"
    	};
    	header.setLabels(new Object[][]{ 
    			fixedHead1,fixedHead2
		},true);
    	params.setObject("header", header);
     	return params;
    }
    /**
     * 列
     * @param header
     * @param col  
     * @param name  列名
     * @param width  列宽
     * @param isHide  是否隐藏
     */
	private void initColumn(RptTableHeader header,RptTableColumn col,String name,int width,boolean isHide) {
		col= new RptTableColumn(name);
		col.setWidth(width);
		col.setHided(isHide);
		header.addColumn(col);
	}
    
	@Override
	protected RptParams _query(Context ctx, RptParams params, int from, int len)
			throws BOSException, EASBizException {
		RptRowSet rowSet = executeQuery(getSql(ctx,params), null, ctx);
    	params.setObject("rowSet", rowSet);
    	return params;
	}
	/**
	 * 查询 ：根据签约日期的开始和截止
	 */
	private String getSql(Context ctx,RptParams params) {
		String startdate = params.getString("startDate");
		String enddate = params.getString("endDate");
		StringBuilder sql = new StringBuilder("");
		sql.append(" /*dialect*/SELECT  FNumber,CompnayName,to_char(FBizDate,'yyyy-MM-dd'),Customer,SkAmount,RecAmount,ActualAmt FROM VIEW_Gghtzzf ");
		sql.append(" where to_char(FBIZDATE,'YYYY-MM-DD') >= '"+startdate+"' and to_char(FBIZDATE,'YYYY-MM-DD') <= '"+enddate+"'");
		return sql.toString();
	}
	
}