package com.steering.pss.ydm.Report;

import CoreFS.SA06.CoreReturnObject;

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class FrmLeaderRpt extends DBCommon{
	/***
	 * 期初重量
	 * 
	 * @param yearMoth
	 * @return
	 */
	public CoreReturnObject getOriginalLast(String yearMoth) {
		return this.getDataBySqlID("FrmLeaderRpt.getOriginalLast",
				new Object[] { yearMoth });
	}
	
	/***
	 * 本月入库量
	 * @param yearMoth
	 * @return
	 */
	public CoreReturnObject getThisIn(String yearMoth)
	{
		return this.getDataBySqlID("FrmLeaderRpt.getThisIn", new Object[]{yearMoth});
	}
	
	/***
	 * 本月出库量
	 * @param yearMoth
	 * @return
	 */
	public CoreReturnObject getThisOut(String yearMoth)
	{
		return this.getDataBySqlID("FrmLeaderRpt.getThisOut", new Object[]{yearMoth});
	}
	
	/***
	 * 本月调差量
	 * @param yearMoth
	 * @return
	 */
	public CoreReturnObject getAdjustWgt(String yearMoth)
	{
		return this.getDataBySqlID("FrmLeaderRpt.getAdjustWgt", new Object[]{yearMoth});
	}
	
	/***
	 * 实物库存
	 * @param yearMoth
	 * @return
	 */
	public CoreReturnObject getThisSwMat(String yearMoth)throws Exception
	{
		Date now = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String bathYearMoth = df.format(now);
		DateFormat sdf=new SimpleDateFormat("yyyyMM");
		String bathYearMothNext = df.format(getNextDate(sdf.parse(yearMoth)));
		if(yearMoth.equals(bathYearMoth))
		{
		    return this.getDataBySqlID("FrmLeaderRpt.getThisSwMat");
		}else
		{
			return this.getDataBySqlID("FrmLeaderRpt.getThisSwMat1", new Object[]{bathYearMothNext});
		}
	}
	/***
	 * 获取当前年月的下一个月
	 * @param date
	 * @return
	 */
	private static Date getNextDate(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MONTH, 1);
        return cal.getTime();
    }
	/***
	 * 销售账面库存
	 * @param yearMoth
	 * @return
	 */
	public CoreReturnObject getThisXsMat(String yearMoth)
	{
		return this.getDataBySqlID("FrmLeaderRpt.getThisXsMat");
	}
	
	/***
	 * 财务账面库存(末次)
	 * @param yearMoth
	 * @return
	 */
	public CoreReturnObject getThisCwMat(String yearMoth)
	{
		return this.getDataBySqlID("FrmLeaderRpt.getThisCwMat");
	}
	
	/***
	 * 财务账面库存(首次)
	 * @param yearMoth
	 * @return
	 */
	public CoreReturnObject getThisCwMat1(String yearMoth)
	{
		return this.getDataBySqlID("FrmLeaderRpt.getThisCwMat1");
	}
	
	public CoreReturnObject doQueryData(String yearMoth)
	{
		return this.getDataBySqlID("FrmLeaderRpt.doQueryData", new Object[]{yearMoth});
	}
}
