package core.stlmes.server.sale.dao;

import java.sql.SQLException;
import java.util.List;

import CoreFS.SA06.CoreReturnObject;
import core.stlmes.server.sale.dbhelp.DbTrans;
import core.stlmes.server.sale.po.*;

public class SlmBalanceMnySubtDao extends BaseService
{
	private List<SlmBalanceMnySubtBean> query(String sqlCondition)
			throws SQLException
	{
		List<SlmBalanceMnySubtBean> list = null;
		String sqlStr = "select * from SLM_BALANCE_MNYSUBT where 1 = 1 ";
		sqlStr = sqlStr + sqlCondition;
		java.sql.ResultSet set = super.executeForResult(sqlStr);
		list = SlmBalanceMnySubtBean.convertResultSetToBeanList(set);
		set.close();
		return list;
	}

	public SlmBalanceMnySubtBean getSlmBalanceMnySubtBySubSeq(String sub_seq)
			throws SQLException
	{
		List<SlmBalanceMnySubtBean> list = null;
		String sqlCondition = super.GetSqlConditionByStringValue("SUB_SEQ",
				sub_seq);
		list = query(sqlCondition);
		if (list == null || list.size() == 0) return null;
		return list.get(0);
	}

	public CoreReturnObject insert(SlmBalanceMnySubtBean bean)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject cro = new CoreReturnObject();
		java.lang.StringBuilder sb = new StringBuilder();
		sb.append("insert into  SLM_BALANCE_MNYSUBT( ");
		sb.append("SUB_SEQ, ");
		sb.append("BUYERCODE, ");
		sb.append("BUYERNAME, ");
		sb.append("FORECORPCODE, ");
		sb.append("FORECORPNAME, ");
		sb.append("MONEY, ");
		sb.append("MONEY_TYPE, ");
		sb.append("MONEY_TYPE_DESC, ");
		sb.append("STATUS_CD, ");
		sb.append("INVOICENO, ");
		sb.append("CREATE_NAME, ");
		sb.append("CREATE_DEPT, ");
		sb.append("CREATE_TIME, ");
		sb.append("AFFRIM_NAME, ");
		sb.append("AFFRIM_TIME, ");
		sb.append("REMARK  ");
		sb.append("  ) values ( ");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ,");
		sb.append("? ");
		sb.append(" ) ");

		Object[] param = new Object[]
		{ bean.getSub_seq(), bean.getBuyercode(), bean.getBuyername(),
				bean.getForecorpcode(), bean.getForecorpname(),
				bean.getMoney(), bean.getMoney_type(),
				bean.getMoney_type_desc(), bean.getStatus_cd(),
				bean.getInvoiceno(), bean.getCreate_name(),
				bean.getCreate_dept(), bean.getCreate_time(),
				bean.getAffrim_name(), bean.getAffrim_time(), bean.getRemark() };
		String sqlStr = super.getPreparedSQL(sb.toString(), param);
		cro = super.ExcuteNonQueryIgnoreTrans(sqlStr);
		return cro;

	}

	public CoreReturnObject delete(String sub_seq)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject cro = new CoreReturnObject();
		String sqlStr = " delete from SLM_BALANCE_MNYSUBT   where 1 = 1 and  SUB_SEQ = ? ";
		Object[] param = new Object[]
		{ sub_seq };
		sqlStr = super.getPreparedSQL(sqlStr, param);
		cro = super.ExcuteNonQueryIgnoreTrans(sqlStr);
		return cro;

	}

	public CoreReturnObject update(SlmBalanceMnySubtBean bean)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject cro = new CoreReturnObject();
		String sqlStr = " update SLM_BALANCE_MNYSUBT set" + " BUYERCODE = ? ,"
				+ " BUYERNAME = ? , " + " FORECORPCODE = ?,"
				+ " FORECORPNAME = ?," + " MONEY = ? ," + " MONEY_TYPE = ?,"
				+ " MONEY_TYPE_DESC = ? ,"
				+ " REMARK = ?  where 1 = 1 and  SUB_SEQ = ? ";
		Object[] param = new Object[]
		{ bean.getBuyercode(), bean.getBuyername(), bean.getForecorpcode(),
				bean.getForecorpname(), bean.getMoney(), bean.getMoney_type(),
				bean.getMoney_type_desc(), bean.getRemark(), bean.getSub_seq() };
		sqlStr = super.getPreparedSQL(sqlStr, param);

		cro = super.ExcuteNonQueryIgnoreTrans(sqlStr);
		return cro;

	}

	public CoreReturnObject affrim(String sub_seq, String affrimperson)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject cro = new CoreReturnObject();
		String sqlStr = " update SLM_BALANCE_MNYSUBT set STATUS_CD = '1' ,AFFRIM_NAME = ?,AFFRIM_TIME = sysdate "
				+ "  where 1 = 1 and  SUB_SEQ = ? ";
		Object[] param = new Object[]
		{ affrimperson, sub_seq };
		sqlStr = super.getPreparedSQL(sqlStr, param);
		cro = super.ExcuteNonQueryIgnoreTrans(sqlStr);
		return cro;

	}

	public CoreReturnObject unaffrim(String sub_seq, String affrimperson)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject cro = new CoreReturnObject();
		String sqlStr = " update SLM_BALANCE_MNYSUBT set STATUS_CD = '0' ,AFFRIM_NAME = '',AFFRIM_TIME = null "
				+ "  where 1 = 1 and  SUB_SEQ = ? ";
		Object[] param = new Object[]
		{ sub_seq };
		sqlStr = super.getPreparedSQL(sqlStr, param);
		cro = super.ExcuteNonQueryIgnoreTrans(sqlStr);
		return cro;

	}

	public CoreReturnObject updateInvoiceNo(String sub_seq, String invoiceNo)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject cro = new CoreReturnObject();
		String sqlStr = " update SLM_BALANCE_MNYSUBT set INVOICENO_DATE = SYSDATE, INVOICENO = ?,STATUS_CD = '2'  "
				+ "  where 1 = 1 and  SUB_SEQ = ? ";
		Object[] param = new Object[]
		{ invoiceNo, sub_seq };
		sqlStr = super.getPreparedSQL(sqlStr, param);
		cro = super.ExcuteNonQueryIgnoreTrans(sqlStr);
		return cro;

	}

	public CoreReturnObject rollbackInvoiceNo(String invoiceNo)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject cro = new CoreReturnObject();
		String sqlStr = " update SLM_BALANCE_MNYSUBT set INVOICENO = '' ,STATUS_CD = '1' "
				+ "  where 1 = 1 and  INVOICENO = ? ";
		Object[] param = new Object[]
		{ invoiceNo };
		sqlStr = super.getPreparedSQL(sqlStr, param);
		cro = super.ExcuteNonQueryIgnoreTrans(sqlStr);
		return cro;

	}
	
	public CoreReturnObject deleteGlInfo(String invoiceNo)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject cro = new CoreReturnObject();
		String sqlStr = " delete SLM_GL_ORDER_BALANCE  "
				+ "  where 1 = 1 and  INVOICENO = ? ";
		Object[] param = new Object[]
		{ invoiceNo };
		sqlStr = super.getPreparedSQL(sqlStr, param);
		cro = super.ExcuteNonQueryIgnoreTrans(sqlStr);
		return cro;

	}

}
